From 88eaf075c56672761b72cc50957db4a35bf24ebd Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 30 May 2009 22:38:53 +0000 Subject: [PATCH] Clean up the newly added C++ AST nodes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72643 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ExprCXX.h | 26 +++++++++++++++++++++++--- lib/AST/ExprCXX.cpp | 27 +++++++++++++++++++++++++-- lib/Sema/SemaExprCXX.cpp | 6 +++--- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index b9bb588e67..852a0916cc 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -419,10 +419,12 @@ class CXXTemporary { 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 @@ class CXXBindTemporaryExpr : public Expr { 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(SubExpr); } Expr *getSubExpr() { return cast(SubExpr); } + void setSubExpr(Expr *E) { SubExpr = E; } virtual SourceRange getSourceRange() const { return SourceRange(); } @@ -1013,13 +1020,26 @@ class CXXExprWithTemporaries : public Expr { 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(SubExpr); } Expr *getSubExpr() { return cast(SubExpr); } + void setSubExpr(Expr *E) { SubExpr = E; } virtual SourceRange getSourceRange() const { return SourceRange(); } diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index fccef01260..4a15245591 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -238,8 +238,12 @@ const char *CXXNamedCastExpr::getCastName() const { 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 @@ CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, 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(Expr *subexpr, } } +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; } diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 2fde49caaf..a8a260dd2e 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -1547,9 +1547,9 @@ Sema::OwningExprResult Sema::ActOnFinishFullExpr(ExprArg Arg) { 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(); } -- 2.40.0