Add CXXExprWithCleanup

llvm-svn: 70000
This commit is contained in:
Anders Carlsson 2009-04-24 22:47:04 +00:00
parent cd2a8c5864
commit defc644e06
4 changed files with 54 additions and 0 deletions

View File

@ -21,6 +21,7 @@
namespace clang {
class CXXConstructorDecl;
class CXXTempVarDecl;
//===--------------------------------------------------------------------===//
// C++ Expressions.
@ -946,6 +947,32 @@ public:
virtual child_iterator child_end();
};
class CXXExprWithCleanup : public Expr {
Stmt *SubExpr;
CXXTempVarDecl **Decls;
unsigned NumDecls;
public:
CXXExprWithCleanup(Expr *subexpr, CXXTempVarDecl **decls, unsigned numdecls);
~CXXExprWithCleanup();
const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
Expr *getSubExpr() { return cast<Expr>(SubExpr); }
virtual SourceRange getSourceRange() const { return SourceRange(); }
// Implement isa/cast/dyncast/etc.
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXExprWithCleanupClass;
}
static bool classof(const CXXExprWithCleanup *) { return true; }
// Iterators
virtual child_iterator child_begin();
virtual child_iterator child_end();
};
} // end namespace clang
#endif

View File

@ -121,6 +121,7 @@ STMT(QualifiedDeclRefExpr , DeclRefExpr)
STMT(UnresolvedDeclRefExpr , Expr)
STMT(CXXDestroyExpr , Expr)
STMT(CXXConstructExpr , Expr)
STMT(CXXExprWithCleanup , Expr)
// Obj-C Expressions.
STMT(ObjCStringLiteral , Expr)

View File

@ -274,6 +274,22 @@ CXXDestroyExpr *CXXDestroyExpr::Create(ASTContext &C, VarDecl *vd) {
return new (C) CXXDestroyExpr(vd, C.VoidTy);
}
CXXExprWithCleanup::CXXExprWithCleanup(Expr *subexpr, CXXTempVarDecl **decls,
unsigned numdecls)
: Expr(CXXExprWithCleanupClass, subexpr->getType(),
subexpr->isTypeDependent(), subexpr->isValueDependent()),
SubExpr(subexpr), Decls(0), NumDecls(numdecls) {
if (NumDecls > 0) {
Decls = new CXXTempVarDecl*[NumDecls];
for (unsigned i = 0; i < NumDecls; ++i)
Decls[i] = decls[i];
}
}
CXXExprWithCleanup::~CXXExprWithCleanup() {
delete[] Decls;
}
// CXXConstructExpr
Stmt::child_iterator CXXConstructExpr::child_begin() {
return &Args[0];
@ -289,3 +305,8 @@ Stmt::child_iterator CXXDestroyExpr::child_begin() {
Stmt::child_iterator CXXDestroyExpr::child_end() {
return child_iterator();
}
// CXXExprWithCleanup
Stmt::child_iterator CXXExprWithCleanup::child_begin() { return &SubExpr; }
Stmt::child_iterator CXXExprWithCleanup::child_end() { return &SubExpr + 1; }

View File

@ -1105,6 +1105,11 @@ void StmtPrinter::VisitCXXDestroyExpr(CXXDestroyExpr *E) {
// Nothing to print.
}
void StmtPrinter::VisitCXXExprWithCleanup(CXXExprWithCleanup *E) {
// Just forward to the sub expression.
PrintExpr(E->getSubExpr());
}
static const char *getTypeTraitName(UnaryTypeTrait UTT) {
switch (UTT) {
default: assert(false && "Unknown type trait");