]> granicus.if.org Git - clang/commitdiff
Add Destroy method to Types, making there destruction more harmonious with
authorTed Kremenek <kremenek@apple.com>
Wed, 21 May 2008 16:38:54 +0000 (16:38 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 21 May 2008 16:38:54 +0000 (16:38 +0000)
the destruction of Decls and Stmts.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51385 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Type.h
lib/AST/ASTContext.cpp
lib/AST/Type.cpp

index 658636662538d70b2aece7e7e0249365f94b6634..431eec03e0214ec5a192978faff1b9d1090d16c3 100644 (file)
@@ -244,7 +244,8 @@ protected:
   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 @@ class VariableArrayType : public ArrayType {
                     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 @@ class FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode {
   
   /// 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 {
index 3165ad065b26b7007e32044854f8e06eed701a5a..923aab291db2f8f1c65973e1e49af39621805e62 100644 (file)
@@ -29,13 +29,7 @@ enum FloatingRank {
 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();
   }
 }
index 741d59bc7668dafa17512e11c86df6d844e0a370..e561a1074cea650f304e4aee310c181d73ede948 100644 (file)
 #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 {