diff --git a/lldb/include/lldb/Breakpoint/BreakpointList.h b/lldb/include/lldb/Breakpoint/BreakpointList.h index a7399d385f6f0..4a921fadfc066 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointList.h +++ b/lldb/include/lldb/Breakpoint/BreakpointList.h @@ -163,8 +163,7 @@ class BreakpointList { bool m_is_internal; public: - typedef LockingAdaptedIterable + typedef LockingAdaptedIterable BreakpointIterable; BreakpointIterable Breakpoints() { return BreakpointIterable(m_breakpoints, GetMutex()); diff --git a/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h b/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h index 34bd309864871..3aef1d658c0e5 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h +++ b/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h @@ -165,8 +165,7 @@ class BreakpointLocationCollection { mutable std::mutex m_collection_mutex; public: - typedef AdaptedIterable + typedef llvm::iterator_range BreakpointLocationCollectionIterable; BreakpointLocationCollectionIterable BreakpointLocations() { return BreakpointLocationCollectionIterable(m_break_loc_collection); diff --git a/lldb/include/lldb/Breakpoint/BreakpointLocationList.h b/lldb/include/lldb/Breakpoint/BreakpointLocationList.h index f76a8fcfdd7e7..17dc0bfe03148 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointLocationList.h +++ b/lldb/include/lldb/Breakpoint/BreakpointLocationList.h @@ -204,8 +204,7 @@ class BreakpointLocationList { BreakpointLocationCollection *m_new_location_recorder; public: - typedef AdaptedIterable + typedef llvm::iterator_range BreakpointLocationIterable; BreakpointLocationIterable BreakpointLocations() { diff --git a/lldb/include/lldb/Breakpoint/WatchpointList.h b/lldb/include/lldb/Breakpoint/WatchpointList.h index bf87495d79dba..d037d36e64290 100644 --- a/lldb/include/lldb/Breakpoint/WatchpointList.h +++ b/lldb/include/lldb/Breakpoint/WatchpointList.h @@ -39,8 +39,7 @@ class WatchpointList { ~WatchpointList(); typedef std::list wp_collection; - typedef LockingAdaptedIterable + typedef LockingAdaptedIterable WatchpointIterable; /// Add a Watchpoint to the list. diff --git a/lldb/include/lldb/Breakpoint/WatchpointResource.h b/lldb/include/lldb/Breakpoint/WatchpointResource.h index 070d84cff8f26..c1a81fc486eb6 100644 --- a/lldb/include/lldb/Breakpoint/WatchpointResource.h +++ b/lldb/include/lldb/Breakpoint/WatchpointResource.h @@ -39,8 +39,7 @@ class WatchpointResource void SetType(bool read, bool write); typedef std::vector WatchpointCollection; - typedef LockingAdaptedIterable + typedef LockingAdaptedIterable WatchpointIterable; /// Iterate over the watchpoint constituents for this resource diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h index 43d931a844740..29b87de88520d 100644 --- a/lldb/include/lldb/Core/ModuleList.h +++ b/lldb/include/lldb/Core/ModuleList.h @@ -521,14 +521,13 @@ class ModuleList { Notifier *m_notifier = nullptr; public: - typedef LockingAdaptedIterable + typedef LockingAdaptedIterable ModuleIterable; ModuleIterable Modules() const { return ModuleIterable(m_modules, GetMutex()); } - typedef AdaptedIterable + typedef llvm::iterator_range ModuleIterableNoLocking; ModuleIterableNoLocking ModulesNoLocking() const { return ModuleIterableNoLocking(m_modules); diff --git a/lldb/include/lldb/Core/ModuleSpec.h b/lldb/include/lldb/Core/ModuleSpec.h index 4cbbbfa8a26e1..86be0383f8b47 100644 --- a/lldb/include/lldb/Core/ModuleSpec.h +++ b/lldb/include/lldb/Core/ModuleSpec.h @@ -389,8 +389,7 @@ class ModuleSpecList { } typedef std::vector collection; - typedef LockingAdaptedIterable + typedef LockingAdaptedIterable ModuleSpecIterable; ModuleSpecIterable ModuleSpecs() { diff --git a/lldb/include/lldb/Host/common/NativeProcessProtocol.h b/lldb/include/lldb/Host/common/NativeProcessProtocol.h index 744699210d4b5..1d5fecfcd5c27 100644 --- a/lldb/include/lldb/Host/common/NativeProcessProtocol.h +++ b/lldb/include/lldb/Host/common/NativeProcessProtocol.h @@ -51,13 +51,9 @@ class NativeProcessProtocol { virtual ~NativeProcessProtocol() = default; typedef std::vector> thread_collection; - template - static NativeThreadProtocol &thread_list_adapter(I &iter) { - assert(*iter); - return **iter; - } - typedef LockingAdaptedIterable + typedef LockingAdaptedIterable< + std::recursive_mutex, thread_collection, + llvm::pointee_iterator> ThreadIterable; virtual Status Resume(const ResumeActionList &resume_actions) = 0; diff --git a/lldb/include/lldb/Symbol/SymbolContext.h b/lldb/include/lldb/Symbol/SymbolContext.h index 69fbe544c73cd..8b6317c6f33c2 100644 --- a/lldb/include/lldb/Symbol/SymbolContext.h +++ b/lldb/include/lldb/Symbol/SymbolContext.h @@ -467,7 +467,7 @@ class SymbolContextList { const_iterator begin() const { return m_symbol_contexts.begin(); } const_iterator end() const { return m_symbol_contexts.end(); } - typedef AdaptedIterable + typedef llvm::iterator_range SymbolContextIterable; SymbolContextIterable SymbolContexts() { return SymbolContextIterable(m_symbol_contexts); diff --git a/lldb/include/lldb/Symbol/TypeList.h b/lldb/include/lldb/Symbol/TypeList.h index d58772ad5b62e..6a38babd942ab 100644 --- a/lldb/include/lldb/Symbol/TypeList.h +++ b/lldb/include/lldb/Symbol/TypeList.h @@ -39,8 +39,7 @@ class TypeList { lldb::TypeSP GetTypeAtIndex(uint32_t idx); typedef std::vector collection; - typedef AdaptedIterable - TypeIterable; + typedef llvm::iterator_range TypeIterable; TypeIterable Types() { return TypeIterable(m_types); } diff --git a/lldb/include/lldb/Symbol/TypeMap.h b/lldb/include/lldb/Symbol/TypeMap.h index 89011efab5c31..6c36ff9369fa5 100644 --- a/lldb/include/lldb/Symbol/TypeMap.h +++ b/lldb/include/lldb/Symbol/TypeMap.h @@ -44,7 +44,8 @@ class TypeMap { lldb::TypeSP FirstType() const; typedef std::multimap collection; - typedef AdaptedIterable TypeIterable; + typedef llvm::iterator_range> + TypeIterable; TypeIterable Types() const { return TypeIterable(m_types); } diff --git a/lldb/include/lldb/Target/QueueList.h b/lldb/include/lldb/Target/QueueList.h index 7c74a6a99ac18..3f177c90d3989 100644 --- a/lldb/include/lldb/Target/QueueList.h +++ b/lldb/include/lldb/Target/QueueList.h @@ -48,9 +48,7 @@ class QueueList { lldb::QueueSP GetQueueAtIndex(uint32_t idx); typedef std::vector collection; - typedef LockingAdaptedIterable - QueueIterable; + typedef LockingAdaptedIterable QueueIterable; /// Iterate over the list of queues /// diff --git a/lldb/include/lldb/Target/TargetList.h b/lldb/include/lldb/Target/TargetList.h index a0cddc6b2966f..080a6039c7ff8 100644 --- a/lldb/include/lldb/Target/TargetList.h +++ b/lldb/include/lldb/Target/TargetList.h @@ -44,8 +44,7 @@ class TargetList : public Broadcaster { } typedef std::vector collection; - typedef LockingAdaptedIterable + typedef LockingAdaptedIterable TargetIterable; /// Create a new Target. diff --git a/lldb/include/lldb/Target/ThreadCollection.h b/lldb/include/lldb/Target/ThreadCollection.h index 29f5103e7eec7..3fe62787649f4 100644 --- a/lldb/include/lldb/Target/ThreadCollection.h +++ b/lldb/include/lldb/Target/ThreadCollection.h @@ -20,8 +20,7 @@ namespace lldb_private { class ThreadCollection { public: typedef std::vector collection; - typedef LockingAdaptedIterable + typedef LockingAdaptedIterable ThreadIterable; ThreadCollection(); diff --git a/lldb/include/lldb/Utility/Iterable.h b/lldb/include/lldb/Utility/Iterable.h index 5c38e46feb925..db1f0e65ef6f1 100644 --- a/lldb/include/lldb/Utility/Iterable.h +++ b/lldb/include/lldb/Utility/Iterable.h @@ -11,172 +11,37 @@ #include +#include namespace lldb_private { -template E map_adapter(I &iter) { - return iter->second; -} - -template E vector_adapter(I &iter) { return *iter; } - -template E list_adapter(I &iter) { return *iter; } - -template -class AdaptedConstIterator { -public: - typedef typename C::const_iterator BackingIterator; - - // Wrapping constructor - AdaptedConstIterator(BackingIterator backing_iterator) - : m_iter(backing_iterator) {} - - // Default-constructible - AdaptedConstIterator() : m_iter() {} - - // Copy-constructible - AdaptedConstIterator(const AdaptedConstIterator &rhs) : m_iter(rhs.m_iter) {} - - // Copy-assignable - AdaptedConstIterator &operator=(const AdaptedConstIterator &rhs) { - m_iter = rhs.m_iter; - return *this; - } - - // Destructible - ~AdaptedConstIterator() = default; - - // Comparable - bool operator==(const AdaptedConstIterator &rhs) { - return m_iter == rhs.m_iter; - } - - bool operator!=(const AdaptedConstIterator &rhs) { - return m_iter != rhs.m_iter; - } - - // Rvalue dereferenceable - E operator*() { return (*A)(m_iter); } - - E operator->() { return (*A)(m_iter); } - - // Offset dereferenceable - E operator[](typename BackingIterator::difference_type offset) { - return AdaptedConstIterator(m_iter + offset); - } - - // Incrementable - AdaptedConstIterator &operator++() { - m_iter++; - return *this; - } - - // Decrementable - AdaptedConstIterator &operator--() { - m_iter--; - return *this; - } - - // Compound assignment - AdaptedConstIterator & - operator+=(typename BackingIterator::difference_type offset) { - m_iter += offset; - return *this; - } - - AdaptedConstIterator & - operator-=(typename BackingIterator::difference_type offset) { - m_iter -= offset; - return *this; - } - - // Arithmetic - AdaptedConstIterator - operator+(typename BackingIterator::difference_type offset) { - return AdaptedConstIterator(m_iter + offset); - } - - AdaptedConstIterator - operator-(typename BackingIterator::difference_type offset) { - return AdaptedConstIterator(m_iter - offset); - } - - // Comparable - bool operator<(AdaptedConstIterator &rhs) { return m_iter < rhs.m_iter; } - - bool operator<=(AdaptedConstIterator &rhs) { return m_iter <= rhs.m_iter; } - - bool operator>(AdaptedConstIterator &rhs) { return m_iter > rhs.m_iter; } - - bool operator>=(AdaptedConstIterator &rhs) { return m_iter >= rhs.m_iter; } - - template - friend AdaptedConstIterator - operator+(typename C1::const_iterator::difference_type, - AdaptedConstIterator &); - - template - friend typename C1::const_iterator::difference_type - operator-(AdaptedConstIterator &, - AdaptedConstIterator &); - - template - friend void swap(AdaptedConstIterator &, - AdaptedConstIterator &); - -private: - BackingIterator m_iter; -}; - -template -AdaptedConstIterator operator+( - typename AdaptedConstIterator::BackingIterator::difference_type - offset, - AdaptedConstIterator &rhs) { - return rhs.operator+(offset); -} - -template -typename AdaptedConstIterator::BackingIterator::difference_type -operator-(AdaptedConstIterator &lhs, - AdaptedConstIterator &rhs) { - return (lhs.m_iter - rhs.m_iter); -} - -template -void swap(AdaptedConstIterator &lhs, - AdaptedConstIterator &rhs) { - std::swap(lhs.m_iter, rhs.m_iter); -} - -template -class AdaptedIterable { -private: - const C &m_container; - -public: - AdaptedIterable(const C &container) : m_container(container) {} - - AdaptedConstIterator begin() { - return AdaptedConstIterator(m_container.begin()); - } - - AdaptedConstIterator end() { - return AdaptedConstIterator(m_container.end()); - } +template ::value_type::second_type> +struct ValueMapIterator + : llvm::iterator_adaptor_base< + ValueMapIterator, WrappedIteratorT, + typename std::iterator_traits::iterator_category, + T> { + ValueMapIterator() = default; + explicit ValueMapIterator(WrappedIteratorT u) + : ValueMapIterator::iterator_adaptor_base(std::move(u)) {} + + const T &operator*() { return (*this->I).second; } + const T &operator*() const { return (*this->I).second; } }; -template -class LockingAdaptedIterable : public AdaptedIterable { +template +class LockingAdaptedIterable : public llvm::iterator_range { public: LockingAdaptedIterable(const C &container, MutexType &mutex) - : AdaptedIterable(container), m_mutex(&mutex) { + : llvm::iterator_range(container), m_mutex(&mutex) { m_mutex->lock(); } LockingAdaptedIterable(LockingAdaptedIterable &&rhs) - : AdaptedIterable(rhs), m_mutex(rhs.m_mutex) { + : llvm::iterator_range(rhs), m_mutex(rhs.m_mutex) { rhs.m_mutex = nullptr; }