diff options
-rw-r--r-- | include/clang/AST/DeclObjC.h | 12 | ||||
-rw-r--r-- | lib/AST/DeclObjC.cpp | 25 | ||||
-rw-r--r-- | lib/AST/TranslationUnit.cpp | 15 |
3 files changed, 49 insertions, 3 deletions
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 7f4e303cc4..a50c08f344 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -110,7 +110,8 @@ private: 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 @@ class ObjCInterfaceDecl : public NamedDecl, public DeclContext { AllocIntfRefProtocols(numRefProtos); } - ~ObjCInterfaceDecl(); + virtual ~ObjCInterfaceDecl(); public: @@ -520,7 +521,14 @@ class ObjCProtocolDecl : public NamedDecl { 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); diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index b3fc131330..a0d281808e 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -102,6 +102,31 @@ ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, 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) { diff --git a/lib/AST/TranslationUnit.cpp b/lib/AST/TranslationUnit.cpp index e78502f267..a683625789 100644 --- a/lib/AST/TranslationUnit.cpp +++ b/lib/AST/TranslationUnit.cpp @@ -46,11 +46,24 @@ TranslationUnit::~TranslationUnit() { 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); } } |