Skip to content

Commit

Permalink
Replace throws by invariant or preconditions
Browse files Browse the repository at this point in the history
  • Loading branch information
romainbrenguier committed Apr 23, 2018
1 parent 7db44fc commit a905a07
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/solvers/prop/prop_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,7 @@ literalt prop_conv_solvert::convert(const exprt &expr)

literalt prop_conv_solvert::convert_bool(const exprt &expr)
{
if(expr.type().id()!=ID_bool)
{
std::string msg="prop_convt::convert_bool got "
"non-boolean expression: ";
msg+=expr.pretty();
throw msg;
}
PRECONDITION(expr.type().id() == ID_bool);

const exprt::operandst &op=expr.operands();

Expand Down Expand Up @@ -280,8 +274,9 @@ literalt prop_conv_solvert::convert_bool(const exprt &expr)
else if(expr.id()==ID_or || expr.id()==ID_and || expr.id()==ID_xor ||
expr.id()==ID_nor || expr.id()==ID_nand)
{
if(op.empty())
throw "operator `"+expr.id_string()+"' takes at least one operand";
INVARIANT(
!op.empty(),
"operator `" + expr.id_string() + "' takes at least one operand");

bvt bv;

Expand All @@ -304,16 +299,12 @@ literalt prop_conv_solvert::convert_bool(const exprt &expr)
}
else if(expr.id()==ID_not)
{
if(op.size()!=1)
throw "not takes one operand";

INVARIANT(op.size() == 1, "not takes one operand");
return !convert(op.front());
}
else if(expr.id()==ID_equal || expr.id()==ID_notequal)
{
if(op.size()!=2)
throw "equality takes two operands";

INVARIANT(op.size() == 2, "equality takes two operands");
bool equal=(expr.id()==ID_equal);

if(op[0].type().id()==ID_bool &&
Expand Down Expand Up @@ -387,13 +378,7 @@ bool prop_conv_solvert::set_equality_to_true(const equal_exprt &expr)

void prop_conv_solvert::set_to(const exprt &expr, bool value)
{
if(expr.type().id()!=ID_bool)
{
std::string msg="prop_convt::set_to got "
"non-boolean expression: ";
msg+=expr.pretty();
throw msg;
}
PRECONDITION(expr.type().id() == ID_bool);

bool boolean=true;

Expand Down

0 comments on commit a905a07

Please sign in to comment.