]> granicus.if.org Git - clang/commitdiff
Separate Stmt::Destroy into the entrypoint for destroying a statement
authorDouglas Gregor <dgregor@apple.com>
Fri, 7 Aug 2009 06:08:38 +0000 (06:08 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 7 Aug 2009 06:08:38 +0000 (06:08 +0000)
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

include/clang/AST/Expr.h
include/clang/AST/ExprCXX.h
include/clang/AST/Stmt.h
include/clang/AST/StmtCXX.h
lib/AST/Expr.cpp
lib/AST/ExprCXX.cpp
lib/AST/Stmt.cpp

index 3cec4e8aaf5662818e242f79437fdf866d6646fb..e65a842d3fdaa9bb7baa5d4f37b4c0621f8ee6b5 100644 (file)
@@ -564,6 +564,10 @@ class StringLiteral : public Expr {
   SourceLocation TokLocs[1];
 
   StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {}
+  
+protected:
+  virtual void DoDestroy(ASTContext &C);
+
 public:
   /// This is the "fully general" constructor that allows representation of
   /// strings formed from multiple concatenated tokens.
@@ -582,7 +586,6 @@ public:
   static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
 
   StringLiteral* Clone(ASTContext &C) const;
-  void Destroy(ASTContext &C);
   
   const char *getStrData() const { return StrData; }
   unsigned getByteLength() const { return ByteLength; }
@@ -780,6 +783,10 @@ class SizeOfAlignOfExpr : public Expr {
     Stmt *Ex;
   } Argument;
   SourceLocation OpLoc, RParenLoc;
+
+protected:
+  virtual void DoDestroy(ASTContext& C);
+
 public:
   SizeOfAlignOfExpr(bool issizeof, QualType T, 
                     QualType resultType, SourceLocation op,
@@ -807,8 +814,6 @@ public:
   explicit SizeOfAlignOfExpr(EmptyShell Empty)
     : Expr(SizeOfAlignOfExprClass, Empty) { }
 
-  virtual void Destroy(ASTContext& C);
-
   bool isSizeOf() const { return isSizeof; }
   void setSizeof(bool S) { isSizeof = S; }
 
@@ -950,6 +955,8 @@ protected:
   // This version of the constructor is for derived classes.
   CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
            QualType t, SourceLocation rparenloc);
+
+  virtual void DoDestroy(ASTContext& C);
   
 public:
   CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 
@@ -960,8 +967,6 @@ public:
 
   ~CallExpr() {}
   
-  void Destroy(ASTContext& C);
-  
   const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
   Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
   void setCallee(Expr *F) { SubExprs[FN] = F; }
@@ -2113,6 +2118,9 @@ private:
     : Expr(DesignatedInitExprClass, EmptyShell()),
       NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
 
+protected:
+  virtual void DoDestroy(ASTContext &C);  
+
 public:
   /// A field designator, e.g., ".x".
   struct FieldDesignator {
@@ -2332,8 +2340,6 @@ public:
 
   virtual SourceRange getSourceRange() const;
 
-  virtual void Destroy(ASTContext &C);
-
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == DesignatedInitExprClass; 
   }
index bee9b2989678d2911edc78e3b71a54e22848668a..008e6af2b73a6bdbdcdfad750deafac267ba8f09 100644 (file)
@@ -431,7 +431,8 @@ class CXXTemporary {
 public:
   static CXXTemporary *Create(ASTContext &C, 
                               const CXXDestructorDecl *Destructor);
-  void Destroy(ASTContext &C);
+  
+  void Destroy(ASTContext &Ctx);
   
   const CXXDestructorDecl *getDestructor() const { return Destructor; }
 };
@@ -448,10 +449,12 @@ class CXXBindTemporaryExpr : public Expr {
           subexpr->getType()), Temp(temp), SubExpr(subexpr) { }
   ~CXXBindTemporaryExpr() { } 
 
+protected:
+  virtual void DoDestroy(ASTContext &C);
+
 public:
   static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 
                                       Expr* SubExpr);
-  void Destroy(ASTContext &C);
   
   CXXTemporary *getTemporary() { return Temp; }
   const CXXTemporary *getTemporary() const { return Temp; }
@@ -489,12 +492,13 @@ protected:
                    Expr **args, unsigned numargs);
   ~CXXConstructExpr() { } 
 
+  virtual void DoDestroy(ASTContext &C);
+
 public:
   static CXXConstructExpr *Create(ASTContext &C, QualType T,
                                   CXXConstructorDecl *D, bool Elidable, 
                                   Expr **Args, unsigned NumArgs);
   
-  void Destroy(ASTContext &C);
   
   CXXConstructorDecl* getConstructor() const { return Constructor; }
 
@@ -653,8 +657,6 @@ public:
                   /*FIXME:integral constant?*/
                     var->getType()->isDependentType()) {}
 
-  virtual void Destroy(ASTContext& Ctx);
-
   SourceLocation getStartLoc() const { return getLocation(); }
   
   VarDecl *getVarDecl() { return cast<VarDecl>(getDecl()); }
@@ -1072,6 +1074,8 @@ class TemplateIdRefExpr : public Expr {
                     unsigned NumTemplateArgs,
                     SourceLocation RAngleLoc);
   
+  virtual void DoDestroy(ASTContext &Context);
+  
 public:
   static TemplateIdRefExpr *
   Create(ASTContext &Context, QualType T,
@@ -1080,8 +1084,6 @@ public:
          SourceLocation LAngleLoc, const TemplateArgument *TemplateArgs,
          unsigned NumTemplateArgs, SourceLocation RAngleLoc);
   
