[cfe-commits] r73921 - in /cfe/trunk: include/clang/Analysis/PathSensitive/MemRegion.h lib/Analysis/MemRegion.cpp

Ted Kremenek kremenek at apple.com
Mon Jun 22 16:34:21 PDT 2009


Author: kremenek
Date: Mon Jun 22 18:34:21 2009
New Revision: 73921

URL: http://llvm.org/viewvc/llvm-project?rev=73921&view=rev
Log:
Migrate factory methods for FieldRegion and ObjCIVarRegion creation to use the
new generalized region-construction code.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
    cfe/trunk/lib/Analysis/MemRegion.cpp

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=73921&r1=73920&r2=73921&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Mon Jun 22 18:34:21 2009
@@ -402,7 +402,7 @@
     : DeclRegion(vd, sReg, VarRegionKind) {}
 
   static void ProfileRegion(llvm::FoldingSetNodeID& ID, const VarDecl* VD,
-                      const MemRegion* superRegion) {
+                            const MemRegion* superRegion) {
     DeclRegion::ProfileRegion(ID, VD, superRegion, VarRegionKind);
   }
   
@@ -438,8 +438,8 @@
     return C.getCanonicalType(getDecl()->getType());
   }    
 
-  static void ProfileRegion(llvm::FoldingSetNodeID& ID, FieldDecl* FD,
-                      const MemRegion* superRegion) {
+  static void ProfileRegion(llvm::FoldingSetNodeID& ID, const FieldDecl* FD,
+                            const MemRegion* superRegion) {
     DeclRegion::ProfileRegion(ID, FD, superRegion, FieldRegionKind);
   }
     
@@ -455,7 +455,8 @@
   ObjCObjectRegion(const ObjCInterfaceDecl* ivd, const MemRegion* sReg)
   : DeclRegion(ivd, sReg, ObjCObjectRegionKind) {}
   
-  static void ProfileRegion(llvm::FoldingSetNodeID& ID, ObjCInterfaceDecl* ivd,
+  static void ProfileRegion(llvm::FoldingSetNodeID& ID,
+                            const ObjCInterfaceDecl* ivd,
                             const MemRegion* superRegion) {
     DeclRegion::ProfileRegion(ID, ivd, superRegion, ObjCObjectRegionKind);
   }
@@ -481,8 +482,8 @@
   ObjCIvarRegion(const ObjCIvarDecl* ivd, const MemRegion* sReg)
     : DeclRegion(ivd, sReg, ObjCIvarRegionKind) {}
 
-  static void ProfileRegion(llvm::FoldingSetNodeID& ID, ObjCIvarDecl* ivd,
-                      const MemRegion* superRegion) {
+  static void ProfileRegion(llvm::FoldingSetNodeID& ID, const ObjCIvarDecl* ivd,
+                            const MemRegion* superRegion) {
     DeclRegion::ProfileRegion(ID, ivd, superRegion, ObjCIvarRegionKind);
   }
   
@@ -653,6 +654,9 @@
   
   template <typename RegionTy, typename A1>
   RegionTy* getRegion(const A1 a1);
+  
+  template <typename RegionTy, typename A1>
+  RegionTy* getRegion(const A1 a1, const MemRegion* superRegion);
 
 private:
   MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region);
@@ -684,6 +688,24 @@
   
   return R;
 }
+
+template <typename RegionTy, typename A1>
+RegionTy* MemRegionManager::getRegion(const A1 a1, const MemRegion *superRegion)
+{  
+  llvm::FoldingSetNodeID ID;  
+  RegionTy::ProfileRegion(ID, a1, superRegion);  
+  void* InsertPos;
+  RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
+                                                                   InsertPos));
+  
+  if (!R) {
+    R = (RegionTy*) A.Allocate<RegionTy>();
+    new (R) RegionTy(a1, superRegion);
+    Regions.InsertNode(R, InsertPos);
+  }
+  
+  return R;
+}
   
 //===----------------------------------------------------------------------===//
 // Traits for constructing regions.

Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=73921&r1=73920&r2=73921&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Mon Jun 22 18:34:21 2009
@@ -314,39 +314,13 @@
 
 FieldRegion* MemRegionManager::getFieldRegion(const FieldDecl* d,
                                               const MemRegion* superRegion) {
-  llvm::FoldingSetNodeID ID;
-  DeclRegion::ProfileRegion(ID, d, superRegion, MemRegion::FieldRegionKind);
-  
-  void* InsertPos;
-  MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
-  FieldRegion* R = cast_or_null<FieldRegion>(data);
-  
-  if (!R) {
-    R = (FieldRegion*) A.Allocate<FieldRegion>();
-    new (R) FieldRegion(d, superRegion);
-    Regions.InsertNode(R, InsertPos);
-  }
-  
-  return R;
+  return getRegion<FieldRegion>(d, superRegion);
 }
 
 ObjCIvarRegion*
 MemRegionManager::getObjCIvarRegion(const ObjCIvarDecl* d,
                                     const MemRegion* superRegion) {
-  llvm::FoldingSetNodeID ID;
-  DeclRegion::ProfileRegion(ID, d, superRegion, MemRegion::ObjCIvarRegionKind);
-  
-  void* InsertPos;
-  MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
-  ObjCIvarRegion* R = cast_or_null<ObjCIvarRegion>(data);
-  
-  if (!R) {
-    R = (ObjCIvarRegion*) A.Allocate<ObjCIvarRegion>();
-    new (R) ObjCIvarRegion(d, superRegion);
-    Regions.InsertNode(R, InsertPos);
-  }
-  
-  return R;
+  return getRegion<ObjCIvarRegion>(d, superRegion);
 }
 
 ObjCObjectRegion*





More information about the cfe-commits mailing list