зеркало из https://github.com/microsoft/clang-1.git
Add an CXXBindReferenceExpr (not used just yet).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94791 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
4b220fae2f
Коммит
eb60edffa1
|
@ -544,6 +544,60 @@ public:
|
||||||
virtual child_iterator child_end();
|
virtual child_iterator child_end();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// CXXBindReferenceExpr - Represents binding an expression to a reference.
|
||||||
|
/// In the example:
|
||||||
|
///
|
||||||
|
/// const int &i = 10;
|
||||||
|
///
|
||||||
|
/// a bind reference expression is inserted to indicate that 10 is bound to
|
||||||
|
/// a reference. (Ans also that a temporary needs to be created to hold the
|
||||||
|
/// value).
|
||||||
|
class CXXBindReferenceExpr : public Expr {
|
||||||
|
// SubExpr - The expression being bound.
|
||||||
|
Stmt *SubExpr;
|
||||||
|
|
||||||
|
// ExtendsLifetime - Whether binding this reference extends the lifetime of
|
||||||
|
// the expression being bound. FIXME: Add C++ reference.
|
||||||
|
bool ExtendsLifetime;
|
||||||
|
|
||||||
|
/// RequiresTemporaryCopy - Whether binding the subexpression requires a
|
||||||
|
/// temporary copy.
|
||||||
|
bool RequiresTemporaryCopy;
|
||||||
|
|
||||||
|
CXXBindReferenceExpr(Expr *subexpr, bool ExtendsLifetime,
|
||||||
|
bool RequiresTemporaryCopy)
|
||||||
|
: Expr(CXXBindReferenceExprClass, subexpr->getType(), false, false),
|
||||||
|
SubExpr(subexpr), ExtendsLifetime(ExtendsLifetime),
|
||||||
|
RequiresTemporaryCopy(RequiresTemporaryCopy) { }
|
||||||
|
~CXXBindReferenceExpr() { }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void DoDestroy(ASTContext &C);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static CXXBindReferenceExpr *Create(ASTContext &C, Expr *SubExpr,
|
||||||
|
bool ExtendsLifetime,
|
||||||
|
bool RequiresTemporaryCopy);
|
||||||
|
|
||||||
|
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 SubExpr->getSourceRange();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implement isa/cast/dyncast/etc.
|
||||||
|
static bool classof(const Stmt *T) {
|
||||||
|
return T->getStmtClass() == CXXBindReferenceExprClass;
|
||||||
|
}
|
||||||
|
static bool classof(const CXXBindReferenceExpr *) { return true; }
|
||||||
|
|
||||||
|
// Iterators
|
||||||
|
virtual child_iterator child_begin();
|
||||||
|
virtual child_iterator child_end();
|
||||||
|
};
|
||||||
|
|
||||||
/// CXXConstructExpr - Represents a call to a C++ constructor.
|
/// CXXConstructExpr - Represents a call to a C++ constructor.
|
||||||
class CXXConstructExpr : public Expr {
|
class CXXConstructExpr : public Expr {
|
||||||
CXXConstructorDecl *Constructor;
|
CXXConstructorDecl *Constructor;
|
||||||
|
|
|
@ -129,6 +129,7 @@ EXPR(UnaryTypeTraitExpr , Expr)
|
||||||
EXPR(DependentScopeDeclRefExpr , Expr)
|
EXPR(DependentScopeDeclRefExpr , Expr)
|
||||||
EXPR(CXXConstructExpr , Expr)
|
EXPR(CXXConstructExpr , Expr)
|
||||||
EXPR(CXXBindTemporaryExpr , Expr)
|
EXPR(CXXBindTemporaryExpr , Expr)
|
||||||
|
EXPR(CXXBindReferenceExpr , Expr)
|
||||||
EXPR(CXXExprWithTemporaries , Expr)
|
EXPR(CXXExprWithTemporaries , Expr)
|
||||||
EXPR(CXXTemporaryObjectExpr , CXXConstructExpr)
|
EXPR(CXXTemporaryObjectExpr , CXXConstructExpr)
|
||||||
EXPR(CXXUnresolvedConstructExpr, Expr)
|
EXPR(CXXUnresolvedConstructExpr, Expr)
|
||||||
|
|
|
@ -1205,6 +1205,9 @@ Expr::isLvalueResult Expr::isLvalueInternal(ASTContext &Ctx) const {
|
||||||
case CXXBindTemporaryExprClass:
|
case CXXBindTemporaryExprClass:
|
||||||
return cast<CXXBindTemporaryExpr>(this)->getSubExpr()->
|
return cast<CXXBindTemporaryExpr>(this)->getSubExpr()->
|
||||||
isLvalueInternal(Ctx);
|
isLvalueInternal(Ctx);
|
||||||
|
case CXXBindReferenceExprClass:
|
||||||
|
// Something that's bound to a reference is always an lvalue.
|
||||||
|
return LV_Valid;
|
||||||
case ConditionalOperatorClass: {
|
case ConditionalOperatorClass: {
|
||||||
// Complicated handling is only for C++.
|
// Complicated handling is only for C++.
|
||||||
if (!Ctx.getLangOptions().CPlusPlus)
|
if (!Ctx.getLangOptions().CPlusPlus)
|
||||||
|
@ -1594,6 +1597,7 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
|
||||||
case Expr::DependentScopeDeclRefExprClass:
|
case Expr::DependentScopeDeclRefExprClass:
|
||||||
case Expr::CXXConstructExprClass:
|
case Expr::CXXConstructExprClass:
|
||||||
case Expr::CXXBindTemporaryExprClass:
|
case Expr::CXXBindTemporaryExprClass:
|
||||||
|
case Expr::CXXBindReferenceExprClass:
|
||||||
case Expr::CXXExprWithTemporariesClass:
|
case Expr::CXXExprWithTemporariesClass:
|
||||||
case Expr::CXXTemporaryObjectExprClass:
|
case Expr::CXXTemporaryObjectExprClass:
|
||||||
case Expr::CXXUnresolvedConstructExprClass:
|
case Expr::CXXUnresolvedConstructExprClass:
|
||||||
|
|
|
@ -395,6 +395,19 @@ void CXXBindTemporaryExpr::DoDestroy(ASTContext &C) {
|
||||||
C.Deallocate(this);
|
C.Deallocate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CXXBindReferenceExpr *CXXBindReferenceExpr::Create(ASTContext &C, Expr *SubExpr,
|
||||||
|
bool ExtendsLifetime,
|
||||||
|
bool RequiresTemporaryCopy) {
|
||||||
|
return new (C) CXXBindReferenceExpr(SubExpr,
|
||||||
|
ExtendsLifetime,
|
||||||
|
RequiresTemporaryCopy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CXXBindReferenceExpr::DoDestroy(ASTContext &C) {
|
||||||
|
this->~CXXBindReferenceExpr();
|
||||||
|
C.Deallocate(this);
|
||||||
|
}
|
||||||
|
|
||||||
CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
|
CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
|
||||||
CXXConstructorDecl *Cons,
|
CXXConstructorDecl *Cons,
|
||||||
QualType writtenTy,
|
QualType writtenTy,
|
||||||
|
@ -493,6 +506,15 @@ Stmt::child_iterator CXXBindTemporaryExpr::child_end() {
|
||||||
return &SubExpr + 1;
|
return &SubExpr + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CXXBindReferenceExpr
|
||||||
|
Stmt::child_iterator CXXBindReferenceExpr::child_begin() {
|
||||||
|
return &SubExpr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stmt::child_iterator CXXBindReferenceExpr::child_end() {
|
||||||
|
return &SubExpr + 1;
|
||||||
|
}
|
||||||
|
|
||||||
// CXXConstructExpr
|
// CXXConstructExpr
|
||||||
Stmt::child_iterator CXXConstructExpr::child_begin() {
|
Stmt::child_iterator CXXConstructExpr::child_begin() {
|
||||||
return &Args[0];
|
return &Args[0];
|
||||||
|
|
|
@ -1038,6 +1038,10 @@ void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
|
||||||
PrintExpr(Node->getSubExpr());
|
PrintExpr(Node->getSubExpr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StmtPrinter::VisitCXXBindReferenceExpr(CXXBindReferenceExpr *Node) {
|
||||||
|
PrintExpr(Node->getSubExpr());
|
||||||
|
}
|
||||||
|
|
||||||
void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
|
void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
|
||||||
OS << Node->getType().getAsString();
|
OS << Node->getType().getAsString();
|
||||||
OS << "(";
|
OS << "(";
|
||||||
|
|
|
@ -465,6 +465,10 @@ void StmtProfiler::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *S) {
|
||||||
const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
|
const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StmtProfiler::VisitCXXBindReferenceExpr(CXXBindReferenceExpr *S) {
|
||||||
|
VisitExpr(S);
|
||||||
|
}
|
||||||
|
|
||||||
void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
|
void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
|
||||||
VisitExpr(S);
|
VisitExpr(S);
|
||||||
VisitDecl(S->getConstructor());
|
VisitDecl(S->getConstructor());
|
||||||
|
|
|
@ -456,6 +456,8 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
|
||||||
return EmitCXXConstructLValue(cast<CXXConstructExpr>(E));
|
return EmitCXXConstructLValue(cast<CXXConstructExpr>(E));
|
||||||
case Expr::CXXBindTemporaryExprClass:
|
case Expr::CXXBindTemporaryExprClass:
|
||||||
return EmitCXXBindTemporaryLValue(cast<CXXBindTemporaryExpr>(E));
|
return EmitCXXBindTemporaryLValue(cast<CXXBindTemporaryExpr>(E));
|
||||||
|
case Expr::CXXBindReferenceExprClass:
|
||||||
|
return EmitLValue(cast<CXXBindReferenceExpr>(E)->getSubExpr());
|
||||||
case Expr::CXXExprWithTemporariesClass:
|
case Expr::CXXExprWithTemporariesClass:
|
||||||
return EmitCXXExprWithTemporariesLValue(cast<CXXExprWithTemporaries>(E));
|
return EmitCXXExprWithTemporariesLValue(cast<CXXExprWithTemporaries>(E));
|
||||||
case Expr::CXXZeroInitValueExprClass:
|
case Expr::CXXZeroInitValueExprClass:
|
||||||
|
|
|
@ -4865,6 +4865,16 @@ TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
|
||||||
return getDerived().TransformExpr(E->getSubExpr());
|
return getDerived().TransformExpr(E->getSubExpr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Transform a C++ reference-binding expression.
|
||||||
|
///
|
||||||
|
/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
|
||||||
|
/// transform the subexpression and return that.
|
||||||
|
template<typename Derived>
|
||||||
|
Sema::OwningExprResult
|
||||||
|
TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
|
||||||
|
return getDerived().TransformExpr(E->getSubExpr());
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Transform a C++ expression that contains temporaries that should
|
/// \brief Transform a C++ expression that contains temporaries that should
|
||||||
/// be destroyed after the expression is evaluated.
|
/// be destroyed after the expression is evaluated.
|
||||||
///
|
///
|
||||||
|
|
|
@ -165,6 +165,7 @@ CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, ASTUnit *TU) {
|
||||||
case Stmt::UnaryTypeTraitExprClass:
|
case Stmt::UnaryTypeTraitExprClass:
|
||||||
case Stmt::DependentScopeDeclRefExprClass:
|
case Stmt::DependentScopeDeclRefExprClass:
|
||||||
case Stmt::CXXBindTemporaryExprClass:
|
case Stmt::CXXBindTemporaryExprClass:
|
||||||
|
case Stmt::CXXBindReferenceExprClass:
|
||||||
case Stmt::CXXExprWithTemporariesClass:
|
case Stmt::CXXExprWithTemporariesClass:
|
||||||
case Stmt::CXXUnresolvedConstructExprClass:
|
case Stmt::CXXUnresolvedConstructExprClass:
|
||||||
case Stmt::CXXDependentScopeMemberExprClass:
|
case Stmt::CXXDependentScopeMemberExprClass:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче