summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/RecordLayout.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-03-08 20:56:29 +0000
committerTed Kremenek <kremenek@apple.com>2010-03-08 20:56:29 +0000
commitc3015a914fc8558ddfcd5e7c581808c5c8eae6cf (patch)
tree59a1414347c2bb8d9f77b4e60f8b2fd81b090b01 /clang/lib/AST/RecordLayout.cpp
parentd3cbaa1ddfa4f3a07b90ac87dff54e0bb9f06927 (diff)
downloadbcm5719-llvm-c3015a914fc8558ddfcd5e7c581808c5c8eae6cf.tar.gz
bcm5719-llvm-c3015a914fc8558ddfcd5e7c581808c5c8eae6cf.zip
Allocate ASTRecordLayout objects using the allocator associated with ASTContext.
This allows them to be allocated using a BumpPtrAllocated in the common case. llvm-svn: 97978
Diffstat (limited to 'clang/lib/AST/RecordLayout.cpp')
-rw-r--r--clang/lib/AST/RecordLayout.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/clang/lib/AST/RecordLayout.cpp b/clang/lib/AST/RecordLayout.cpp
new file mode 100644
index 00000000000..9f8bdec94ee
--- /dev/null
+++ b/clang/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;
+}
OpenPOWER on IntegriCloud