Deleted Added
full compact
RecordLayout.h (199482) RecordLayout.h (199990)
1//===--- RecordLayout.h - Layout information for a struct/union -*- C++ -*-===//
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//===----------------------------------------------------------------------===//

--- 33 unchanged lines hidden (view full) ---

42 uint64_t *FieldOffsets;
43
44 // Alignment - Alignment of record in bits.
45 unsigned Alignment;
46
47 // FieldCount - Number of fields.
48 unsigned FieldCount;
49
1//===--- RecordLayout.h - Layout information for a struct/union -*- C++ -*-===//
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//===----------------------------------------------------------------------===//

--- 33 unchanged lines hidden (view full) ---

42 uint64_t *FieldOffsets;
43
44 // Alignment - Alignment of record in bits.
45 unsigned Alignment;
46
47 // FieldCount - Number of fields.
48 unsigned FieldCount;
49
50public:
51 /// PrimaryBaseInfo - Contains info about a primary base.
52 struct PrimaryBaseInfo {
53 PrimaryBaseInfo() {}
54
55 PrimaryBaseInfo(const CXXRecordDecl *Base, bool IsVirtual)
56 : Value(Base, IsVirtual) {}
57
58 /// Value - Points to the primary base. The single-bit value
59 /// will be non-zero when the primary base is virtual.
60 llvm::PointerIntPair<const CXXRecordDecl *, 1, bool> Value;
61
62 /// getBase - Returns the primary base.
63 const CXXRecordDecl *getBase() const { return Value.getPointer(); }
64
65 /// isVirtual - Returns whether the primary base is virtual or not.
66 bool isVirtual() const { return Value.getInt(); }
67
68 friend bool operator==(const PrimaryBaseInfo &X, const PrimaryBaseInfo &Y) {
69 return X.Value == Y.Value;
70 }
71 };
72
73 /// primary_base_info_iterator - An iterator for iterating the primary base
74 /// class chain.
75 class primary_base_info_iterator {
76 /// Current - The current base class info.
77 PrimaryBaseInfo Current;
78
79 public:
80 primary_base_info_iterator() {}
81 primary_base_info_iterator(PrimaryBaseInfo Info) : Current(Info) {}
82
83 const PrimaryBaseInfo &operator*() const { return Current; }
84
85 primary_base_info_iterator& operator++() {
86 const CXXRecordDecl *RD = Current.getBase();
87 Current = RD->getASTContext().getASTRecordLayout(RD).getPrimaryBaseInfo();
88 return *this;
89 }
90
91 friend bool operator==(const primary_base_info_iterator &X,
92 const primary_base_info_iterator &Y) {
93 return X.Current == Y.Current;
94 }
95 friend bool operator!=(const primary_base_info_iterator &X,
96 const primary_base_info_iterator &Y) {
97 return !(X == Y);
98 }
99 };
100
101private:
102 /// CXXRecordLayoutInfo - Contains C++ specific layout information.
50 struct CXXRecordLayoutInfo {
51 /// NonVirtualSize - The non-virtual size (in bits) of an object, which is
52 /// the size of the object without virtual bases.
53 uint64_t NonVirtualSize;
54
55 /// NonVirtualAlign - The non-virtual alignment (in bits) of an object,
56 /// which is the alignment of the object without virtual bases.
57 uint64_t NonVirtualAlign;
58
103 struct CXXRecordLayoutInfo {
104 /// NonVirtualSize - The non-virtual size (in bits) of an object, which is
105 /// the size of the object without virtual bases.
106 uint64_t NonVirtualSize;
107
108 /// NonVirtualAlign - The non-virtual alignment (in bits) of an object,
109 /// which is the alignment of the object without virtual bases.
110 uint64_t NonVirtualAlign;
111
59 /// PrimaryBase - The primary base for our vtable.
60 const CXXRecordDecl *PrimaryBase;
61 /// PrimaryBase - Wether or not the primary base was a virtual base.
62 bool PrimaryBaseWasVirtual;
63
112 /// PrimaryBase - The primary base info for this record.
113 PrimaryBaseInfo PrimaryBase;
114
64 /// BaseOffsets - Contains a map from base classes to their offset.
65 /// FIXME: This should really use a SmallPtrMap, once we have one in LLVM :)
66 llvm::DenseMap<const CXXRecordDecl *, uint64_t> BaseOffsets;
67
68 /// VBaseOffsets - Contains a map from vbase classes to their offset.
69 /// FIXME: This should really use a SmallPtrMap, once we have one in LLVM :)
70 llvm::DenseMap<const CXXRecordDecl *, uint64_t> VBaseOffsets;
115 /// BaseOffsets - Contains a map from base classes to their offset.
116 /// FIXME: This should really use a SmallPtrMap, once we have one in LLVM :)
117 llvm::DenseMap<const CXXRecordDecl *, uint64_t> BaseOffsets;
118
119 /// VBaseOffsets - Contains a map from vbase classes to their offset.
120 /// FIXME: This should really use a SmallPtrMap, once we have one in LLVM :)
121 llvm::DenseMap<const CXXRecordDecl *, uint64_t> VBaseOffsets;
122
123 /// KeyFunction - The key function, according to the Itanium C++ ABI,
124 /// section 5.2.3:
125 ///
126 /// ...the first non-pure virtual function that is not inline at the point
127 /// of class definition.
128 const CXXMethodDecl *KeyFunction;
71 };
72
73 /// CXXInfo - If the record layout is for a C++ record, this will have
74 /// C++ specific information about the record.
75 CXXRecordLayoutInfo *CXXInfo;
76
77 friend class ASTContext;
78 friend class ASTRecordLayoutBuilder;

--- 8 unchanged lines hidden (view full) ---

87 FieldOffsets[i] = fieldoffsets[i];
88 }
89 }
90
91 // Constructor for C++ records.
92 ASTRecordLayout(uint64_t size, unsigned alignment, uint64_t datasize,
93 const uint64_t *fieldoffsets, unsigned fieldcount,
94 uint64_t nonvirtualsize, unsigned nonvirtualalign,
129 };
130
131 /// CXXInfo - If the record layout is for a C++ record, this will have
132 /// C++ specific information about the record.
133 CXXRecordLayoutInfo *CXXInfo;
134
135 friend class ASTContext;
136 friend class ASTRecordLayoutBuilder;

