Skip to content

Commit 5f90785

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 6f628d8 commit 5f90785

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/util/expr.h

+16
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ class exprt:public irept
9797
const operandst &operands() const
9898
{ return (const operandst &)get_sub(); }
9999

100+
/// Add the source location from \p location, if it is non-nil.
101+
exprt &with_source_location(source_locationt location) &
102+
{
103+
if(location.is_not_nil())
104+
add_source_location() = std::move(location);
105+
return *this;
106+
}
107+
108+
/// Add the source location from \p location, if it is non-nil.
109+
exprt &&with_source_location(source_locationt location) &&
110+
{
111+
if(location.is_not_nil())
112+
add_source_location() = std::move(location);
113+
return std::move(*this);
114+
}
115+
100116
/// Add the source location from \p other, if it has any.
101117
exprt &with_source_location(const exprt &other) &
102118
{

src/util/std_expr.h

+32
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,38 @@ class symbol_exprt : public nullary_exprt
161161
{
162162
return get(ID_identifier);
163163
}
164+
165+
/// Add the source location from \p location, if it is non-nil.
166+
symbol_exprt &with_source_location(source_locationt location) &
167+
{
168+
if(location.is_not_nil())
169+
add_source_location() = std::move(location);
170+
return *this;
171+
}
172+
173+
/// Add the source location from \p location, if it is non-nil.
174+
symbol_exprt &&with_source_location(source_locationt location) &&
175+
{
176+
if(location.is_not_nil())
177+
add_source_location() = std::move(location);
178+
return std::move(*this);
179+
}
180+
181+
/// Add the source location from \p other, if it has any.
182+
symbol_exprt &with_source_location(const exprt &other) &
183+
{
184+
if(other.source_location().is_not_nil())
185+
add_source_location() = other.source_location();
186+
return *this;
187+
}
188+
189+
/// Add the source location from \p other, if it has any.
190+
symbol_exprt &&with_source_location(const exprt &other) &&
191+
{
192+
if(other.source_location().is_not_nil())
193+
add_source_location() = other.source_location();
194+
return std::move(*this);
195+
}
164196
};
165197

166198
// NOLINTNEXTLINE(readability/namespace)

0 commit comments

Comments
 (0)