File tree Expand file tree Collapse file tree 2 files changed +37
-9
lines changed Expand file tree Collapse file tree 2 files changed +37
-9
lines changed Original file line number Diff line number Diff line change @@ -283,10 +283,8 @@ void c_typecheck_baset::typecheck_type(typet &type)
283
283
else // give up, just use subtype
284
284
result = to_type_with_subtype (type).subtype ();
285
285
286
- // save the location
287
- result.add_source_location ()=type.source_location ();
288
-
289
- type=result;
286
+ // preserve the location
287
+ type = result.with_source_location (type);
290
288
}
291
289
else if (underlying_type.id ()==ID_complex)
292
290
{
@@ -303,9 +301,7 @@ void c_typecheck_baset::typecheck_type(typet &type)
303
301
result = to_type_with_subtype (type).subtype ();
304
302
305
303
// save the location
306
- result.add_source_location ()=type.source_location ();
307
-
308
- type=complex_typet (result);
304
+ type = complex_typet (result).with_source_location (type);
309
305
}
310
306
else
311
307
{
@@ -726,9 +722,8 @@ void c_typecheck_baset::typecheck_vector_type(typet &type)
726
722
// produce the type with ID_vector
727
723
vector_typet new_type (
728
724
c_index_type (), subtype, from_integer (s, signed_size_type ()));
729
- new_type.add_source_location () = source_location;
730
725
new_type.size ().add_source_location () = source_location;
731
- type = new_type;
726
+ type = new_type. with_source_location (source_location) ;
732
727
}
733
728
734
729
void c_typecheck_baset::typecheck_compound_type (struct_union_typet &type)
Original file line number Diff line number Diff line change @@ -79,6 +79,39 @@ class typet:public irept
79
79
return static_cast <source_locationt &>(add (ID_C_source_location));
80
80
}
81
81
82
+ // / This is a 'fluent style' method for creating a new type
83
+ // / with an added-on source location.
84
+ typet &&with_source_location(source_locationt location) &&
85
+ {
86
+ if (location.is_not_nil ())
87
+ add_source_location () = std::move (location);
88
+ return std::move (*this );
89
+ }
90
+
91
+ // / This is a 'fluent style' method for adding a source location.
92
+ typet &with_source_location (source_locationt location) &
93
+ {
94
+ if (location.is_not_nil ())
95
+ add_source_location () = std::move (location);
96
+ return *this ;
97
+ }
98
+
99
+ // / This is a 'fluent style' method for creating a new type
100
+ // / with an added-on source location.
101
+ typet &&with_source_location(const typet &type) &&
102
+ {
103
+ return std::move (*this ).with_source_location (type.source_location ());
104
+ }
105
+
106
+ // / This is a 'fluent style' method for adding a source location.
107
+ typet &with_source_location (const typet &type) &
108
+ {
109
+ auto &location = type.source_location ();
110
+ if (location.is_not_nil ())
111
+ add_source_location () = location;
112
+ return *this ;
113
+ }
114
+
82
115
typet &add_type (const irep_idt &name)
83
116
{
84
117
return static_cast <typet &>(add (name));
You can’t perform that action at this time.
0 commit comments