From 4f20c6d354d4c6eba00148c2dfc9ad2dae8fd140 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 3 Jan 2011 01:38:29 +0000 Subject: [PATCH] really get this working with a custom allocator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122722 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/ScopedHashTable.h | 44 +++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/include/llvm/ADT/ScopedHashTable.h b/include/llvm/ADT/ScopedHashTable.h index 0df2484ccc1..731ff7db04d 100644 --- a/include/llvm/ADT/ScopedHashTable.h +++ b/include/llvm/ADT/ScopedHashTable.h @@ -40,7 +40,7 @@ template , typename AllocatorTy = MallocAllocator> class ScopedHashTable; -template > +template class ScopedHashTableVal { ScopedHashTableVal *NextInScope; ScopedHashTableVal *NextForKey; @@ -78,29 +78,30 @@ public: } }; -template > +template , + typename AllocatorTy = MallocAllocator> class ScopedHashTableScope { /// HT - The hashtable that we are active for. - ScopedHashTable &HT; + ScopedHashTable &HT; /// PrevScope - This is the scope that we are shadowing in HT. ScopedHashTableScope *PrevScope; /// LastValInScope - This is the last value that was inserted for this scope /// or null if none have been inserted yet. - ScopedHashTableVal *LastValInScope; + ScopedHashTableVal *LastValInScope; void operator=(ScopedHashTableScope&); // DO NOT IMPLEMENT ScopedHashTableScope(ScopedHashTableScope&); // DO NOT IMPLEMENT public: - ScopedHashTableScope(ScopedHashTable &HT); + ScopedHashTableScope(ScopedHashTable &HT); ~ScopedHashTableScope(); private: - friend class ScopedHashTable; - ScopedHashTableVal *getLastValInScope() { + friend class ScopedHashTable; + ScopedHashTableVal *getLastValInScope() { return LastValInScope; } - void setLastValInScope(ScopedHashTableVal *Val) { + void setLastValInScope(ScopedHashTableVal *Val) { LastValInScope = Val; } }; @@ -108,9 +109,9 @@ private: template > class ScopedHashTableIterator { - ScopedHashTableVal *Node; + ScopedHashTableVal *Node; public: - ScopedHashTableIterator(ScopedHashTableVal *node) : Node(node) {} + ScopedHashTableIterator(ScopedHashTableVal *node) : Node(node) {} V &operator*() const { assert(Node && "Dereference end()"); @@ -140,15 +141,15 @@ public: template class ScopedHashTable { - typedef ScopedHashTableVal ValTy; + typedef ScopedHashTableVal ValTy; DenseMap TopLevelMap; - ScopedHashTableScope *CurScope; + ScopedHashTableScope *CurScope; AllocatorTy Allocator; ScopedHashTable(const ScopedHashTable&); // NOT YET IMPLEMENTED void operator=(const ScopedHashTable&); // NOT YET IMPLEMENTED - friend class ScopedHashTableScope; + friend class ScopedHashTableScope; public: ScopedHashTable() : CurScope(0) {} ScopedHashTable(AllocatorTy A) : CurScope(0), Allocator(A) {} @@ -176,7 +177,7 @@ public: void insert(const K &Key, const V &Val) { assert(CurScope && "No scope active!"); - ScopedHashTableVal *&KeyEntry = TopLevelMap[Key]; + ScopedHashTableVal *&KeyEntry = TopLevelMap[Key]; KeyEntry = ValTy::Create(CurScope->getLastValInScope(), KeyEntry, Key, Val, Allocator); @@ -197,29 +198,28 @@ public: /// ScopedHashTableScope ctor - Install this as the current scope for the hash /// table. -template -ScopedHashTableScope:: - ScopedHashTableScope(ScopedHashTable &ht) : HT(ht) { +template +ScopedHashTableScope:: + ScopedHashTableScope(ScopedHashTable &ht) : HT(ht) { PrevScope = HT.CurScope; HT.CurScope = this; LastValInScope = 0; } -template -ScopedHashTableScope::~ScopedHashTableScope() { +template +ScopedHashTableScope::~ScopedHashTableScope() { assert(HT.CurScope == this && "Scope imbalance!"); HT.CurScope = PrevScope; // Pop and delete all values corresponding to this scope. - while (ScopedHashTableVal *ThisEntry = LastValInScope) { + while (ScopedHashTableVal *ThisEntry = LastValInScope) { // Pop this value out of the TopLevelMap. if (ThisEntry->getNextForKey() == 0) { assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry && "Scope imbalance!"); HT.TopLevelMap.erase(ThisEntry->getKey()); } else { - ScopedHashTableVal *&KeyEntry = - HT.TopLevelMap[ThisEntry->getKey()]; + ScopedHashTableVal *&KeyEntry = HT.TopLevelMap[ThisEntry->getKey()]; assert(KeyEntry == ThisEntry && "Scope imbalance!"); KeyEntry = ThisEntry->getNextForKey(); } -- 2.34.1