Skip to content

Commit 824b51d

Browse files
Refactoring in boolbvt::convert_add_sub
1 parent 7849645 commit 824b51d

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

src/solvers/flattening/boolbv_add_sub.cpp

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,30 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
2626
type.id()!=ID_vector)
2727
return conversion_failed(expr);
2828

29-
std::size_t width=boolbv_width(type);
30-
29+
const std::size_t width = boolbv_width(type);
3130
if(width==0)
3231
return conversion_failed(expr);
3332

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

36-
if(operands.empty())
37-
throw "operator "+expr.id_string()+" takes at least one operand";
38-
35+
INVARIANT(
36+
!operands.empty(),
37+
"operator " + expr.id_string() + " takes at least one operand");
3938
const exprt &op0=expr.op0();
4039
DATA_INVARIANT(
4140
op0.type() == type, "add/sub with mixed types:\n" + expr.pretty());
4241

4342
bvt bv=convert_bv(op0);
4443

45-
if(bv.size()!=width)
46-
throw "convert_add_sub: unexpected operand 0 width";
47-
48-
bool subtract=(expr.id()==ID_minus ||
49-
expr.id()=="no-overflow-minus");
50-
51-
bool no_overflow=(expr.id()=="no-overflow-plus" ||
52-
expr.id()=="no-overflow-minus");
44+
const typet arithmetic_type =
45+
(type.id() == ID_vector || type.id() == ID_complex)
46+
? ns.follow(type.subtype())
47+
: type;
5348

54-
typet arithmetic_type=
55-
(type.id()==ID_vector || type.id()==ID_complex)?
56-
ns.follow(type.subtype()):type;
57-
58-
bv_utilst::representationt rep=
59-
(arithmetic_type.id()==ID_signedbv ||
60-
arithmetic_type.id()==ID_fixedbv)?bv_utilst::representationt::SIGNED:
61-
bv_utilst::representationt::UNSIGNED;
49+
const bv_utilst::representationt rep =
50+
(arithmetic_type.id() == ID_signedbv || arithmetic_type.id() == ID_fixedbv)
51+
? bv_utilst::representationt::SIGNED
52+
: bv_utilst::representationt::UNSIGNED;
6253

6354
for(exprt::operandst::const_iterator
6455
it=operands.begin()+1;
@@ -75,13 +66,12 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
7566
if(type.id()==ID_vector || type.id()==ID_complex)
7667
{
7768
const typet &subtype=ns.follow(type.subtype());
69+
const std::size_t sub_width = boolbv_width(subtype);
70+
INVARIANT(
71+
sub_width != 0 && width % sub_width == 0,
72+
"convert_add_sub: unexpected vector operand width");
7873

79-
std::size_t sub_width=boolbv_width(subtype);
80-
81-
if(sub_width==0 || width%sub_width!=0)
82-
throw "convert_add_sub: unexpected vector operand width";
83-
84-
std::size_t size=width/sub_width;
74+
const std::size_t size = width / sub_width;
8575
bv.resize(width);
8676

8777
for(std::size_t i=0; i<size; i++)

0 commit comments

Comments
 (0)