Skip to content

Commit d4120c4

Browse files
author
Daniel Kroening
committed
prop_conv_solvert::get_bool now always returns a value
The previous implementation has considered the case of an unknown expression and a known expression with unknown value. In both cases, the next layer returns 'false'. The new implementation now returns 'false' directly.
1 parent 5d80ef9 commit d4120c4

File tree

2 files changed

+19
-56
lines changed

2 files changed

+19
-56
lines changed

src/solvers/prop/prop_conv_solver.cpp

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,16 @@ literalt prop_conv_solvert::get_literal(const irep_idt &identifier)
4343
}
4444

4545
/// get a boolean value from counter example if not valid
46-
bool prop_conv_solvert::get_bool(const exprt &expr, tvt &value) const
46+
bool prop_conv_solvert::get_bool(const exprt &expr) const
4747
{
4848
// trivial cases
4949

5050
if(expr.is_true())
5151
{
52-
value = tvt(true);
53-
return false;
52+
return true;
5453
}
5554
else if(expr.is_false())
5655
{
57-
value = tvt(false);
5856
return false;
5957
}
6058
else if(expr.id() == ID_symbol)
@@ -63,10 +61,9 @@ bool prop_conv_solvert::get_bool(const exprt &expr, tvt &value) const
6361
symbols.find(to_symbol_expr(expr).get_identifier());
6462

6563
if(result == symbols.end())
66-
return true;
64+
return false; // default value
6765

68-
value = prop.l_get(result->second);
69-
return false;
66+
return prop.l_get(result->second).is_true();
7067
}
7168

7269
// sub-expressions
@@ -75,58 +72,40 @@ bool prop_conv_solvert::get_bool(const exprt &expr, tvt &value) const
7572
{
7673
if(expr.type().id() == ID_bool && expr.operands().size() == 1)
7774
{
78-
if(get_bool(expr.op0(), value))
79-
return true;
80-
value = !value;
81-
return false;
75+
return get_bool(expr.op0());
8276
}
8377
}
8478
else if(expr.id() == ID_and || expr.id() == ID_or)
8579
{
8680
if(expr.type().id() == ID_bool && expr.operands().size() >= 1)
8781
{
88-
value = tvt(expr.id() == ID_and);
89-
9082
forall_operands(it, expr)
9183
{
92-
tvt tmp;
93-
if(get_bool(*it, tmp))
94-
return true;
84+
auto tmp = get_bool(*it);
9585

9686
if(expr.id() == ID_and)
9787
{
98-
if(tmp.is_false())
99-
{
100-
value = tvt(false);
88+
if(tmp == false)
10189
return false;
102-
}
103-
104-
value = value && tmp;
10590
}
10691
else // or
10792
{
108-
if(tmp.is_true())
109-
{
110-
value = tvt(true);
111-
return false;
112-
}
113-
114-
value = value || tmp;
93+
if(tmp == true)
94+
return true;
11595
}
11696
}
11797

118-
return false;
98+
return expr.id() == ID_and;
11999
}
120100
}
121101

122102
// check cache
123103

124104
cachet::const_iterator cache_result = cache.find(expr);
125105
if(cache_result == cache.end())
126-
return true;
127-
128-
value = prop.l_get(cache_result->second);
129-
return false;
106+
return false; // default value
107+
else
108+
return prop.l_get(cache_result->second).is_true();
130109
}
131110

132111
literalt prop_conv_solvert::convert(const exprt &expr)
@@ -459,28 +438,12 @@ decision_proceduret::resultt prop_conv_solvert::dec_solve()
459438

460439
exprt prop_conv_solvert::get(const exprt &expr) const
461440
{
462-
tvt value;
463-
464-
if(expr.type().id() == ID_bool && !get_bool(expr, value))
465-
{
466-
switch(value.get_value())
467-
{
468-
case tvt::tv_enumt::TV_TRUE:
469-
return true_exprt();
470-
case tvt::tv_enumt::TV_FALSE:
471-
return false_exprt();
472-
case tvt::tv_enumt::TV_UNKNOWN:
473-
return false_exprt(); // default
474-
}
475-
}
441+
PRECONDITION(expr.type().id() == ID_bool);
476442

477-
exprt tmp = expr;
478-
for(auto &op : tmp.operands())
479-
{
480-
exprt tmp_op = get(op);
481-
op.swap(tmp_op);
482-
}
483-
return tmp;
443+
if(get_bool(expr))
444+
return true_exprt();
445+
else
446+
return false_exprt();
484447
}
485448

486449
void prop_conv_solvert::print_assignment(std::ostream &out) const

src/solvers/prop/prop_conv_solver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class prop_conv_solvert : public prop_convt, public solver_resource_limitst
112112
bool post_processing_done = false;
113113

114114
// get a _boolean_ value from counterexample if not valid
115-
virtual bool get_bool(const exprt &expr, tvt &value) const;
115+
virtual bool get_bool(const exprt &expr) const;
116116

117117
virtual literalt convert_rest(const exprt &expr);
118118
virtual literalt convert_bool(const exprt &expr);

0 commit comments

Comments
 (0)