[cfe-commits] r72643 - in /cfe/trunk: include/clang/AST/ExprCXX.h lib/AST/ExprCXX.cpp lib/Sema/SemaExprCXX.cpp

Anders Carlsson andersca at mac.com
Sat May 30 15:38:54 PDT 2009


Author: andersca
Date: Sat May 30 17:38:53 2009
New Revision: 72643

URL: http://llvm.org/viewvc/llvm-project?rev=72643&view=rev
Log:
Clean up the newly added C++ AST nodes.

Modified:
    cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/trunk/lib/AST/ExprCXX.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Sat May 30 17:38:53 2009
@@ -419,10 +419,12 @@
   
   CXXTemporary(const CXXDestructorDecl *destructor)
     : Destructor(destructor) { }
+  ~CXXTemporary() { }
 
 public:
   static CXXTemporary *Create(ASTContext &C, 
                               const CXXDestructorDecl *Destructor);
+  void Destroy(ASTContext &C);
 };
 
 /// CXXBindTemporaryExpr - Represents binding an expression to a temporary, 
@@ -435,13 +437,18 @@
   CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr) 
    : Expr(CXXBindTemporaryExprClass,
           subexpr->getType()), Temp(temp), SubExpr(subexpr) { }
-  
+  ~CXXBindTemporaryExpr() { } 
+
 public:
   static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 
                                       Expr* SubExpr);
+  void Destroy(ASTContext &C);
+  
+  CXXTemporary *getTemporary() { return Temp; }
   
   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
+  void setSubExpr(Expr *E) { SubExpr = E; }
 
   virtual SourceRange getSourceRange() const { return SourceRange(); }
 
@@ -1013,13 +1020,26 @@
   CXXTemporary **Temps;
   unsigned NumTemps;
 
-public:
   CXXExprWithTemporaries(Expr *subexpr, CXXTemporary **temps, 
                          unsigned numtemps);
   ~CXXExprWithTemporaries();
-
+  
+public:
+  static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
+                                        CXXTemporary **Temps, 
+                                        unsigned NumTemps);
+  void Destroy(ASTContext &C);
+  
+  unsigned getNumTemporaries() const { return NumTemps; }
+  CXXTemporary *getTemporary(unsigned i) {
+    assert(i < NumTemps && "Index out of range");
+    return Temps[i];
+  }
+  void removeLastTemporary() { NumTemps--; }
+  
   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
+  void setSubExpr(Expr *E) { SubExpr = E; }
 
   virtual SourceRange getSourceRange() const { return SourceRange(); }
 

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

==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Sat May 30 17:38:53 2009
@@ -238,8 +238,12 @@
 
 CXXTemporary *CXXTemporary::Create(ASTContext &C, 
                                    const CXXDestructorDecl *Destructor) {
-  // FIXME: Allocate using the ASTContext.
-  return new CXXTemporary(Destructor);
+  return new (C) CXXTemporary(Destructor);
+}
+
+void CXXTemporary::Destroy(ASTContext &C) {
+  this->~CXXTemporary();
+  C.Deallocate(this);
 }
 
 CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, 
@@ -251,6 +255,12 @@
   return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
 }
 
+void CXXBindTemporaryExpr::Destroy(ASTContext &C) {
+  Temp->Destroy(C);
+  this->~CXXBindTemporaryExpr();
+  C.Deallocate(this);
+}
+
 CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
                                                CXXConstructorDecl *Cons,
                                                QualType writtenTy,
@@ -306,6 +316,19 @@
   }
 }
 
+CXXExprWithTemporaries *CXXExprWithTemporaries::Create(ASTContext &C, 
+                                                       Expr *SubExpr,
+                                                       CXXTemporary **Temps, 
+                                                       unsigned NumTemps) {
+  return new (C) CXXExprWithTemporaries(SubExpr, Temps, NumTemps);
+}
+
+void CXXExprWithTemporaries::Destroy(ASTContext &C) {
+  DestroyChildren(C);
+  this->~CXXExprWithTemporaries();
+  C.Deallocate(this);
+}
+
 CXXExprWithTemporaries::~CXXExprWithTemporaries() {
   delete[] Temps;
 }

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=72643&r1=72642&r2=72643&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sat May 30 17:38:53 2009
@@ -1547,9 +1547,9 @@
 
   if (FullExpr && !ExprTemporaries.empty()) {
     // Create a cleanup expr.
-    FullExpr = 
-      new (Context) CXXExprWithTemporaries(FullExpr, &ExprTemporaries[0],
-                                           ExprTemporaries.size());
+    FullExpr = CXXExprWithTemporaries::Create(Context, FullExpr,
+                                              &ExprTemporaries[0], 
+                                              ExprTemporaries.size());
     ExprTemporaries.clear();
   }
 





More information about the cfe-commits mailing list