[cfe-commits] r94791 - in /cfe/trunk: include/clang/AST/ExprCXX.h include/clang/AST/StmtNodes.def lib/AST/Expr.cpp lib/AST/ExprCXX.cpp lib/AST/StmtPrinter.cpp lib/AST/StmtProfile.cpp lib/CodeGen/CGExpr.cpp lib/Sema/TreeTransform.h tools/CIndex/CXCursor.cpp

Anders Carlsson andersca at mac.com
Thu Jan 28 18:39:33 PST 2010


Author: andersca
Date: Thu Jan 28 20:39:32 2010
New Revision: 94791

URL: http://llvm.org/viewvc/llvm-project?rev=94791&view=rev
Log:
Add an CXXBindReferenceExpr (not used just yet).

Modified:
    cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/trunk/include/clang/AST/StmtNodes.def
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/AST/ExprCXX.cpp
    cfe/trunk/lib/AST/StmtPrinter.cpp
    cfe/trunk/lib/AST/StmtProfile.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/tools/CIndex/CXCursor.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=94791&r1=94790&r2=94791&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Thu Jan 28 20:39:32 2010
@@ -544,6 +544,60 @@
   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.
 class CXXConstructExpr : public Expr {
   CXXConstructorDecl *Constructor;

Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=94791&r1=94790&r2=94791&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Thu Jan 28 20:39:32 2010
@@ -129,6 +129,7 @@
 EXPR(DependentScopeDeclRefExpr  , Expr)
 EXPR(CXXConstructExpr       , Expr)
 EXPR(CXXBindTemporaryExpr   , Expr)
+EXPR(CXXBindReferenceExpr   , Expr)
 EXPR(CXXExprWithTemporaries , Expr)
 EXPR(CXXTemporaryObjectExpr , CXXConstructExpr)
 EXPR(CXXUnresolvedConstructExpr, Expr)

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=94791&r1=94790&r2=94791&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu Jan 28 20:39:32 2010
@@ -1205,6 +1205,9 @@
   case CXXBindTemporaryExprClass:
     return cast<CXXBindTemporaryExpr>(this)->getSubExpr()->
       isLvalueInternal(Ctx);
+  case CXXBindReferenceExprClass:
+    // Something that's bound to a reference is always an lvalue.
+    return LV_Valid;
   case ConditionalOperatorClass: {
     // Complicated handling is only for C++.
     if (!Ctx.getLangOptions().CPlusPlus)
@@ -1594,6 +1597,7 @@
   case Expr::DependentScopeDeclRefExprClass:
   case Expr::CXXConstructExprClass:
   case Expr::CXXBindTemporaryExprClass:
+  case Expr::CXXBindReferenceExprClass:
   case Expr::CXXExprWithTemporariesClass:
   case Expr::CXXTemporaryObjectExprClass:
   case Expr::CXXUnresolvedConstructExprClass:

Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=94791&r1=94790&r2=94791&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Thu Jan 28 20:39:32 2010
@@ -395,6 +395,19 @@
   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,
                                                CXXConstructorDecl *Cons,
                                                QualType writtenTy,
@@ -493,6 +506,15 @@
   return &SubExpr + 1;
 }
 
+// CXXBindReferenceExpr
+Stmt::child_iterator CXXBindReferenceExpr::child_begin() {
+  return &SubExpr;
+}
+
+Stmt::child_iterator CXXBindReferenceExpr::child_end() {
+  return &SubExpr + 1;
+}
+
 // CXXConstructExpr
 Stmt::child_iterator CXXConstructExpr::child_begin() {
   return &Args[0];

Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=94791&r1=94790&r2=94791&view=diff

==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Thu Jan 28 20:39:32 2010
@@ -1038,6 +1038,10 @@
   PrintExpr(Node->getSubExpr());
 }
 
+void StmtPrinter::VisitCXXBindReferenceExpr(CXXBindReferenceExpr *Node) {
+  PrintExpr(Node->getSubExpr());
+}
+
 void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
   OS << Node->getType().getAsString();
   OS << "(";

Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=94791&r1=94790&r2=94791&view=diff

==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Thu Jan 28 20:39:32 2010
@@ -465,6 +465,10 @@
          const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
 }
 
+void StmtProfiler::VisitCXXBindReferenceExpr(CXXBindReferenceExpr *S) {
+  VisitExpr(S);
+}
+
 void StmtProfiler::VisitCXXConstructExpr(CXXConstructExpr *S) {
   VisitExpr(S);
   VisitDecl(S->getConstructor());

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=94791&r1=94790&r2=94791&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jan 28 20:39:32 2010
@@ -456,6 +456,8 @@
     return EmitCXXConstructLValue(cast<CXXConstructExpr>(E));
   case Expr::CXXBindTemporaryExprClass:
     return EmitCXXBindTemporaryLValue(cast<CXXBindTemporaryExpr>(E));
+  case Expr::CXXBindReferenceExprClass:
+    return EmitLValue(cast<CXXBindReferenceExpr>(E)->getSubExpr());
   case Expr::CXXExprWithTemporariesClass:
     return EmitCXXExprWithTemporariesLValue(cast<CXXExprWithTemporaries>(E));
   case Expr::CXXZeroInitValueExprClass:

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=94791&r1=94790&r2=94791&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Thu Jan 28 20:39:32 2010
@@ -4865,6 +4865,16 @@
   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
 /// be destroyed after the expression is evaluated.
 ///

Modified: cfe/trunk/tools/CIndex/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CXCursor.cpp?rev=94791&r1=94790&r2=94791&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CXCursor.cpp (original)
+++ cfe/trunk/tools/CIndex/CXCursor.cpp Thu Jan 28 20:39:32 2010
@@ -165,6 +165,7 @@
   case Stmt::UnaryTypeTraitExprClass:     
   case Stmt::DependentScopeDeclRefExprClass:  
   case Stmt::CXXBindTemporaryExprClass:   
+  case Stmt::CXXBindReferenceExprClass:   
   case Stmt::CXXExprWithTemporariesClass: 
   case Stmt::CXXUnresolvedConstructExprClass:
   case Stmt::CXXDependentScopeMemberExprClass:





More information about the cfe-commits mailing list