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

Sam Bishop sam at bishop.dhs.org
Fri Apr 11 11:04:39 PDT 2008


Author: sbishop
Date: Fri Apr 11 13:04:39 2008
New Revision: 49547

URL: http://llvm.org/viewvc/llvm-project?rev=49547&view=rev
Log:
Invoke destructors in Decl::Destroy().

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

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Apr 11 13:04:39 2008
@@ -372,6 +372,7 @@
   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 @@
   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 @@
   static TypedefDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
   
   friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
+  friend void Decl::Destroy(ASTContext& C) const;
 };
 
 

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Fri Apr 11 13:04:39 2008
@@ -118,12 +118,10 @@
     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; }
 

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Apr 11 13:04:39 2008
@@ -103,7 +103,7 @@
     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 @@
   // 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:

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

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Apr 11 13:04:39 2008
@@ -329,10 +329,43 @@
   return (*DeclAttrs)[this];
 }
 
+#define CASE(KIND) case KIND: cast<KIND##Decl>(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<RecordDecl>(this)->~RecordDecl();
+    break;
+
+  default: assert(0 && "Unknown decl kind!");
+  }
+
   C.getAllocator().Deallocate((void *)this);
 }
 
+#undef CASE
+
 //===----------------------------------------------------------------------===//
 // DeclContext Implementation
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list