2010-03-09 04:56:29 +08:00
|
|
|
//===-- RecordLayout.cpp - Layout information for a struct/union -*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the RecordLayout interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/RecordLayout.h"
|
2011-09-28 03:12:27 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2010-03-09 04:56:29 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
void ASTRecordLayout::Destroy(ASTContext &Ctx) {
|
2010-08-25 08:32:19 +08:00
|
|
|
if (CXXInfo) {
|
|
|
|
CXXInfo->~CXXRecordLayoutInfo();
|
2014-05-24 15:19:25 +08:00
|
|
|
Ctx.Deallocate(CXXInfo);
|
2010-08-25 08:32:19 +08:00
|
|
|
}
|
2010-03-09 04:56:29 +08:00
|
|
|
this->~ASTRecordLayout();
|
|
|
|
Ctx.Deallocate(this);
|
|
|
|
}
|
|
|
|
|
2011-02-09 09:59:34 +08:00
|
|
|
ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CharUnits size,
|
2016-05-25 02:10:50 +08:00
|
|
|
CharUnits alignment,
|
2013-12-06 08:01:17 +08:00
|
|
|
CharUnits requiredAlignment,
|
|
|
|
CharUnits datasize,
|
2016-05-25 02:10:50 +08:00
|
|
|
ArrayRef<uint64_t> fieldoffsets)
|
|
|
|
: Size(size), DataSize(datasize), Alignment(alignment),
|
|
|
|
RequiredAlignment(requiredAlignment), CXXInfo(nullptr) {
|
|
|
|
FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
|
2010-03-09 04:56:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor for C++ records.
|
2011-01-12 17:06:06 +08:00
|
|
|
ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx,
|
2011-02-15 10:32:40 +08:00
|
|
|
CharUnits size, CharUnits alignment,
|
2013-12-06 08:01:17 +08:00
|
|
|
CharUnits requiredAlignment,
|
2013-11-14 06:16:13 +08:00
|
|
|
bool hasOwnVFPtr, bool hasExtendableVFPtr,
|
2013-10-12 04:19:00 +08:00
|
|
|
CharUnits vbptroffset,
|
2011-10-22 06:49:56 +08:00
|
|
|
CharUnits datasize,
|
2016-05-25 02:10:50 +08:00
|
|
|
ArrayRef<uint64_t> fieldoffsets,
|
2011-02-01 09:52:10 +08:00
|
|
|
CharUnits nonvirtualsize,
|
2014-01-09 08:30:56 +08:00
|
|
|
CharUnits nonvirtualalignment,
|
2010-11-01 06:13:23 +08:00
|
|
|
CharUnits SizeOfLargestEmptySubobject,
|
2010-05-26 13:20:58 +08:00
|
|
|
const CXXRecordDecl *PrimaryBase,
|
2010-11-25 07:20:19 +08:00
|
|
|
bool IsPrimaryBaseVirtual,
|
2013-11-08 19:45:35 +08:00
|
|
|
const CXXRecordDecl *BaseSharingVBPtr,
|
2016-05-24 01:16:12 +08:00
|
|
|
bool EndsWithZeroSizedObject,
|
2013-12-07 03:54:25 +08:00
|
|
|
bool LeadsWithZeroSizedBase,
|
2010-03-11 12:10:39 +08:00
|
|
|
const BaseOffsetsMapTy& BaseOffsets,
|
2012-05-01 16:55:32 +08:00
|
|
|
const VBaseOffsetsMapTy& VBaseOffsets)
|
2013-12-06 08:01:17 +08:00
|
|
|
: Size(size), DataSize(datasize), Alignment(alignment),
|
2016-05-25 02:10:50 +08:00
|
|
|
RequiredAlignment(requiredAlignment), CXXInfo(new (Ctx) CXXRecordLayoutInfo)
|
2010-03-09 04:56:29 +08:00
|
|
|
{
|
2016-05-25 02:10:50 +08:00
|
|
|
FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
|
2010-03-09 04:56:29 +08:00
|
|
|
|
2010-11-25 07:20:19 +08:00
|
|
|
CXXInfo->PrimaryBase.setPointer(PrimaryBase);
|
|
|
|
CXXInfo->PrimaryBase.setInt(IsPrimaryBaseVirtual);
|
2010-03-09 04:56:29 +08:00
|
|
|
CXXInfo->NonVirtualSize = nonvirtualsize;
|
2014-01-09 08:30:56 +08:00
|
|
|
CXXInfo->NonVirtualAlignment = nonvirtualalignment;
|
2010-05-09 06:35:05 +08:00
|
|
|
CXXInfo->SizeOfLargestEmptySubobject = SizeOfLargestEmptySubobject;
|
2010-03-11 12:10:39 +08:00
|
|
|
CXXInfo->BaseOffsets = BaseOffsets;
|
|
|
|
CXXInfo->VBaseOffsets = VBaseOffsets;
|
2012-05-01 16:55:32 +08:00
|
|
|
CXXInfo->HasOwnVFPtr = hasOwnVFPtr;
|
2011-09-28 03:12:27 +08:00
|
|
|
CXXInfo->VBPtrOffset = vbptroffset;
|
2013-11-14 06:16:13 +08:00
|
|
|
CXXInfo->HasExtendableVFPtr = hasExtendableVFPtr;
|
2013-11-08 19:45:35 +08:00
|
|
|
CXXInfo->BaseSharingVBPtr = BaseSharingVBPtr;
|
2016-05-24 01:16:12 +08:00
|
|
|
CXXInfo->EndsWithZeroSizedObject = EndsWithZeroSizedObject;
|
2013-12-07 03:54:25 +08:00
|
|
|
CXXInfo->LeadsWithZeroSizedBase = LeadsWithZeroSizedBase;
|
2013-10-12 04:19:00 +08:00
|
|
|
|
2010-03-11 09:49:18 +08:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
if (const CXXRecordDecl *PrimaryBase = getPrimaryBase()) {
|
2011-09-28 03:12:27 +08:00
|
|
|
if (isPrimaryBaseVirtual()) {
|
2013-01-26 06:30:49 +08:00
|
|
|
if (Ctx.getTargetInfo().getCXXABI().hasPrimaryVBases()) {
|
|
|
|
assert(getVBaseClassOffset(PrimaryBase).isZero() &&
|
|
|
|
"Primary virtual base must be at offset 0!");
|
2011-09-28 03:12:27 +08:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-05 02:45:14 +08:00
|
|
|
assert(getBaseClassOffset(PrimaryBase).isZero() &&
|
2010-03-11 09:49:18 +08:00
|
|
|
"Primary base must be at offset 0!");
|
2011-09-28 03:12:27 +08:00
|
|
|
}
|
2010-03-11 09:49:18 +08:00
|
|
|
}
|
|
|
|
#endif
|
2010-03-09 04:56:29 +08:00
|
|
|
}
|