Skip to content

Commit

Permalink
Use invariant instead of printing error message to cerr
Browse files Browse the repository at this point in the history
  • Loading branch information
peterschrammel committed Mar 8, 2018
1 parent aaf9477 commit fe40b19
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 66 deletions.
18 changes: 5 additions & 13 deletions src/solvers/flattening/boolbv_add_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ Author: Daniel Kroening, [email protected]

#include "boolbv.h"

#include <iostream>

#include <util/invariant.h>
#include <util/std_types.h>

#include "../floatbv/float_utils.h"
Expand Down Expand Up @@ -38,12 +37,8 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
throw "operator "+expr.id_string()+" takes at least one operand";

const exprt &op0=expr.op0();

if(op0.type()!=type)
{
std::cerr << expr.pretty() << '\n';
throw "add/sub with mixed types";
}
DATA_INVARIANT(
op0.type() == type, "add/sub with mixed types:\n" + expr.pretty());

bvt bv=convert_bv(op0);

Expand All @@ -69,11 +64,8 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
it=operands.begin()+1;
it!=operands.end(); it++)
{
if(it->type()!=type)
{
std::cerr << expr.pretty() << '\n';
throw "add/sub with mixed types";
}
DATA_INVARIANT(
it->type() == type, "add/sub with mixed types:\n" + expr.pretty());

const bvt &op=convert_bv(*it);

Expand Down
30 changes: 11 additions & 19 deletions src/solvers/flattening/boolbv_case.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Author: Daniel Kroening, [email protected]

#include "boolbv.h"

#include <iostream>
#include <util/invariant.h>

bvt boolbvt::convert_case(const exprt &expr)
{
Expand Down Expand Up @@ -49,15 +49,11 @@ bvt boolbvt::convert_case(const exprt &expr)
break;

case COMPARE:
if(compare_bv.size()!=op.size())
{
std::cerr << "compare operand: " << compare_bv.size()
<< "\noperand: " << op.size() << '\n'
<< it->pretty()
<< '\n';

throw "size of compare operand does not match";
}
DATA_INVARIANT(
compare_bv.size() == op.size(),
std::string("size of compare operand does not match:\n") +
"compare operand: " + std::to_string(compare_bv.size()) +
"\noperand: " + std::to_string(op.size()) + '\n' + it->pretty());

compare_literal=bv_utils.equal(compare_bv, op);
compare_literal=prop.land(!previous_compare, compare_literal);
Expand All @@ -68,15 +64,11 @@ bvt boolbvt::convert_case(const exprt &expr)
break;

case VALUE:
if(bv.size()!=op.size())
{
std::cerr << "result size: " << bv.size()
<< "\noperand: " << op.size() << '\n'
<< it->pretty()
<< '\n';

throw "size of value operand does not match";
}
DATA_INVARIANT(
bv.size() == op.size(),
std::string("size of value operand does not match:\n") +
"result size: " + std::to_string(bv.size()) +
"\noperand: " + std::to_string(op.size()) + '\n' + it->pretty());

{
literalt value_literal=bv_utils.equal(bv, op);
Expand Down
16 changes: 6 additions & 10 deletions src/solvers/flattening/boolbv_cond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Author: Daniel Kroening, [email protected]

#include "boolbv.h"

#include <iostream>
#include <util/invariant.h>

bvt boolbvt::convert_cond(const exprt &expr)
{
Expand Down Expand Up @@ -51,15 +51,11 @@ bvt boolbvt::convert_cond(const exprt &expr)
{
const bvt &op=convert_bv(*it);

if(bv.size()!=op.size())
{
std::cerr << "result size: " << bv.size()
<< "\noperand: " << op.size() << '\n'
<< it->pretty()
<< '\n';

throw "size of value operand does not match";
}
DATA_INVARIANT(
bv.size() == op.size(),
std::string("size of value operand does not match:\n") +
"result size: " + std::to_string(bv.size()) +
"\noperand: " + std::to_string(op.size()) + '\n' + it->pretty());

literalt value_literal=bv_utils.equal(bv, op);

Expand Down
30 changes: 12 additions & 18 deletions src/solvers/flattening/boolbv_equality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Author: Daniel Kroening, [email protected]

#include "boolbv.h"

#include <iostream>

#include <util/std_expr.h>
#include <util/base_type.h>
#include <util/invariant.h>
Expand Down Expand Up @@ -44,14 +42,12 @@ literalt boolbvt::convert_equality(const equal_exprt &expr)
const bvt &bv0=convert_bv(expr.lhs());
const bvt &bv1=convert_bv(expr.rhs());

if(bv0.size()!=bv1.size())
{
std::cerr << "lhs: " << expr.lhs().pretty() << '\n';
std::cerr << "lhs size: " << bv0.size() << '\n';
std::cerr << "rhs: " << expr.rhs().pretty() << '\n';
std::cerr << "rhs size: " << bv1.size() << '\n';
throw "unexpected size mismatch on equality";
}
DATA_INVARIANT(
bv0.size() == bv1.size(),
std::string("unexpected size mismatch on equality:\n") + "lhs: " +
expr.lhs().pretty() + '\n' + "lhs size: " + std::to_string(bv0.size()) +
'\n' + "rhs: " + expr.rhs().pretty() + '\n' +
"rhs size: " + std::to_string(bv1.size()));

if(bv0.empty())
{
Expand Down Expand Up @@ -80,14 +76,12 @@ literalt boolbvt::convert_verilog_case_equality(
const bvt &bv0=convert_bv(expr.lhs());
const bvt &bv1=convert_bv(expr.rhs());

if(bv0.size()!=bv1.size())
{
std::cerr << "lhs: " << expr.lhs().pretty() << '\n';
std::cerr << "lhs size: " << bv0.size() << '\n';
std::cerr << "rhs: " << expr.rhs().pretty() << '\n';
std::cerr << "rhs size: " << bv1.size() << '\n';
throw "unexpected size mismatch on verilog_case_equality";
}
DATA_INVARIANT(
bv0.size() == bv1.size(),
std::string("unexpected size mismatch on verilog_case_equality:\n") +
"lhs: " + expr.lhs().pretty() + '\n' + "lhs size: " +
std::to_string(bv0.size()) + '\n' + "rhs: " + expr.rhs().pretty() + '\n' +
"rhs size: " + std::to_string(bv1.size()));

if(expr.id()==ID_verilog_case_inequality)
return !bv_utils.equal(bv0, bv1);
Expand Down
9 changes: 3 additions & 6 deletions src/solvers/flattening/boolbv_floatbv_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,9 @@ bvt boolbvt::convert_floatbv_op(const exprt &expr)
bvt bv2=convert_bv(op2);

const typet &type=ns.follow(expr.type());

if(op0.type()!=type || op1.type()!=type)
{
std::cerr << expr.pretty() << '\n';
throw "float op with mixed types";
}
DATA_INVARIANT(
op0.type() == type && op1.type() == type,
"float op with mixed types:\n" + expr.pretty());

float_utilst float_utils(prop);

Expand Down

0 comments on commit fe40b19

Please sign in to comment.