Skip to content

Commit 26a3d90

Browse files
Cleanup invariants in remove_vector
1 parent f5331ce commit 26a3d90

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/goto-programs/remove_vector.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,16 @@ static void remove_vector(exprt &expr)
8282
expr.id()==ID_mod || expr.id()==ID_bitxor ||
8383
expr.id()==ID_bitand || expr.id()==ID_bitor)
8484
{
85+
// FIXME plus, mult, bitxor, bitor and bitand are not binary operators
86+
// normally. It is unclear why is it safe to assume that they are
87+
// in this context
88+
auto const &binary_expr = to_binary_expr(expr);
8589
remove_vector(expr.type());
8690
array_typet array_type=to_array_type(expr.type());
8791

8892
mp_integer dimension;
8993
to_integer(array_type.size(), dimension);
9094

91-
assert(expr.operands().size()==2);
9295
const typet subtype=array_type.subtype();
9396
// do component-wise:
9497
// x+y -> vector(x[0]+y[0],x[1]+y[1],...)
@@ -99,22 +102,23 @@ static void remove_vector(exprt &expr)
99102
{
100103
exprt index=from_integer(i, array_type.size().type());
101104

102-
array_expr.operands()[i]=
103-
binary_exprt(index_exprt(expr.op0(), index, subtype), expr.id(),
104-
index_exprt(expr.op1(), index, subtype));
105+
array_expr.operands()[i] = binary_exprt(
106+
index_exprt(binary_expr.op0(), index, subtype),
107+
binary_expr.id(),
108+
index_exprt(binary_expr.op1(), index, subtype));
105109
}
106110

107111
expr=array_expr;
108112
}
109113
else if(expr.id()==ID_unary_minus || expr.id()==ID_bitnot)
110114
{
115+
auto const &unary_expr = to_unary_expr(expr);
111116
remove_vector(expr.type());
112117
array_typet array_type=to_array_type(expr.type());
113118

114119
mp_integer dimension;
115120
to_integer(array_type.size(), dimension);
116121

117-
assert(expr.operands().size()==1);
118122
const typet subtype=array_type.subtype();
119123
// do component-wise:
120124
// -x -> vector(-x[0],-x[1],...)
@@ -125,8 +129,8 @@ static void remove_vector(exprt &expr)
125129
{
126130
exprt index=from_integer(i, array_type.size().type());
127131

128-
array_expr.operands()[i]=
129-
unary_exprt(expr.id(), index_exprt(expr.op0(), index, subtype));
132+
array_expr.operands()[i] = unary_exprt(
133+
unary_expr.id(), index_exprt(unary_expr.op0(), index, subtype));
130134
}
131135

132136
expr=array_expr;

0 commit comments

Comments
 (0)