--- 8 unchanged lines hidden (view full) ---

145 FieldOffsets[i] = fieldoffsets[i];
146 }
147 }
148
149 // Constructor for C++ records.
150 ASTRecordLayout(uint64_t size, unsigned alignment, uint64_t datasize,
151 const uint64_t *fieldoffsets, unsigned fieldcount,
152 uint64_t nonvirtualsize, unsigned nonvirtualalign,
95 const CXXRecordDecl *PB, bool PBVirtual,
153 const PrimaryBaseInfo &PrimaryBase,
96 const std::pair<const CXXRecordDecl *, uint64_t> *bases,
97 unsigned numbases,
98 const std::pair<const CXXRecordDecl *, uint64_t> *vbases,
154 const std::pair<const CXXRecordDecl *, uint64_t> *bases,
155 unsigned numbases,
156 const std::pair<const CXXRecordDecl *, uint64_t> *vbases,
99 unsigned numvbases)
157 unsigned numvbases,
158 const CXXMethodDecl *KeyFunction)
100 : Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment),
101 FieldCount(fieldcount), CXXInfo(new CXXRecordLayoutInfo) {
102 if (FieldCount > 0) {
103 FieldOffsets = new uint64_t[FieldCount];
104 for (unsigned i = 0; i < FieldCount; ++i)
105 FieldOffsets[i] = fieldoffsets[i];
106 }
107
159 : Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment),
160 FieldCount(fieldcount), CXXInfo(new CXXRecordLayoutInfo) {
161 if (FieldCount > 0) {
162 FieldOffsets = new uint64_t[FieldCount];
163 for (unsigned i = 0; i < FieldCount; ++i)
164 FieldOffsets[i] = fieldoffsets[i];
165 }
166
108 CXXInfo->PrimaryBase = PB;
109 CXXInfo->PrimaryBaseWasVirtual = PBVirtual;
167 CXXInfo->PrimaryBase = PrimaryBase;
110 CXXInfo->NonVirtualSize = nonvirtualsize;
111 CXXInfo->NonVirtualAlign = nonvirtualalign;
112 for (unsigned i = 0; i != numbases; ++i)
113 CXXInfo->BaseOffsets[bases[i].first] = bases[i].second;
114 for (unsigned i = 0; i != numvbases; ++i)
115 CXXInfo->VBaseOffsets[vbases[i].first] = vbases[i].second;
168 CXXInfo->NonVirtualSize = nonvirtualsize;
169 CXXInfo->NonVirtualAlign = nonvirtualalign;
170 for (unsigned i = 0; i != numbases; ++i)
171 CXXInfo->BaseOffsets[bases[i].first] = bases[i].second;
172 for (unsigned i = 0; i != numvbases; ++i)
173 CXXInfo->VBaseOffsets[vbases[i].first] = vbases[i].second;
174 CXXInfo->KeyFunction = KeyFunction;
116 }
117
118 ~ASTRecordLayout() {
119 delete [] FieldOffsets;
120 delete CXXInfo;
121 }
122
123 ASTRecordLayout(const ASTRecordLayout&); // DO NOT IMPLEMENT

