@@ -26,39 +26,30 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
26
26
type.id ()!=ID_vector)
27
27
return conversion_failed (expr);
28
28
29
- std::size_t width=boolbv_width (type);
30
-
29
+ const std::size_t width = boolbv_width (type);
31
30
if (width==0 )
32
31
return conversion_failed (expr);
33
32
34
33
const exprt::operandst &operands=expr.operands ();
35
34
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 " );
39
38
const exprt &op0=expr.op0 ();
40
39
DATA_INVARIANT (
41
40
op0.type () == type, " add/sub with mixed types:\n " + expr.pretty ());
42
41
43
42
bvt bv=convert_bv (op0);
44
43
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;
53
48
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;
62
53
63
54
for (exprt::operandst::const_iterator
64
55
it=operands.begin ()+1 ;
@@ -75,13 +66,12 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
75
66
if (type.id ()==ID_vector || type.id ()==ID_complex)
76
67
{
77
68
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" );
78
73
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;
85
75
bv.resize (width);
86
76
87
77
for (std::size_t i=0 ; i<size; i++)
0 commit comments