]> granicus.if.org Git - clang/commitdiff
Added region ObjCObjectRegion that represents an instance of an Objective-C object.
authorTed Kremenek <kremenek@apple.com>
Fri, 24 Oct 2008 20:30:08 +0000 (20:30 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 24 Oct 2008 20:30:08 +0000 (20:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58106 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/MemRegion.h
lib/Analysis/MemRegion.cpp

index e0ecb7180fc52df16a9bbfb45f3fc8891b7ebc2c..514760a4ac7b457d3f1c1268e3ad8a26f2aecabd 100644 (file)
@@ -39,7 +39,7 @@ public:
               // Typed regions.
               BEG_TYPED_REGIONS,
               VarRegionKind, FieldRegionKind, ElementRegionKind,
-              ObjCIvarRegionKind,
+              ObjCIvarRegionKind, ObjCObjectRegionKind,
               AnonTypedRegionKind, AnonPointeeRegionKind,
               END_TYPED_REGIONS };  
 private:
@@ -127,7 +127,7 @@ protected:
   TypedRegion(const MemRegion* sReg, Kind k) : SubRegion(sReg, k) {}
   
 public:
-  virtual QualType getType() const = 0;
+  virtual QualType getType(ASTContext&) const = 0;
     
   static bool classof(const MemRegion* R) {
     unsigned k = R->getKind();
@@ -150,7 +150,7 @@ protected:
                             const MemRegion* superRegion);
 
 public:
-  QualType getType() const { return T; }
+  QualType getType(ASTContext&) const { return T; }
   
 
   void Profile(llvm::FoldingSetNodeID& ID) const;
@@ -210,7 +210,7 @@ class VarRegion : public DeclRegion {
   
 public:  
   const VarDecl* getDecl() const { return cast<VarDecl>(D); }
-  QualType getType() const { return getDecl()->getType(); }
+  QualType getType(ASTContext&) const { return getDecl()->getType(); }
   
   void print(llvm::raw_ostream& os) const;
   
@@ -230,7 +230,7 @@ public:
   void print(llvm::raw_ostream& os) const;
   
   const FieldDecl* getDecl() const { return cast<FieldDecl>(D); }
-  QualType getType() const { return getDecl()->getType(); }
+  QualType getType(ASTContext&) const { return getDecl()->getType(); }
 
   static void ProfileRegion(llvm::FoldingSetNodeID& ID, FieldDecl* FD,
                       const MemRegion* superRegion) {
@@ -242,6 +242,33 @@ public:
   }
 };
   
+class ObjCObjectRegion : public DeclRegion {
+  
+  friend class MemRegionManager;
+  
+  ObjCObjectRegion(const ObjCInterfaceDecl* ivd, const MemRegion* sReg)
+  : DeclRegion(ivd, sReg, ObjCObjectRegionKind) {}
+  
+  static void ProfileRegion(llvm::FoldingSetNodeID& ID, ObjCInterfaceDecl* ivd,
+                            const MemRegion* superRegion) {
+    DeclRegion::ProfileRegion(ID, ivd, superRegion, ObjCObjectRegionKind);
+  }
+  
+public:
+  const ObjCInterfaceDecl* getInterface() const {
+    return cast<ObjCInterfaceDecl>(D);
+  }
+  
+  QualType getType(ASTContext& C) const {
+    ObjCInterfaceDecl* ID = const_cast<ObjCInterfaceDecl*>(getInterface());
+    return C.getObjCInterfaceType(ID);
+  }
+  
+  static bool classof(const MemRegion* R) {
+    return R->getKind() == ObjCObjectRegionKind;
+  }
+};  
+  
 class ObjCIvarRegion : public DeclRegion {
   
   friend class MemRegionManager;
@@ -256,7 +283,7 @@ class ObjCIvarRegion : public DeclRegion {
   
 public:
   const ObjCIvarDecl* getDecl() const { return cast<ObjCIvarDecl>(D); }
-  QualType getType() const { return getDecl()->getType(); }
+  QualType getType(ASTContext&) const { return getDecl()->getType(); }
   
   static bool classof(const MemRegion* R) {
     return R->getKind() == ObjCIvarRegionKind;
@@ -343,6 +370,11 @@ public:
   ///  a structure or class).
   FieldRegion* getFieldRegion(const FieldDecl* fd, const MemRegion* superRegion);
   
+  /// getObjCObjectRegion - Retrieve or create the memory region associated with
+  ///  the instance of a specified Objective-C class.
+  ObjCObjectRegion* getObjCObjectRegion(const ObjCInterfaceDecl* ID,
+                                  const MemRegion* superRegion);
+  
   /// getObjCIvarRegion - Retrieve or create the memory region associated with
   ///   a specified Objective-c instance variable.  'superRegion' corresponds
   ///   to the containing region (which typically represents the Objective-C
index 9c76e452e886947851cbe2f1c9c15f82e5617f45..5dad3560f0a1883873df5e1774b6864acb5ea2b9 100644 (file)
@@ -230,6 +230,27 @@ MemRegionManager::getObjCIvarRegion(const ObjCIvarDecl* d,
   return R;
 }
 
+ObjCObjectRegion*
+MemRegionManager::getObjCObjectRegion(const ObjCInterfaceDecl* d,
+                                    const MemRegion* superRegion) {
+  llvm::FoldingSetNodeID ID;
+  DeclRegion::ProfileRegion(ID, d, superRegion,
+                            MemRegion::ObjCObjectRegionKind);
+  
+  void* InsertPos;
+  MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
+  ObjCObjectRegion* R = cast_or_null<ObjCObjectRegion>(data);
+  
+  if (!R) {
+    R = (ObjCObjectRegion*) A.Allocate<ObjCObjectRegion>();
+    new (R) ObjCObjectRegion(d, superRegion);
+    Regions.InsertNode(R, InsertPos);
+  }
+  
+  return R;
+}
+
+
 AnonPointeeRegion* MemRegionManager::getAnonPointeeRegion(const VarDecl* d) {
   llvm::FoldingSetNodeID ID;
   QualType T = d->getType();