forked from OSchip/llvm-project
Add a CXXConstructExpr that represents an implicit call to a C++ constructor. I think CXXTemporaryObjectExpr is going to become a subclass of CXXConstructExpr, since CXXTemporaryObjectExpr represents a syntactic temporary, for example T()
llvm-svn: 69854
This commit is contained in:
parent
22b0ada8cf
commit
0781ce7cce
|
@ -890,10 +890,57 @@ public:
|
|||
virtual StmtIterator child_end();
|
||||
};
|
||||
|
||||
/// CXXConstructExpr - Represents a call to a C++ constructor.
|
||||
class CXXConstructExpr : public Expr {
|
||||
VarDecl *VD;
|
||||
CXXConstructorDecl *Constructor;
|
||||
|
||||
bool Elidable;
|
||||
|
||||
Stmt **Args;
|
||||
unsigned NumArgs;
|
||||
|
||||
CXXConstructExpr(ASTContext &C, VarDecl *vd, QualType T,
|
||||
CXXConstructorDecl *d, bool elidable,
|
||||
Expr **args, unsigned numargs);
|
||||
~CXXConstructExpr() { }
|
||||
|
||||
public:
|
||||
static CXXConstructExpr *Create(ASTContext &C, VarDecl *VD, QualType T,
|
||||
CXXConstructorDecl *D, bool Elidable,
|
||||
Expr **Args, unsigned NumArgs);
|
||||
|
||||
void Destroy(ASTContext &C);
|
||||
|
||||
const VarDecl* getVarDecl() const { return VD; }
|
||||
const CXXConstructorDecl* getConstructor() const { return Constructor; }
|
||||
|
||||
typedef ExprIterator arg_iterator;
|
||||
typedef ConstExprIterator const_arg_iterator;
|
||||
|
||||
arg_iterator arg_begin() { return Args; }
|
||||
arg_iterator arg_end() { return Args + NumArgs; }
|
||||
const_arg_iterator arg_begin() const { return Args; }
|
||||
const_arg_iterator arg_end() const { return Args + NumArgs; }
|
||||
|
||||
unsigned getNumArgs() const { return NumArgs; }
|
||||
|
||||
virtual SourceRange getSourceRange() const { return SourceRange(); }
|
||||
|
||||
static bool classof(const Stmt *T) {
|
||||
return T->getStmtClass() == CXXConstructExprClass;
|
||||
}
|
||||
static bool classof(const CXXConstructExpr *) { return true; }
|
||||
|
||||
// Iterators
|
||||
virtual child_iterator child_begin();
|
||||
virtual child_iterator child_end();
|
||||
};
|
||||
|
||||
/// CXXDestroyExpr - Represents an implicit call to a C++ destructor.
|
||||
class CXXDestroyExpr : public Expr {
|
||||
VarDecl *VD;
|
||||
|
||||
protected:
|
||||
CXXDestroyExpr(VarDecl* vd, QualType T)
|
||||
: Expr(CXXDestroyExprClass, T, false, vd->getType()->isDependentType()),
|
||||
VD(vd) { }
|
||||
|
|
|
@ -120,6 +120,7 @@ STMT(UnaryTypeTraitExpr , Expr)
|
|||
STMT(QualifiedDeclRefExpr , DeclRefExpr)
|
||||
STMT(UnresolvedDeclRefExpr , Expr)
|
||||
STMT(CXXDestroyExpr , Expr)
|
||||
STMT(CXXConstructExpr , Expr)
|
||||
|
||||
// Obj-C Expressions.
|
||||
STMT(ObjCStringLiteral , Expr)
|
||||
|
|
|
@ -254,6 +254,37 @@ CXXTemporaryObjectExpr::~CXXTemporaryObjectExpr() {
|
|||
delete [] Args;
|
||||
}
|
||||
|
||||
CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, VarDecl *VD,
|
||||
QualType T, CXXConstructorDecl *D,
|
||||
bool Elidable,
|
||||
Expr **Args, unsigned NumArgs) {
|
||||
return new (C) CXXConstructExpr(C, VD, T, D, Elidable, Args, NumArgs);
|
||||
}
|
||||
|
||||
CXXConstructExpr::CXXConstructExpr(ASTContext &C, VarDecl *vd,
|
||||
QualType T, CXXConstructorDecl *D,
|
||||
bool elidable,
|
||||
Expr **args, unsigned numargs)
|
||||
: Expr(CXXConstructExprClass, T,
|
||||
T->isDependentType(),
|
||||
(T->isDependentType() ||
|
||||
CallExpr::hasAnyValueDependentArguments(args, numargs))),
|
||||
VD(vd), Constructor(D), Elidable(elidable), Args(0), NumArgs(numargs) {
|
||||
if (NumArgs > 0) {
|
||||
Args = new (C) Stmt*[NumArgs];
|
||||
for (unsigned i = 0; i < NumArgs; ++i)
|
||||
Args[i] = args[i];
|
||||
}
|
||||
}
|
||||
|
||||
void CXXConstructExpr::Destroy(ASTContext &C) {
|
||||
DestroyChildren(C);
|
||||
if (Args)
|
||||
C.Deallocate(Args);
|
||||
this->~CXXConstructExpr();
|
||||
C.Deallocate(this);
|
||||
}
|
||||
|
||||
CXXDestroyExpr *CXXDestroyExpr::Create(ASTContext &C, VarDecl *vd) {
|
||||
assert(vd->getKind() == Decl::CXXTempVar || vd->getKind() == Decl::Var &&
|
||||
"Can only create a destroy expr with a temp var decl or a var decl!");
|
||||
|
@ -261,6 +292,15 @@ CXXDestroyExpr *CXXDestroyExpr::Create(ASTContext &C, VarDecl *vd) {
|
|||
return new (C) CXXDestroyExpr(vd, C.VoidTy);
|
||||
}
|
||||
|
||||
// CXXConstructExpr
|
||||
Stmt::child_iterator CXXConstructExpr::child_begin() {
|
||||
return &Args[0];
|
||||
}
|
||||
Stmt::child_iterator CXXConstructExpr::child_end() {
|
||||
return &Args[0]+NumArgs;
|
||||
}
|
||||
|
||||
// CXXDestroyExpr
|
||||
Stmt::child_iterator CXXDestroyExpr::child_begin() {
|
||||
return child_iterator();
|
||||
}
|
||||
|
|
|
@ -1097,6 +1097,10 @@ void StmtPrinter::VisitUnresolvedFunctionNameExpr(UnresolvedFunctionNameExpr *E)
|
|||
OS << E->getName().getAsString();
|
||||
}
|
||||
|
||||
void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
|
||||
// Nothing to print.
|
||||
}
|
||||
|
||||
void StmtPrinter::VisitCXXDestroyExpr(CXXDestroyExpr *E) {
|
||||
// Nothing to print.
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue