Skip to content

Commit cbc78db

Browse files
Replace throws with invariants in boolbv_equality
1 parent 4cae2a3 commit cbc78db

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/solvers/flattening/boolbv_equality.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ literalt boolbvt::convert_equality(const equal_exprt &expr)
1919
{
2020
const bool is_base_type_eq =
2121
base_type_eq(expr.lhs().type(), expr.rhs().type(), ns);
22-
if(!is_base_type_eq)
23-
{
24-
const std::string error_msg =
25-
std::string("equality without matching types:\n") + "######### lhs: " +
26-
expr.lhs().pretty() + '\n' + "######### rhs: " + expr.rhs().pretty();
27-
throw bitvector_conversion_exceptiont(error_msg, expr);
28-
}
22+
DATA_INVARIANT_WITH_DIAGNOSTICS(
23+
is_base_type_eq,
24+
"types of expressions on each side of equality should match",
25+
irep_pretty_diagnosticst{expr.lhs()},
26+
irep_pretty_diagnosticst{expr.rhs()});
2927

3028
// see if it is an unbounded array
3129
if(is_unbounded_array(expr.lhs().type()))
@@ -44,12 +42,13 @@ literalt boolbvt::convert_equality(const equal_exprt &expr)
4442
const bvt &lhs_bv = convert_bv(expr.lhs());
4543
const bvt &rhs_bv = convert_bv(expr.rhs());
4644

47-
DATA_INVARIANT(
45+
DATA_INVARIANT_WITH_DIAGNOSTICS(
4846
lhs_bv.size() == rhs_bv.size(),
49-
std::string("unexpected size mismatch on equality:\n") +
50-
"lhs: " + expr.lhs().pretty() + '\n' + "lhs size: " +
51-
std::to_string(lhs_bv.size()) + '\n' + "rhs: " + expr.rhs().pretty() +
52-
'\n' + "rhs size: " + std::to_string(rhs_bv.size()));
47+
"sizes of lhs and rhs bitvectors should match",
48+
irep_pretty_diagnosticst{expr.lhs()},
49+
"lhs size: " + std::to_string(lhs_bv.size()),
50+
irep_pretty_diagnosticst{expr.rhs()},
51+
"rhs size: " + std::to_string(rhs_bv.size()));
5352

5453
if(lhs_bv.empty())
5554
{
@@ -69,21 +68,22 @@ literalt boolbvt::convert_verilog_case_equality(
6968

7069
const bool is_base_type_eq =
7170
base_type_eq(expr.lhs().type(), expr.rhs().type(), ns);
72-
DATA_INVARIANT(
71+
DATA_INVARIANT_WITH_DIAGNOSTICS(
7372
is_base_type_eq,
74-
std::string("verilog_case_equality without matching types:\n") +
75-
"######### lhs: " + expr.lhs().pretty() + '\n' +
76-
"######### rhs: " + expr.rhs().pretty());
73+
"lhs and rhs types should match in verilog_case_equality",
74+
irep_pretty_diagnosticst{expr.lhs()},
75+
irep_pretty_diagnosticst{expr.rhs()});
7776

7877
const bvt &lhs_bv = convert_bv(expr.lhs());
7978
const bvt &rhs_bv = convert_bv(expr.rhs());
8079

81-
DATA_INVARIANT(
80+
DATA_INVARIANT_WITH_DIAGNOSTICS(
8281
lhs_bv.size() == rhs_bv.size(),
83-
std::string("unexpected size mismatch on verilog_case_equality:\n") +
84-
"lhs: " + expr.lhs().pretty() + '\n' + "lhs size: " +
85-
std::to_string(lhs_bv.size()) + '\n' + "rhs: " + expr.rhs().pretty() +
86-
'\n' + "rhs size: " + std::to_string(rhs_bv.size()));
82+
"bitvector arguments to verilog_case_equality should have the same size",
83+
irep_pretty_diagnosticst{expr.lhs()},
84+
"lhs size: " + std::to_string(lhs_bv.size()),
85+
irep_pretty_diagnosticst{expr.rhs()},
86+
"rhs size: " + std::to_string(rhs_bv.size()));
8787

8888
if(expr.id()==ID_verilog_case_inequality)
8989
return !bv_utils.equal(lhs_bv, rhs_bv);

0 commit comments

Comments
 (0)