Skip to content

Commit 49453bf

Browse files
authored
[lldb][NFC] remove AdaptedConstIterator and AdaptedIterable (#127507)
AdaptedConstIterator currently doesn't have iterator traits, so I can't use STL algorithms with containers like WatchpointList. This patch replaces AdaptedConstIterator and AdaptedIterable with llvm::iterator_adaped_base and llvm::iterator_range respectively.
1 parent 360630b commit 49453bf

15 files changed

+38
-188
lines changed

lldb/include/lldb/Breakpoint/BreakpointList.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ class BreakpointList {
163163
bool m_is_internal;
164164

165165
public:
166-
typedef LockingAdaptedIterable<bp_collection, lldb::BreakpointSP,
167-
list_adapter, std::recursive_mutex>
166+
typedef LockingAdaptedIterable<std::recursive_mutex, bp_collection>
168167
BreakpointIterable;
169168
BreakpointIterable Breakpoints() {
170169
return BreakpointIterable(m_breakpoints, GetMutex());

lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ class BreakpointLocationCollection {
165165
mutable std::mutex m_collection_mutex;
166166

167167
public:
168-
typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
169-
vector_adapter>
168+
typedef llvm::iterator_range<collection::const_iterator>
170169
BreakpointLocationCollectionIterable;
171170
BreakpointLocationCollectionIterable BreakpointLocations() {
172171
return BreakpointLocationCollectionIterable(m_break_loc_collection);

lldb/include/lldb/Breakpoint/BreakpointLocationList.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ class BreakpointLocationList {
204204
BreakpointLocationCollection *m_new_location_recorder;
205205

206206
public:
207-
typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
208-
vector_adapter>
207+
typedef llvm::iterator_range<collection::const_iterator>
209208
BreakpointLocationIterable;
210209

211210
BreakpointLocationIterable BreakpointLocations() {

lldb/include/lldb/Breakpoint/WatchpointList.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ class WatchpointList {
3939
~WatchpointList();
4040

4141
typedef std::list<lldb::WatchpointSP> wp_collection;
42-
typedef LockingAdaptedIterable<wp_collection, lldb::WatchpointSP,
43-
vector_adapter, std::recursive_mutex>
42+
typedef LockingAdaptedIterable<std::recursive_mutex, wp_collection>
4443
WatchpointIterable;
4544

4645
/// Add a Watchpoint to the list.

lldb/include/lldb/Breakpoint/WatchpointResource.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ class WatchpointResource
3939
void SetType(bool read, bool write);
4040

4141
typedef std::vector<lldb::WatchpointSP> WatchpointCollection;
42-
typedef LockingAdaptedIterable<WatchpointCollection, lldb::WatchpointSP,
43-
vector_adapter, std::mutex>
42+
typedef LockingAdaptedIterable<std::mutex, WatchpointCollection>
4443
WatchpointIterable;
4544

4645
/// Iterate over the watchpoint constituents for this resource

lldb/include/lldb/Core/ModuleList.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,13 @@ class ModuleList {
521521
Notifier *m_notifier = nullptr;
522522

523523
public:
524-
typedef LockingAdaptedIterable<collection, lldb::ModuleSP, vector_adapter,
525-
std::recursive_mutex>
524+
typedef LockingAdaptedIterable<std::recursive_mutex, collection>
526525
ModuleIterable;
527526
ModuleIterable Modules() const {
528527
return ModuleIterable(m_modules, GetMutex());
529528
}
530529

531-
typedef AdaptedIterable<collection, lldb::ModuleSP, vector_adapter>
530+
typedef llvm::iterator_range<collection::const_iterator>
532531
ModuleIterableNoLocking;
533532
ModuleIterableNoLocking ModulesNoLocking() const {
534533
return ModuleIterableNoLocking(m_modules);

lldb/include/lldb/Core/ModuleSpec.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ class ModuleSpecList {
389389
}
390390

391391
typedef std::vector<ModuleSpec> collection;
392-
typedef LockingAdaptedIterable<collection, ModuleSpec, vector_adapter,
393-
std::recursive_mutex>
392+
typedef LockingAdaptedIterable<std::recursive_mutex, collection>
394393
ModuleSpecIterable;
395394

396395
ModuleSpecIterable ModuleSpecs() {

lldb/include/lldb/Host/common/NativeProcessProtocol.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,9 @@ class NativeProcessProtocol {
5151
virtual ~NativeProcessProtocol() = default;
5252

5353
typedef std::vector<std::unique_ptr<NativeThreadProtocol>> thread_collection;
54-
template <typename I>
55-
static NativeThreadProtocol &thread_list_adapter(I &iter) {
56-
assert(*iter);
57-
return **iter;
58-
}
59-
typedef LockingAdaptedIterable<thread_collection, NativeThreadProtocol &,
60-
thread_list_adapter, std::recursive_mutex>
54+
typedef LockingAdaptedIterable<
55+
std::recursive_mutex, thread_collection,
56+
llvm::pointee_iterator<thread_collection::const_iterator>>
6157
ThreadIterable;
6258

6359
virtual Status Resume(const ResumeActionList &resume_actions) = 0;

lldb/include/lldb/Symbol/SymbolContext.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class SymbolContextList {
467467
const_iterator begin() const { return m_symbol_contexts.begin(); }
468468
const_iterator end() const { return m_symbol_contexts.end(); }
469469

470-
typedef AdaptedIterable<collection, SymbolContext, vector_adapter>
470+
typedef llvm::iterator_range<collection::const_iterator>
471471
SymbolContextIterable;
472472
SymbolContextIterable SymbolContexts() {
473473
return SymbolContextIterable(m_symbol_contexts);

lldb/include/lldb/Symbol/TypeList.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ class TypeList {
3939
lldb::TypeSP GetTypeAtIndex(uint32_t idx);
4040

4141
typedef std::vector<lldb::TypeSP> collection;
42-
typedef AdaptedIterable<collection, lldb::TypeSP, vector_adapter>
43-
TypeIterable;
42+
typedef llvm::iterator_range<collection::const_iterator> TypeIterable;
4443

4544
TypeIterable Types() { return TypeIterable(m_types); }
4645

lldb/include/lldb/Symbol/TypeMap.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class TypeMap {
4444
lldb::TypeSP FirstType() const;
4545

4646
typedef std::multimap<lldb::user_id_t, lldb::TypeSP> collection;
47-
typedef AdaptedIterable<collection, lldb::TypeSP, map_adapter> TypeIterable;
47+
typedef llvm::iterator_range<ValueMapIterator<collection::const_iterator>>
48+
TypeIterable;
4849

4950
TypeIterable Types() const { return TypeIterable(m_types); }
5051

lldb/include/lldb/Target/QueueList.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ class QueueList {
4848
lldb::QueueSP GetQueueAtIndex(uint32_t idx);
4949

5050
typedef std::vector<lldb::QueueSP> collection;
51-
typedef LockingAdaptedIterable<collection, lldb::QueueSP, vector_adapter,
52-
std::mutex>
53-
QueueIterable;
51+
typedef LockingAdaptedIterable<std::mutex, collection> QueueIterable;
5452

5553
/// Iterate over the list of queues
5654
///

lldb/include/lldb/Target/TargetList.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ class TargetList : public Broadcaster {
4444
}
4545

4646
typedef std::vector<lldb::TargetSP> collection;
47-
typedef LockingAdaptedIterable<collection, lldb::TargetSP, vector_adapter,
48-
std::recursive_mutex>
47+
typedef LockingAdaptedIterable<std::recursive_mutex, collection>
4948
TargetIterable;
5049

5150
/// Create a new Target.

lldb/include/lldb/Target/ThreadCollection.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ namespace lldb_private {
2020
class ThreadCollection {
2121
public:
2222
typedef std::vector<lldb::ThreadSP> collection;
23-
typedef LockingAdaptedIterable<collection, lldb::ThreadSP, vector_adapter,
24-
std::recursive_mutex>
23+
typedef LockingAdaptedIterable<std::recursive_mutex, collection>
2524
ThreadIterable;
2625

2726
ThreadCollection();

lldb/include/lldb/Utility/Iterable.h

+20-155
Original file line numberDiff line numberDiff line change
@@ -11,172 +11,37 @@
1111

1212
#include <utility>
1313

14+
#include <llvm/ADT/iterator.h>
1415

1516
namespace lldb_private {
1617

17-
template <typename I, typename E> E map_adapter(I &iter) {
18-
return iter->second;
19-
}
20-
21-
template <typename I, typename E> E vector_adapter(I &iter) { return *iter; }
22-
23-
template <typename I, typename E> E list_adapter(I &iter) { return *iter; }
24-
25-
template <typename C, typename E, E (*A)(typename C::const_iterator &)>
26-
class AdaptedConstIterator {
27-
public:
28-
typedef typename C::const_iterator BackingIterator;
29-
30-
// Wrapping constructor
31-
AdaptedConstIterator(BackingIterator backing_iterator)
32-
: m_iter(backing_iterator) {}
33-
34-
// Default-constructible
35-
AdaptedConstIterator() : m_iter() {}
36-
37-
// Copy-constructible
38-
AdaptedConstIterator(const AdaptedConstIterator &rhs) : m_iter(rhs.m_iter) {}
39-
40-
// Copy-assignable
41-
AdaptedConstIterator &operator=(const AdaptedConstIterator &rhs) {
42-
m_iter = rhs.m_iter;
43-
return *this;
44-
}
45-
46-
// Destructible
47-
~AdaptedConstIterator() = default;
48-
49-
// Comparable
50-
bool operator==(const AdaptedConstIterator &rhs) {
51-
return m_iter == rhs.m_iter;
52-
}
53-
54-
bool operator!=(const AdaptedConstIterator &rhs) {
55-
return m_iter != rhs.m_iter;
56-
}
57-
58-
// Rvalue dereferenceable
59-
E operator*() { return (*A)(m_iter); }
60-
61-
E operator->() { return (*A)(m_iter); }
62-
63-
// Offset dereferenceable
64-
E operator[](typename BackingIterator::difference_type offset) {
65-
return AdaptedConstIterator(m_iter + offset);
66-
}
67-
68-
// Incrementable
69-
AdaptedConstIterator &operator++() {
70-
m_iter++;
71-
return *this;
72-
}
73-
74-
// Decrementable
75-
AdaptedConstIterator &operator--() {
76-
m_iter--;
77-
return *this;
78-
}
79-
80-
// Compound assignment
81-
AdaptedConstIterator &
82-
operator+=(typename BackingIterator::difference_type offset) {
83-
m_iter += offset;
84-
return *this;
85-
}
86-
87-
AdaptedConstIterator &
88-
operator-=(typename BackingIterator::difference_type offset) {
89-
m_iter -= offset;
90-
return *this;
91-
}
92-
93-
// Arithmetic
94-
AdaptedConstIterator
95-
operator+(typename BackingIterator::difference_type offset) {
96-
return AdaptedConstIterator(m_iter + offset);
97-
}
98-
99-
AdaptedConstIterator
100-
operator-(typename BackingIterator::difference_type offset) {
101-
return AdaptedConstIterator(m_iter - offset);
102-
}
103-
104-
// Comparable
105-
bool operator<(AdaptedConstIterator &rhs) { return m_iter < rhs.m_iter; }
106-
107-
bool operator<=(AdaptedConstIterator &rhs) { return m_iter <= rhs.m_iter; }
108-
109-
bool operator>(AdaptedConstIterator &rhs) { return m_iter > rhs.m_iter; }
110-
111-
bool operator>=(AdaptedConstIterator &rhs) { return m_iter >= rhs.m_iter; }
112-
113-
template <typename C1, typename E1, E1 (*A1)(typename C1::const_iterator &)>
114-
friend AdaptedConstIterator<C1, E1, A1>
115-
operator+(typename C1::const_iterator::difference_type,
116-
AdaptedConstIterator<C1, E1, A1> &);
117-
118-
template <typename C1, typename E1, E1 (*A1)(typename C1::const_iterator &)>
119-
friend typename C1::const_iterator::difference_type
120-
operator-(AdaptedConstIterator<C1, E1, A1> &,
121-
AdaptedConstIterator<C1, E1, A1> &);
122-
123-
template <typename C1, typename E1, E1 (*A1)(typename C1::const_iterator &)>
124-
friend void swap(AdaptedConstIterator<C1, E1, A1> &,
125-
AdaptedConstIterator<C1, E1, A1> &);
126-
127-
private:
128-
BackingIterator m_iter;
129-
};
130-
131-
template <typename C, typename E, E (*A)(typename C::const_iterator &)>
132-
AdaptedConstIterator<C, E, A> operator+(
133-
typename AdaptedConstIterator<C, E, A>::BackingIterator::difference_type
134-
offset,
135-
AdaptedConstIterator<C, E, A> &rhs) {
136-
return rhs.operator+(offset);
137-
}
138-
139-
template <typename C, typename E, E (*A)(typename C::const_iterator &)>
140-
typename AdaptedConstIterator<C, E, A>::BackingIterator::difference_type
141-
operator-(AdaptedConstIterator<C, E, A> &lhs,
142-
AdaptedConstIterator<C, E, A> &rhs) {
143-
return (lhs.m_iter - rhs.m_iter);
144-
}
145-
146-
template <typename C, typename E, E (*A)(typename C::const_iterator &)>
147-
void swap(AdaptedConstIterator<C, E, A> &lhs,
148-
AdaptedConstIterator<C, E, A> &rhs) {
149-
std::swap(lhs.m_iter, rhs.m_iter);
150-
}
151-
152-
template <typename C, typename E, E (*A)(typename C::const_iterator &)>
153-
class AdaptedIterable {
154-
private:
155-
const C &m_container;
156-
157-
public:
158-
AdaptedIterable(const C &container) : m_container(container) {}
159-
160-
AdaptedConstIterator<C, E, A> begin() {
161-
return AdaptedConstIterator<C, E, A>(m_container.begin());
162-
}
163-
164-
AdaptedConstIterator<C, E, A> end() {
165-
return AdaptedConstIterator<C, E, A>(m_container.end());
166-
}
18+
template <typename WrappedIteratorT,
19+
typename T = typename std::iterator_traits<
20+
WrappedIteratorT>::value_type::second_type>
21+
struct ValueMapIterator
22+
: llvm::iterator_adaptor_base<
23+
ValueMapIterator<WrappedIteratorT, T>, WrappedIteratorT,
24+
typename std::iterator_traits<WrappedIteratorT>::iterator_category,
25+
T> {
26+
ValueMapIterator() = default;
27+
explicit ValueMapIterator(WrappedIteratorT u)
28+
: ValueMapIterator::iterator_adaptor_base(std::move(u)) {}
29+
30+
const T &operator*() { return (*this->I).second; }
31+
const T &operator*() const { return (*this->I).second; }
16732
};
16833

169-
template <typename C, typename E, E (*A)(typename C::const_iterator &),
170-
typename MutexType>
171-
class LockingAdaptedIterable : public AdaptedIterable<C, E, A> {
34+
template <typename MutexType, typename C,
35+
typename IteratorT = typename C::const_iterator>
36+
class LockingAdaptedIterable : public llvm::iterator_range<IteratorT> {
17237
public:
17338
LockingAdaptedIterable(const C &container, MutexType &mutex)
174-
: AdaptedIterable<C, E, A>(container), m_mutex(&mutex) {
39+
: llvm::iterator_range<IteratorT>(container), m_mutex(&mutex) {
17540
m_mutex->lock();
17641
}
17742

17843
LockingAdaptedIterable(LockingAdaptedIterable &&rhs)
179-
: AdaptedIterable<C, E, A>(rhs), m_mutex(rhs.m_mutex) {
44+
: llvm::iterator_range<IteratorT>(rhs), m_mutex(rhs.m_mutex) {
18045
rhs.m_mutex = nullptr;
18146
}
18247

0 commit comments

Comments
 (0)