clang: include/clang/AST/RecordLayout.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_CLANG_AST_RECORDLAYOUT_H

14#define LLVM_CLANG_AST_RECORDLAYOUT_H

15

20#include "llvm/ADT/ArrayRef.h"

21#include "llvm/ADT/DenseMap.h"

22#include "llvm/ADT/PointerIntPair.h"

23#include

24#include

25

27

28class ASTContext;

29class CXXRecordDecl;

30

31

32

33

34

35

36

37

39public:

41

42

44

45 private:

46

47

48

49 bool HasVtorDisp = false;

50

51 public:

55

57 };

58

59 using VBaseOffsetsMapTy = llvm::DenseMap<const CXXRecordDecl *, VBaseInfo>;

60

61private:

63

64

66

67

69

70

72

73

74

75

77

78

79

81

82

83

85

86

88

89

90 struct CXXRecordLayoutInfo {

91

92

94

95

96

98

99

100

101

103

104

105

106

107 CharUnits SizeOfLargestEmptySubobject;

108

109

111

112

113

114

115 bool HasOwnVFPtr : 1;

116

117

118

119

120 bool HasExtendableVFPtr : 1;

121

122

123

124

125 bool EndsWithZeroSizedObject : 1;

126

127

128

129 bool LeadsWithZeroSizedBase : 1;

130

131

132 llvm::PointerIntPair<const CXXRecordDecl *, 1, bool> PrimaryBase;

133

134

136

137

138 using BaseOffsetsMapTy = llvm::DenseMap<const CXXRecordDecl *, CharUnits>;

139

140

141 BaseOffsetsMapTy BaseOffsets;

142

143

145 };

146

147

148

149 CXXRecordLayoutInfo *CXXInfo = nullptr;

150

155

156 using BaseOffsetsMapTy = CXXRecordLayoutInfo::BaseOffsetsMapTy;

157

158

166 CharUnits SizeOfLargestEmptySubobject,

167 const CXXRecordDecl *PrimaryBase, bool IsPrimaryBaseVirtual,

169 bool EndsWithZeroSizedObject, bool LeadsWithZeroSizedBase,

170 const BaseOffsetsMapTy &BaseOffsets,

172

174

176

177public:

180

181

183

184

185

187

188

189

191

192

194

195

197

198

199

201 return FieldOffsets[FieldNo];

202 }

203

204

205

207

208

209

211 assert(CXXInfo && "Record layout does not have C++ specific info!");

212

213 return CXXInfo->NonVirtualSize;

214 }

215

216

217

219 assert(CXXInfo && "Record layout does not have C++ specific info!");

220

221 return CXXInfo->NonVirtualAlignment;

222 }

223

224

225

226

228 assert(CXXInfo && "Record layout does not have C++ specific info!");

229

230 return CXXInfo->PreferredNVAlignment;

231 }

232

233

235 assert(CXXInfo && "Record layout does not have C++ specific info!");

236

237 return CXXInfo->PrimaryBase.getPointer();

238 }

239

240

241

243 assert(CXXInfo && "Record layout does not have C++ specific info!");

244

245 return CXXInfo->PrimaryBase.getInt();

246 }

247

248

250 assert(CXXInfo && "Record layout does not have C++ specific info!");

251

252 Base = Base->getDefinition();

253 assert(CXXInfo->BaseOffsets.count(Base) && "Did not find base!");

254

255 return CXXInfo->BaseOffsets[Base];

256 }

257

258

260 assert(CXXInfo && "Record layout does not have C++ specific info!");

261

263 assert(CXXInfo->VBaseOffsets.count(VBase) && "Did not find base!");

264

265 return CXXInfo->VBaseOffsets[VBase].VBaseOffset;

266 }

267

269 assert(CXXInfo && "Record layout does not have C++ specific info!");

270 return CXXInfo->SizeOfLargestEmptySubobject;

271 }

272

273

274

275

276

277

278

279

281 assert(CXXInfo && "Record layout does not have C++ specific info!");

282 return CXXInfo->HasOwnVFPtr;

283 }

284

285

286

287

289 assert(CXXInfo && "Record layout does not have C++ specific info!");

