Record layout builder cleanup.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82502 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anders Carlsson 2009-09-22 00:04:45 +00:00
Родитель 183700f494
Коммит e4feb834fb
3 изменённых файлов: 19 добавлений и 29 удалений

Просмотреть файл

@ -91,9 +91,10 @@ class ASTRecordLayout {
const uint64_t *fieldoffsets, unsigned fieldcount,
uint64_t nonvirtualsize, unsigned nonvirtualalign,
const CXXRecordDecl *PB, bool PBVirtual,
const CXXRecordDecl **bases, const uint64_t *baseoffsets,
unsigned basecount, const CXXRecordDecl **vbases,
const uint64_t *vbaseoffsets,unsigned vbasecount)
const std::pair<const CXXRecordDecl *, uint64_t> *bases,
unsigned numbases,
const std::pair<const CXXRecordDecl *, uint64_t> *vbases,
unsigned numvbases)
: Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment),
FieldCount(fieldcount), CXXInfo(new CXXRecordLayoutInfo) {
if (FieldCount > 0) {
@ -106,10 +107,10 @@ class ASTRecordLayout {
CXXInfo->PrimaryBaseWasVirtual = PBVirtual;
CXXInfo->NonVirtualSize = nonvirtualsize;
CXXInfo->NonVirtualAlign = nonvirtualalign;
for (unsigned i = 0; i != basecount; ++i)
CXXInfo->BaseOffsets[bases[i]] = baseoffsets[i];
for (unsigned i = 0; i != vbasecount; ++i)
CXXInfo->VBaseOffsets[vbases[i]] = vbaseoffsets[i];
for (unsigned i = 0; i != numbases; ++i)
CXXInfo->BaseOffsets[bases[i].first] = bases[i].second;
for (unsigned i = 0; i != numvbases; ++i)
CXXInfo->VBaseOffsets[vbases[i].first] = vbases[i].second;
}
~ASTRecordLayout() {

Просмотреть файл

@ -198,8 +198,7 @@ void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *RD,
// 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);
VBases.push_back(std::make_pair(Base, Offset));
} else if (IndirectPrimary.count(Base)) {
// Someone else will eventually lay this out.
;
@ -210,7 +209,7 @@ void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *RD,
// Mark it so we don't lay it out twice.
mark.insert(Base);
LayoutVirtualBase(Base);
BaseOffset = *(VBaseOffsets.end()-1);
BaseOffset = VBases.back().second;
}
}
if (Base->getNumVBases()) {
@ -236,13 +235,10 @@ void ASTRecordLayoutBuilder::LayoutBaseNonVirtually(const CXXRecordDecl *RD,
Size = (Size + (BaseAlign-1)) & ~(BaseAlign-1);
// Add base class offsets.
if (IsVirtualBase) {
VBases.push_back(RD);
VBaseOffsets.push_back(Size);
} else {
Bases.push_back(RD);
BaseOffsets.push_back(Size);
}
if (IsVirtualBase)
VBases.push_back(std::make_pair(RD, Size));
else
Bases.push_back(std::make_pair(RD, Size));
#if 0
// And now add offsets for all our primary virtual bases as well, so
@ -469,11 +465,6 @@ ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx,
// FIXME: IsPODForThePurposeOfLayout should be stored in the record layout.
bool IsPODForThePurposeOfLayout = cast<CXXRecordDecl>(D)->isPOD();
assert(Builder.Bases.size() == Builder.BaseOffsets.size() &&
"Base offsets vector must be same size as bases vector!");
assert(Builder.VBases.size() == Builder.VBaseOffsets.size() &&
"Base offsets vector must be same size as bases vector!");
// FIXME: This should be done in FinalizeLayout.
uint64_t DataSize =
IsPODForThePurposeOfLayout ? Builder.Size : Builder.NextOffset;
@ -488,10 +479,8 @@ ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx,
Builder.PrimaryBase,
Builder.PrimaryBaseWasVirtual,
Builder.Bases.data(),
Builder.BaseOffsets.data(),
Builder.Bases.size(),
Builder.VBases.data(),
Builder.VBaseOffsets.data(),
Builder.VBases.size());
}

Просмотреть файл

@ -40,11 +40,11 @@ class ASTRecordLayoutBuilder {
const CXXRecordDecl *PrimaryBase;
bool PrimaryBaseWasVirtual;
llvm::SmallVector<const CXXRecordDecl *, 4> Bases;
llvm::SmallVector<uint64_t, 4> BaseOffsets;
llvm::SmallVector<const CXXRecordDecl *, 4> VBases;
llvm::SmallVector<uint64_t, 4> VBaseOffsets;
typedef llvm::SmallVector<std::pair<const CXXRecordDecl *,
uint64_t>, 4> BaseOffsetsTy;
BaseOffsetsTy Bases;
BaseOffsetsTy VBases;
ASTRecordLayoutBuilder(ASTContext &Ctx);