23 #include "llvm/Support/Casting.h" 27 using namespace clang;
29 #define DUMP_OVERRIDERS 0 33 bool GenerateDefinition)
34 : Ctx(Ctx), MostDerivedClass(MostDerivedClass),
35 MostDerivedClassLayout(Ctx.getASTRecordLayout(MostDerivedClass)),
36 GenerateDefinition(GenerateDefinition) {
45 if (VTableClass == MostDerivedClass) {
46 assert(!SecondaryVirtualPointerIndices.count(Base) &&
47 "A virtual pointer index already exists for this base subobject!");
48 SecondaryVirtualPointerIndices[Base] = VTTComponents.size();
51 if (!GenerateDefinition) {
56 VTTComponents.push_back(
VTTComponent(VTableIndex, Base));
62 for (
const auto &I : RD->
bases()) {
68 cast<CXXRecordDecl>(I.getType()->getAs<
RecordType>()->getDecl());
72 Layout.getBaseClassOffset(BaseDecl);
80 VTTBuilder::LayoutSecondaryVirtualPointers(
BaseSubobject Base,
81 bool BaseIsMorallyVirtual,
84 VisitedVirtualBasesSetTy &VBases) {
92 for (
const auto &I : RD->
bases()) {
94 cast<CXXRecordDecl>(I.getType()->getAs<
RecordType>()->getDecl());
106 bool BaseDeclIsMorallyVirtual = BaseIsMorallyVirtual;
107 bool BaseDeclIsNonVirtualPrimaryBase =
false;
111 if (!VBases.insert(BaseDecl).second)
115 BaseDeclIsMorallyVirtual =
true;
124 BaseDeclIsNonVirtualPrimaryBase =
true;
132 if (!BaseDeclIsNonVirtualPrimaryBase &&
133 (BaseDecl->
getNumVBases() || BaseDeclIsMorallyVirtual)) {
135 AddVTablePointer(
BaseSubobject(BaseDecl, BaseOffset), VTableIndex,
140 LayoutSecondaryVirtualPointers(
BaseSubobject(BaseDecl, BaseOffset),
141 BaseDeclIsMorallyVirtual, VTableIndex,
142 VTableClass, VBases);
147 VTTBuilder::LayoutSecondaryVirtualPointers(
BaseSubobject Base,
148 uint64_t VTableIndex) {
149 VisitedVirtualBasesSetTy VBases;
150 LayoutSecondaryVirtualPointers(Base,
false,
151 VTableIndex, Base.
getBase(), VBases);
155 VisitedVirtualBasesSetTy &VBases) {
156 for (
const auto &I : RD->
bases()) {
158 cast<CXXRecordDecl>(I.getType()->getAs<
RecordType>()->getDecl());
163 if (!VBases.insert(BaseDecl).second)
175 LayoutVirtualVTTs(BaseDecl, VBases);
179 void VTTBuilder::LayoutVTT(
BaseSubobject Base,
bool BaseIsVirtual) {
188 bool IsPrimaryVTT = Base.
getBase() == MostDerivedClass;
192 SubVTTIndicies[Base] = VTTComponents.size();
195 uint64_t VTableIndex = VTTVTables.size();
196 VTTVTables.push_back(
VTTVTable(Base, BaseIsVirtual));
199 AddVTablePointer(Base, VTableIndex, RD);
202 LayoutSecondaryVTTs(Base);
205 LayoutSecondaryVirtualPointers(Base, VTableIndex);
209 VisitedVirtualBasesSetTy VBases;
210 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.