2009-07-19 04:20:21 +08:00
|
|
|
//===- ASTRecordLayoutBuilder.h - Helper class for building record layouts ===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_AST_RECORDLAYOUTBUILDER_H
|
|
|
|
#define LLVM_CLANG_AST_RECORDLAYOUTBUILDER_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-08-06 06:37:18 +08:00
|
|
|
#include "llvm/ADT/SmallSet.h"
|
2009-07-19 10:17:34 +08:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2009-07-19 04:20:21 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class ASTContext;
|
|
|
|
class ASTRecordLayout;
|
2009-07-19 08:18:47 +08:00
|
|
|
class CXXRecordDecl;
|
2009-07-19 04:20:21 +08:00
|
|
|
class FieldDecl;
|
2009-07-19 04:50:59 +08:00
|
|
|
class ObjCImplementationDecl;
|
|
|
|
class ObjCInterfaceDecl;
|
2009-07-19 04:20:21 +08:00
|
|
|
class RecordDecl;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-19 04:20:21 +08:00
|
|
|
class ASTRecordLayoutBuilder {
|
|
|
|
ASTContext &Ctx;
|
|
|
|
|
|
|
|
uint64_t Size;
|
2009-07-29 03:24:15 +08:00
|
|
|
unsigned Alignment;
|
2009-07-19 04:20:21 +08:00
|
|
|
llvm::SmallVector<uint64_t, 16> FieldOffsets;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-09 03:38:24 +08:00
|
|
|
bool Packed;
|
|
|
|
unsigned MaxFieldAlignment;
|
2009-07-30 09:02:10 +08:00
|
|
|
uint64_t NextOffset;
|
2009-07-19 04:20:21 +08:00
|
|
|
bool IsUnion;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-29 03:24:15 +08:00
|
|
|
uint64_t NonVirtualSize;
|
|
|
|
unsigned NonVirtualAlignment;
|
2009-08-06 06:37:18 +08:00
|
|
|
const CXXRecordDecl *PrimaryBase;
|
2009-08-08 03:00:50 +08:00
|
|
|
bool PrimaryBaseWasVirtual;
|
2009-08-06 06:37:18 +08:00
|
|
|
|
2009-07-29 03:24:15 +08:00
|
|
|
llvm::SmallVector<const CXXRecordDecl *, 4> Bases;
|
|
|
|
llvm::SmallVector<uint64_t, 4> BaseOffsets;
|
2009-08-14 09:44:03 +08:00
|
|
|
|
|
|
|
llvm::SmallVector<const CXXRecordDecl *, 4> VBases;
|
|
|
|
llvm::SmallVector<uint64_t, 4> VBaseOffsets;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-19 04:20:21 +08:00
|
|
|
ASTRecordLayoutBuilder(ASTContext &Ctx);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-19 04:20:21 +08:00
|
|
|
void Layout(const RecordDecl *D);
|
2009-07-19 08:18:47 +08:00
|
|
|
void Layout(const CXXRecordDecl *D);
|
2009-07-19 04:50:59 +08:00
|
|
|
void Layout(const ObjCInterfaceDecl *D,
|
|
|
|
const ObjCImplementationDecl *Impl);
|
|
|
|
|
2009-07-19 05:48:39 +08:00
|
|
|
void LayoutFields(const RecordDecl *D);
|
2009-07-19 04:20:21 +08:00
|
|
|
void LayoutField(const FieldDecl *D);
|
2009-07-19 05:19:52 +08:00
|
|
|
|
2009-08-14 06:53:07 +08:00
|
|
|
void SelectPrimaryBase(const CXXRecordDecl *RD,
|
|
|
|
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary);
|
2009-08-13 05:50:08 +08:00
|
|
|
void SelectPrimaryVBase(const CXXRecordDecl *RD,
|
|
|
|
const CXXRecordDecl *&FirstPrimary,
|
|
|
|
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary);
|
2009-08-06 06:37:18 +08:00
|
|
|
void SelectPrimaryForBase(const CXXRecordDecl *RD,
|
|
|
|
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary);
|
2009-08-08 03:00:50 +08:00
|
|
|
void setPrimaryBase(const CXXRecordDecl *PB, bool Virtual) {
|
|
|
|
PrimaryBase = PB;
|
|
|
|
PrimaryBaseWasVirtual = Virtual;
|
|
|
|
}
|
2009-08-06 06:37:18 +08:00
|
|
|
bool IsNearlyEmpty(const CXXRecordDecl *RD);
|
2009-08-14 06:53:07 +08:00
|
|
|
void LayoutVtable(const CXXRecordDecl *RD,
|
|
|
|
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary);
|
2009-07-19 08:18:47 +08:00
|
|
|
void LayoutNonVirtualBases(const CXXRecordDecl *RD);
|
2009-08-14 09:44:03 +08:00
|
|
|
void LayoutBaseNonVirtually(const CXXRecordDecl *RD, bool IsVBase);
|
2009-08-06 21:41:24 +08:00
|
|
|
void LayoutVirtualBase(const CXXRecordDecl *RD);
|
2009-08-17 03:04:13 +08:00
|
|
|
void LayoutVirtualBases(const CXXRecordDecl *RD, const CXXRecordDecl *PB,
|
2009-08-16 09:46:26 +08:00
|
|
|
int64_t Offset,
|
|
|
|
llvm::SmallSet<const CXXRecordDecl*, 32> &mark,
|
2009-08-13 10:02:14 +08:00
|
|
|
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-19 05:19:52 +08:00
|
|
|
/// FinishLayout - Finalize record layout. Adjust record size based on the
|
|
|
|
/// alignment.
|
2009-07-19 04:20:21 +08:00
|
|
|
void FinishLayout();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-19 04:20:21 +08:00
|
|
|
void UpdateAlignment(unsigned NewAlignment);
|
|
|
|
|
|
|
|
ASTRecordLayoutBuilder(const ASTRecordLayoutBuilder&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const ASTRecordLayoutBuilder&); // DO NOT IMPLEMENT
|
|
|
|
public:
|
2009-09-09 23:08:12 +08:00
|
|
|
static const ASTRecordLayout *ComputeLayout(ASTContext &Ctx,
|
2009-07-19 04:20:21 +08:00
|
|
|
const RecordDecl *RD);
|
2009-07-19 04:50:59 +08:00
|
|
|
static const ASTRecordLayout *ComputeLayout(ASTContext &Ctx,
|
|
|
|
const ObjCInterfaceDecl *D,
|
|
|
|
const ObjCImplementationDecl *Impl);
|
2009-07-19 04:20:21 +08:00
|
|
|
};
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-19 04:20:21 +08:00
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|