]> granicus.if.org Git - clang/commitdiff
Add CXXRecordDecl::getIndirectPrimaryBases.
authorAnders Carlsson <andersca@mac.com>
Wed, 24 Nov 2010 22:50:27 +0000 (22:50 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 24 Nov 2010 22:50:27 +0000 (22:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120129 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/CXXInheritance.h
include/clang/AST/DeclCXX.h
lib/AST/CXXInheritance.cpp
lib/CodeGen/CGRecordLayoutBuilder.cpp

index 5a84e404a1b6b5fdfcb59b8676d09c9376b65247..2d30cb3b8b6252444522d636721a998688dd98e9 100644 (file)
@@ -20,6 +20,7 @@
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeOrdering.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include <list>
 #include <map>
@@ -359,7 +360,11 @@ public:
 /// subobjects of that type.
 class CXXFinalOverriderMap 
   : public llvm::DenseMap<const CXXMethodDecl *, OverridingMethods> { };
-  
+
+/// \brief A set of all the primary bases for a class.
+class CXXIndirectPrimaryBaseSet
+  : public llvm::SmallSet<const CXXRecordDecl*, 32> { };
+
 } // end namespace clang
 
 #endif
index 53f04fd79ab69d3699443b0af7b7094648b95b71..0a7e755a9aac2c42d2d002dc32e4979d3c3db742 100644 (file)
@@ -35,6 +35,7 @@ class CXXMethodDecl;
 class CXXRecordDecl;
 class CXXMemberLookupCriteria;
 class CXXFinalOverriderMap;
+class CXXIndirectPrimaryBaseSet;
 class FriendDecl;
   
 /// \brief Represents any kind of function declaration, whether it is a
@@ -955,6 +956,9 @@ public:
   /// most-derived class in the class hierarchy.
   void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
 
+  /// \brief Get the indirect primary bases for this class.
+  void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
+
   /// viewInheritance - Renders and displays an inheritance diagram
   /// for this C++ class and all of its base classes (transitively) using
   /// GraphViz.
index c563c37d58f45ea4d98036017c1865bf60b8690c..90a214ed8e7b5832168749f4c31cf0efdba60434 100644 (file)
@@ -11,6 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/RecordLayout.h"
 #include "clang/AST/DeclCXX.h"
 #include <algorithm>
 #include <set>
@@ -662,3 +663,50 @@ CXXRecordDecl::getFinalOverriders(CXXFinalOverriderMap &FinalOverriders) const {
     }
   }
 }
+
+static void 
+AddIndirectPrimaryBases(const CXXRecordDecl *RD, ASTContext &Context,
+                        CXXIndirectPrimaryBaseSet& Bases) {
+  // If the record has a virtual primary base class, add it to our set.
+  const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
+  if (Layout.getPrimaryBaseWasVirtual())
+    Bases.insert(Layout.getPrimaryBase());
+
+  for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
+       E = RD->bases_end(); I != E; ++I) {
+    assert(!E->getType()->isDependentType() &&
+           "Cannot get indirect primary bases for class with dependent bases.");
+
+    const CXXRecordDecl *BaseDecl =
+      cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
+
+    // Only bases with virtual bases participate in computing the
+    // indirect primary virtual base classes.
+    if (BaseDecl->getNumVBases())
+      AddIndirectPrimaryBases(BaseDecl, Context, Bases);
+  }
+
+}
+
+void 
+CXXRecordDecl::getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const {
+  ASTContext &Context = getASTContext();
+
+  if (!getNumVBases())
+    return;
+
+  for (CXXRecordDecl::base_class_const_iterator I = bases_begin(),
+       E = bases_end(); I != E; ++I) {
+    assert(!E->getType()->isDependentType() &&
+           "Cannot get indirect primary bases for class with dependent bases.");
+
+    const CXXRecordDecl *BaseDecl =
+      cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
+
+    // Only bases with virtual bases participate in computing the
+    // indirect primary virtual base classes.
+    if (BaseDecl->getNumVBases())
+      AddIndirectPrimaryBases(BaseDecl, Context, Bases);
+  }
+}
+
index f846fca50691b3439b52e8116882bc0d3f94d494..fcaf1e112d60889b496c6040ce97981305185005 100644 (file)
@@ -14,6 +14,7 @@
 #include "CGRecordLayout.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecordLayout.h"
@@ -63,7 +64,11 @@ public:
 
   typedef std::pair<const CXXRecordDecl *, unsigned> LLVMBaseInfo;
   llvm::SmallVector<LLVMBaseInfo, 16> LLVMNonVirtualBases;
-  
+
+  /// IndirectPrimaryBases - Virtual base classes, direct or indirect, that are
+  /// primary base classes for some other direct or indirect base class.
+  CXXIndirectPrimaryBaseSet IndirectPrimaryBases;
+
   /// IsZeroInitializable - Whether this struct can be C++
   /// zero-initialized with an LLVM zeroinitializer.
   bool IsZeroInitializable;