 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
0.0% |
0 / 0 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
0.0% |
0 / 0 |
| |
|
Line Coverage: |
100.0% |
4 / 4 |
| |
 |
|
 |
1 : //===- ASTRecordLayoutBuilder.h - Helper class for building record layouts ===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 :
10 : #ifndef LLVM_CLANG_AST_RECORDLAYOUTBUILDER_H
11 : #define LLVM_CLANG_AST_RECORDLAYOUTBUILDER_H
12 :
13 : #include "clang/AST/RecordLayout.h"
14 : #include "llvm/ADT/SmallVector.h"
15 : #include "llvm/ADT/SmallSet.h"
16 : #include "llvm/System/DataTypes.h"
17 : #include <map>
18 :
19 : namespace clang {
20 : class ASTContext;
21 : class ASTRecordLayout;
22 : class CXXRecordDecl;
23 : class FieldDecl;
24 : class ObjCImplementationDecl;
25 : class ObjCInterfaceDecl;
26 : class RecordDecl;
27 :
28 1800: class ASTRecordLayoutBuilder {
29 : ASTContext &Ctx;
30 :
31 : /// Size - The current size of the record layout.
32 : uint64_t Size;
33 :
34 : /// Alignment - The current alignment of the record layout.
35 : unsigned Alignment;
36 :
37 : llvm::SmallVector<uint64_t, 16> FieldOffsets;
38 :
39 : /// Packed - Whether the record is packed or not.
40 : bool Packed;
41 :
42 : /// UnfilledBitsInLastByte - If the last field laid out was a bitfield,
43 : /// this contains the number of bits in the last byte that can be used for
44 : /// an adjacent bitfield if necessary.
45 : unsigned char UnfilledBitsInLastByte;
46 :
47 : /// MaxFieldAlignment - The maximum allowed field alignment. This is set by
48 : /// #pragma pack.
49 : unsigned MaxFieldAlignment;
50 :
51 : /// DataSize - The data size of the record being laid out.
52 : uint64_t DataSize;
53 :
54 : bool IsUnion;
55 :
56 : uint64_t NonVirtualSize;
57 : unsigned NonVirtualAlignment;
58 :
59 : ASTRecordLayout::PrimaryBaseInfo PrimaryBase;
60 :
61 : typedef llvm::SmallVector<std::pair<const CXXRecordDecl *,
62 : uint64_t>, 4> BaseOffsetsTy;
63 :
64 : /// Bases - base classes and their offsets from the record.
65 : BaseOffsetsTy Bases;
66 :
67 : // VBases - virtual base classes and their offsets from the record.
68 : BaseOffsetsTy VBases;
69 :
70 : /// IndirectPrimaryBases - Virtual base classes, direct or indirect, that are
71 : /// primary base classes for some other direct or indirect base class.
72 : llvm::SmallSet<const CXXRecordDecl*, 32> IndirectPrimaryBases;
73 :
74 : /// EmptyClassOffsets - A map from offsets to empty record decls.
75 : typedef std::multimap<uint64_t, const CXXRecordDecl *> EmptyClassOffsetsTy;
76 : EmptyClassOffsetsTy EmptyClassOffsets;
77 :
78 : ASTRecordLayoutBuilder(ASTContext &Ctx);
79 :
80 : void Layout(const RecordDecl *D);
81 : void Layout(const CXXRecordDecl *D);
82 : void Layout(const ObjCInterfaceDecl *D,
83 : const ObjCImplementationDecl *Impl);
84 :
85 : void LayoutFields(const RecordDecl *D);
86 : void LayoutField(const FieldDecl *D);
87 : void LayoutBitField(const FieldDecl *D);
88 :
89 : void SelectPrimaryBase(const CXXRecordDecl *RD);
90 : void SelectPrimaryVBase(const CXXRecordDecl *RD,
91 : const CXXRecordDecl *&FirstPrimary);
92 :
93 : /// IdentifyPrimaryBases - Identify all virtual base classes, direct or
94 : /// indirect, that are primary base classes for some other direct or indirect
95 : /// base class.
96 : void IdentifyPrimaryBases(const CXXRecordDecl *RD);
97 :
98 96: void setPrimaryBase(const CXXRecordDecl *Base, bool IsVirtual) {
99 96: PrimaryBase = ASTRecordLayout::PrimaryBaseInfo(Base, IsVirtual);
100 96: }
101 :
102 : bool IsNearlyEmpty(const CXXRecordDecl *RD) const;
103 :
104 : /// LayoutBase - Will lay out a base and return the offset where it was
105 : /// placed, in bits.
106 : uint64_t LayoutBase(const CXXRecordDecl *RD);
107 :
108 : void LayoutVtable(const CXXRecordDecl *RD);
109 : void LayoutNonVirtualBases(const CXXRecordDecl *RD);
110 : void LayoutBaseNonVirtually(const CXXRecordDecl *RD, bool IsVBase);
111 : void LayoutVirtualBase(const CXXRecordDecl *RD);
112 : void LayoutVirtualBases(const CXXRecordDecl *Class, const CXXRecordDecl *RD,
113 : const CXXRecordDecl *PB, uint64_t Offset,
114 : llvm::SmallSet<const CXXRecordDecl*, 32> &mark,
115 : llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary);
116 :
117 : /// canPlaceRecordAtOffset - Return whether a record (either a base class
118 : /// or a field) can be placed at the given offset.
119 : /// Returns false if placing the record will result in two components
120 : /// (direct or indirect) of the same type having the same offset.
121 : bool canPlaceRecordAtOffset(const CXXRecordDecl *RD, uint64_t Offset) const;
122 :
123 : /// canPlaceFieldAtOffset - Return whether a field can be placed at the given
124 : /// offset.
125 : bool canPlaceFieldAtOffset(const FieldDecl *FD, uint64_t Offset) const;
126 :
127 : /// UpdateEmptyClassOffsets - Called after a record (either a base class
128 : /// or a field) has been placed at the given offset. Will update the
129 : /// EmptyClassOffsets map if the class is empty or has any empty bases or
130 : /// fields.
131 : void UpdateEmptyClassOffsets(const CXXRecordDecl *RD, uint64_t Offset);
132 :
133 : /// UpdateEmptyClassOffsets - Called after a field has been placed at the
134 : /// given offset.
135 : void UpdateEmptyClassOffsets(const FieldDecl *FD, uint64_t Offset);
136 :
137 : /// getBaseOffset - Get the offset of a direct base class.
138 : uint64_t getBaseOffset(const CXXRecordDecl *Base);
139 :
140 : /// FinishLayout - Finalize record layout. Adjust record size based on the
141 : /// alignment.
142 : void FinishLayout();
143 :
144 : void UpdateAlignment(unsigned NewAlignment);
145 :
146 : ASTRecordLayoutBuilder(const ASTRecordLayoutBuilder&); // DO NOT IMPLEMENT
147 : void operator=(const ASTRecordLayoutBuilder&); // DO NOT IMPLEMENT
148 : public:
149 : static const ASTRecordLayout *ComputeLayout(ASTContext &Ctx,
150 : const RecordDecl *RD);
151 : static const ASTRecordLayout *ComputeLayout(ASTContext &Ctx,
152 : const ObjCInterfaceDecl *D,
153 : const ObjCImplementationDecl *Impl);
154 : static const CXXMethodDecl *ComputeKeyFunction(const CXXRecordDecl *RD);
155 : };
156 :
157 : } // end namespace clang
158 :
159 : #endif
160 :
Generated: 2010-02-10 01:31 by zcov