mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-12 21:56:54 +00:00
clangparser: add support for parents
Summary: Add support in ClangTypeParser for parents. Reviewed By: JakeHillion Differential Revision: D53708619
This commit is contained in:
parent
1ba742b433
commit
c367e7fa01
@ -17,6 +17,7 @@
|
||||
|
||||
#include <clang/AST/ASTContext.h>
|
||||
#include <clang/AST/Decl.h>
|
||||
#include <clang/AST/DeclCXX.h>
|
||||
#include <clang/AST/DeclTemplate.h>
|
||||
#include <clang/AST/QualTypeNames.h>
|
||||
#include <clang/AST/RecordLayout.h>
|
||||
@ -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<TemplateParam> ClangTypeParser::enumerateTemplateTemplateParam(
|
||||
}
|
||||
}
|
||||
|
||||
void ClangTypeParser::enumerateClassParents(const clang::RecordType& ty,
|
||||
std::vector<Parent>& parents) {
|
||||
assert(parents.empty());
|
||||
|
||||
auto* decl = ty.getDecl();
|
||||
auto* cxxDecl = llvm::dyn_cast<clang::CXXRecordDecl>(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<uint64_t>(offset)});
|
||||
}
|
||||
}
|
||||
|
||||
void ClangTypeParser::enumerateClassMembers(const clang::RecordType& ty,
|
||||
std::vector<Member>& members) {
|
||||
assert(members.empty());
|
||||
|
@ -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<TemplateParam> enumerateTemplateTemplateParam(
|
||||
const clang::TemplateName&);
|
||||
|
||||
void enumerateClassParents(const clang::RecordType&, std::vector<Parent>&);
|
||||
void enumerateClassMembers(const clang::RecordType&, std::vector<Member>&);
|
||||
|
||||
ContainerInfo* getContainerInfo(const std::string& fqName) const;
|
||||
|
Loading…
Reference in New Issue
Block a user