@@ -42,91 +42,77 @@ literalt prop_conv_solvert::get_literal(const irep_idt &identifier)
42
42
return literal;
43
43
}
44
44
45
- // / get a boolean value from counter example if not valid
46
- bool prop_conv_solvert::get_bool (const exprt &expr, tvt &value) const
45
+ optionalt<bool > prop_conv_solvert::get_bool (const exprt &expr) const
47
46
{
48
47
// trivial cases
49
48
50
49
if (expr.is_true ())
51
50
{
52
- value = tvt (true );
53
- return false ;
51
+ return true ;
54
52
}
55
53
else if (expr.is_false ())
56
54
{
57
- value = tvt (false );
58
55
return false ;
59
56
}
60
57
else if (expr.id () == ID_symbol)
61
58
{
62
59
symbolst::const_iterator result =
63
60
symbols.find (to_symbol_expr (expr).get_identifier ());
64
61
62
+ // This may fail if the symbol isn't Boolean or
63
+ // not in the formula.
65
64
if (result == symbols.end ())
66
- return true ;
65
+ return {} ;
67
66
68
- value = prop.l_get (result->second );
69
- return false ;
67
+ return prop.l_get (result->second ).is_true ();
70
68
}
71
69
72
70
// sub-expressions
73
71
74
72
if (expr.id () == ID_not)
75
73
{
76
- if (expr.type ().id () == ID_bool && expr. operands (). size () == 1 )
74
+ if (expr.type ().id () == ID_bool)
77
75
{
78
- if (get_bool (expr.op0 (), value))
79
- return true ;
80
- value = !value;
81
- return false ;
76
+ auto tmp = get_bool (to_not_expr (expr).op ());
77
+ if (tmp.has_value ())
78
+ return !*tmp;
79
+ else
80
+ return {};
82
81
}
83
82
}
84
83
else if (expr.id () == ID_and || expr.id () == ID_or)
85
84
{
86
85
if (expr.type ().id () == ID_bool && expr.operands ().size () >= 1 )
87
86
{
88
- value = tvt (expr.id () == ID_and);
89
-
90
87
forall_operands (it, expr)
91
88
{
92
- tvt tmp;
93
- if (get_bool (*it, tmp))
94
- return true ;
89
+ auto tmp = get_bool (*it) ;
90
+ if (! tmp. has_value ( ))
91
+ return {} ;
95
92
96
93
if (expr.id () == ID_and)
97
94
{
98
- if (tmp.is_false ())
99
- {
100
- value = tvt (false );
95
+ if (*tmp == false )
101
96
return false ;
102
- }
103
-
104
- value = value && tmp;
105
97
}
106
98
else // or
107
99
{
108
- if (tmp.is_true ())
109
- {
110
- value = tvt (true );
111
- return false ;
112
- }
113
-
114
- value = value || tmp;
100
+ if (*tmp == true )
101
+ return true ;
115
102
}
116
103
}
117
104
118
- return false ;
105
+ return expr. id () == ID_and ;
119
106
}
120
107
}
121
108
122
109
// check cache
123
110
124
111
cachet::const_iterator cache_result = cache.find (expr);
125
112
if (cache_result == cache.end ())
126
- return true ;
127
-
128
- value = prop.l_get (cache_result->second );
129
- return false ;
113
+ return {}; // not in formula
114
+ else
115
+ return prop.l_get (cache_result->second ).is_true ();
130
116
}
131
117
132
118
literalt prop_conv_solvert::convert (const exprt &expr)
@@ -459,18 +445,16 @@ decision_proceduret::resultt prop_conv_solvert::dec_solve()
459
445
460
446
exprt prop_conv_solvert::get (const exprt &expr) const
461
447
{
462
- tvt value;
463
-
464
- if (expr.type ().id () == ID_bool && !get_bool (expr, value))
448
+ if (expr.type ().id () == ID_bool)
465
449
{
466
- switch (value.get_value ())
450
+ auto value = get_bool (expr);
451
+
452
+ if (value.has_value ())
467
453
{
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
454
+ if (*value)
455
+ return true_exprt ();
456
+ else
457
+ return false_exprt ();
474
458
}
475
459
}
476
460
0 commit comments