Skip to content

Commit 71af819

Browse files
committed
Cleanup validation of reference_typet
validate_type is not actually used (anymore), instead static member functions `check` are used.
1 parent f85b11d commit 71af819

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/util/std_types.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,19 @@ class reference_typet:public pointer_typet
15561556
{
15571557
set(ID_C_reference, true);
15581558
}
1559+
1560+
static void check(
1561+
const typet &type,
1562+
const validation_modet vm = validation_modet::INVARIANT)
1563+
{
1564+
PRECONDITION(type.id() == ID_pointer);
1565+
const reference_typet &reference_type =
1566+
static_cast<const reference_typet &>(type);
1567+
DATA_CHECK(
1568+
vm, !reference_type.get(ID_width).empty(), "reference must have width");
1569+
DATA_CHECK(
1570+
vm, reference_type.get_width() > 0, "reference must have non-zero width");
1571+
}
15591572
};
15601573

15611574
/// Check whether a reference to a typet is a \ref reference_typet.
@@ -1567,12 +1580,6 @@ inline bool can_cast_type<reference_typet>(const typet &type)
15671580
return can_cast_type<pointer_typet>(type) && type.get_bool(ID_C_reference);
15681581
}
15691582

1570-
inline void validate_type(const reference_typet &type)
1571-
{
1572-
DATA_INVARIANT(!type.get(ID_width).empty(), "reference must have width");
1573-
DATA_INVARIANT(type.get_width() > 0, "reference must have non-zero width");
1574-
}
1575-
15761583
/// \brief Cast a typet to a \ref reference_typet
15771584
///
15781585
/// This is an unchecked conversion. \a type must be known to be \ref

src/util/validate_types.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ void call_on_type(const typet &type, Args &&... args)
4646
}
4747
else if(type.id() == ID_pointer)
4848
{
49-
CALL_ON_TYPE(pointer_typet);
49+
if(type.get_bool(ID_C_reference))
50+
CALL_ON_TYPE(reference_typet);
51+
else
52+
CALL_ON_TYPE(pointer_typet);
5053
}
5154
else if(type.id() == ID_c_bool)
5255
{

0 commit comments

Comments
 (0)