Skip to content

Commit 4dc7725

Browse files
author
Daniel Kroening
committed
vector_typet::size() is now a constant_exprt
The codebase assumes basically globally that vector_typet::size() is a constant_exprt. This is now enforced by the signature.
1 parent 934f310 commit 4dc7725

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

src/util/std_types.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,19 @@ bool is_constant_or_has_constant_components(
283283

284284
return false;
285285
}
286+
287+
vector_typet::vector_typet(const typet &_subtype, const constant_exprt &_size)
288+
: type_with_subtypet(ID_vector, _subtype)
289+
{
290+
size() = _size;
291+
}
292+
293+
const constant_exprt &vector_typet::size() const
294+
{
295+
return static_cast<const constant_exprt &>(find(ID_size));
296+
}
297+
298+
constant_exprt &vector_typet::size()
299+
{
300+
return static_cast<constant_exprt &>(add(ID_size));
301+
}

src/util/std_types.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,28 +1751,18 @@ inline range_typet &to_range_type(typet &type)
17511751
/// Used to represent the short vectors used by CPU instruction sets such as
17521752
/// MMX, SSE and AVX. They all provide registers that are something like
17531753
/// 8 x int32, for example, and corresponding operations that operate
1754-
/// element-wise on their operand vectors. Compared to \ref array_typet
1755-
/// that has no element-wise operators. Note that `remove_vector.h` removes
1756-
/// this data type by compilation into arrays.
1754+
/// element-wise on their operand vectors. Compared to \ref array_typet,
1755+
/// vector_typet has a fixed size whereas array_typet has no element-wise
1756+
/// operators.
1757+
/// Note that `remove_vector.h` removes this data type by compilation into
1758+
/// arrays.
17571759
class vector_typet:public type_with_subtypet
17581760
{
17591761
public:
1760-
vector_typet(
1761-
const typet &_subtype,
1762-
const exprt &_size):type_with_subtypet(ID_vector, _subtype)
1763-
{
1764-
size()=_size;
1765-
}
1762+
vector_typet(const typet &_subtype, const constant_exprt &_size);
17661763

1767-
const exprt &size() const
1768-
{
1769-
return static_cast<const exprt &>(find(ID_size));
1770-
}
1771-
1772-
exprt &size()
1773-
{
1774-
return static_cast<exprt &>(add(ID_size));
1775-
}
1764+
const constant_exprt &size() const;
1765+
constant_exprt &size();
17761766
};
17771767

17781768
/// Check whether a reference to a typet is a \ref vector_typet.

unit/solvers/lowering/byte_operators.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
6868
unsignedbv_typet u32(32);
6969
unsignedbv_typet u64(64);
7070

71-
exprt size = from_integer(8, size_type());
71+
constant_exprt size = from_integer(8, size_type());
7272

7373
std::vector<typet> types = {
7474
struct_typet({{"comp1", u32}, {"comp2", u64}}),
@@ -211,7 +211,7 @@ SCENARIO("byte_update_lowering", "[core][solvers][lowering][byte_update]")
211211
unsignedbv_typet u32(32);
212212
unsignedbv_typet u64(64);
213213

214-
exprt size = from_integer(8, size_type());
214+
constant_exprt size = from_integer(8, size_type());
215215

216216
std::vector<typet> types = {
217217
// TODO: only arrays and scalars

0 commit comments

Comments
 (0)