diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-03-09 20:28:08 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-03-09 20:28:08 +0000 |
commit | ed65d3d97132fbcdd124aef4d2478e348dfbd36b (patch) | |
tree | c79d2d94b116f52f169274138ec54b86cbf121d5 | |
parent | fda79d1ce6ea89aa5fe516a543ea273a01142107 (diff) |
Add member template "MemRegion::getAs<RegionType>" that dynamically casts a
given MemRegion object to a target region type. This differs from dyn_cast<> in
that it also ignores TypedViewRegions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66439 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Analysis/PathSensitive/MemRegion.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h index 3c9d705176..d22dccc77c 100644 --- a/include/clang/Analysis/PathSensitive/MemRegion.h +++ b/include/clang/Analysis/PathSensitive/MemRegion.h @@ -70,6 +70,8 @@ public: Kind getKind() const { return kind; } + template<typename RegionTy> const RegionTy* getAs() const; + virtual bool isBoundable(ASTContext&) const { return true; } static bool classof(const MemRegion*) { return true; } @@ -452,6 +454,26 @@ public: return R->getKind() == ElementRegionKind; } }; + +template<typename RegionTy> +const RegionTy* MemRegion::getAs() const { + const MemRegion *R = this; + + do { + if (const RegionTy* RT = dyn_cast<RegionTy>(R)) + return RT; + + if (const TypedViewRegion *TR = dyn_cast<TypedViewRegion>(R)) { + R = TR->getSuperRegion(); + continue; + } + + break; + } + while (R); + + return 0; +} //===----------------------------------------------------------------------===// // MemRegionManager - Factory object for creating regions. @@ -543,7 +565,7 @@ public: private: MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region); -}; +}; } // end clang namespace namespace llvm { |