From ed65d3d97132fbcdd124aef4d2478e348dfbd36b Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 9 Mar 2009 20:28:08 +0000 Subject: [PATCH] Add member template "MemRegion::getAs" 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 --- .../clang/Analysis/PathSensitive/MemRegion.h | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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 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 +const RegionTy* MemRegion::getAs() const { + const MemRegion *R = this; + + do { + if (const RegionTy* RT = dyn_cast(R)) + return RT; + + if (const TypedViewRegion *TR = dyn_cast(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 { -- 2.40.0