aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/RegionStore.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-03-03 01:35:36 +0000
committerTed Kremenek <kremenek@apple.com>2009-03-03 01:35:36 +0000
commit59e8f1128019aef95f45c6fa09cc0f8bfea99f13 (patch)
treed0bee9017b232d51c86f3bf7a58c1417afbc2ea0 /lib/Analysis/RegionStore.cpp
parent935fd768f95edc21f03c6c61f8b48ee99ff8bab6 (diff)
Add StoreManager::getSubRegionMap(). This method returns an opaque mapping for clients of StoreManagers from MemRegions to their subregions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65914 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/RegionStore.cpp')
-rw-r--r--lib/Analysis/RegionStore.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp
index a76a870eb4..0671a806d2 100644
--- a/lib/Analysis/RegionStore.cpp
+++ b/lib/Analysis/RegionStore.cpp
@@ -105,6 +105,37 @@ namespace clang {
namespace {
+class VISIBILITY_HIDDEN RegionStoreSubRegionMap : public SubRegionMap {
+ typedef llvm::DenseMap<const MemRegion*,
+ llvm::ImmutableSet<const MemRegion*> > Map;
+
+ llvm::ImmutableSet<const MemRegion*>::Factory F;
+ Map M;
+
+public:
+ void add(const MemRegion* Parent, const MemRegion* SubRegion) {
+ Map::iterator I = M.find(Parent);
+ M.insert(std::make_pair(Parent,
+ F.Add(I == M.end() ? F.GetEmptySet() : I->second, SubRegion)));
+ }
+
+ ~RegionStoreSubRegionMap() {}
+
+ void iterSubRegions(const MemRegion* Parent, Visitor& V) const {
+ Map::iterator I = M.find(Parent);
+
+ if (I == M.end())
+ return;
+
+ llvm::ImmutableSet<const MemRegion*> S = I->second;
+ for (llvm::ImmutableSet<const MemRegion*>::iterator SI=S.begin(),SE=S.end();
+ SI != SE; ++SI) {
+ if (!V.Visit(Parent, *SI))
+ return;
+ }
+ }
+};
+
class VISIBILITY_HIDDEN RegionStoreManager : public StoreManager {
RegionBindingsTy::Factory RBFactory;
RegionViews::Factory RVFactory;
@@ -128,6 +159,8 @@ public:
MemRegionManager& getRegionManager() { return MRMgr; }
+ std::auto_ptr<SubRegionMap> getSubRegionMap(const GRState *state);
+
const GRState* BindCompoundLiteral(const GRState* St,
const CompoundLiteralExpr* CL, SVal V);
@@ -268,6 +301,18 @@ StoreManager* clang::CreateRegionStoreManager(GRStateManager& StMgr) {
return new RegionStoreManager(StMgr);
}
+std::auto_ptr<SubRegionMap>
+RegionStoreManager::getSubRegionMap(const GRState *state) {
+ RegionBindingsTy B = GetRegionBindings(state->getStore());
+ RegionStoreSubRegionMap *M = new RegionStoreSubRegionMap();
+
+ for (RegionBindingsTy::iterator I=B.begin(), E=B.end(); I!=E; ++I) {
+ if (const SubRegion* R = dyn_cast<SubRegion>(I.getKey()))
+ M->add(R->getSuperRegion(), R);
+ }
+
+ return std::auto_ptr<SubRegionMap>(M);
+}
/// getLValueString - Returns an SVal representing the lvalue of a
/// StringLiteral. Within RegionStore a StringLiteral has an