X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FScopedHashTable.h;h=a6803ee0eddf0f1ff9bcc564475822018107a76c;hb=910cf7f712a1895b993df4677c1059c595353dcc;hp=731ff7db04d779017f803ae74f026ddf71edc7b8;hpb=4f20c6d354d4c6eba00148c2dfc9ad2dae8fd140;p=oota-llvm.git diff --git a/include/llvm/ADT/ScopedHashTable.h b/include/llvm/ADT/ScopedHashTable.h index 731ff7db04d..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,6 +165,8 @@ public: assert(CurScope == 0 && TopLevelMap.empty() && "Scope imbalance!"); } + + /// Access to the allocator. typedef typename ReferenceAdder::result AllocatorRefTy; typedef typename ReferenceAdder::result AllocatorCRefTy; AllocatorRefTy getAllocator() { return Allocator; } @@ -175,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; @@ -194,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