From 9392fa63e45716e32061d05673fa28909f325b02 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Wed, 26 May 2010 05:41:04 +0000 Subject: [PATCH] Move the ASTRecordLayoutBuilder class declaration into the .cpp file. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104686 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/RecordLayoutBuilder.cpp | 158 +++++++++++++++++++++++++++++++- lib/AST/RecordLayoutBuilder.h | 153 ------------------------------- 2 files changed, 155 insertions(+), 156 deletions(-) diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index 34351a6f1e..577ad9badb 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -1,4 +1,4 @@ -//=== ASTRecordLayoutBuilder.cpp - Helper class for building record layouts ==// +//=== RecordLayoutBuilder.cpp - Helper class for building record layouts ---==// // // The LLVM Compiler Infrastructure // @@ -7,20 +7,172 @@ // //===----------------------------------------------------------------------===// -#include "RecordLayoutBuilder.h" - #include "clang/AST/Attr.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/Expr.h" +#include "clang/AST/RecordLayout.h" #include "clang/Basic/TargetInfo.h" #include "llvm/Support/Format.h" #include "llvm/ADT/SmallSet.h" #include "llvm/Support/MathExtras.h" +#include using namespace clang; +class ASTRecordLayoutBuilder { + // FIXME: Remove this and make the appropriate fields public. + friend class clang::ASTContext; + + ASTContext &Context; + + /// Size - The current size of the record layout. + uint64_t Size; + + /// Alignment - The current alignment of the record layout. + unsigned Alignment; + + llvm::SmallVector FieldOffsets; + + /// Packed - Whether the record is packed or not. + bool Packed; + + /// UnfilledBitsInLastByte - If the last field laid out was a bitfield, + /// this contains the number of bits in the last byte that can be used for + /// an adjacent bitfield if necessary. + unsigned char UnfilledBitsInLastByte; + + /// MaxFieldAlignment - The maximum allowed field alignment. This is set by + /// #pragma pack. + unsigned MaxFieldAlignment; + + /// DataSize - The data size of the record being laid out. + uint64_t DataSize; + + bool IsUnion; + + uint64_t NonVirtualSize; + unsigned NonVirtualAlignment; + + /// PrimaryBase - the primary base class (if one exists) of the class + /// we're laying out. + const CXXRecordDecl *PrimaryBase; + + /// PrimaryBaseIsVirtual - Whether the primary base of the class we're laying + /// out is virtual. + bool PrimaryBaseIsVirtual; + + typedef llvm::DenseMap BaseOffsetsMapTy; + + /// Bases - base classes and their offsets in the record. + BaseOffsetsMapTy Bases; + + // VBases - virtual base classes and their offsets in the record. + BaseOffsetsMapTy VBases; + + /// IndirectPrimaryBases - Virtual base classes, direct or indirect, that are + /// primary base classes for some other direct or indirect base class. + llvm::SmallSet IndirectPrimaryBases; + + /// FirstNearlyEmptyVBase - The first nearly empty virtual base class in + /// inheritance graph order. Used for determining the primary base class. + const CXXRecordDecl *FirstNearlyEmptyVBase; + + /// VisitedVirtualBases - A set of all the visited virtual bases, used to + /// avoid visiting virtual bases more than once. + llvm::SmallPtrSet VisitedVirtualBases; + + /// SizeOfLargestEmptySubobject - When laying out C++ classes, this holds the + /// size of the largest empty subobject (either a base or a member). + /// Will be zero if the record being built doesn't contain any empty classes. + uint64_t SizeOfLargestEmptySubobject; + + /// EmptyClassOffsets - A map from offsets to empty record decls. + typedef std::multimap EmptyClassOffsetsTy; + EmptyClassOffsetsTy EmptyClassOffsets; + + ASTRecordLayoutBuilder(ASTContext &Ctx); + + void Layout(const RecordDecl *D); + void Layout(const ObjCInterfaceDecl *D); + + void LayoutFields(const RecordDecl *D); + void LayoutField(const FieldDecl *D); + void LayoutWideBitField(uint64_t FieldSize, uint64_t TypeSize); + void LayoutBitField(const FieldDecl *D); + + /// ComputeEmptySubobjectSizes - Compute the size of the largest base or + /// member subobject that is empty. + void ComputeEmptySubobjectSizes(const CXXRecordDecl *RD); + + /// DeterminePrimaryBase - Determine the primary base of the given class. + void DeterminePrimaryBase(const CXXRecordDecl *RD); + + void SelectPrimaryVBase(const CXXRecordDecl *RD); + + /// IdentifyPrimaryBases - Identify all virtual base classes, direct or + /// indirect, that are primary base classes for some other direct or indirect + /// base class. + void IdentifyPrimaryBases(const CXXRecordDecl *RD); + + bool IsNearlyEmpty(const CXXRecordDecl *RD) const; + + /// LayoutNonVirtualBases - Determines the primary base class (if any) and + /// lays it out. Will then proceed to lay out all non-virtual base clasess. + void LayoutNonVirtualBases(const CXXRecordDecl *RD); + + /// LayoutNonVirtualBase - Lays out a single non-virtual base. + void LayoutNonVirtualBase(const CXXRecordDecl *RD); + + void AddPrimaryVirtualBaseOffsets(const CXXRecordDecl *RD, uint64_t Offset, + const CXXRecordDecl *MostDerivedClass); + + /// LayoutVirtualBases - Lays out all the virtual bases. + void LayoutVirtualBases(const CXXRecordDecl *RD, + const CXXRecordDecl *MostDerivedClass); + + /// LayoutVirtualBase - Lays out a single virtual base. + void LayoutVirtualBase(const CXXRecordDecl *RD); + + /// LayoutBase - Will lay out a base and return the offset where it was + /// placed, in bits. + uint64_t LayoutBase(const CXXRecordDecl *RD); + + /// canPlaceRecordAtOffset - Return whether a record (either a base class + /// or a field) can be placed at the given offset. + /// Returns false if placing the record will result in two components + /// (direct or indirect) of the same type having the same offset. + bool canPlaceRecordAtOffset(const CXXRecordDecl *RD, uint64_t Offset, + bool CheckVBases) const; + + /// canPlaceFieldAtOffset - Return whether a field can be placed at the given + /// offset. + bool canPlaceFieldAtOffset(const FieldDecl *FD, uint64_t Offset) const; + + /// UpdateEmptyClassOffsets - Called after a record (either a base class + /// or a field) has been placed at the given offset. Will update the + /// EmptyClassOffsets map if the class is empty or has any empty bases or + /// fields. + void UpdateEmptyClassOffsets(const CXXRecordDecl *RD, uint64_t Offset, + bool UpdateVBases); + + /// UpdateEmptyClassOffsets - Called after a field has been placed at the + /// given offset. + void UpdateEmptyClassOffsets(const FieldDecl *FD, uint64_t Offset); + + /// FinishLayout - Finalize record layout. Adjust record size based on the + /// alignment. + void FinishLayout(); + + void UpdateAlignment(unsigned NewAlignment); + + ASTRecordLayoutBuilder(const ASTRecordLayoutBuilder&); // DO NOT IMPLEMENT + void operator=(const ASTRecordLayoutBuilder&); // DO NOT IMPLEMENT +public: + static const CXXMethodDecl *ComputeKeyFunction(const CXXRecordDecl *RD); +}; + ASTRecordLayoutBuilder::ASTRecordLayoutBuilder(ASTContext &Context) : Context(Context), Size(0), Alignment(8), Packed(false), UnfilledBitsInLastByte(0), MaxFieldAlignment(0), DataSize(0), IsUnion(false), diff --git a/lib/AST/RecordLayoutBuilder.h b/lib/AST/RecordLayoutBuilder.h index fdd4286d45..870e1d85e7 100644 --- a/lib/AST/RecordLayoutBuilder.h +++ b/lib/AST/RecordLayoutBuilder.h @@ -14,7 +14,6 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallSet.h" #include "llvm/System/DataTypes.h" -#include namespace clang { class ASTContext; @@ -25,158 +24,6 @@ namespace clang { class ObjCInterfaceDecl; class RecordDecl; -class ASTRecordLayoutBuilder { - // FIXME: Remove this and make the appropriate fields public. - friend class ASTContext; - - ASTContext &Context; - - /// Size - The current size of the record layout. - uint64_t Size; - - /// Alignment - The current alignment of the record layout. - unsigned Alignment; - - llvm::SmallVector FieldOffsets; - - /// Packed - Whether the record is packed or not. - bool Packed; - - /// UnfilledBitsInLastByte - If the last field laid out was a bitfield, - /// this contains the number of bits in the last byte that can be used for - /// an adjacent bitfield if necessary. - unsigned char UnfilledBitsInLastByte; - - /// MaxFieldAlignment - The maximum allowed field alignment. This is set by - /// #pragma pack. - unsigned MaxFieldAlignment; - - /// DataSize - The data size of the record being laid out. - uint64_t DataSize; - - bool IsUnion; - - uint64_t NonVirtualSize; - unsigned NonVirtualAlignment; - - /// PrimaryBase - the primary base class (if one exists) of the class - /// we're laying out. - const CXXRecordDecl *PrimaryBase; - - /// PrimaryBaseIsVirtual - Whether the primary base of the class we're laying - /// out is virtual. - bool PrimaryBaseIsVirtual; - - typedef llvm::DenseMap BaseOffsetsMapTy; - - /// Bases - base classes and their offsets in the record. - BaseOffsetsMapTy Bases; - - // VBases - virtual base classes and their offsets in the record. - BaseOffsetsMapTy VBases; - - /// IndirectPrimaryBases - Virtual base classes, direct or indirect, that are - /// primary base classes for some other direct or indirect base class. - llvm::SmallSet IndirectPrimaryBases; - - /// FirstNearlyEmptyVBase - The first nearly empty virtual base class in - /// inheritance graph order. Used for determining the primary base class. - const CXXRecordDecl *FirstNearlyEmptyVBase; - - /// VisitedVirtualBases - A set of all the visited virtual bases, used to - /// avoid visiting virtual bases more than once. - llvm::SmallPtrSet VisitedVirtualBases; - - /// SizeOfLargestEmptySubobject - When laying out C++ classes, this holds the - /// size of the largest empty subobject (either a base or a member). - /// Will be zero if the record being built doesn't contain any empty classes. - uint64_t SizeOfLargestEmptySubobject; - - /// EmptyClassOffsets - A map from offsets to empty record decls. - typedef std::multimap EmptyClassOffsetsTy; - EmptyClassOffsetsTy EmptyClassOffsets; - - ASTRecordLayoutBuilder(ASTContext &Ctx); - - void Layout(const RecordDecl *D); - void Layout(const ObjCInterfaceDecl *D); - - void LayoutFields(const RecordDecl *D); - void LayoutField(const FieldDecl *D); - void LayoutWideBitField(uint64_t FieldSize, uint64_t TypeSize); - void LayoutBitField(const FieldDecl *D); - - /// ComputeEmptySubobjectSizes - Compute the size of the largest base or - /// member subobject that is empty. - void ComputeEmptySubobjectSizes(const CXXRecordDecl *RD); - - /// DeterminePrimaryBase - Determine the primary base of the given class. - void DeterminePrimaryBase(const CXXRecordDecl *RD); - - void SelectPrimaryVBase(const CXXRecordDecl *RD); - - /// IdentifyPrimaryBases - Identify all virtual base classes, direct or - /// indirect, that are primary base classes for some other direct or indirect - /// base class. - void IdentifyPrimaryBases(const CXXRecordDecl *RD); - - bool IsNearlyEmpty(const CXXRecordDecl *RD) const; - - /// LayoutNonVirtualBases - Determines the primary base class (if any) and - /// lays it out. Will then proceed to lay out all non-virtual base clasess. - void LayoutNonVirtualBases(const CXXRecordDecl *RD); - - /// LayoutNonVirtualBase - Lays out a single non-virtual base. - void LayoutNonVirtualBase(const CXXRecordDecl *RD); - - void AddPrimaryVirtualBaseOffsets(const CXXRecordDecl *RD, uint64_t Offset, - const CXXRecordDecl *MostDerivedClass); - - /// LayoutVirtualBases - Lays out all the virtual bases. - void LayoutVirtualBases(const CXXRecordDecl *RD, - const CXXRecordDecl *MostDerivedClass); - - /// LayoutVirtualBase - Lays out a single virtual base. - void LayoutVirtualBase(const CXXRecordDecl *RD); - - /// LayoutBase - Will lay out a base and return the offset where it was - /// placed, in bits. - uint64_t LayoutBase(const CXXRecordDecl *RD); - - /// canPlaceRecordAtOffset - Return whether a record (either a base class - /// or a field) can be placed at the given offset. - /// Returns false if placing the record will result in two components - /// (direct or indirect) of the same type having the same offset. - bool canPlaceRecordAtOffset(const CXXRecordDecl *RD, uint64_t Offset, - bool CheckVBases) const; - - /// canPlaceFieldAtOffset - Return whether a field can be placed at the given - /// offset. - bool canPlaceFieldAtOffset(const FieldDecl *FD, uint64_t Offset) const; - - /// UpdateEmptyClassOffsets - Called after a record (either a base class - /// or a field) has been placed at the given offset. Will update the - /// EmptyClassOffsets map if the class is empty or has any empty bases or - /// fields. - void UpdateEmptyClassOffsets(const CXXRecordDecl *RD, uint64_t Offset, - bool UpdateVBases); - - /// UpdateEmptyClassOffsets - Called after a field has been placed at the - /// given offset. - void UpdateEmptyClassOffsets(const FieldDecl *FD, uint64_t Offset); - - /// FinishLayout - Finalize record layout. Adjust record size based on the - /// alignment. - void FinishLayout(); - - void UpdateAlignment(unsigned NewAlignment); - - ASTRecordLayoutBuilder(const ASTRecordLayoutBuilder&); // DO NOT IMPLEMENT - void operator=(const ASTRecordLayoutBuilder&); // DO NOT IMPLEMENT -public: - static const CXXMethodDecl *ComputeKeyFunction(const CXXRecordDecl *RD); -}; - } // end namespace clang #endif -- 2.40.0