diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-03-08 20:56:29 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-03-08 20:56:29 +0000 |
commit | 503524acc73f2f8280080ca0d200377406001b65 (patch) | |
tree | e366fb5c08f328117a06c12b56b3733acb7569ae /lib/AST/RecordLayout.cpp | |
parent | 0804e6e0ad2862826497677a4c26c6a9d7c3d66c (diff) |
Allocate ASTRecordLayout objects using the allocator associated with ASTContext.
This allows them to be allocated using a BumpPtrAllocated
in the common case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97978 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/RecordLayout.cpp')
-rw-r--r-- | lib/AST/RecordLayout.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/AST/RecordLayout.cpp b/lib/AST/RecordLayout.cpp new file mode 100644 index 0000000000..9f8bdec94e --- /dev/null +++ b/lib/AST/RecordLayout.cpp @@ -0,0 +1,69 @@ +//===-- 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" + +using namespace clang; + +void ASTRecordLayout::Destroy(ASTContext &Ctx) { + if (FieldOffsets) + Ctx.Deallocate(FieldOffsets); + if (CXXInfo) + Ctx.Deallocate(CXXInfo); + this->~ASTRecordLayout(); + Ctx.Deallocate(this); +} + +ASTRecordLayout::ASTRecordLayout(ASTContext &Ctx, uint64_t size, unsigned alignment, + unsigned datasize, const uint64_t *fieldoffsets, + unsigned fieldcount) + : Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment), + FieldCount(fieldcount), CXXInfo(0) { + if (FieldCount > 0) { + FieldOffsets = new (Ctx) uint64_t[FieldCount]; + for (unsigned i = 0; i < FieldCount; ++i) + FieldOffsets[i] = fieldoffsets[i]; + } +} + +// Constructor for C++ records. +ASTRecordLayout::ASTRecordLayout(ASTContext &Ctx, + uint64_t size, unsigned alignment, + uint64_t datasize, + const uint64_t *fieldoffsets, + unsigned fieldcount, + uint64_t nonvirtualsize, + unsigned nonvirtualalign, + const PrimaryBaseInfo &PrimaryBase, + 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 (Ctx) CXXRecordLayoutInfo) +{ + if (FieldCount > 0) { + FieldOffsets = new (Ctx) uint64_t[FieldCount]; + for (unsigned i = 0; i < FieldCount; ++i) + FieldOffsets[i] = fieldoffsets[i]; + } + + CXXInfo->PrimaryBase = PrimaryBase; + CXXInfo->NonVirtualSize = nonvirtualsize; + CXXInfo->NonVirtualAlign = nonvirtualalign; + 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; +} |