Separate Stmt::Destroy into the entrypoint for destroying a statement
or expression (Destroy) from the virtual function used to actually
destroy a given expression (DoDestroy). 



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78375 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 842caa8..0f3cbe1 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -111,10 +111,9 @@
                 TokLocs, NumConcatenated);
 }
 
-void StringLiteral::Destroy(ASTContext &C) {
+void StringLiteral::DoDestroy(ASTContext &C) {
   C.Deallocate(const_cast<char*>(StrData));
-  this->~StringLiteral();
-  C.Deallocate(this);
+  Expr::DoDestroy(C);
 }
 
 void StringLiteral::setStrData(ASTContext &C, const char *Str, unsigned Len) {
@@ -218,7 +217,7 @@
   SubExprs = new (C) Stmt*[1];
 }
 
-void CallExpr::Destroy(ASTContext& C) {
+void CallExpr::DoDestroy(ASTContext& C) {
   DestroyChildren(C);
   if (SubExprs) C.Deallocate(SubExprs);
   this->~CallExpr();
@@ -1657,7 +1656,7 @@
   memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs);
 }
 
-void SizeOfAlignOfExpr::Destroy(ASTContext& C) {
+void SizeOfAlignOfExpr::DoDestroy(ASTContext& C) {
   // Override default behavior of traversing children. If this has a type
   // operand and the type is a variable-length array, the child iteration
   // will iterate over the size expression. However, this expression belongs
@@ -1668,7 +1667,7 @@
     C.Deallocate(this);
   }
   else
-    Expr::Destroy(C);
+    Expr::DoDestroy(C);
 }
 
 //===----------------------------------------------------------------------===//
@@ -1831,9 +1830,9 @@
   NumDesignators = NumDesignators - 1 + NumNewDesignators;
 }
 
-void DesignatedInitExpr::Destroy(ASTContext &C) {
+void DesignatedInitExpr::DoDestroy(ASTContext &C) {
   delete [] Designators;
-  Expr::Destroy(C);
+  Expr::DoDestroy(C);
 }
 
 ImplicitValueInitExpr *ImplicitValueInitExpr::Clone(ASTContext &C) const {
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp
index d8e069d..67d62a9 100644
--- a/lib/AST/ExprCXX.cpp
+++ b/lib/AST/ExprCXX.cpp
@@ -17,14 +17,6 @@
 #include "clang/AST/ExprCXX.h"
 using namespace clang;
 
-void CXXConditionDeclExpr::Destroy(ASTContext& C) {
-  // FIXME: Cannot destroy the decl here, because it is linked into the
-  // DeclContext's chain.
-  //getVarDecl()->Destroy(C);
-  this->~CXXConditionDeclExpr();
-  C.Deallocate(this);
-}
-
 //===----------------------------------------------------------------------===//
 //  Child Iterators for iterating over subexpressions/substatements
 //===----------------------------------------------------------------------===//
@@ -196,11 +188,13 @@
                                      NumTemplateArgs, RAngleLoc);
 }
 
-void TemplateIdRefExpr::Destroy(ASTContext &Context) {
+void TemplateIdRefExpr::DoDestroy(ASTContext &Context) {
   const TemplateArgument *TemplateArgs = getTemplateArgs();
   for (unsigned I = 0; I != NumTemplateArgs; ++I)
     if (Expr *E = TemplateArgs[I].getAsExpr())
       E->Destroy(Context);
+  this->~TemplateIdRefExpr();
+  Context.Deallocate(this);
 }
 
 Stmt::child_iterator TemplateIdRefExpr::child_begin() {
@@ -348,9 +342,9 @@
   return new (C) CXXTemporary(Destructor);
 }
 
-void CXXTemporary::Destroy(ASTContext &C) {
+void CXXTemporary::Destroy(ASTContext &Ctx) {
   this->~CXXTemporary();
-  C.Deallocate(this);
+  Ctx.Deallocate(this);
 }
 
 CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, 
@@ -362,7 +356,7 @@
   return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
 }
 
-void CXXBindTemporaryExpr::Destroy(ASTContext &C) {
+void CXXBindTemporaryExpr::DoDestroy(ASTContext &C) {
   Temp->Destroy(C);
   this->~CXXBindTemporaryExpr();
   C.Deallocate(this);
@@ -406,7 +400,7 @@
     }
 }
 
-void CXXConstructExpr::Destroy(ASTContext &C) {
+void CXXConstructExpr::DoDestroy(ASTContext &C) {
   DestroyChildren(C);
   if (Args)
     C.Deallocate(Args);
@@ -438,7 +432,7 @@
                                         ShouldDestroyTemps);
 }
 
-void CXXExprWithTemporaries::Destroy(ASTContext &C) {
+void CXXExprWithTemporaries::DoDestroy(ASTContext &C) {
   DestroyChildren(C);
   this->~CXXExprWithTemporaries();
   C.Deallocate(this);
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index 1757791..668f7ef 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -51,19 +51,12 @@
     if (Stmt* Child = *I++) Child->Destroy(C);
 }
 
-void Stmt::Destroy(ASTContext &C) {
+void Stmt::DoDestroy(ASTContext &C) {
   DestroyChildren(C);
-  // FIXME: Eventually all Stmts should be allocated with the allocator
-  //  in ASTContext, just like with Decls.
   this->~Stmt();
   C.Deallocate((void *)this);
 }
 
-void DeclStmt::Destroy(ASTContext &C) {
-  this->~DeclStmt();
-  C.Deallocate((void *)this);
-}
-
 void Stmt::PrintStats() {
   // Ensure the table is primed.
   getStmtInfoTableEntry(Stmt::NullStmtClass);
@@ -569,10 +562,10 @@
   return QualType();
 }
 
-void CXXCatchStmt::Destroy(ASTContext& C) {
+void CXXCatchStmt::DoDestroy(ASTContext& C) {
   if (ExceptionDecl)
     ExceptionDecl->Destroy(C);
-  Stmt::Destroy(C);
+  Stmt::DoDestroy(C);
 }
 
 // CXXTryStmt