Skip to content

Commit a905a07

Browse files
Replace throws by invariant or preconditions
1 parent 7db44fc commit a905a07

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

src/solvers/prop/prop_conv.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,7 @@ literalt prop_conv_solvert::convert(const exprt &expr)
208208

209209
literalt prop_conv_solvert::convert_bool(const exprt &expr)
210210
{
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-
}
211+
PRECONDITION(expr.type().id() == ID_bool);
218212

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

@@ -280,8 +274,9 @@ literalt prop_conv_solvert::convert_bool(const exprt &expr)
280274
else if(expr.id()==ID_or || expr.id()==ID_and || expr.id()==ID_xor ||
281275
expr.id()==ID_nor || expr.id()==ID_nand)
282276
{
283-
if(op.empty())
284-
throw "operator `"+expr.id_string()+"' takes at least one operand";
277+
INVARIANT(
278+
!op.empty(),
279+
"operator `" + expr.id_string() + "' takes at least one operand");
285280

286281
bvt bv;
287282

@@ -304,16 +299,12 @@ literalt prop_conv_solvert::convert_bool(const exprt &expr)
304299
}
305300
else if(expr.id()==ID_not)
306301
{
307-
if(op.size()!=1)
308-
throw "not takes one operand";
309-
302+
INVARIANT(op.size() == 1, "not takes one operand");
310303
return !convert(op.front());
311304
}
312305
else if(expr.id()==ID_equal || expr.id()==ID_notequal)
313306
{
314-
if(op.size()!=2)
315-
throw "equality takes two operands";
316-
307+
INVARIANT(op.size() == 2, "equality takes two operands");
317308
bool equal=(expr.id()==ID_equal);
318309

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

388379
void prop_conv_solvert::set_to(const exprt &expr, bool value)
389380
{
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-
}
381+
PRECONDITION(expr.type().id() == ID_bool);
397382

398383
bool boolean=true;
399384

0 commit comments

Comments
 (0)