290 return CXXInfo->HasExtendableVFPtr;

291 }

292

293

294

295

296

297

298

299

301 assert(CXXInfo && "Record layout does not have C++ specific info!");

302 return hasVBPtr() && !CXXInfo->BaseSharingVBPtr;

303 }

304

305

307 assert(CXXInfo && "Record layout does not have C++ specific info!");

308 return !CXXInfo->VBPtrOffset.isNegative();

309 }

310

312

314 return CXXInfo && CXXInfo->EndsWithZeroSizedObject;

315 }

316

318 assert(CXXInfo && "Record layout does not have C++ specific info!");

319 return CXXInfo->LeadsWithZeroSizedBase;

320 }

321

322

323

325 assert(CXXInfo && "Record layout does not have C++ specific info!");

326 return CXXInfo->VBPtrOffset;

327 }

328

330 assert(CXXInfo && "Record layout does not have C++ specific info!");

331 return CXXInfo->BaseSharingVBPtr;

332 }

333

335 assert(CXXInfo && "Record layout does not have C++ specific info!");

336 return CXXInfo->VBaseOffsets;

337 }

338};

339

340}

341

342#endif

Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....

Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...

bool endsWithZeroSizedObject() const

bool hasOwnVFPtr() const

hasOwnVFPtr - Does this class provide its own virtual-function table pointer, rather than inheriting ...

CharUnits getAlignment() const

getAlignment - Get the record alignment in characters.

const CXXRecordDecl * getBaseSharingVBPtr() const

CharUnits getPreferredAlignment() const

getPreferredFieldAlignment - Get the record preferred alignment in characters.

bool hasOwnVBPtr() const

hasOwnVBPtr - Does this class provide its own virtual-base table pointer, rather than inheriting one ...

llvm::DenseMap< const CXXRecordDecl *, VBaseInfo > VBaseOffsetsMapTy

ASTRecordLayout & operator=(const ASTRecordLayout &)=delete

CharUnits getSize() const

getSize - Get the record size in characters.

unsigned getFieldCount() const

getFieldCount - Get the number of fields in the layout.

bool hasVBPtr() const

hasVBPtr - Does this class have a virtual function table pointer.

bool leadsWithZeroSizedBase() const

uint64_t getFieldOffset(unsigned FieldNo) const

getFieldOffset - Get the offset of the given field index, in bits.

CharUnits getNonVirtualAlignment() const

getNonVirtualAlignment - Get the non-virtual alignment (in chars) of an object, which is the alignmen...

CharUnits getVBPtrOffset() const

getVBPtrOffset - Get the offset for virtual base table pointer.

CharUnits getDataSize() const

getDataSize() - Get the record data size, which is the record size without tail padding,...

ASTRecordLayout(const ASTRecordLayout &)=delete

CharUnits getRequiredAlignment() const

CharUnits getSizeOfLargestEmptySubobject() const

CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const

getBaseClassOffset - Get the offset, in chars, for the given base class.

CharUnits getPreferredNVAlignment() const

getPreferredNVAlignment - Get the preferred non-virtual alignment (in chars) of an object,...

CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const

getVBaseClassOffset - Get the offset, in chars, for the given base class.

const VBaseOffsetsMapTy & getVBaseOffsetsMap() const

const CXXRecordDecl * getPrimaryBase() const

getPrimaryBase - Get the primary base for this record.

bool hasExtendableVFPtr() const

hasVFPtr - Does this class have a virtual function table pointer that can be extended by a derived cl...

bool isPrimaryBaseVirtual() const

isPrimaryBaseVirtual - Get whether the primary base for this record is virtual or not.

CharUnits getNonVirtualSize() const

getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...

CharUnits getUnadjustedAlignment() const

getUnadjustedAlignment - Get the record alignment in characters, before alignment adjustement.

Represents a C++ struct/union/class.

CXXRecordDecl * getDefinition() const

CharUnits - This is an opaque type for sizes expressed in character units.

The JSON file list parser is used to communicate input to InstallAPI.

VBaseInfo(CharUnits VBaseOffset, bool hasVtorDisp)

CharUnits VBaseOffset

The offset to this virtual base in the complete-object layout of this class.