[cfe-commits] r51385 - in /cfe/trunk: include/clang/AST/Type.h lib/AST/ASTContext.cpp lib/AST/Type.cpp

Ted Kremenek kremenek at apple.com
Wed May 21 09:38:54 PDT 2008


Author: kremenek
Date: Wed May 21 11:38:54 2008
New Revision: 51385

URL: http://llvm.org/viewvc/llvm-project?rev=51385&view=rev
Log:
Add Destroy method to Types, making there destruction more harmonious with
the destruction of Decls and Stmts.

Modified:
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/Type.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed May 21 11:38:54 2008
@@ -244,7 +244,8 @@
   Type(TypeClass tc, QualType Canonical)
     : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical),
       TC(tc) {}
-  virtual ~Type();
+  virtual ~Type() {};
+  virtual void Destroy(ASTContext& C);
   friend class ASTContext;
   
   void EmitTypeInternal(llvm::Serializer& S) const;
@@ -722,6 +723,8 @@
                     ArraySizeModifier sm, unsigned tq)
     : ArrayType(VariableArray, et, can, sm, tq), SizeExpr(e) {}
   friend class ASTContext;  // ASTContext creates these.
+  virtual void Destroy(ASTContext& C);
+
 public:
   const Expr *getSizeExpr() const { return SizeExpr; }
   Expr *getSizeExpr() { return SizeExpr; }
@@ -916,7 +919,10 @@
   
   /// ArgInfo - There is an variable size array after the class in memory that
   /// holds the argument types.
+  
   friend class ASTContext;  // ASTContext creates these.
+  virtual void Destroy(ASTContext& C);
+
 public:
   unsigned getNumArgs() const { return NumArgs; }
   QualType getArgType(unsigned i) const {

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

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed May 21 11:38:54 2008
@@ -29,13 +29,7 @@
 ASTContext::~ASTContext() {
   // Deallocate all the types.
   while (!Types.empty()) {
-    if (FunctionTypeProto *FT = dyn_cast<FunctionTypeProto>(Types.back())) {
-      // Destroy the object, but don't call delete.  These are malloc'd.
-      FT->~FunctionTypeProto();
-      free(FT);
-    } else {
-      delete Types.back();
-    }
+    Types.back()->Destroy(*this);
     Types.pop_back();
   }
 }

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

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Wed May 21 11:38:54 2008
@@ -22,7 +22,18 @@
 #include <sstream>
 using namespace clang;
 
-Type::~Type() {}
+void Type::Destroy(ASTContext& C) { delete this; }
+
+void FunctionTypeProto::Destroy(ASTContext& C) {
+  // Destroy the object, but don't call delete.  These are malloc'd.
+  this->~FunctionTypeProto();
+  free(this);  
+}
+
+void VariableArrayType::Destroy(ASTContext& C) {
+  SizeExpr->Destroy(C);
+  delete this;  
+}
 
 /// isVoidType - Helper method to determine if this is the 'void' type.
 bool Type::isVoidType() const {





More information about the cfe-commits mailing list