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) {
|
|
|
|
if (FieldOffsets)
|
|
|
|
Ctx.Deallocate(FieldOffsets);
|
2010-08-25 08:32:19 +08:00
|
|
|
if (CXXInfo) {
|
2010-03-09 04:56:29 +08:00
|
|
|
Ctx.Deallocate(CXXInfo);
|
2010-08-25 08:32:19 +08:00
|
|
|
CXXInfo->~CXXRecordLayoutInfo();
|
|
|
|
}
|
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,
|
2011-02-15 10:32:40 +08:00
|
|
|
CharUnits alignment, CharUnits datasize,
|
2011-01-12 17:06:06 +08:00
|
|
|
const uint64_t *fieldoffsets,
|
|
|
|
unsigned fieldcount)
|
2012-05-01 16:55:32 +08:00
|
|
|
: Size(size), DataSize(datasize), Alignment(alignment), FieldOffsets(0),
|
2010-03-09 04:56:29 +08:00
|
|
|
FieldCount(fieldcount), CXXInfo(0) {
|
|
|
|
if (FieldCount > 0) {
|
|
|
|
FieldOffsets = new (Ctx) uint64_t[FieldCount];
|
2010-03-09 20:53:38 +08:00
|
|
|
memcpy(FieldOffsets, fieldoffsets, FieldCount * sizeof(*FieldOffsets));
|
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-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,
|
2010-03-11 12:10:39 +08:00
|
|
|
const uint64_t *fieldoffsets,
|
|
|
|
unsigned fieldcount,
|
2011-02-01 09:52:10 +08:00
|
|
|
CharUnits nonvirtualsize,
|
2011-02-08 10:02:47 +08:00
|
|
|
CharUnits nonvirtualalign,
|
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,
|
2013-10-12 04:19:00 +08:00
|
|
|
bool AlignAfterVBases,
|
2010-03-11 12:10:39 +08:00
|
|
|
const BaseOffsetsMapTy& BaseOffsets,
|
2012-05-01 16:55:32 +08:00
|
|
|
const VBaseOffsetsMapTy& VBaseOffsets)
|
|
|
|
: Size(size), DataSize(datasize), Alignment(alignment), FieldOffsets(0),
|
2010-03-09 04:56:29 +08:00
|
|
|
FieldCount(fieldcount), CXXInfo(new (Ctx) CXXRecordLayoutInfo)
|
|
|
|
{
|
|
|
|
if (FieldCount > 0) {
|
|
|
|
FieldOffsets = new (Ctx) uint64_t[FieldCount];
|
2010-03-09 20:53:38 +08:00
|
|
|
memcpy(FieldOffsets, fieldoffsets, FieldCount * sizeof(*FieldOffsets));
|
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;
|
|
|
|
CXXInfo->NonVirtualAlign = nonvirtualalign;
|
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;
|
2013-10-12 04:19:00 +08:00
|
|
|
CXXInfo->AlignAfterVBases = AlignAfterVBases;
|
|
|
|
|
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
|
|
|
}
|