本文整理汇总了C++中cxxrecorddecl::base_class_const_iterator::isVirtual方法的典型用法代码示例。如果您正苦于以下问题:C++ base_class_const_iterator::isVirtual方法的具体用法?C++ base_class_const_iterator::isVirtual怎么用?C++ base_class_const_iterator::isVirtual使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cxxrecorddecl::base_class_const_iterator
的用法示例。
在下文中一共展示了base_class_const_iterator::isVirtual方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
void
ASTRecordLayoutBuilder::SelectPrimaryVBase(const CXXRecordDecl *RD,
const CXXRecordDecl *&FirstPrimary) {
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
assert(!i->getType()->isDependentType() &&
"Cannot layout class with dependent bases.");
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
if (!i->isVirtual()) {
SelectPrimaryVBase(Base, FirstPrimary);
if (PrimaryBase.getBase())
return;
continue;
}
if (IsNearlyEmpty(Base)) {
if (FirstPrimary==0)
FirstPrimary = Base;
if (!IndirectPrimaryBases.count(Base)) {
setPrimaryBase(Base, /*IsVirtual=*/true);
return;
}
}
assert(i->isVirtual());
SelectPrimaryVBase(Base, FirstPrimary);
if (PrimaryBase.getBase())
return;
}
}
示例2: WriteNode
void InheritanceHierarchyWriter::WriteNode(QualType Type, bool FromVirtual) {
QualType CanonType = Context.getCanonicalType(Type);
if (FromVirtual) {
if (KnownVirtualBases.find(CanonType) != KnownVirtualBases.end())
return;
// We haven't seen this virtual base before, so display it and
// its bases.
KnownVirtualBases.insert(CanonType);
}
// Declare the node itself.
Out << " ";
WriteNodeReference(Type, FromVirtual);
// Give the node a label based on the name of the class.
std::string TypeName = Type.getAsString();
Out << " [ shape=\"box\", label=\"" << DOT::EscapeString(TypeName);
// If the name of the class was a typedef or something different
// from the "real" class name, show the real class name in
// parentheses so we don't confuse ourselves.
if (TypeName != CanonType.getAsString()) {
Out << "\\n(" << CanonType.getAsString() << ")";
}
// Finished describing the node.
Out << " \"];\n";
// Display the base classes.
const CXXRecordDecl *Decl
= static_cast<const CXXRecordDecl *>(Type->getAs<RecordType>()->getDecl());
for (CXXRecordDecl::base_class_const_iterator Base = Decl->bases_begin();
Base != Decl->bases_end(); ++Base) {
QualType CanonBaseType = Context.getCanonicalType(Base->getType());
// If this is not virtual inheritance, bump the direct base
// count for the type.
if (!Base->isVirtual())
++DirectBaseCount[CanonBaseType];
// Write out the node (if we need to).
WriteNode(Base->getType(), Base->isVirtual());
// Write out the edge.
Out << " ";
WriteNodeReference(Type, FromVirtual);
Out << " -> ";
WriteNodeReference(Base->getType(), Base->isVirtual());
// Write out edge attributes to show the kind of inheritance.
if (Base->isVirtual()) {
Out << " [ style=\"dashed\" ]";
}
Out << ";";
}
}
示例3:
/// LayoutVirtualBases - layout the non-virtual bases of a record decl.
bool
CGRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *RD,
const ASTRecordLayout &Layout) {
for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
E = RD->bases_end(); I != E; ++I) {
const CXXRecordDecl *BaseDecl =
cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
// We only want to lay out virtual bases that aren't indirect primary bases
// of some other base.
if (I->isVirtual() && !IndirectPrimaryBases.count(BaseDecl)) {
// Only lay out the base once.
if (!LaidOutVirtualBases.insert(BaseDecl))
continue;
CharUnits vbaseOffset = Layout.getVBaseClassOffset(BaseDecl);
if (!LayoutVirtualBase(BaseDecl, vbaseOffset))
return false;
}
if (!BaseDecl->getNumVBases()) {
// This base isn't interesting since it doesn't have any virtual bases.
continue;
}
if (!LayoutVirtualBases(BaseDecl, Layout))
return false;
}
return true;
}
示例4: if
bool
CGRecordLayoutBuilder::LayoutNonVirtualBases(const CXXRecordDecl *RD,
const ASTRecordLayout &Layout) {
const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
// If we have a primary base, lay it out first.
if (PrimaryBase) {
if (!Layout.isPrimaryBaseVirtual()) {
if (!LayoutNonVirtualBase(PrimaryBase, CharUnits::Zero()))
return false;
} else {
if (!LayoutVirtualBase(PrimaryBase, CharUnits::Zero()))
return false;
}
// Otherwise, add a vtable / vf-table if the layout says to do so.
} else if (Layout.hasOwnVFPtr()) {
llvm::Type *FunctionType =
llvm::FunctionType::get(llvm::Type::getInt32Ty(Types.getLLVMContext()),
/*isVarArg=*/true);
llvm::Type *VTableTy = FunctionType->getPointerTo();
if (getTypeAlignment(VTableTy) > Alignment) {
// FIXME: Should we allow this to happen in Sema?
assert(!Packed && "Alignment is wrong even with packed struct!");
return false;
}
assert(NextFieldOffset.isZero() &&
"VTable pointer must come first!");
AppendField(CharUnits::Zero(), VTableTy->getPointerTo());
}
// Layout the non-virtual bases.
for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
E = RD->bases_end(); I != E; ++I) {
if (I->isVirtual())
continue;
const CXXRecordDecl *BaseDecl =
cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
// We've already laid out the primary base.
if (BaseDecl == PrimaryBase && !Layout.isPrimaryBaseVirtual())
continue;
if (!LayoutNonVirtualBase(BaseDecl, Layout.getBaseClassOffset(BaseDecl)))
return false;
}
// Add a vb-table pointer if the layout insists.
if (Layout.hasOwnVBPtr()) {
CharUnits VBPtrOffset = Layout.getVBPtrOffset();
llvm::Type *Vbptr = llvm::Type::getInt32PtrTy(Types.getLLVMContext());
AppendPadding(VBPtrOffset, getTypeAlignment(Vbptr));
AppendField(VBPtrOffset, Vbptr);
}
return true;
}
示例5: UpdateEmptyClassOffsets
void ASTRecordLayoutBuilder::UpdateEmptyClassOffsets(const CXXRecordDecl *RD,
uint64_t Offset) {
if (RD->isEmpty())
EmptyClassOffsets.insert(std::make_pair(Offset, RD));
const ASTRecordLayout &Info = Ctx.getASTRecordLayout(RD);
// Update bases.
for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
E = RD->bases_end(); I != E; ++I) {
assert(!I->getType()->isDependentType() &&
"Cannot layout class with dependent bases.");
if (I->isVirtual())
continue;
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
uint64_t BaseClassOffset = Info.getBaseClassOffset(Base);
UpdateEmptyClassOffsets(Base, Offset + BaseClassOffset);
}
// Update fields.
unsigned FieldNo = 0;
for (CXXRecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
I != E; ++I, ++FieldNo) {
const FieldDecl *FD = *I;
uint64_t FieldOffset = Info.getFieldOffset(FieldNo);
UpdateEmptyClassOffsets(FD, Offset + FieldOffset);
}
// FIXME: Update virtual bases.
}
示例6: LayoutVirtualVTTs
void VTTBuilder::LayoutVirtualVTTs(const CXXRecordDecl *RD,
VisitedVirtualBasesSetTy &VBases) {
for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
E = RD->bases_end(); I != E; ++I) {
const CXXRecordDecl *BaseDecl =
cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
// Check if this is a virtual base.
if (I->isVirtual()) {
// Check if we've seen this base before.
if (!VBases.insert(BaseDecl))
continue;
CharUnits BaseOffset =
MostDerivedClassLayout.getVBaseClassOffset(BaseDecl);
LayoutVTT(BaseSubobject(BaseDecl, BaseOffset), /*BaseIsVirtual=*/true);
}
// We only need to layout virtual VTTs for this base if it actually has
// virtual bases.
if (BaseDecl->getNumVBases())
LayoutVirtualVTTs(BaseDecl, VBases);
}
}
示例7: CanUseSingleInheritance
// CanUseSingleInheritance - Return whether the given record decl has a "single,
// public, non-virtual base at offset zero (i.e. the derived class is dynamic
// iff the base is)", according to Itanium C++ ABI, 2.95p6b.
static bool CanUseSingleInheritance(const CXXRecordDecl *RD) {
// Check the number of bases.
if (RD->getNumBases() != 1)
return false;
// Get the base.
CXXRecordDecl::base_class_const_iterator Base = RD->bases_begin();
// Check that the base is not virtual.
if (Base->isVirtual())
return false;
// Check that the base is public.
if (Base->getAccessSpecifier() != AS_public)
return false;
// Check that the class is dynamic iff the base is.
const CXXRecordDecl *BaseDecl =
cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
if (!BaseDecl->isEmpty() &&
BaseDecl->isDynamicClass() != RD->isDynamicClass())
return false;
return true;
}
示例8: LayoutVirtualBases
void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *RD,
const CXXRecordDecl *PB,
int64_t Offset,
llvm::SmallSet<const CXXRecordDecl*, 32> &mark,
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary) {
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
#if 0
const ASTRecordLayout &L = Ctx.getASTRecordLayout(Base);
const CXXRecordDecl *PB = L.getPrimaryBase();
if (PB && L.getPrimaryBaseWasVirtual()
&& IndirectPrimary.count(PB)) {
int64_t BaseOffset;
// FIXME: calculate this.
BaseOffset = (1<<63) | (1<<31);
VBases.push_back(PB);
VBaseOffsets.push_back(BaseOffset);
}
#endif
int64_t BaseOffset = Offset;;
// FIXME: Calculate BaseOffset.
if (i->isVirtual()) {
if (Base == PB) {
// Only lay things out once.
if (mark.count(Base))
continue;
// Mark it so we don't lay it out twice.
mark.insert(Base);
assert (IndirectPrimary.count(Base) && "IndirectPrimary was wrong");
VBases.push_back(Base);
VBaseOffsets.push_back(Offset);
} else if (IndirectPrimary.count(Base)) {
// Someone else will eventually lay this out.
;
} else {
// Only lay things out once.
if (mark.count(Base))
continue;
// Mark it so we don't lay it out twice.
mark.insert(Base);
LayoutVirtualBase(Base);
BaseOffset = *(VBaseOffsets.end()-1);
}
}
if (Base->getNumVBases()) {
const ASTRecordLayout &L = Ctx.getASTRecordLayout(Base);
const CXXRecordDecl *PB = L.getPrimaryBase();
LayoutVirtualBases(Base, PB, BaseOffset, mark, IndirectPrimary);
}
}
}
示例9: LayoutBaseNonVirtually
void
ASTRecordLayoutBuilder::LayoutNonVirtualBases(const CXXRecordDecl *RD) {
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
if (!i->isVirtual()) {
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
// Skip the PrimaryBase here, as it is laid down first.
if (Base != PrimaryBase || PrimaryBaseWasVirtual)
LayoutBaseNonVirtually(Base, false);
}
}
}
示例10: LayoutVirtualBases
void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *Class,
const CXXRecordDecl *RD,
const CXXRecordDecl *PB,
uint64_t Offset,
llvm::SmallSet<const CXXRecordDecl*, 32> &mark,
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary) {
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
assert(!i->getType()->isDependentType() &&
"Cannot layout class with dependent bases.");
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
uint64_t BaseOffset = Offset;
if (i->isVirtual()) {
if (Base == PB) {
// Only lay things out once.
if (mark.count(Base))
continue;
// Mark it so we don't lay it out twice.
mark.insert(Base);
assert (IndirectPrimary.count(Base) && "IndirectPrimary was wrong");
VBases.push_back(std::make_pair(Base, Offset));
} else if (IndirectPrimary.count(Base)) {
// Someone else will eventually lay this out.
;
} else {
// Only lay things out once.
if (mark.count(Base))
continue;
// Mark it so we don't lay it out twice.
mark.insert(Base);
LayoutVirtualBase(Base);
BaseOffset = VBases.back().second;
}
} else {
if (RD == Class)
BaseOffset = getBaseOffset(Base);
else {
const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
BaseOffset = Offset + Layout.getBaseClassOffset(Base);
}
}
if (Base->getNumVBases()) {
const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Base);
const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBaseInfo().getBase();
LayoutVirtualBases(Class, Base, PrimaryBase, BaseOffset, mark,
IndirectPrimary);
}
}
}
示例11: SelectPrimaryBase
/// SelectPrimaryBase - Selects the primary base for the given class and
/// record that with setPrimaryBase. We also calculate the IndirectPrimaries.
void ASTRecordLayoutBuilder::SelectPrimaryBase(const CXXRecordDecl *RD) {
// Compute all the primary virtual bases for all of our direct and
// indirect bases, and record all their primary virtual base classes.
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
assert(!i->getType()->isDependentType() &&
"Cannot layout class with dependent bases.");
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
IdentifyPrimaryBases(Base);
}
// If the record has a dynamic base class, attempt to choose a primary base
// class. It is the first (in direct base class order) non-virtual dynamic
// base class, if one exists.
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
// Ignore virtual bases.
if (i->isVirtual())
continue;
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
if (Base->isDynamicClass()) {
// We found it.
PrimaryBase = ASTRecordLayout::PrimaryBaseInfo(Base, /*IsVirtual=*/false);
return;
}
}
// Otherwise, it is the first nearly empty virtual base that is not an
// indirect primary virtual base class, if one exists.
// If we have no virtual bases at this point, bail out as the searching below
// is expensive.
if (RD->getNumVBases() == 0)
return;
// Then we can search for the first nearly empty virtual base itself.
const CXXRecordDecl *FirstPrimary = 0;
SelectPrimaryVBase(RD, FirstPrimary);
// Otherwise if is the first nearly empty virtual base, if one exists,
// otherwise there is no primary base class.
if (!PrimaryBase.getBase())
setPrimaryBase(FirstPrimary, /*IsVirtual=*/true);
}
示例12: canPlaceRecordAtOffset
bool ASTRecordLayoutBuilder::canPlaceRecordAtOffset(const CXXRecordDecl *RD,
uint64_t Offset) const {
// Look for an empty class with the same type at the same offset.
for (EmptyClassOffsetsTy::const_iterator I =
EmptyClassOffsets.lower_bound(Offset),
E = EmptyClassOffsets.upper_bound(Offset); I != E; ++I) {
if (I->second == RD)
return false;
}
const ASTRecordLayout &Info = Ctx.getASTRecordLayout(RD);
// Check bases.
for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
E = RD->bases_end(); I != E; ++I) {
assert(!I->getType()->isDependentType() &&
"Cannot layout class with dependent bases.");
if (I->isVirtual())
continue;
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
uint64_t BaseClassOffset = Info.getBaseClassOffset(Base);
if (!canPlaceRecordAtOffset(Base, Offset + BaseClassOffset))
return false;
}
// Check fields.
unsigned FieldNo = 0;
for (CXXRecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
I != E; ++I, ++FieldNo) {
const FieldDecl *FD = *I;
uint64_t FieldOffset = Info.getFieldOffset(FieldNo);
if (!canPlaceFieldAtOffset(FD, Offset + FieldOffset))
return false;
}
// FIXME: virtual bases.
return true;
}
示例13: SelectPrimaryBase
/// SelectPrimaryBase - Selects the primary base for the given class and
/// record that with setPrimaryBase. We also calculate the IndirectPrimaries.
void ASTRecordLayoutBuilder::SelectPrimaryBase(const CXXRecordDecl *RD,
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary) {
// We compute all the primary virtual bases for all of our direct and
// indirect bases, and record all their primary virtual base classes.
const CXXRecordDecl *FirstPrimary = 0;
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
SelectPrimaryForBase(Base, IndirectPrimary);
}
// The primary base is the first non-virtual indirect or direct base class,
// if one exists.
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
if (!i->isVirtual()) {
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
if (Base->isDynamicClass()) {
setPrimaryBase(Base, false);
return;
}
}
}
setPrimaryBase(0, false);
// Otherwise, it is the first nearly empty virtual base that is not an
// indirect primary virtual base class, if one exists.
// If we have no virtual bases at this point, bail out as the searching below
// is expensive.
if (RD->getNumVBases() == 0)
return;
// Then we can search for the first nearly empty virtual base itself.
SelectPrimaryVBase(RD, FirstPrimary, IndirectPrimary);
// Otherwise if is the first nearly empty virtual base, if one exists,
// otherwise there is no primary base class.
setPrimaryBase(FirstPrimary, true);
return;
}
示例14: LayoutSecondaryVTTs
void VTTBuilder::LayoutSecondaryVTTs(BaseSubobject Base) {
const CXXRecordDecl *RD = Base.getBase();
for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
E = RD->bases_end(); I != E; ++I) {
// Don't layout virtual bases.
if (I->isVirtual())
continue;
const CXXRecordDecl *BaseDecl =
cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
CharUnits BaseOffset = Base.getBaseOffset() +
Layout.getBaseClassOffset(BaseDecl);
// Layout the VTT for this base.
LayoutVTT(BaseSubobject(BaseDecl, BaseOffset), /*BaseIsVirtual=*/false);
}
}
示例15: SelectPrimaryVBase
void ASTRecordLayoutBuilder::SelectPrimaryVBase(const CXXRecordDecl *RD,
const CXXRecordDecl *&FirstPrimary,
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary) {
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
if (!i->isVirtual()) {
SelectPrimaryVBase(Base, FirstPrimary, IndirectPrimary);
if (PrimaryBase)
return;
continue;
}
if (IsNearlyEmpty(Base)) {
if (FirstPrimary==0)
FirstPrimary = Base;
if (!IndirectPrimary.count(Base)) {
setPrimaryBase(Base, true);
return;
}
}
}
}