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

Chris Lattner sabre at nondot.org
Thu Feb 19 22:03:09 PST 2009


Author: lattner
Date: Fri Feb 20 00:03:09 2009
New Revision: 65112

URL: http://llvm.org/viewvc/llvm-project?rev=65112&view=rev
Log:
move more objc destruction out of dtors into Destroy.

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

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Feb 20 00:03:09 2009
@@ -261,7 +261,7 @@
                     IdentifierInfo *Id)
     : NamedDecl(DK, DC, L, Id), DeclContext(DK) {}
 
-  virtual ~ObjCContainerDecl();
+  virtual ~ObjCContainerDecl() {}
 
   // Iterator access to properties.
   typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
@@ -382,16 +382,11 @@
   SourceLocation EndLoc; // marks the '>', '}', or identifier.
 
   ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
-                    SourceLocation CLoc, bool FD, bool isInternal)
-    : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id),
-      TypeForDecl(0), SuperClass(0),
-      Ivars(0), NumIvars(0),
-      CategoryList(0), 
-      ForwardDecl(FD), InternalInterface(isInternal),
-      ClassLoc(CLoc) {
-      }
+                    SourceLocation CLoc, bool FD, bool isInternal);
   
-  virtual ~ObjCInterfaceDecl();
+  virtual ~ObjCInterfaceDecl() {
+    assert(Ivars == 0 && "Destroy not called?");
+  }
   
 public:
 
@@ -648,19 +643,10 @@
   unsigned NumForwardDecls;
   
   ObjCClassDecl(DeclContext *DC, SourceLocation L, 
-                ObjCInterfaceDecl **Elts, unsigned nElts)
-    : Decl(ObjCClass, DC, L) { 
-    if (nElts) {
-      ForwardDecls = new ObjCInterfaceDecl*[nElts];
-      memcpy(ForwardDecls, Elts, nElts*sizeof(ObjCInterfaceDecl*));
-    } else {
-      ForwardDecls = 0;
-    }
-    NumForwardDecls = nElts;
+                ObjCInterfaceDecl **Elts, unsigned nElts);
+  virtual ~ObjCClassDecl() {
+    assert(ForwardDecls == 0 && "Destroy not called?");
   }
-  
-  virtual ~ObjCClassDecl();
-  
 public:
   
   /// Destroy - Call destructors and release memory.
@@ -695,25 +681,19 @@
   unsigned NumReferencedProtocols;
   
   ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
-                          ObjCProtocolDecl **Elts, unsigned nElts)
-    : Decl(ObjCForwardProtocol, DC, L) { 
-    NumReferencedProtocols = nElts;
-    if (nElts) {
-      ReferencedProtocols = new ObjCProtocolDecl*[nElts];
-      memcpy(ReferencedProtocols, Elts, nElts*sizeof(ObjCProtocolDecl*));
-    } else {
-      ReferencedProtocols = 0;
-    }
+                          ObjCProtocolDecl **Elts, unsigned nElts);  
+  virtual ~ObjCForwardProtocolDecl() {
+    assert(ReferencedProtocols == 0 && "Destroy not called?");
   }
   
-  virtual ~ObjCForwardProtocolDecl();
-  
 public:
   static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
                                          SourceLocation L, 
                                          ObjCProtocolDecl **Elts, unsigned Num);
 
-  
+  /// Destroy - Call destructors and release memory.
+  virtual void Destroy(ASTContext& C);
+
   void setForwardProtocolDecl(unsigned idx, ObjCProtocolDecl *OID) {
     assert(idx < NumReferencedProtocols && "index out of range");
     ReferencedProtocols[idx] = OID;

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Feb 20 00:03:09 2009
@@ -48,6 +48,7 @@
   Decl::Destroy(C);
 }
 
+
 ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
                                              DeclContext *DC,
                                              SourceLocation atLoc,
@@ -58,18 +59,23 @@
                                      isInternal);
 }
 
-ObjCContainerDecl::~ObjCContainerDecl() {
-}
-
-ObjCInterfaceDecl::~ObjCInterfaceDecl() {
-  delete [] Ivars;
-  // FIXME: CategoryList?
+ObjCInterfaceDecl::
+ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
+                  SourceLocation CLoc, bool FD, bool isInternal)
+  : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id),
+    TypeForDecl(0), SuperClass(0), Ivars(0), NumIvars(0),
+    CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal),
+    ClassLoc(CLoc) {
 }
 
-void ObjCInterfaceDecl::Destroy(ASTContext& C) {  
+void ObjCInterfaceDecl::Destroy(ASTContext &C) {  
   for (ivar_iterator I=ivar_begin(), E=ivar_end(); I!=E; ++I)
     if (*I) (*I)->Destroy(C);
   
+  delete [] Ivars;
+  Ivars = 0;
+  // FIXME: CategoryList?
+  
   // FIXME: Because there is no clear ownership
   //  role between ObjCInterfaceDecls and the ObjCPropertyDecls that they
   //  reference, we destroy ObjCPropertyDecls in ~TranslationUnit.
@@ -116,11 +122,19 @@
   return new (C) ObjCClassDecl(DC, L, Elts, nElts);
 }
 
-ObjCClassDecl::~ObjCClassDecl() {
-  delete [] ForwardDecls;
+ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L, 
+                             ObjCInterfaceDecl **Elts, unsigned nElts)
+  : Decl(ObjCClass, DC, L) { 
+  if (nElts) {
+    ForwardDecls = new ObjCInterfaceDecl*[nElts];
+    memcpy(ForwardDecls, Elts, nElts*sizeof(ObjCInterfaceDecl*));
+  } else {
+    ForwardDecls = 0;
+  }
+  NumForwardDecls = nElts;
 }
 
-void ObjCClassDecl::Destroy(ASTContext& C) {
+void ObjCClassDecl::Destroy(ASTContext &C) {
   
   // FIXME: There is no clear ownership policy now for referenced
   //  ObjCInterfaceDecls.  Some of them can be forward declarations that
@@ -130,6 +144,9 @@
   //  obviating this problem.  Because of this situation, referenced
   //  ObjCInterfaceDecls are destroyed in ~TranslationUnit.
   
+  delete [] ForwardDecls;
+  ForwardDecls = 0;
+
   Decl::Destroy(C);
 }
 
@@ -140,8 +157,22 @@
   return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts);
 }
 
-ObjCForwardProtocolDecl::~ObjCForwardProtocolDecl() {
+ObjCForwardProtocolDecl::
+ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
+                        ObjCProtocolDecl **Elts, unsigned nElts)
+  : Decl(ObjCForwardProtocol, DC, L) { 
+  NumReferencedProtocols = nElts;
+  if (nElts) {
+    ReferencedProtocols = new ObjCProtocolDecl*[nElts];
+    memcpy(ReferencedProtocols, Elts, nElts*sizeof(ObjCProtocolDecl*));
+  } else {
+    ReferencedProtocols = 0;
+  }
+}
+
+void ObjCForwardProtocolDecl::Destroy(ASTContext &C) {
   delete [] ReferencedProtocols;
+  ReferencedProtocols = 0;
 }
 
 ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,





More information about the cfe-commits mailing list