-  void Destroy(ASTContext &Context);
-  
   /// \brief Retrieve the nested name specifier used to qualify the name of
   /// this template-id, e.g., the "std::sort" in @c std::sort<int>, or NULL
   /// if this template-id was an unqualified-id.
@@ -1143,12 +1145,14 @@ class CXXExprWithTemporaries : public Expr {
   CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps, 
                          unsigned NumTemps, bool ShouldDestroyTemps);
   ~CXXExprWithTemporaries();
-  
+
+protected:
+  virtual void DoDestroy(ASTContext &C);
+
 public:
   static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
                                         CXXTemporary **Temps, unsigned NumTemps,
                                         bool ShouldDestroyTemporaries);
-  void Destroy(ASTContext &C);
   
   unsigned getNumTemporaries() const { return NumTemps; }
   CXXTemporary *getTemporary(unsigned i) {
index e841f25d766e1f915dfaf74424ce409713ec0f41..239c6b5f4320fcef259eea030a94e949cda407c5 100644 (file)
@@ -155,13 +155,21 @@ protected:
     if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
   }
 
+  /// \brief Virtual method that performs the actual destruction of
+  /// this statement.
+  ///
+  /// Subclasses should override this method (not Destroy()) to
+  /// provide class-specific destruction.
+  virtual void DoDestroy(ASTContext &Ctx);
+  
 public:
   Stmt(StmtClass SC) : sClass(SC) { 
     if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
   }
   virtual ~Stmt() {}
   
-  virtual void Destroy(ASTContext &Ctx);
+  /// \brief Destroy the current statement and its children.
+  void Destroy(ASTContext &Ctx) { DoDestroy(Ctx); }
 
   StmtClass getStmtClass() const { return sClass; }
   const char *getStmtClassName() const;
@@ -256,6 +264,7 @@ public:
 class DeclStmt : public Stmt {
   DeclGroupRef DG;
   SourceLocation StartLoc, EndLoc;
+  
 public:
   DeclStmt(DeclGroupRef dg, SourceLocation startLoc, 
            SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
@@ -264,8 +273,6 @@ public:
   /// \brief Build an empty declaration statement.
   explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
 
-  virtual void Destroy(ASTContext& Ctx);
-
   /// isSingleDecl - This method returns true if this DeclStmt refers
   /// to a single Decl.
   bool isSingleDecl() const {
index 2338f1457a84d2a91335972b77797f95f4c6304a..28fe348c4591328777de807069f4d2352884ee3c 100644 (file)
@@ -29,13 +29,14 @@ class CXXCatchStmt : public Stmt {
   /// The handler block.
   Stmt *HandlerBlock;
 
+protected:
+  virtual void DoDestroy(ASTContext& Ctx);
+
 public:
   CXXCatchStmt(SourceLocation catchLoc, VarDecl *exDecl, Stmt *handlerBlock)
   : Stmt(CXXCatchStmtClass), CatchLoc(catchLoc), ExceptionDecl(exDecl),
     HandlerBlock(handlerBlock) {}
 
-  virtual void Destroy(ASTContext& Ctx);
-
   virtual SourceRange getSourceRange() const {
     return SourceRange(CatchLoc, HandlerBlock->getLocEnd());
   }
index 842caa8d00a82e71e69a6353f5ea7c027b203958..0f3cbe18d9e923c5e58762c0c052d42ec099c5bf 100644 (file)
@@ -111,10 +111,9 @@ StringLiteral* StringLiteral::Clone(ASTContext &C) const {
                 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 @@ CallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty)
   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 @@ void ShuffleVectorExpr::setExprs(Expr ** Exprs, unsigned NumExprs) {
   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 @@ void SizeOfAlignOfExpr::Destroy(ASTContext& C) {
     C.Deallocate(this);
   }
   else
-    Expr::Destroy(C);
+    Expr::DoDestroy(C);
 }
 
 //===----------------------------------------------------------------------===//
@@ -1831,9 +1830,9 @@ void DesignatedInitExpr::ExpandDesignator(unsigned Idx,
   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 {
index d8e069d0002c97396e09535757951c68a5a896fc..67d62a94ecefe0f087c0881f2fc0215afacd7d92 100644 (file)
 #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 @@ TemplateIdRefExpr::Create(ASTContext &Context, QualType T,
                                      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 @@ CXXTemporary *CXXTemporary::Create(ASTContext &C,
   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 @@ CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
   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 @@ CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
     }
 }
 
-void CXXConstructExpr::Destroy(ASTContext &C) {
+void CXXConstructExpr::DoDestroy(ASTContext &C) {
   DestroyChildren(C);
   if (Args)
     C.Deallocate(Args);
@@ -438,7 +432,7 @@ CXXExprWithTemporaries *CXXExprWithTemporaries::Create(ASTContext &C,
                                         ShouldDestroyTemps);
 }
 
-void CXXExprWithTemporaries::Destroy(ASTContext &C) {
+void CXXExprWithTemporaries::DoDestroy(ASTContext &C) {
   DestroyChildren(C);
   this->~CXXExprWithTemporaries();
   C.Deallocate(this);
index 17577910d2a36da81ffcf4018648c22f75fe259d..668f7ef57fb6fb6f190df3004aa8825c06ddcc46 100644 (file)
@@ -51,19 +51,12 @@ void Stmt::DestroyChildren(ASTContext &C) {
     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 @@ QualType CXXCatchStmt::getCaughtType() {
   return QualType();
 }
 
-void CXXCatchStmt::Destroy(ASTContext& C) {
+void CXXCatchStmt::DoDestroy(ASTContext& C) {
   if (ExceptionDecl)
     ExceptionDecl->Destroy(C);
-  Stmt::Destroy(C);
+  Stmt::DoDestroy(C);
 }
 
 // CXXTryStmt