[cfe-commits] r101004 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/AST/DeclCXX.cpp lib/CodeGen/CGClass.cpp lib/Sema/SemaDeclCXX.cpp

Anders Carlsson andersca at mac.com
Sun Apr 11 17:51:03 PDT 2010


Author: andersca
Date: Sun Apr 11 19:51:03 2010
New Revision: 101004

URL: http://llvm.org/viewvc/llvm-project?rev=101004&view=rev
Log:
Have the CXXBaseOrMemberInitializer keep track of whether an initializer initializes a virtual base or not.

Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/AST/DeclCXX.cpp
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=101004&r1=101003&r2=101004&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sun Apr 11 19:51:03 2010
@@ -1057,6 +1057,10 @@
   /// and AnonUnionMember holds field decl for au_i1.
   FieldDecl *AnonUnionMember;
 
+  /// IsVirtual - If the initializer is a base initializer, this keeps track
+  /// of whether the base is virtual or not.
+  bool IsVirtual;
+  
   /// LParenLoc - Location of the left paren of the ctor-initializer.
   SourceLocation LParenLoc;
 
@@ -1067,7 +1071,7 @@
   /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
   explicit
   CXXBaseOrMemberInitializer(ASTContext &Context,
-                             TypeSourceInfo *TInfo,
+                             TypeSourceInfo *TInfo, bool IsVirtual,
                              SourceLocation L, 
                              Expr *Init,
                              SourceLocation R);
@@ -1100,7 +1104,14 @@
   /// Otherwise, returns NULL.
   const Type *getBaseClass() const;
   Type *getBaseClass();
-  
+
+  /// Returns whether the base is virtual or not.
+  bool isBaseVirtual() const {
+    assert(isBaseInitializer() && "Must call this on base initializer!");
+    
+    return IsVirtual;
+  }
+
   /// \brief Returns the declarator information for a base class initializer.
   TypeSourceInfo *getBaseClassInfo() const {
     return BaseOrMember.dyn_cast<TypeSourceInfo *>();

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=101004&r1=101003&r2=101004&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Sun Apr 11 19:51:03 2010
@@ -686,9 +686,9 @@
 
 CXXBaseOrMemberInitializer::
 CXXBaseOrMemberInitializer(ASTContext &Context,
-                           TypeSourceInfo *TInfo, 
+                           TypeSourceInfo *TInfo, bool IsVirtual,
                            SourceLocation L, Expr *Init, SourceLocation R)
-  : BaseOrMember(TInfo), Init(Init), AnonUnionMember(0),
+  : BaseOrMember(TInfo), Init(Init), AnonUnionMember(0), IsVirtual(IsVirtual),
     LParenLoc(L), RParenLoc(R) 
 {
 }

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=101004&r1=101003&r2=101004&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Sun Apr 11 19:51:03 2010
@@ -782,15 +782,7 @@
   CXXRecordDecl *BaseClassDecl =
     cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl());
 
-  // FIXME: This method of determining whether a base is virtual is ridiculous;
-  // it should be part of BaseInit.
-  bool isBaseVirtual = false;
-  for (CXXRecordDecl::base_class_const_iterator I = ClassDecl->vbases_begin(),
-       E = ClassDecl->vbases_end(); I != E; ++I)
-    if (I->getType()->getAs<RecordType>()->getDecl() == BaseClassDecl) {
-      isBaseVirtual = true;
-      break;
-    }
+  bool isBaseVirtual = BaseInit->isBaseVirtual();
 
   // The base constructor doesn't construct virtual bases.
   if (CtorType == Ctor_Base && isBaseVirtual)
@@ -976,8 +968,6 @@
 
   llvm::SmallVector<CXXBaseOrMemberInitializer *, 8> MemberInitializers;
   
-  // FIXME: Add vbase initialization
-  
   for (CXXConstructorDecl::init_const_iterator B = CD->init_begin(),
        E = CD->init_end();
        B != E; ++B) {

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=101004&r1=101003&r2=101004&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sun Apr 11 19:51:03 2010
@@ -1337,6 +1337,7 @@
                           ExprTemporaries.end());
 
     return new (Context) CXXBaseOrMemberInitializer(Context, BaseTInfo, 
+                                                    /*IsVirtual=*/false,
                                                     LParenLoc, 
                                                     BaseInit.takeAs<Expr>(),
                                                     RParenLoc);
@@ -1417,12 +1418,14 @@
       = Owned(new (Context) ParenListExpr(Context, LParenLoc, Args, NumArgs,
                                           RParenLoc));
     return new (Context) CXXBaseOrMemberInitializer(Context, BaseTInfo,
+                                                    BaseSpec->isVirtual(),
                                                     LParenLoc, 
                                                     Init.takeAs<Expr>(),
                                                     RParenLoc);
   }
 
   return new (Context) CXXBaseOrMemberInitializer(Context, BaseTInfo,
+                                                  BaseSpec->isVirtual(),
                                                   LParenLoc, 
                                                   BaseInit.takeAs<Expr>(),
                                                   RParenLoc);
@@ -1494,6 +1497,7 @@
         new (Context) CXXBaseOrMemberInitializer(Context,
                            Context.getTrivialTypeSourceInfo(VBase->getType(), 
                                                             SourceLocation()),
+                                                 /*IsVirtual=*/true,
                                                  SourceLocation(),
                                                  BaseInit.takeAs<Expr>(),
                                                  SourceLocation());
@@ -1528,6 +1532,7 @@
         new (Context) CXXBaseOrMemberInitializer(Context,
                            Context.getTrivialTypeSourceInfo(Base->getType(), 
                                                             SourceLocation()),
+                                                 /*IsVirtual=*/false,
                                                  SourceLocation(),
                                                  BaseInit.takeAs<Expr>(),
                                                  SourceLocation());





More information about the cfe-commits mailing list