aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-02-27 22:51:57 +0000
committerChris Lattner <sabre@nondot.org>2011-02-27 22:51:57 +0000
commitcdac46d18e8bf1850b435960ccc29fb8743d9b05 (patch)
tree0001fec4571c63cc60250534a56389f48646b0bc
parent878ad7afa512ef300d5df4e7ca0189775342dfc2 (diff)
downloadexternal_llvm-cdac46d18e8bf1850b435960ccc29fb8743d9b05.zip
external_llvm-cdac46d18e8bf1850b435960ccc29fb8743d9b05.tar.gz
external_llvm-cdac46d18e8bf1850b435960ccc29fb8743d9b05.tar.bz2
add the ability to walk the scope tree and insert at not-the-current
scope. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126591 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/ADT/ScopedHashTable.h36
1 files changed, 25 insertions, 11 deletions
diff --git a/include/llvm/ADT/ScopedHashTable.h b/include/llvm/ADT/ScopedHashTable.h
index af3c482..a6803ee 100644
--- a/include/llvm/ADT/ScopedHashTable.h
+++ b/include/llvm/ADT/ScopedHashTable.h
@@ -96,6 +96,9 @@ public:
ScopedHashTableScope(ScopedHashTable<K, V, KInfo, AllocatorTy> &HT);
~ScopedHashTableScope();
+ ScopedHashTableScope *getParentScope() { return PrevScope; }
+ const ScopedHashTableScope *getParentScope() const { return PrevScope; }
+
private:
friend class ScopedHashTable<K, V, KInfo, AllocatorTy>;
ScopedHashTableVal<K, V> *getLastValInScope() {
@@ -141,9 +144,14 @@ public:
template <typename K, typename V, typename KInfo, typename AllocatorTy>
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<K, V, KInfo, AllocatorTy> ScopeTy;
+private:
typedef ScopedHashTableVal<K, V> ValTy;
DenseMap<K, ValTy*, KInfo> TopLevelMap;
- ScopedHashTableScope<K, V, KInfo, AllocatorTy> *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<K, V, KInfo, AllocatorTy> ScopeTy;
/// Access to the allocator.
typedef typename ReferenceAdder<AllocatorTy>::result AllocatorRefTy;
@@ -180,13 +185,7 @@ public:
}
void insert(const K &Key, const V &Val) {
- assert(CurScope && "No scope active!");
-
- ScopedHashTableVal<K, V> *&KeyEntry = TopLevelMap[Key];
-
- KeyEntry = ValTy::Create(CurScope->getLastValInScope(), KeyEntry, Key, Val,
- Allocator);
- CurScope->setLastValInScope(KeyEntry);
+ insertIntoScope(CurScope, Key, Val);
}
typedef ScopedHashTableIterator<K, V, KInfo> 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<K, V> *&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