[cfe-commits] r78375 - in /cfe/trunk: 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

Douglas Gregor dgregor at apple.com
Thu Aug 6 23:08:38 PDT 2009


Author: dgregor
Date: Fri Aug  7 01:08:38 2009
New Revision: 78375

URL: http://llvm.org/viewvc/llvm-project?rev=78375&view=rev
Log:
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). 


Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/include/clang/AST/StmtCXX.h
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/AST/ExprCXX.cpp
    cfe/trunk/lib/AST/Stmt.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Aug  7 01:08:38 2009
@@ -564,6 +564,10 @@
   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 @@
   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 @@
     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 @@
   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 @@
   // 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 @@
 
   ~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 @@
     : 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 @@
 
   virtual SourceRange getSourceRange() const;
 
-  virtual void Destroy(ASTContext &C);
-
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == DesignatedInitExprClass; 
   }

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

==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Fri Aug  7 01:08:38 2009
@@ -431,7 +431,8 @@
 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 @@
           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 @@
                    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 @@
                   /*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 @@
                     unsigned NumTemplateArgs,
                     SourceLocation RAngleLoc);
   
+  virtual void DoDestroy(ASTContext &Context);
+  
 public:
   static TemplateIdRefExpr *
   Create(ASTContext &Context, QualType T,
@@ -1080,8 +1084,6 @@
          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 @@
   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) {

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

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Fri Aug  7 01:08:38 2009
@@ -155,13 +155,21 @@
     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 @@
 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 @@
   /// \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 {

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

==============================================================================
--- cfe/trunk/include/clang/AST/StmtCXX.h (original)
+++ cfe/trunk/include/clang/AST/StmtCXX.h Fri Aug  7 01:08:38 2009
@@ -29,13 +29,14 @@
   /// 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());
   }

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

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Aug  7 01:08:38 2009
@@ -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 {

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

==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Fri Aug  7 01:08:38 2009
@@ -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);

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

==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Fri Aug  7 01:08:38 2009
@@ -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





More information about the cfe-commits mailing list