|
17 | 17 |
|
18 | 18 | #include <clang/AST/ASTContext.h>
|
19 | 19 | #include <clang/AST/Decl.h>
|
| 20 | +#include <clang/AST/DeclCXX.h> |
20 | 21 | #include <clang/AST/DeclTemplate.h>
|
21 | 22 | #include <clang/AST/QualTypeNames.h>
|
22 | 23 | #include <clang/AST/RecordLayout.h>
|
@@ -214,7 +215,7 @@ Type& ClangTypeParser::enumerateClass(const clang::RecordType& ty) {
|
214 | 215 | if (options_.mustProcessTemplateParams.contains(fqnWithoutTemplateParams))
|
215 | 216 | enumerateClassTemplateParams(ty, c.templateParams);
|
216 | 217 |
|
217 |
| - // enumerateClassParents(ty, c.parents); |
| 218 | + enumerateClassParents(ty, c.parents); |
218 | 219 | enumerateClassMembers(ty, c.members);
|
219 | 220 |
|
220 | 221 | return c;
|
@@ -312,6 +313,31 @@ std::optional<TemplateParam> ClangTypeParser::enumerateTemplateTemplateParam(
|
312 | 313 | }
|
313 | 314 | }
|
314 | 315 |
|
| 316 | +void ClangTypeParser::enumerateClassParents(const clang::RecordType& ty, |
| 317 | + std::vector<Parent>& parents) { |
| 318 | + assert(parents.empty()); |
| 319 | + |
| 320 | + auto* decl = ty.getDecl(); |
| 321 | + auto* cxxDecl = llvm::dyn_cast<clang::CXXRecordDecl>(decl); |
| 322 | + if (cxxDecl == nullptr) |
| 323 | + return; |
| 324 | + |
| 325 | + const auto& layout = decl->getASTContext().getASTRecordLayout(cxxDecl); |
| 326 | + for (const auto& base : cxxDecl->bases()) { |
| 327 | + auto baseType = base.getType(); |
| 328 | + if (baseType.isNull()) |
| 329 | + continue; |
| 330 | + |
| 331 | + auto* baseCxxDecl = baseType->getAsCXXRecordDecl(); |
| 332 | + if (baseCxxDecl == nullptr) |
| 333 | + continue; |
| 334 | + |
| 335 | + auto offset = layout.getBaseClassOffset(baseCxxDecl).getQuantity(); |
| 336 | + auto& ptype = enumerateType(*baseType); |
| 337 | + parents.emplace_back(Parent{ptype, static_cast<uint64_t>(offset)}); |
| 338 | + } |
| 339 | +} |
| 340 | + |
315 | 341 | void ClangTypeParser::enumerateClassMembers(const clang::RecordType& ty,
|
316 | 342 | std::vector<Member>& members) {
|
317 | 343 | assert(members.empty());
|
|
0 commit comments