From: Evan Cheng Date: Tue, 2 Mar 2010 22:10:24 +0000 (+0000) Subject: Allow specialization of ScopedHashTable of non-default DenseMapInfo. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d5e9e5f22176fbd0d18a558901e2786106fd03f5;p=oota-llvm.git Allow specialization of ScopedHashTable of non-default DenseMapInfo. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97594 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/ScopedHashTable.h b/include/llvm/ADT/ScopedHashTable.h index df766935db7..f325e2b9f30 100644 --- a/include/llvm/ADT/ScopedHashTable.h +++ b/include/llvm/ADT/ScopedHashTable.h @@ -36,10 +36,10 @@ namespace llvm { -template +template > class ScopedHashTable; -template +template > class ScopedHashTableVal { ScopedHashTableVal *NextInScope; ScopedHashTableVal *NextForKey; @@ -61,35 +61,39 @@ public: ScopedHashTableVal *getNextInScope() { return NextInScope; } }; -template +template > 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() { return LastValInScope; } - void setLastValInScope(ScopedHashTableVal *Val) { LastValInScope = Val; } + friend class ScopedHashTable; + ScopedHashTableVal *getLastValInScope() { + return LastValInScope; + } + void setLastValInScope(ScopedHashTableVal *Val) { + LastValInScope = Val; + } }; -template +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()"); @@ -117,13 +121,13 @@ public: }; -template +template class ScopedHashTable { - DenseMap*> TopLevelMap; - ScopedHashTableScope *CurScope; + DenseMap*, KInfo> TopLevelMap; + ScopedHashTableScope *CurScope; ScopedHashTable(const ScopedHashTable&); // NOT YET IMPLEMENTED void operator=(const ScopedHashTable&); // NOT YET IMPLEMENTED - friend class ScopedHashTableScope; + friend class ScopedHashTableScope; public: ScopedHashTable() : CurScope(0) {} ~ScopedHashTable() { @@ -141,19 +145,19 @@ public: void insert(const K &Key, const V &Val) { assert(CurScope && "No scope active!"); - ScopedHashTableVal *&KeyEntry = TopLevelMap[Key]; + ScopedHashTableVal *&KeyEntry = TopLevelMap[Key]; - KeyEntry = new ScopedHashTableVal(CurScope->getLastValInScope(), - KeyEntry, Key, Val); + KeyEntry= new ScopedHashTableVal(CurScope->getLastValInScope(), + KeyEntry, Key, Val); CurScope->setLastValInScope(KeyEntry); } - typedef ScopedHashTableIterator iterator; + typedef ScopedHashTableIterator iterator; iterator end() { return iterator(0); } iterator begin(const K &Key) { - typename DenseMap*>::iterator I = + typename DenseMap*, KInfo>::iterator I = TopLevelMap.find(Key); if (I == TopLevelMap.end()) return end(); return iterator(I->second); @@ -162,28 +166,29 @@ 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(); }