Implement "Destroy" and destructor for ObjCProtocolDecl, allowing us to reclaim its memory and the memory of the Decls it owns.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52055 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index b3fc131..a0d2818 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -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) {