Skip to content

Commit c25e56f

Browse files
committed
Respond to @NathanJPhillips' review feedback
1 parent 3a4d364 commit c25e56f

File tree

1 file changed

+12
-57
lines changed

1 file changed

+12
-57
lines changed

src/util/expr_cast.h

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ inline void validate_expr(const exprt &) {}
4141
namespace detail // NOLINT
4242
{
4343

44-
// We hide these functions in a namespace so that only functions that they only
45-
// participate in overload resolution when explicitly requested.
44+
// We hide these functions in a namespace so that they only participate in
45+
// overload resolution when explicitly requested.
4646

4747
/// \brief Try to cast a reference to a generic exprt to a specific derived
4848
/// class
@@ -56,39 +56,21 @@ template <typename T, typename TExpr>
5656
optionalt<std::reference_wrapper<typename std::remove_reference<T>::type>>
5757
expr_try_dynamic_cast(TExpr &base)
5858
{
59-
typedef typename std::decay<T>::type TUnderlyingt;
60-
typedef typename std::remove_reference<T>::type TConstt;
59+
typedef typename std::decay<T>::type decayt;
6160
static_assert(
6261
std::is_same<typename std::remove_const<TExpr>::type, exprt>::value,
6362
"Tried to expr_try_dynamic_cast from something that wasn't an exprt");
6463
static_assert(
6564
std::is_reference<T>::value,
6665
"Tried to convert exprt & to non-reference type");
6766
static_assert(
68-
std::is_base_of<exprt, TUnderlyingt>::value,
67+
std::is_base_of<exprt, decayt>::value,
6968
"The template argument T must be derived from exprt.");
70-
if(!can_cast_expr<TUnderlyingt>(base))
69+
if(!can_cast_expr<decayt>(base))
7170
return {};
7271
T ret=static_cast<T>(base);
7372
validate_expr(ret);
74-
return std::reference_wrapper<TConstt>(ret);
75-
}
76-
77-
/// \brief Try to cast a reference to a generic exprt to a specific derived
78-
/// class
79-
/// \tparam T The reference or const reference type to \a TUnderlying to cast
80-
/// to
81-
/// \tparam TExpr The original type to cast from, either exprt or const exprt
82-
/// \param base Reference to a generic \ref exprt
83-
/// \return Reference to object of type \a TUnderlying
84-
/// or valueless optional if \a base is not an instance of \a TUnderlying
85-
template <typename T, typename TExpr>
86-
optionalt<std::reference_wrapper<typename std::remove_reference<T>::type>>
87-
expr_try_checked_cast(TExpr &base)
88-
{
89-
typedef typename std::decay<T>::type TUnderlyingt;
90-
PRECONDITION(can_cast_expr<TUnderlyingt>(base));
91-
return expr_try_checked_cast<T>(base);
73+
return std::reference_wrapper<typename std::remove_reference<T>::type>(ret);
9274
}
9375

9476
} // namespace detail
@@ -119,37 +101,11 @@ expr_try_dynamic_cast(exprt &base)
119101
return detail::expr_try_dynamic_cast<T>(base);
120102
}
121103

122-
/// \brief Try to cast a constant reference to a generic exprt to a specific
123-
/// derived class. Also assert that the expr invariants are not violated.
124-
/// \tparam T The exprt-derived class to cast to
125-
/// \param base Reference to a generic \ref exprt
126-
/// \return Reference to object of type \a T or valueless optional if \a base
127-
/// is not an instance of \a T
128-
template<typename T>
129-
optionalt<std::reference_wrapper<typename std::remove_reference<T>::type>>
130-
expr_try_checked_cast(const exprt &base)
131-
{
132-
return detail::expr_try_checked_cast<T>(base);
133-
}
134-
135-
/// \brief Try to cast a reference to a generic exprt to a specific derived
136-
/// class. Also assert that the expr invariants are not violated.
137-
/// \tparam T The exprt-derived class to cast to
138-
/// \param base Reference to a generic \ref exprt
139-
/// \return Reference to object of type \a T or valueless optional if \a base is
140-
/// not an instance of \a T
141-
template<typename T>
142-
optionalt<std::reference_wrapper<typename std::remove_reference<T>::type>>
143-
expr_try_checked_cast(exprt &base)
144-
{
145-
return detail::expr_try_checked_cast<T>(base);
146-
}
147-
148104
namespace detail // NOLINT
149105
{
150106

151-
// We hide these functions in a namespace so that only functions that they only
152-
// participate in overload resolution when explicitly requested.
107+
// We hide these functions in a namespace so that they only participate in
108+
// overload resolution when explicitly requested.
153109

154110
/// \brief Cast a reference to a generic exprt to a specific derived class.
155111
/// \tparam T The reference or const reference type to \a TUnderlying to cast to
@@ -160,17 +116,17 @@ namespace detail // NOLINT
160116
template<typename T, typename TExpr>
161117
T expr_dynamic_cast(TExpr &base)
162118
{
163-
typedef typename std::decay<T>::type TUnderlyingt;
119+
typedef typename std::decay<T>::type decayt;
164120
static_assert(
165121
std::is_same<typename std::remove_const<TExpr>::type, exprt>::value,
166122
"Tried to expr_dynamic_cast from something that wasn't an exprt");
167123
static_assert(
168124
std::is_reference<T>::value,
169125
"Tried to convert exprt & to non-reference type");
170126
static_assert(
171-
std::is_base_of<exprt, TUnderlyingt>::value,
127+
std::is_base_of<exprt, decayt>::value,
172128
"The template argument T must be derived from exprt.");
173-
if(!can_cast_expr<TUnderlyingt>(base))
129+
if(!can_cast_expr<decayt>(base))
174130
throw std::bad_cast();
175131
T ret=static_cast<T>(base);
176132
validate_expr(ret);
@@ -189,8 +145,7 @@ T expr_dynamic_cast(TExpr &base)
189145
template<typename T, typename TExpr>
190146
T expr_checked_cast(TExpr &base)
191147
{
192-
typedef typename std::decay<T>::type TUnderlyingt;
193-
PRECONDITION(can_cast_expr<TUnderlyingt>(base));
148+
PRECONDITION(can_cast_expr<typename std::decay<T>::type>(base));
194149
return expr_dynamic_cast<T>(base);
195150
}
196151

0 commit comments

Comments
 (0)