diff options
Diffstat (limited to 'include/llvm/ADT/ImmutableSet.h')
-rw-r--r-- | include/llvm/ADT/ImmutableSet.h | 121 |
1 files changed, 60 insertions, 61 deletions
diff --git a/include/llvm/ADT/ImmutableSet.h b/include/llvm/ADT/ImmutableSet.h index 9c9bcb81f76b..9d580c5a3d41 100644 --- a/include/llvm/ADT/ImmutableSet.h +++ b/include/llvm/ADT/ImmutableSet.h @@ -41,18 +41,16 @@ template <typename ImutInfo> class ImutAVLTreeGenericIterator; template <typename ImutInfo > class ImutAVLTree { public: - typedef typename ImutInfo::key_type_ref key_type_ref; - typedef typename ImutInfo::value_type value_type; - typedef typename ImutInfo::value_type_ref value_type_ref; + using key_type_ref = typename ImutInfo::key_type_ref; + using value_type = typename ImutInfo::value_type; + using value_type_ref = typename ImutInfo::value_type_ref; + using Factory = ImutAVLFactory<ImutInfo>; + using iterator = ImutAVLTreeInOrderIterator<ImutInfo>; - typedef ImutAVLFactory<ImutInfo> Factory; friend class ImutAVLFactory<ImutInfo>; friend class ImutIntervalAVLFactory<ImutInfo>; - friend class ImutAVLTreeGenericIterator<ImutInfo>; - typedef ImutAVLTreeInOrderIterator<ImutInfo> iterator; - //===----------------------------------------------------===// // Public Interface. //===----------------------------------------------------===// @@ -225,17 +223,17 @@ private: Factory *factory; ImutAVLTree *left; ImutAVLTree *right; - ImutAVLTree *prev; - ImutAVLTree *next; + ImutAVLTree *prev = nullptr; + ImutAVLTree *next = nullptr; - unsigned height : 28; - unsigned IsMutable : 1; - unsigned IsDigestCached : 1; - unsigned IsCanonicalized : 1; + unsigned height : 28; + bool IsMutable : 1; + bool IsDigestCached : 1; + bool IsCanonicalized : 1; value_type value; - uint32_t digest; - uint32_t refCount; + uint32_t digest = 0; + uint32_t refCount = 0; //===----------------------------------------------------===// // Internal methods (node manipulation; used by Factory). @@ -246,9 +244,8 @@ private: /// ImutAVLFactory. ImutAVLTree(Factory *f, ImutAVLTree* l, ImutAVLTree* r, value_type_ref v, unsigned height) - : factory(f), left(l), right(r), prev(nullptr), next(nullptr), - height(height), IsMutable(true), IsDigestCached(false), - IsCanonicalized(0), value(v), digest(0), refCount(0) + : factory(f), left(l), right(r), height(height), IsMutable(true), + IsDigestCached(false), IsCanonicalized(false), value(v) { if (left) left->retain(); if (right) right->retain(); @@ -369,11 +366,11 @@ public: template <typename ImutInfo > class ImutAVLFactory { friend class ImutAVLTree<ImutInfo>; - typedef ImutAVLTree<ImutInfo> TreeTy; - typedef typename TreeTy::value_type_ref value_type_ref; - typedef typename TreeTy::key_type_ref key_type_ref; - typedef DenseMap<unsigned, TreeTy*> CacheTy; + using TreeTy = ImutAVLTree<ImutInfo>; + using value_type_ref = typename TreeTy::value_type_ref; + using key_type_ref = typename TreeTy::key_type_ref; + using CacheTy = DenseMap<unsigned, TreeTy*>; CacheTy Cache; uintptr_t Allocator; @@ -659,7 +656,7 @@ public: enum VisitFlag { VisitedNone=0x0, VisitedLeft=0x1, VisitedRight=0x3, Flags=0x3 }; - typedef ImutAVLTree<ImutInfo> TreeTy; + using TreeTy = ImutAVLTree<ImutInfo>; ImutAVLTreeGenericIterator() = default; ImutAVLTreeGenericIterator(const TreeTy *Root) { @@ -764,11 +761,12 @@ template <typename ImutInfo> class ImutAVLTreeInOrderIterator : public std::iterator<std::bidirectional_iterator_tag, ImutAVLTree<ImutInfo>> { - typedef ImutAVLTreeGenericIterator<ImutInfo> InternalIteratorTy; + using InternalIteratorTy = ImutAVLTreeGenericIterator<ImutInfo>; + InternalIteratorTy InternalItr; public: - typedef ImutAVLTree<ImutInfo> TreeTy; + using TreeTy = ImutAVLTree<ImutInfo>; ImutAVLTreeInOrderIterator(const TreeTy* Root) : InternalItr(Root) { if (Root) @@ -840,8 +838,8 @@ struct ImutAVLValueIterator /// and generic handling of pointers is done below. template <typename T> struct ImutProfileInfo { - typedef const T value_type; - typedef const T& value_type_ref; + using value_type = const T; + using value_type_ref = const T&; static void Profile(FoldingSetNodeID &ID, value_type_ref X) { FoldingSetTrait<T>::Profile(X,ID); @@ -851,8 +849,8 @@ struct ImutProfileInfo { /// Profile traits for integers. template <typename T> struct ImutProfileInteger { - typedef const T value_type; - typedef const T& value_type_ref; + using value_type = const T; + using value_type_ref = const T&; static void Profile(FoldingSetNodeID &ID, value_type_ref X) { ID.AddInteger(X); @@ -878,8 +876,8 @@ PROFILE_INTEGER_INFO(unsigned long long) /// Profile traits for booleans. template <> struct ImutProfileInfo<bool> { - typedef const bool value_type; - typedef const bool& value_type_ref; + using value_type = const bool; + using value_type_ref = const bool&; static void Profile(FoldingSetNodeID &ID, value_type_ref X) { ID.AddBoolean(X); @@ -890,8 +888,8 @@ struct ImutProfileInfo<bool> { /// references to unique objects. template <typename T> struct ImutProfileInfo<T*> { - typedef const T* value_type; - typedef value_type value_type_ref; + using value_type = const T*; + using value_type_ref = value_type; static void Profile(FoldingSetNodeID &ID, value_type_ref X) { ID.AddPointer(X); @@ -910,12 +908,12 @@ struct ImutProfileInfo<T*> { /// std::equal_to<> and std::less<> to perform comparison of elements. template <typename T> struct ImutContainerInfo : public ImutProfileInfo<T> { - typedef typename ImutProfileInfo<T>::value_type value_type; - typedef typename ImutProfileInfo<T>::value_type_ref value_type_ref; - typedef value_type key_type; - typedef value_type_ref key_type_ref; - typedef bool data_type; - typedef bool data_type_ref; + using value_type = typename ImutProfileInfo<T>::value_type; + using value_type_ref = typename ImutProfileInfo<T>::value_type_ref; + using key_type = value_type; + using key_type_ref = value_type_ref; + using data_type = bool; + using data_type_ref = bool; static key_type_ref KeyOfValue(value_type_ref D) { return D; } static data_type_ref DataOfValue(value_type_ref) { return true; } @@ -936,12 +934,12 @@ struct ImutContainerInfo : public ImutProfileInfo<T> { /// their addresses. template <typename T> struct ImutContainerInfo<T*> : public ImutProfileInfo<T*> { - typedef typename ImutProfileInfo<T*>::value_type value_type; - typedef typename ImutProfileInfo<T*>::value_type_ref value_type_ref; - typedef value_type key_type; - typedef value_type_ref key_type_ref; - typedef bool data_type; - typedef bool data_type_ref; + using value_type = typename ImutProfileInfo<T*>::value_type; + using value_type_ref = typename ImutProfileInfo<T*>::value_type_ref; + using key_type = value_type; + using key_type_ref = value_type_ref; + using data_type = bool; + using data_type_ref = bool; static key_type_ref KeyOfValue(value_type_ref D) { return D; } static data_type_ref DataOfValue(value_type_ref) { return true; } @@ -960,9 +958,9 @@ struct ImutContainerInfo<T*> : public ImutProfileInfo<T*> { template <typename ValT, typename ValInfo = ImutContainerInfo<ValT>> class ImmutableSet { public: - typedef typename ValInfo::value_type value_type; - typedef typename ValInfo::value_type_ref value_type_ref; - typedef ImutAVLTree<ValInfo> TreeTy; + using value_type = typename ValInfo::value_type; + using value_type_ref = typename ValInfo::value_type_ref; + using TreeTy = ImutAVLTree<ValInfo>; private: TreeTy *Root; @@ -980,6 +978,10 @@ public: if (Root) { Root->retain(); } } + ~ImmutableSet() { + if (Root) { Root->release(); } + } + ImmutableSet &operator=(const ImmutableSet &X) { if (Root != X.Root) { if (X.Root) { X.Root->retain(); } @@ -989,10 +991,6 @@ public: return *this; } - ~ImmutableSet() { - if (Root) { Root->release(); } - } - class Factory { typename TreeTy::Factory F; const bool Canonicalize; @@ -1084,7 +1082,7 @@ public: // Iterators. //===--------------------------------------------------===// - typedef ImutAVLValueIterator<ImmutableSet> iterator; + using iterator = ImutAVLValueIterator<ImmutableSet>; iterator begin() const { return iterator(Root); } iterator end() const { return iterator(); } @@ -1112,10 +1110,10 @@ public: template <typename ValT, typename ValInfo = ImutContainerInfo<ValT>> class ImmutableSetRef { public: - typedef typename ValInfo::value_type value_type; - typedef typename ValInfo::value_type_ref value_type_ref; - typedef ImutAVLTree<ValInfo> TreeTy; - typedef typename TreeTy::Factory FactoryTy; + using value_type = typename ValInfo::value_type; + using value_type_ref = typename ValInfo::value_type_ref; + using TreeTy = ImutAVLTree<ValInfo>; + using FactoryTy = typename TreeTy::Factory; private: TreeTy *Root; @@ -1138,6 +1136,10 @@ public: if (Root) { Root->retain(); } } + ~ImmutableSetRef() { + if (Root) { Root->release(); } + } + ImmutableSetRef &operator=(const ImmutableSetRef &X) { if (Root != X.Root) { if (X.Root) { X.Root->retain(); } @@ -1147,9 +1149,6 @@ public: } return *this; } - ~ImmutableSetRef() { - if (Root) { Root->release(); } - } static ImmutableSetRef getEmptySet(FactoryTy *F) { return ImmutableSetRef(0, F); @@ -1196,7 +1195,7 @@ public: // Iterators. //===--------------------------------------------------===// - typedef ImutAVLValueIterator<ImmutableSetRef> iterator; + using iterator = ImutAVLValueIterator<ImmutableSetRef>; iterator begin() const { return iterator(Root); } iterator end() const { return iterator(); } |