--- 33 unchanged lines hidden (view full) ---

157 /// getNonVirtualSize - Get the non-virtual alignment (in bits) of an object,
158 /// which is the alignment of the object without virtual bases.
159 unsigned getNonVirtualAlign() const {
160 assert(CXXInfo && "Record layout does not have C++ specific info!");
161
162 return CXXInfo->NonVirtualAlign;
163 }
164
175 }
176
177 ~ASTRecordLayout() {
178 delete [] FieldOffsets;
179 delete CXXInfo;
180 }
181
182 ASTRecordLayout(const ASTRecordLayout&); // DO NOT IMPLEMENT

--- 33 unchanged lines hidden (view full) ---

216 /// getNonVirtualSize - Get the non-virtual alignment (in bits) of an object,
217 /// which is the alignment of the object without virtual bases.
218 unsigned getNonVirtualAlign() const {
219 assert(CXXInfo && "Record layout does not have C++ specific info!");
220
221 return CXXInfo->NonVirtualAlign;
222 }
223
165 /// getPrimaryBase - Get the primary base.
166 const CXXRecordDecl *getPrimaryBase() const {
224 /// getPrimaryBaseInfo - Get the primary base info.
225 const PrimaryBaseInfo &getPrimaryBaseInfo() const {
167 assert(CXXInfo && "Record layout does not have C++ specific info!");
168
169 return CXXInfo->PrimaryBase;
170 }
226 assert(CXXInfo && "Record layout does not have C++ specific info!");
227
228 return CXXInfo->PrimaryBase;
229 }
171 /// getPrimaryBaseWasVirtual - Indicates if the primary base was virtual.
172 bool getPrimaryBaseWasVirtual() const {
173 assert(CXXInfo && "Record layout does not have C++ specific info!");
174
230
175 return CXXInfo->PrimaryBaseWasVirtual;
231 // FIXME: Migrate off of this function and use getPrimaryBaseInfo directly.
232 const CXXRecordDecl *getPrimaryBase() const {
233 return getPrimaryBaseInfo().getBase();
176 }
177
234 }
235
236 // FIXME: Migrate off of this function and use getPrimaryBaseInfo directly.
237 bool getPrimaryBaseWasVirtual() const {
238 return getPrimaryBaseInfo().isVirtual();
239 }
240
178 /// getBaseClassOffset - Get the offset, in bits, for the given base class.
179 uint64_t getBaseClassOffset(const CXXRecordDecl *Base) const {
180 assert(CXXInfo && "Record layout does not have C++ specific info!");
181 assert(CXXInfo->BaseOffsets.count(Base) && "Did not find base!");
182
183 return CXXInfo->BaseOffsets[Base];
184 }
185
186 /// getVBaseClassOffset - Get the offset, in bits, for the given base class.
187 uint64_t getVBaseClassOffset(const CXXRecordDecl *VBase) const {
188 assert(CXXInfo && "Record layout does not have C++ specific info!");
189 assert(CXXInfo->VBaseOffsets.count(VBase) && "Did not find base!");
190
191 return CXXInfo->VBaseOffsets[VBase];
192 }
241 /// getBaseClassOffset - Get the offset, in bits, for the given base class.
242 uint64_t getBaseClassOffset(const CXXRecordDecl *Base) const {
243 assert(CXXInfo && "Record layout does not have C++ specific info!");
244 assert(CXXInfo->BaseOffsets.count(Base) && "Did not find base!");
245
246 return CXXInfo->BaseOffsets[Base];
247 }
248
249 /// getVBaseClassOffset - Get the offset, in bits, for the given base class.
250 uint64_t getVBaseClassOffset(const CXXRecordDecl *VBase) const {
251 assert(CXXInfo && "Record layout does not have C++ specific info!");
252 assert(CXXInfo->VBaseOffsets.count(VBase) && "Did not find base!");
253
254 return CXXInfo->VBaseOffsets[VBase];
255 }
256
257 /// getKeyFunction - Get the key function.
258 const CXXMethodDecl *getKeyFunction() const {
259 assert(CXXInfo && "Record layout does not have C++ specific info!");
260
261 return CXXInfo->KeyFunction;
262 }
263
264 primary_base_info_iterator primary_base_begin() const {
265 assert(CXXInfo && "Record layout does not have C++ specific info!");
266
267 return primary_base_info_iterator(getPrimaryBaseInfo());
268 }
269
270 primary_base_info_iterator primary_base_end() const {
271 assert(CXXInfo && "Record layout does not have C++ specific info!");
272
273 return primary_base_info_iterator();
274 }
193};
194
195} // end namespace clang
196
197#endif
275};
276
277} // end namespace clang
278
279#endif