]> granicus.if.org Git - clang/commitdiff
Add an enum to CXXConstructExpr so we can determine if the construction expression...
authorAnders Carlsson <andersca@mac.com>
Sun, 2 May 2010 22:54:08 +0000 (22:54 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 2 May 2010 22:54:08 +0000 (22:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102879 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExprCXX.h
lib/AST/ExprCXX.cpp
lib/Sema/Sema.h
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaInit.cpp

index d26efa7296c925bd4be69311c73351720b435ac9..250e09af53d2a8b156f92df8ff476e006b5099df 100644 (file)
@@ -630,12 +630,20 @@ public:
 
 /// CXXConstructExpr - Represents a call to a C++ constructor.
 class CXXConstructExpr : public Expr {
+public:
+  enum ConstructionKind {
+    CK_Complete,
+    CK_NonVirtualBase,
+    CK_VirtualBase
+  };
+    
+private:
   CXXConstructorDecl *Constructor;
 
   SourceLocation Loc;
   bool Elidable : 1;
   bool ZeroInitialization : 1;
-  bool BaseInitialization : 1;
+  unsigned ConstructKind : 2;
   Stmt **Args;
   unsigned NumArgs;
 
@@ -645,7 +653,7 @@ protected:
                    CXXConstructorDecl *d, bool elidable,
                    Expr **args, unsigned numargs,
                    bool ZeroInitialization = false,
-                   bool BaseInitialization = false);
+                   ConstructionKind ConstructKind = CK_Complete);
   ~CXXConstructExpr() { }
 
   virtual void DoDestroy(ASTContext &C);
@@ -682,8 +690,12 @@ public:
   
   /// \brief Determines whether this constructor is actually constructing
   /// a base class (rather than a complete object).
-  bool isBaseInitialization() const { return BaseInitialization; }
-  void setBaseInitialization(bool BI) { BaseInitialization = BI; }
+  bool isBaseInitialization() const { 
+    return ConstructKind != CK_Complete;
+  }
+  void setConstructionKind(ConstructionKind CK) { 
+    ConstructKind = CK;
+  }
   
   typedef ExprIterator arg_iterator;
   typedef ConstExprIterator const_arg_iterator;
index 592d887d31076be0f492d873e8e199630c87477a..1b94aa0ca3a8205a2ba283ba07b40d15d1963676 100644 (file)
@@ -474,22 +474,23 @@ CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
                                            bool BaseInitialization) {
   return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D, 
                                   Elidable, Args, NumArgs, ZeroInitialization,
-                                  BaseInitialization);
+                                  BaseInitialization ? CK_NonVirtualBase :
+                                  CK_Complete);
 }
 
 CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
                                    SourceLocation Loc,
                                    CXXConstructorDecl *D, bool elidable,
                                    Expr **args, unsigned numargs,
-                                   bool ZeroInitialization,
-                                   bool BaseInitialization)
+                                   bool ZeroInitialization, 
+                                   ConstructionKind ConstructKind)
 : Expr(SC, T,
        T->isDependentType(),
        (T->isDependentType() ||
         CallExpr::hasAnyValueDependentArguments(args, numargs))),
   Constructor(D), Loc(Loc), Elidable(elidable), 
-  ZeroInitialization(ZeroInitialization), 
-  BaseInitialization(BaseInitialization), Args(0), NumArgs(numargs) 
+  ZeroInitialization(ZeroInitialization), ConstructKind(ConstructKind),
+  Args(0), NumArgs(numargs) 
 {
   if (NumArgs) {
     Args = new (C) Stmt*[NumArgs];
index 1c82baf617197eb2c20dd13ec5423709c1c4d54d..8a9be3ab0153ff56c1620f0330b5a67b10a9c2a7 100644 (file)
@@ -25,6 +25,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/FullExpr.h"
 #include "clang/Parse/Action.h"
 #include "clang/Sema/SemaDiagnostic.h"
@@ -2140,22 +2141,21 @@ public:
 
   /// BuildCXXConstructExpr - Creates a complete call to a constructor,
   /// including handling of its default argument expressions.
-  OwningExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc,
-                                         QualType DeclInitType,
-                                         CXXConstructorDecl *Constructor,
-                                         MultiExprArg Exprs,
-                                         bool RequiresZeroInit = false,
-                                         bool BaseInitialization = false);
+  OwningExprResult
+  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
+                        CXXConstructorDecl *Constructor, MultiExprArg Exprs,
+                        bool RequiresZeroInit = false,
+                        CXXConstructExpr::ConstructionKind ConstructKind =
+                        CXXConstructExpr::CK_Complete);
 
   // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
   // the constructor can be elidable?
