X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FScopedHashTable.h;h=a6803ee0eddf0f1ff9bcc564475822018107a76c;hb=cbeb8d9869aafec3c2c1ee0922f0a4d5bb4a916a;hp=af3c482043b1eba557c313afda90c736e9b39243;hpb=152096275ad45bb13d5652f7019f48be5ccd67f8;p=oota-llvm.git diff --git a/include/llvm/ADT/ScopedHashTable.h b/include/llvm/ADT/ScopedHashTable.h index af3c482043b..a6803ee0edd 100644 --- a/include/llvm/ADT/ScopedHashTable.h +++ b/include/llvm/ADT/ScopedHashTable.h @@ -96,6 +96,9 @@ public: ScopedHashTableScope(ScopedHashTable &HT); ~ScopedHashTableScope(); + ScopedHashTableScope *getParentScope() { return PrevScope; } + const ScopedHashTableScope *getParentScope() const { return PrevScope; } + private: friend class ScopedHashTable; ScopedHashTableVal *getLastValInScope() { @@ -141,9 +144,14 @@ public: template class ScopedHashTable { +public: + /// ScopeTy - This is a helpful typedef that allows clients to get easy access + /// to the name of the scope for this hash table. + typedef ScopedHashTableScope ScopeTy; +private: typedef ScopedHashTableVal ValTy; DenseMap TopLevelMap; - ScopedHashTableScope *CurScope; + ScopeTy *CurScope; AllocatorTy Allocator; @@ -157,9 +165,6 @@ public: assert(CurScope == 0 && TopLevelMap.empty() && "Scope imbalance!"); } - /// ScopeTy - This is a helpful typedef that allows clients to get easy access - /// to the name of the scope for this hash table. - typedef ScopedHashTableScope ScopeTy; /// Access to the allocator. typedef typename ReferenceAdder::result AllocatorRefTy; @@ -180,13 +185,7 @@ public: } void insert(const K &Key, const V &Val) { - assert(CurScope && "No scope active!"); - - ScopedHashTableVal *&KeyEntry = TopLevelMap[Key]; - - KeyEntry = ValTy::Create(CurScope->getLastValInScope(), KeyEntry, Key, Val, - Allocator); - CurScope->setLastValInScope(KeyEntry); + insertIntoScope(CurScope, Key, Val); } typedef ScopedHashTableIterator iterator; @@ -199,6 +198,21 @@ public: if (I == TopLevelMap.end()) return end(); return iterator(I->second); } + + ScopeTy *getCurScope() { return CurScope; } + const ScopeTy *getCurScope() const { return CurScope; } + + /// insertIntoScope - This inserts the specified key/value at the specified + /// (possibly not the current) scope. While it is ok to insert into a scope + /// that isn't the current one, it isn't ok to insert *underneath* an existing + /// value of the specified key. + void insertIntoScope(ScopeTy *S, const K &Key, const V &Val) { + assert(S && "No scope active!"); + ScopedHashTableVal *&KeyEntry = TopLevelMap[Key]; + KeyEntry = ValTy::Create(S->getLastValInScope(), KeyEntry, Key, Val, + Allocator); + S->setLastValInScope(KeyEntry); + } }; /// ScopedHashTableScope ctor - Install this as the current scope for the hash