]> granicus.if.org Git - clang/commitdiff
Add a CXXBindTemporaryExpr.
authorAnders Carlsson <andersca@mac.com>
Sat, 30 May 2009 20:03:25 +0000 (20:03 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 30 May 2009 20:03:25 +0000 (20:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72627 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExprCXX.h
include/clang/AST/StmtNodes.def
lib/AST/ExprCXX.cpp
lib/AST/StmtPrinter.cpp
lib/Sema/SemaTemplateInstantiateExpr.cpp

index 13df65047f050dad91db4deff1b38d3a1bdd0828..ed713c843b2dc874d2840ca69f0af33d2ec2d0d6 100644 (file)
@@ -423,7 +423,38 @@ class CXXTemporary {
 public:
   static CXXTemporary *Create(ASTContext &C, CXXDestructorDecl *Destructor);
 };
+
+/// CXXBindTemporaryExpr - Represents binding an expression to a temporary, 
+/// so its destructor can be called later.
+class CXXBindTemporaryExpr : public Expr {
+  CXXTemporary *Temp;
+  
+  Stmt *SubExpr;
+
+  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr) 
+   : Expr(CXXBindTemporaryExprClass,
+          subexpr->getType()), Temp(temp), SubExpr(subexpr) { }
+  
+public:
+  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 
+                                      Expr* SubExpr);
   
+  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() == CXXBindTemporaryExprClass;
+  }
+  static bool classof(const CXXBindTemporaryExpr *) { return true; }
+
+  // Iterators
+  virtual child_iterator child_begin();
+  virtual child_iterator child_end();
+};
+
 /// CXXConstructExpr - Represents a call to a C++ constructor.
 class CXXConstructExpr : public Expr {
   VarDecl *VD;
index 060a586ee994d43b3696fbdd0255cff981db1988..ab6524663d6324dc3b808674527d66dca390859c 100644 (file)
@@ -124,6 +124,7 @@ EXPR(UnaryTypeTraitExpr     , Expr)
 EXPR(QualifiedDeclRefExpr   , DeclRefExpr)
 EXPR(UnresolvedDeclRefExpr  , Expr)
 EXPR(CXXConstructExpr       , Expr)
+EXPR(CXXBindTemporaryExpr   , Expr)
 EXPR(CXXExprWithTemporaries , Expr)
 EXPR(CXXTemporaryObjectExpr , CXXConstructExpr)
 EXPR(CXXUnresolvedConstructExpr, Expr)
index 16b9c4b67b0695cc546f24672d0f23007b1c6fbc..d0032fb5e5acbbfb17ea413ac88d6ac9bdfa6a0a 100644 (file)
@@ -242,6 +242,15 @@ CXXTemporary *CXXTemporary::Create(ASTContext &C,
   return new CXXTemporary(Destructor);
 }
 
+CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, 
+                                                   CXXTemporary *Temp,
+                                                   Expr* SubExpr) {
+  assert(SubExpr->getType()->isRecordType() && 
+         "Expression bound to a temporary must have record type!");
+
+  return new CXXBindTemporaryExpr(Temp, SubExpr);
+}
+
 CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, VarDecl *vd,
                                                CXXConstructorDecl *Cons,
                                                QualType writtenTy,
@@ -303,6 +312,15 @@ CXXExprWithTemporaries::~CXXExprWithTemporaries() {
   delete[] Decls;
 }
 
+// CXXBindTemporaryExpr
+Stmt::child_iterator CXXBindTemporaryExpr::child_begin() {
+  return &SubExpr;
+}
+
+Stmt::child_iterator CXXBindTemporaryExpr::child_end() { 
+  return &SubExpr + 1;
+}
+
 // CXXConstructExpr
 Stmt::child_iterator CXXConstructExpr::child_begin() {
   return &Args[0];
index 594b98f863e8b926711d345d688a5e9964543ad2..710da6386133e4662ceed09a3cbd28225058bfb3 100644 (file)
@@ -988,6 +988,10 @@ void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
   OS << ")";
 }
 
+void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
+  PrintExpr(Node->getSubExpr());
+}
+
 void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
   OS << Node->getType().getAsString();
   OS << "(";
index c312bb8542001561ccd4ef0434404cbadba41156..3b28813a7251a2aa700191514da170c1df8c1675 100644 (file)
@@ -975,6 +975,16 @@ TemplateExprInstantiator::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
   return SemaRef.ExprError();
 }
 
+Sema::OwningExprResult 
+TemplateExprInstantiator::VisitCXXBindTemporaryExpr(
+                                                  CXXBindTemporaryExpr *E) {
+  OwningExprResult SubExpr = Visit(E->getSubExpr());
+  if (SubExpr.isInvalid())
+    return SemaRef.ExprError();
+
+  return move(SubExpr);
+}
+
 Sema::OwningExprResult 
 TemplateExprInstantiator::VisitCXXConstructExpr(CXXConstructExpr *E) {
   assert(!cast<CXXRecordDecl>(E->getConstructor()->getDeclContext())