[cfe-commits] r66439 - /cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
Ted Kremenek
kremenek at apple.com
Mon Mar 9 13:28:08 PDT 2009
Author: kremenek
Date: Mon Mar 9 15:28:08 2009
New Revision: 66439
URL: http://llvm.org/viewvc/llvm-project?rev=66439&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h?rev=66439&r1=66438&r2=66439&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Mon Mar 9 15:28:08 2009
@@ -70,6 +70,8 @@
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 @@
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 @@
private:
MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region);
-};
+};
} // end clang namespace
namespace llvm {
More information about the cfe-commits
mailing list