Skip to content

Commit bba0da4

Browse files
committed
Add exprt::with_source_location with source_locationt parameter
We already supported the fluent-style with_source_location for copying from another expression (since 917f9a0). Now also support passing a source location directly.
1 parent 47a62f6 commit bba0da4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/util/expr.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,30 @@ class exprt:public irept
9797
const operandst &operands() const
9898
{ return (const operandst &)get_sub(); }
9999

100+
/// Add the source location from \p other, if it has any.
101+
template <typename T>
102+
T &with_source_location(source_locationt location) &
103+
{
104+
static_assert(
105+
std::is_base_of<exprt, T>::value,
106+
"The template argument T must be derived from exprt.");
107+
if(location.is_not_nil())
108+
add_source_location() = std::move(location);
109+
return *static_cast<T *>(this);
110+
}
111+
112+
/// Add the source location from \p other, if it has any.
113+
template <typename T>
114+
T &&with_source_location(source_locationt location) &&
115+
{
116+
static_assert(
117+
std::is_base_of<exprt, T>::value,
118+
"The template argument T must be derived from exprt.");
119+
if(location.is_not_nil())
120+
add_source_location() = std::move(location);
121+
return std::move(*static_cast<T *>(this));
122+
}
123+
100124
/// Add the source location from \p other, if it has any.
101125
template <typename T>
102126
T &with_source_location(const exprt &other) &

0 commit comments

Comments
 (0)