From ef8b94ae846b2ff0aafcbb40dba3c9670443cef4 Mon Sep 17 00:00:00 2001 From: Sam Bishop Date: Fri, 11 Apr 2008 18:04:39 +0000 Subject: [PATCH] Invoke destructors in Decl::Destroy(). llvm-svn: 49547 --- clang/include/clang/AST/Decl.h | 3 +++ clang/include/clang/AST/DeclBase.h | 8 +++----- clang/include/clang/AST/DeclObjC.h | 4 +++- clang/lib/AST/Decl.cpp | 33 ++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 019673ab1bd2..ac08f9650862 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -372,6 +372,7 @@ protected: static FunctionDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C); friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C); + friend void Decl::Destroy(ASTContext& C) const; }; @@ -452,6 +453,7 @@ protected: static EnumConstantDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C); friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C); + friend void Decl::Destroy(ASTContext& C) const; }; @@ -504,6 +506,7 @@ protected: static TypedefDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C); friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C); + friend void Decl::Destroy(ASTContext& C) const; }; diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index ec3c753051cc..058cb9223ce1 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -118,12 +118,10 @@ protected: HasAttrs(false) { if (Decl::CollectingStats()) addDeclKind(DK); } - -public: - // TODO: This should probably be made protected once derived classes have - // destructors. + virtual ~Decl(); - + +public: SourceLocation getLocation() const { return Loc; } void setLocation(SourceLocation L) { Loc = L; } diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index e9d03a1769c1..0efdd2e60d9b 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -103,7 +103,7 @@ private: SelName(SelInfo), MethodDeclType(T), ParamInfo(0), NumMethodParams(0), MethodAttrs(M), EndLoc(endLoc), Body(0), SelfDecl(0) {} - virtual ~ObjCMethodDecl(); + ~ObjCMethodDecl(); public: static ObjCMethodDecl *Create(ASTContext &C, @@ -175,6 +175,8 @@ public: // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return D->getKind() == ObjCMethod; } static bool classof(const ObjCMethodDecl *D) { return true; } + + friend void Decl::Destroy(ASTContext& C) const; }; /// ObjCInterfaceDecl - Represents an ObjC class declaration. For example: diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 43da07cc245d..c0ec3085e575 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -329,10 +329,43 @@ const Attr *Decl::getAttrs() const { return (*DeclAttrs)[this]; } +#define CASE(KIND) case KIND: cast(this)->~KIND##Decl(); break + void Decl::Destroy(ASTContext& C) const { + switch (getKind()) { + CASE(Field); + CASE(ObjCIvar); + CASE(ObjCCategory); + CASE(ObjCCategoryImpl); + CASE(ObjCImplementation); + CASE(ObjCProtocol); + CASE(ObjCProperty); + CASE(Typedef); + CASE(Enum); + CASE(EnumConstant); + CASE(Function); + CASE(BlockVar); + CASE(FileVar); + CASE(ParmVar); + CASE(ObjCInterface); + CASE(ObjCCompatibleAlias); + CASE(ObjCMethod); + CASE(ObjCClass); + CASE(ObjCForwardProtocol); + CASE(LinkageSpec); + + case Struct: case Union: case Class: + cast(this)->~RecordDecl(); + break; + + default: assert(0 && "Unknown decl kind!"); + } + C.getAllocator().Deallocate((void *)this); } +#undef CASE + //===----------------------------------------------------------------------===// // DeclContext Implementation //===----------------------------------------------------------------------===//