24 #include "llvm/Support/Casting.h" 28 using namespace clang;
30 #define DUMP_OVERRIDERS 0 34 bool GenerateDefinition)
35 : Ctx(Ctx), MostDerivedClass(MostDerivedClass),
36 MostDerivedClassLayout(Ctx.getASTRecordLayout(MostDerivedClass)),
37 GenerateDefinition(GenerateDefinition) {
46 if (VTableClass == MostDerivedClass) {
47 assert(!SecondaryVirtualPointerIndices.count(Base) &&
48 "A virtual pointer index already exists for this base subobject!");
49 SecondaryVirtualPointerIndices[Base] = VTTComponents.size();
52 if (!GenerateDefinition) {
57 VTTComponents.push_back(
VTTComponent(VTableIndex, Base));
63 for (
const auto &I : RD->
bases()) {
69 cast<CXXRecordDecl>(I.getType()->getAs<
RecordType>()->getDecl());
73 Layout.getBaseClassOffset(BaseDecl);
81 VTTBuilder::LayoutSecondaryVirtualPointers(
BaseSubobject Base,
82 bool BaseIsMorallyVirtual,
85 VisitedVirtualBasesSetTy &VBases) {
93 for (
const auto &I : RD->
bases()) {
95 cast<CXXRecordDecl>(I.getType()->getAs<
RecordType>()->getDecl());
107 bool BaseDeclIsMorallyVirtual = BaseIsMorallyVirtual;
108 bool BaseDeclIsNonVirtualPrimaryBase =
false;
112 if (!VBases.insert(BaseDecl).second)
116 BaseDeclIsMorallyVirtual =
true;
125 BaseDeclIsNonVirtualPrimaryBase =
true;
133 if (!BaseDeclIsNonVirtualPrimaryBase &&
134 (BaseDecl->
getNumVBases() || BaseDeclIsMorallyVirtual)) {
136 AddVTablePointer(
BaseSubobject(BaseDecl, BaseOffset), VTableIndex,
141 LayoutSecondaryVirtualPointers(
BaseSubobject(BaseDecl, BaseOffset),
142 BaseDeclIsMorallyVirtual, VTableIndex,
143 VTableClass, VBases);
148 VTTBuilder::LayoutSecondaryVirtualPointers(
BaseSubobject Base,
149 uint64_t VTableIndex) {
150 VisitedVirtualBasesSetTy VBases;
151 LayoutSecondaryVirtualPointers(Base,
false,
152 VTableIndex, Base.
getBase(), VBases);
156 VisitedVirtualBasesSetTy &VBases) {
157 for (
const auto &I : RD->
bases()) {
159 cast<CXXRecordDecl>(I.getType()->getAs<
RecordType>()->getDecl());
164 if (!VBases.insert(BaseDecl).second)
176 LayoutVirtualVTTs(BaseDecl, VBases);
180 void VTTBuilder::LayoutVTT(
BaseSubobject Base,
bool BaseIsVirtual) {
189 bool IsPrimaryVTT = Base.
getBase() == MostDerivedClass;
193 SubVTTIndicies[Base] = VTTComponents.size();
196 uint64_t VTableIndex = VTTVTables.size();
197 VTTVTables.push_back(
VTTVTable(Base, BaseIsVirtual));
200 AddVTablePointer(Base, VTableIndex, RD);
203 LayoutSecondaryVTTs(Base);
206 LayoutSecondaryVirtualPointers(Base, VTableIndex);
210 VisitedVirtualBasesSetTy VBases;
211 LayoutVirtualVTTs(Base.
getBase(), VBases);
Defines the clang::ASTContext interface.
bool isPrimaryBaseVirtual() const
isPrimaryBaseVirtual - Get whether the primary base for this record is virtual or not...
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
C Language Family Type Representation.
CharUnits getBaseOffset() const
getBaseOffset - Returns the base class offset.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const
getVBaseClassOffset - Get the offset, in chars, for the given base class.
CharUnits - This is an opaque type for sizes expressed in character units.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
bool isDynamicClass() const
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
const CXXRecordDecl * getPrimaryBase() const
getPrimaryBase - Get the primary base for this record.
const CXXRecordDecl * getBase() const
getBase - Returns the base class declaration.
Dataflow Directional Tag Classes.
VTTBuilder(ASTContext &Ctx, const CXXRecordDecl *MostDerivedClass, bool GenerateDefinition)
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Represents a C++ struct/union/class.