diff --git a/oi/type_graph/ClangTypeParser.cpp b/oi/type_graph/ClangTypeParser.cpp index cd9e202..6510bb7 100644 --- a/oi/type_graph/ClangTypeParser.cpp +++ b/oi/type_graph/ClangTypeParser.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -214,7 +215,7 @@ Type& ClangTypeParser::enumerateClass(const clang::RecordType& ty) { if (options_.mustProcessTemplateParams.contains(fqnWithoutTemplateParams)) enumerateClassTemplateParams(ty, c.templateParams); - // enumerateClassParents(ty, c.parents); + enumerateClassParents(ty, c.parents); enumerateClassMembers(ty, c.members); return c; @@ -312,6 +313,31 @@ std::optional ClangTypeParser::enumerateTemplateTemplateParam( } } +void ClangTypeParser::enumerateClassParents(const clang::RecordType& ty, + std::vector& parents) { + assert(parents.empty()); + + auto* decl = ty.getDecl(); + auto* cxxDecl = llvm::dyn_cast(decl); + if (cxxDecl == nullptr) + return; + + const auto& layout = decl->getASTContext().getASTRecordLayout(cxxDecl); + for (const auto& base : cxxDecl->bases()) { + auto baseType = base.getType(); + if (baseType.isNull()) + continue; + + auto* baseCxxDecl = baseType->getAsCXXRecordDecl(); + if (baseCxxDecl == nullptr) + continue; + + auto offset = layout.getBaseClassOffset(baseCxxDecl).getQuantity(); + auto& ptype = enumerateType(*baseType); + parents.emplace_back(Parent{ptype, static_cast(offset)}); + } +} + void ClangTypeParser::enumerateClassMembers(const clang::RecordType& ty, std::vector& members) { assert(members.empty()); diff --git a/oi/type_graph/ClangTypeParser.h b/oi/type_graph/ClangTypeParser.h index 2e126a4..e7daaa1 100644 --- a/oi/type_graph/ClangTypeParser.h +++ b/oi/type_graph/ClangTypeParser.h @@ -50,6 +50,7 @@ class Array; class Class; class Enum; class Member; +struct Parent; class Primitive; class Reference; class Type; @@ -116,6 +117,7 @@ class ClangTypeParser { std::optional enumerateTemplateTemplateParam( const clang::TemplateName&); + void enumerateClassParents(const clang::RecordType&, std::vector&); void enumerateClassMembers(const clang::RecordType&, std::vector&); ContainerInfo* getContainerInfo(const std::string& fqName) const;