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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
unsigned StructPacking;
|
2009-07-30 09:02:10 +08:00
|
|
|
uint64_t NextOffset;
|
2009-07-19 04:20:21 +08:00
|
|
|
bool IsUnion;
|
|
|
|
|
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-07-19 04:20:21 +08:00
|
|
|
ASTRecordLayoutBuilder(ASTContext &Ctx);
|
|
|
|
|
|
|
|
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-06 06:37:18 +08:00
|
|
|
void SelectPrimaryBase(const CXXRecordDecl *RD);
|
|
|
|
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-07-30 08:22:38 +08:00
|
|
|
void LayoutVtable(const CXXRecordDecl *RD);
|
2009-07-19 08:18:47 +08:00
|
|
|
void LayoutNonVirtualBases(const CXXRecordDecl *RD);
|
2009-08-06 21:41:24 +08:00
|
|
|
void LayoutBaseNonVirtually(const CXXRecordDecl *RD);
|
|
|
|
void LayoutVirtualBase(const CXXRecordDecl *RD);
|
|
|
|
void LayoutVirtualBases(const CXXRecordDecl *RD);
|
2009-07-19 08:18:47 +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();
|
|
|
|
|
|
|
|
void UpdateAlignment(unsigned NewAlignment);
|
|
|
|
|
|
|
|
ASTRecordLayoutBuilder(const ASTRecordLayoutBuilder&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const ASTRecordLayoutBuilder&); // DO NOT IMPLEMENT
|
|
|
|
public:
|
|
|
|
static const ASTRecordLayout *ComputeLayout(ASTContext &Ctx,
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|