-  OwningExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc,
-                                         QualType DeclInitType,
-                                         CXXConstructorDecl *Constructor,
-                                         bool Elidable,
-                                         MultiExprArg Exprs,
-                                         bool RequiresZeroInit = false,
-                                         bool BaseInitialization = false);
+  OwningExprResult
+  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
+                        CXXConstructorDecl *Constructor, bool Elidable,
+                        MultiExprArg Exprs, bool RequiresZeroInit = false,
+                        CXXConstructExpr::ConstructionKind ConstructKind =
+                        CXXConstructExpr::CK_Complete);
 
   /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
   /// the default expr if needed.
index e4a154d400cd39269d6fa1e2f7eb49368ac2a2b8..d628d4407771c031a1c88aac82230841d45b6480 100644 (file)
@@ -4579,7 +4579,7 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
                             CXXConstructorDecl *Constructor,
                             MultiExprArg ExprArgs,
                             bool RequiresZeroInit,
-                            bool BaseInitialization) {
+                            CXXConstructExpr::ConstructionKind ConstructKind) {
   bool Elidable = false;
 
   // C++0x [class.copy]p34:
@@ -4601,7 +4601,7 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
 
   return BuildCXXConstructExpr(ConstructLoc, DeclInitType, Constructor,
                                Elidable, move(ExprArgs), RequiresZeroInit,
-                               BaseInitialization);
+                               ConstructKind);
 }
 
 /// BuildCXXConstructExpr - Creates a complete call to a constructor,
@@ -4611,14 +4611,14 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
                             CXXConstructorDecl *Constructor, bool Elidable,
                             MultiExprArg ExprArgs,
                             bool RequiresZeroInit,
-                            bool BaseInitialization) {
+                            CXXConstructExpr::ConstructionKind ConstructKind) {
   unsigned NumExprs = ExprArgs.size();
   Expr **Exprs = (Expr **)ExprArgs.release();
 
   MarkDeclarationReferenced(ConstructLoc, Constructor);
   return Owned(CXXConstructExpr::Create(Context, DeclInitType, ConstructLoc,
                                         Constructor, Elidable, Exprs, NumExprs, 
-                                        RequiresZeroInit, BaseInitialization));
+                                        RequiresZeroInit, ConstructKind));
 }
 
 bool Sema::InitializeVarWithConstructor(VarDecl *VD,
index 4678822413d69ebc71d187ec9f9d440bbd6437c8..5e6aa2c0a660cc1398b3150f0c945468acc49c42 100644 (file)
@@ -3747,12 +3747,21 @@ InitializationSequence::Perform(Sema &S,
                                                                  NumExprs,
                                                 Kind.getParenRange().getEnd(),
                                              ConstructorInitRequiresZeroInit));
-      } else
+      } else {
+        CXXConstructExpr::ConstructionKind ConstructKind =
+          CXXConstructExpr::CK_Complete;
+        
+        if (Entity.getKind() == InitializedEntity::EK_Base) {
+          ConstructKind = Entity.getBaseSpecifier()->isVirtual() ?
+            CXXConstructExpr::CK_VirtualBase : 
+            CXXConstructExpr::CK_NonVirtualBase;
+        }    
         CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType(),
                                           Constructor, 
                                           move_arg(ConstructorArgs),
                                           ConstructorInitRequiresZeroInit,
-                               Entity.getKind() == InitializedEntity::EK_Base);
+                                          ConstructKind);
+      }
       if (CurInit.isInvalid())
         return S.ExprError();