Skip to content

Commit 1ab9a7f

Browse files
Merge pull request #4694 from romainbrenguier/clean-up/value-set2
Replace definition of value_sett::object_map_dt
2 parents 7b56d70 + fdfca41 commit 1ab9a7f

File tree

3 files changed

+19
-80
lines changed

3 files changed

+19
-80
lines changed

src/pointer-analysis/value_set.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Author: Daniel Kroening, [email protected]
3333
// Due to a large number of functions defined inline, `value_sett` and
3434
// associated types are documented in its header file, `value_set.h`.
3535

36-
const value_sett::object_map_dt value_sett::object_map_dt::blank{};
36+
const value_sett::object_map_dt value_sett::empty_object_map{};
3737
object_numberingt value_sett::object_numbering;
3838

3939
bool value_sett::field_sensitive(const irep_idt &id, const typet &type)

src/pointer-analysis/value_set.h

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -89,73 +89,10 @@ class value_sett
8989
/// offsets (`offsett` instances). This is the RHS set of a single row of
9090
/// the enclosing `value_sett`, such as `{ null, dynamic_object1 }`.
9191
/// The set is represented as a map from numbered `exprt`s to `offsett`
92-
/// instead of a set of pairs to make lookup by `exprt` easier. All
93-
/// methods matching the interface of `std::map` forward those methods
94-
/// to the internal map.
95-
class object_map_dt
96-
{
97-
typedef std::map<object_numberingt::number_type, offsett> data_typet;
98-
data_typet data;
99-
100-
public:
101-
// NOLINTNEXTLINE(readability/identifiers)
102-
typedef data_typet::iterator iterator;
103-
// NOLINTNEXTLINE(readability/identifiers)
104-
typedef data_typet::const_iterator const_iterator;
105-
// NOLINTNEXTLINE(readability/identifiers)
106-
typedef data_typet::value_type value_type;
107-
// NOLINTNEXTLINE(readability/identifiers)
108-
typedef data_typet::key_type key_type;
109-
110-
iterator begin() { return data.begin(); }
111-
const_iterator begin() const { return data.begin(); }
112-
const_iterator cbegin() const { return data.cbegin(); }
113-
114-
iterator end() { return data.end(); }
115-
const_iterator end() const { return data.end(); }
116-
const_iterator cend() const { return data.cend(); }
117-
118-
size_t size() const { return data.size(); }
119-
bool empty() const { return data.empty(); }
120-
121-
void erase(key_type i) { data.erase(i); }
122-
void erase(const_iterator it) { data.erase(it); }
123-
124-
offsett &operator[](key_type i)
125-
{
126-
return data[i];
127-
}
128-
offsett &at(key_type i)
129-
{
130-
return data.at(i);
131-
}
132-
const offsett &at(key_type i) const
133-
{
134-
return data.at(i);
135-
}
136-
137-
template <typename It>
138-
void insert(It b, It e) { data.insert(b, e); }
139-
140-
template <typename T>
141-
const_iterator find(T &&t) const { return data.find(std::forward<T>(t)); }
92+
/// instead of a set of pairs to make lookup by `exprt` easier.
93+
using object_map_dt = std::map<object_numberingt::number_type, offsett>;
14294

143-
static const object_map_dt blank;
144-
145-
object_map_dt()=default;
146-
147-
bool operator==(const object_map_dt &other) const
148-
{
149-
return data==other.data;
150-
}
151-
bool operator!=(const object_map_dt &other) const
152-
{
153-
return !(*this==other);
154-
}
155-
156-
protected:
157-
~object_map_dt()=default;
158-
};
95+
static const object_map_dt empty_object_map;
15996

16097
/// Converts an `object_map_dt` element `object_number -> offset` into an
16198
/// `object_descriptor_exprt` with
@@ -175,7 +112,7 @@ class value_sett
175112
///
176113
/// Then the set { dynamic_object1 }, represented by an `object_map_dt`, can
177114
/// be shared between the two `value_sett` instances.
178-
typedef reference_counting<object_map_dt> object_mapt;
115+
using object_mapt = reference_counting<object_map_dt, empty_object_map>;
179116

180117
/// Sets an element in object map `dest` to match an existing element `it`
181118
/// from a different map. Any existing element for the same `exprt` is

src/util/reference_counting.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include "invariant.h"
1616

17-
template<typename T>
17+
/// \tparam empty: pointer to empty data, if unspecified use a reference to
18+
/// T::blank
19+
template <typename T, const T &empty = T::blank>
1820
// NOLINTNEXTLINE(readability/identifiers)
1921
class reference_counting
2022
{
@@ -67,7 +69,7 @@ class reference_counting
6769
const T &read() const
6870
{
6971
if(d==nullptr)
70-
return T::blank;
72+
return empty;
7173
return *d;
7274
}
7375

@@ -115,8 +117,8 @@ class reference_counting
115117
}
116118
};
117119

118-
template<class T>
119-
void reference_counting<T>::remove_ref(dt *old_d)
120+
template <class T, const T &empty>
121+
void reference_counting<T, empty>::remove_ref(dt *old_d)
120122
{
121123
if(old_d==nullptr)
122124
return;
@@ -144,8 +146,8 @@ void reference_counting<T>::remove_ref(dt *old_d)
144146
}
145147
}
146148

147-
template<class T>
148-
void reference_counting<T>::detach()
149+
template <class T, const T &empty>
150+
void reference_counting<T, empty>::detach()
149151
{
150152
#ifdef REFERENCE_COUNTING_DEBUG
151153
std::cout << "DETACH1: " << d << '\n';
@@ -179,20 +181,20 @@ void reference_counting<T>::detach()
179181
#endif
180182
}
181183

182-
template<class T>
184+
template <class T, const T &empty>
183185
bool operator==(
184-
const reference_counting<T> &o1,
185-
const reference_counting<T> &o2)
186+
const reference_counting<T, empty> &o1,
187+
const reference_counting<T, empty> &o2)
186188
{
187189
if(o1.get_d()==o2.get_d())
188190
return true;
189191
return o1.read()==o2.read();
190192
}
191193

192-
template<class T>
194+
template <class T, const T &empty>
193195
inline bool operator!=(
194-
const reference_counting<T> &i1,
195-
const reference_counting<T> &i2)
196+
const reference_counting<T, empty> &i1,
197+
const reference_counting<T, empty> &i2)
196198
{ return !(i1==i2); }
197199

198200
#endif // CPROVER_UTIL_REFERENCE_COUNTING_H

0 commit comments

Comments
 (0)