Initial work on additional memory collection for ObjC AST objects.  We now
have Destroy methods of ObjcMethodDecl and ObjCInterfaceDecl which recursively
destroy their owned Decls and Stmts.  There are a few cases where it is not
clear what to do (FIXMEs included in the patch).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52050 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index 6536df6..f3d81a1 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -35,6 +35,21 @@
                                   isVariadic, isSynthesized, impControl);
 }
 
+ObjCMethodDecl::~ObjCMethodDecl() {  
+  delete [] ParamInfo;
+  //delete [] MethodAttrs;  // FIXME: Also destroy the stored Expr*.
+}
+
+void ObjCMethodDecl::Destroy(ASTContext& C) {
+  if (Body) Body->Destroy(C);
+  if (SelfDecl) SelfDecl->Destroy(C);
+  
+  for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
+    if (*I) (*I)->Destroy(C);
+  
+  Decl::Destroy(C);
+}
+
 ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
                                              SourceLocation atLoc,
                                              unsigned numRefProtos,
@@ -47,6 +62,34 @@
                                      isInternal);
 }
 
+ObjCInterfaceDecl::~ObjCInterfaceDecl() {
+  delete [] Ivars;
+  delete [] InstanceMethods;
+  delete [] ClassMethods;
+  delete [] PropertyDecl;
+  // FIXME: CategoryList?
+}
+
+void ObjCInterfaceDecl::Destroy(ASTContext& C) {  
+  for (ivar_iterator I=ivar_begin(), E=ivar_end(); I!=E; ++I)
+    if (*I) (*I)->Destroy(C);
+  
+  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: Cannot destroy properties right now because the properties of
+  //  both the super class and this class are in this array.  This can
+  //  cause double-deletions.
+  //for (classprop_iterator I=classprop_begin(), E=classprop_end(); I!=E; ++I)
+//    if (*I) (*I)->Destroy(C);
+//  
+  Decl::Destroy(C);
+}
+
+
 ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L,
                                    IdentifierInfo *Id, QualType T) {
   void *Mem = C.getAllocator().Allocate<ObjCIvarDecl>();
@@ -135,10 +178,6 @@
   }
 }
 
-ObjCMethodDecl::~ObjCMethodDecl() {
-  delete[] ParamInfo;
-}
-
 /// FindPropertyDeclaration - Finds declaration of the property given its name
 /// in 'PropertyId' and returns it. It returns 0, if not found.
 ///