stub types in OIL via config (#484)

This commit is contained in:
Jon Haslam 2024-02-14 15:23:35 +00:00 committed by GitHub
parent 7103680894
commit bfafe2eeae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 1 deletions

View File

@ -31,7 +31,9 @@
#include <range/v3/view/for_each.hpp> #include <range/v3/view/for_each.hpp>
#include <range/v3/view/take.hpp> #include <range/v3/view/take.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <set>
#include <stdexcept> #include <stdexcept>
#include <string>
#include <unordered_map> #include <unordered_map>
#include <variant> #include <variant>
@ -85,6 +87,7 @@ class ConsumerContext {
std::unordered_map<std::string, type_graph::Type*> nameToTypeMap; std::unordered_map<std::string, type_graph::Type*> nameToTypeMap;
std::optional<bool> pic; std::optional<bool> pic;
const std::vector<std::unique_ptr<ContainerInfo>>& containerInfos; const std::vector<std::unique_ptr<ContainerInfo>>& containerInfos;
std::set<std::string_view> typesToStub;
private: private:
clang::Sema* sema = nullptr; clang::Sema* sema = nullptr;
@ -133,6 +136,12 @@ int OIGenerator::generate(clang::tooling::CompilationDatabase& db,
} }
ConsumerContext ctx{containerInfos}; ConsumerContext ctx{containerInfos};
for (const auto& [stubType, stubMember] : generatorConfig.membersToStub) {
if (stubMember == "*")
ctx.typesToStub.insert(stubType);
}
CreateTypeGraphActionFactory factory{ctx}; CreateTypeGraphActionFactory factory{ctx};
clang::tooling::ClangTool tool{db, sourcePaths}; clang::tooling::ClangTool tool{db, sourcePaths};
@ -239,6 +248,8 @@ class CreateTypeGraphConsumer : public clang::ASTConsumer {
return; return;
type_graph::ClangTypeParserOptions opts; type_graph::ClangTypeParserOptions opts;
opts.typesToStub = ctx.typesToStub;
type_graph::ClangTypeParser parser{ctx.typeGraph, ctx.containerInfos, opts}; type_graph::ClangTypeParser parser{ctx.typeGraph, ctx.containerInfos, opts};
auto& Sema = *ctx.sema; auto& Sema = *ctx.sema;

View File

@ -19,6 +19,7 @@
#include <clang/AST/Decl.h> #include <clang/AST/Decl.h>
#include <clang/AST/DeclTemplate.h> #include <clang/AST/DeclTemplate.h>
#include <clang/AST/QualTypeNames.h> #include <clang/AST/QualTypeNames.h>
#include <clang/AST/RecordLayout.h>
#include <clang/AST/Type.h> #include <clang/AST/Type.h>
#include <clang/Basic/DiagnosticSema.h> #include <clang/Basic/DiagnosticSema.h>
#include <clang/Sema/Sema.h> #include <clang/Sema/Sema.h>
@ -71,6 +72,7 @@ Type& ClangTypeParser::enumerateType(const clang::Type& ty) {
if (!requireCompleteType(*sema, ty)) { if (!requireCompleteType(*sema, ty)) {
std::string fqName = clang::TypeName::getFullyQualifiedName( std::string fqName = clang::TypeName::getFullyQualifiedName(
clang::QualType(&ty, 0), *ast, {ast->getLangOpts()}); clang::QualType(&ty, 0), *ast, {ast->getLangOpts()});
VLOG(3) << "Returning incomplete type for " << fqName;
return makeType<Incomplete>(ty, std::move(fqName)); return makeType<Incomplete>(ty, std::move(fqName));
} }
@ -194,12 +196,23 @@ Type& ClangTypeParser::enumerateClass(const clang::RecordType& ty) {
int virtuality = 0; int virtuality = 0;
std::string fqnWithoutTemplateParams = decl->getQualifiedNameAsString();
if (options_.typesToStub.contains(fqnWithoutTemplateParams)) {
uint64_t alignment = decl->getASTContext()
.getASTRecordLayout(decl)
.getAlignment()
.getQuantity();
auto& c = makeType<Dummy>(ty, size, alignment, fqName);
return c;
}
auto& c = makeType<Class>( auto& c = makeType<Class>(
ty, kind, std::move(name), std::move(fqName), size, virtuality); ty, kind, std::move(name), std::move(fqName), size, virtuality);
c.setAlign(ast->getTypeAlign(clang::QualType(&ty, 0)) / 8); c.setAlign(ast->getTypeAlign(clang::QualType(&ty, 0)) / 8);
enumerateClassTemplateParams(ty, c.templateParams); enumerateClassTemplateParams(ty, c.templateParams);
// enumerateClassParents(type, c.parents); // enumerateClassParents(ty, c.parents);
enumerateClassMembers(ty, c.members); enumerateClassMembers(ty, c.members);
// enumerateClassFunctions(type, c.functions); // enumerateClassFunctions(type, c.functions);

View File

@ -60,6 +60,7 @@ struct TemplateParam;
struct ClangTypeParserOptions { struct ClangTypeParserOptions {
bool chaseRawPointers = false; bool chaseRawPointers = false;
bool readEnumValues = false; bool readEnumValues = false;
std::set<std::string_view> typesToStub;
}; };
/* /*