[cfe-commits] r69854 - in /cfe/trunk: include/clang/AST/ExprCXX.h include/clang/AST/StmtNodes.def lib/AST/ExprCXX.cpp lib/AST/StmtPrinter.cpp

Anders Carlsson andersca at mac.com
Wed Apr 22 19:32:43 PDT 2009


Author: andersca
Date: Wed Apr 22 21:32:43 2009
New Revision: 69854

URL: http://llvm.org/viewvc/llvm-project?rev=69854&view=rev
Log:
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()

Modified:
    cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/trunk/include/clang/AST/StmtNodes.def
    cfe/trunk/lib/AST/ExprCXX.cpp
    cfe/trunk/lib/AST/StmtPrinter.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Wed Apr 22 21:32:43 2009
@@ -890,10 +890,57 @@
   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) { }

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

==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Wed Apr 22 21:32:43 2009
@@ -120,6 +120,7 @@
 STMT(QualifiedDeclRefExpr   , DeclRefExpr)
 STMT(UnresolvedDeclRefExpr  , Expr)
 STMT(CXXDestroyExpr         , Expr)
+STMT(CXXConstructExpr       , Expr)
 
 // Obj-C Expressions.
 STMT(ObjCStringLiteral    , Expr)

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

==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Wed Apr 22 21:32:43 2009
@@ -254,6 +254,37 @@
   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 @@
   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();
 }

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

==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Wed Apr 22 21:32:43 2009
@@ -1097,6 +1097,10 @@
   OS << E->getName().getAsString();
 }
 
+void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
+  // Nothing to print.
+}
+
 void StmtPrinter::VisitCXXDestroyExpr(CXXDestroyExpr *E) {
   // Nothing to print.
 }





More information about the cfe-commits mailing list