@@ -7,40 +7,30 @@ Author: Daniel Kroening, kroening@kroening.com
77\*******************************************************************/
88
99#include " prop_conv.h"
10-
11- #include < cassert>
12- #include < cstdlib>
13- #include < map>
14-
15- #include < util/std_expr.h>
16- #include < util/symbol.h>
17- #include < util/threeval.h>
18-
19- #include " prop.h"
20- #include " literal_expr.h"
10+ #include < algorithm>
2111
2212// / determine whether a variable is in the final conflict
2313bool prop_convt::is_in_conflict (literalt l) const
2414{
25- assert ( false ) ;
15+ UNREACHABLE ;
2616 return false ;
2717}
2818
2919void prop_convt::set_assumptions (const bvt &)
3020{
31- assert ( false ) ;
21+ UNREACHABLE ;
3222}
3323
3424void prop_convt::set_frozen (const literalt)
3525{
36- assert ( false ) ;
26+ UNREACHABLE ;
3727}
3828
3929void prop_convt::set_frozen (const bvt &bv)
4030{
41- for (unsigned i= 0 ; i<bv. size (); i++ )
42- if (!bv[i] .is_constant ())
43- set_frozen (bv[i] );
31+ for (const auto &bit : bv )
32+ if (!bit .is_constant ())
33+ set_frozen (bit );
4434}
4535
4636bool prop_conv_solvert::literal (const exprt &expr, literalt &dest) const
@@ -65,17 +55,14 @@ bool prop_conv_solvert::literal(const exprt &expr, literalt &dest) const
6555
6656literalt prop_conv_solvert::get_literal (const irep_idt &identifier)
6757{
68- std::pair<symbolst::iterator, bool > result=
58+ auto result =
6959 symbols.insert (std::pair<irep_idt, literalt>(identifier, literalt ()));
7060
7161 if (!result.second )
7262 return result.first ->second ;
7363
74- // produce new variable
7564 literalt literal=prop.new_variable ();
76-
77- // set the name of the new variable
78- prop.set_variable_name (literal, id2string (identifier));
65+ prop.set_variable_name (literal, identifier);
7966
8067 // insert
8168 result.first ->second =literal;
@@ -183,10 +170,9 @@ literalt prop_conv_solvert::convert(const exprt &expr)
183170 prop.set_frozen (literal);
184171 return literal;
185172 }
186- // check cache first
187173
188- std::pair<cachet::iterator, bool > result=
189- cache.insert (std::pair<exprt, literalt>( expr, literalt ()) );
174+ // check cache first
175+ auto result = cache.insert ({ expr, literalt ()} );
190176
191177 if (!result.second )
192178 return result.first ->second ;
@@ -208,13 +194,7 @@ literalt prop_conv_solvert::convert(const exprt &expr)
208194
209195literalt prop_conv_solvert::convert_bool (const exprt &expr)
210196{
211- if (expr.type ().id ()!=ID_bool)
212- {
213- std::string msg=" prop_convt::convert_bool got "
214- " non-boolean expression: " ;
215- msg+=expr.pretty ();
216- throw msg;
217- }
197+ PRECONDITION (expr.type ().id () == ID_bool);
218198
219199 const exprt::operandst &op=expr.operands ();
220200
@@ -280,8 +260,9 @@ literalt prop_conv_solvert::convert_bool(const exprt &expr)
280260 else if (expr.id ()==ID_or || expr.id ()==ID_and || expr.id ()==ID_xor ||
281261 expr.id ()==ID_nor || expr.id ()==ID_nand)
282262 {
283- if (op.empty ())
284- throw " operator `" +expr.id_string ()+" ' takes at least one operand" ;
263+ INVARIANT (
264+ !op.empty (),
265+ " operator `" + expr.id_string () + " ' takes at least one operand" );
285266
286267 bvt bv;
287268
@@ -304,16 +285,12 @@ literalt prop_conv_solvert::convert_bool(const exprt &expr)
304285 }
305286 else if (expr.id ()==ID_not)
306287 {
307- if (op.size ()!=1 )
308- throw " not takes one operand" ;
309-
288+ INVARIANT (op.size () == 1 , " not takes one operand" );
310289 return !convert (op.front ());
311290 }
312291 else if (expr.id ()==ID_equal || expr.id ()==ID_notequal)
313292 {
314- if (op.size ()!=2 )
315- throw " equality takes two operands" ;
316-
293+ INVARIANT (op.size () == 2 , " equality takes two operands" );
317294 bool equal=(expr.id ()==ID_equal);
318295
319296 if (op[0 ].type ().id ()==ID_bool &&
@@ -387,24 +364,14 @@ bool prop_conv_solvert::set_equality_to_true(const equal_exprt &expr)
387364
388365void prop_conv_solvert::set_to (const exprt &expr, bool value)
389366{
390- if (expr.type ().id ()!=ID_bool)
391- {
392- std::string msg=" prop_convt::set_to got "
393- " non-boolean expression: " ;
394- msg+=expr.pretty ();
395- throw msg;
396- }
367+ PRECONDITION (expr.type ().id () == ID_bool);
397368
398- bool boolean=true ;
399-
400- forall_operands (it, expr)
401- if (it->type ().id ()!=ID_bool)
402- {
403- boolean=false ;
404- break ;
405- }
369+ const bool has_only_boolean_operands = std::all_of (
370+ expr.operands ().begin (),
371+ expr.operands ().end (),
372+ [](const exprt &expr) { return expr.type ().id () == ID_bool; });
406373
407- if (boolean )
374+ if (has_only_boolean_operands )
408375 {
409376 if (expr.id ()==ID_not)
410377 {
@@ -507,16 +474,12 @@ decision_proceduret::resultt prop_conv_solvert::dec_solve()
507474
508475 statistics () << " Solving with " << prop.solver_text () << eom;
509476
510- propt::resultt result=prop.prop_solve ();
511-
512- switch (result)
477+ switch (prop.prop_solve ())
513478 {
514479 case propt::resultt::P_SATISFIABLE: return resultt::D_SATISFIABLE;
515480 case propt::resultt::P_UNSATISFIABLE: return resultt::D_UNSATISFIABLE;
516481 default : return resultt::D_ERROR;
517482 }
518-
519- return resultt::D_ERROR;
520483}
521484
522485exprt prop_conv_solvert::get (const exprt &expr) const
@@ -534,19 +497,17 @@ exprt prop_conv_solvert::get(const exprt &expr) const
534497 }
535498 }
536499
537- exprt tmp=expr;
538-
539- Forall_operands (it, tmp)
500+ exprt tmp = expr;
501+ for (auto &op : tmp.operands ())
540502 {
541- exprt tmp_op= get (*it );
542- it-> swap (tmp_op);
503+ exprt tmp_op = get (op );
504+ op. swap (tmp_op);
543505 }
544-
545506 return tmp;
546507}
547508
548509void prop_conv_solvert::print_assignment (std::ostream &out) const
549510{
550- for (const auto &it : symbols)
551- out << it .first << " = " << prop.l_get (it .second ) << " \n " ;
511+ for (const auto &symbol : symbols)
512+ out << symbol .first << " = " << prop.l_get (symbol .second ) << ' \n ' ;
552513}
0 commit comments