[cfe-commits] r52055 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/AST/TranslationUnit.cpp

Ted Kremenek kremenek at apple.com
Fri Jun 6 12:48:58 PDT 2008


Author: kremenek
Date: Fri Jun  6 14:48:57 2008
New Revision: 52055

URL: http://llvm.org/viewvc/llvm-project?rev=52055&view=rev
Log:
Implement "Destroy" and destructor for ObjCProtocolDecl, allowing us to reclaim its memory and the memory of the Decls it owns.

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/AST/TranslationUnit.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=52055&r1=52054&r2=52055&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Jun  6 14:48:57 2008
@@ -110,7 +110,8 @@
     ParamInfo(0), NumMethodParams(0),
     MethodAttrs(M), EndLoc(endLoc), Body(0), SelfDecl(0) {}
 
-  ~ObjCMethodDecl();
+  virtual ~ObjCMethodDecl();
+  
 public:
   
   /// Destroy - Call destructors and release memory.
@@ -267,7 +268,7 @@
         AllocIntfRefProtocols(numRefProtos);
       }
   
-  ~ObjCInterfaceDecl();
+  virtual ~ObjCInterfaceDecl();
   
 public:
 
@@ -520,7 +521,14 @@
       isForwardProtoDecl(true) {
     AllocReferencedProtocols(numRefProtos);
   }
+  
+  virtual ~ObjCProtocolDecl();
+  
 public:
+    
+  /// Destroy - Call destructors and release memory.
+  virtual void Destroy(ASTContext& C);
+  
   static ObjCProtocolDecl *Create(ASTContext &C, SourceLocation L,
                                   unsigned numRefProtos, IdentifierInfo *Id);
 

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=52055&r1=52054&r2=52055&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Jun  6 14:48:57 2008
@@ -102,6 +102,31 @@
   return new (Mem) ObjCProtocolDecl(L, numRefProtos, Id);
 }
 
+ObjCProtocolDecl::~ObjCProtocolDecl() {
+  delete [] ReferencedProtocols;
+  delete [] InstanceMethods;
+  delete [] ClassMethods;
+  delete [] PropertyDecl;
+}
+
+void ObjCProtocolDecl::Destroy(ASTContext& C) {
+  
+  // Referenced Protocols are not owned, so don't Destroy them.
+  
+  for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I!=E; ++I)
+    if (*I) (*I)->Destroy(C);
+  
+  for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I!=E; ++I)
+    if (*I) (*I)->Destroy(C);
+  
+  // FIXME: Because there is no clear ownership
+  //  role between ObjCProtocolDecls and the ObjCPropertyDecls that they
+  //  reference, we destroy ObjCPropertyDecls in ~TranslationUnit.
+  
+  Decl::Destroy(C);
+}
+
+
 ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C,
                                      SourceLocation L,
                                      ObjCInterfaceDecl **Elts, unsigned nElts) {

Modified: cfe/trunk/lib/AST/TranslationUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TranslationUnit.cpp?rev=52055&r1=52054&r2=52055&view=diff

==============================================================================
--- cfe/trunk/lib/AST/TranslationUnit.cpp (original)
+++ cfe/trunk/lib/AST/TranslationUnit.cpp Fri Jun  6 14:48:57 2008
@@ -46,11 +46,24 @@
       if (ObjCInterfaceDecl* IDecl = dyn_cast<ObjCInterfaceDecl>(*I))
         for (ObjCInterfaceDecl::classprop_iterator ID=IDecl->classprop_begin(),
              ED=IDecl->classprop_end(); ID!=ED; ++ID) {
-          if (Killed.count(*ID)) continue;
+          if (!*ID || Killed.count(*ID)) continue;
           Killed.insert(*ID);
           (*ID)->Destroy(*Context);
         }
       
+      // FIXME: This is a horrible hack.  Because there is no clear ownership
+      //  role between ObjCProtocolDecls and the ObjCPropertyDecls that they
+      //  reference, we need to destroy ObjCPropertyDecls here.  This will
+      //  eventually be fixed when the ownership of ObjCPropertyDecls gets
+      //  cleaned up.
+      if (ObjCProtocolDecl* PDecl = dyn_cast<ObjCProtocolDecl>(*I))
+        for (ObjCInterfaceDecl::classprop_iterator PD=PDecl->classprop_begin(),
+             ED=PDecl->classprop_end(); PD!=ED; ++PD) {          
+          if (!*PD || Killed.count(*PD)) continue;
+          Killed.insert(*PD);
+          (*PD)->Destroy(*Context);
+        }
+      
       (*I)->Destroy(*Context);
     }
   }





More information about the cfe-commits mailing list