File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,30 @@ class exprt:public irept
98
98
const operandst &operands () const
99
99
{ return (const operandst &)get_sub (); }
100
100
101
+ // / Add the source location from \p other, if it has any.
102
+ template <typename T>
103
+ T &with_source_location (const exprt &other) &
104
+ {
105
+ static_assert (
106
+ std::is_base_of<exprt, T>::value,
107
+ " The template argument T must be derived from exprt." );
108
+ if (other.source_location ().is_not_nil ())
109
+ add_source_location () = other.source_location ();
110
+ return *static_cast <T *>(this );
111
+ }
112
+
113
+ // / Add the source location from \p other, if it has any.
114
+ template <typename T>
115
+ T &&with_source_location(const exprt &other) &&
116
+ {
117
+ static_assert (
118
+ std::is_base_of<exprt, T>::value,
119
+ " The template argument T must be derived from exprt." );
120
+ if (other.source_location ().is_not_nil ())
121
+ add_source_location () = other.source_location ();
122
+ return std::move (*static_cast <T *>(this ));
123
+ }
124
+
101
125
protected:
102
126
exprt &op0 ()
103
127
{ return operands ().front (); }
Original file line number Diff line number Diff line change @@ -1571,6 +1571,16 @@ class array_exprt : public multi_ary_exprt
1571
1571
{
1572
1572
return static_cast <array_typet &>(multi_ary_exprt::type ());
1573
1573
}
1574
+
1575
+ array_exprt &with_source_location (const exprt &other) &
1576
+ {
1577
+ return exprt::with_source_location<array_exprt>(other);
1578
+ }
1579
+
1580
+ array_exprt &&with_source_location(const exprt &other) &&
1581
+ {
1582
+ return std::move (*this ).exprt ::with_source_location<array_exprt>(other);
1583
+ }
1574
1584
};
1575
1585
1576
1586
template <>
Original file line number Diff line number Diff line change @@ -53,8 +53,5 @@ array_exprt string_constantt::to_array_expr() const
53
53
*it = from_integer (ch, char_type);
54
54
}
55
55
56
- if (source_location ().is_not_nil ())
57
- dest.add_source_location () = source_location ();
58
-
59
- return dest;
56
+ return std::move (dest).with_source_location (*this );
60
57
}
You can’t perform that action at this time.
0 commit comments