14 const clang::tooling::CompilationDatabase& db,
15 const std::filesystem::path& filename,
16 const std::filesystem::path& tmpdir)
18 clang::tooling::ClangTool Tool(db, filename.string());
20 int success = Tool.run(&ast_build_action);
22 throw std::runtime_error(
"Error while creating the AST for " + filename.string() +
23 ". Check for issing includes due to generated instantiations.");
29bool is_cached(
const clang::tooling::CompilationDatabase& db,
const std::filesystem::path& file,
const std::filesystem::path& tmpdir)
31 clang::tooling::ClangTool Tool(db, file.string());
32 std::vector<std::string> deps;
33 class SingleFrontendActionFactory :
public clang::tooling::FrontendActionFactory
35 std::vector<std::string>* deps;
38 SingleFrontendActionFactory(std::vector<std::string>* deps)
42 std::unique_ptr<clang::FrontendAction> create()
override
44 auto dep_action = std::make_unique<DependencyAction>();
45 dep_action->dependencies = deps;
46 return std::move(dep_action);
50 auto wrapper = std::make_unique<SingleFrontendActionFactory>(&deps);
51 [[maybe_unused]]
int result = Tool.run(wrapper.get());
53 if(not std::filesystem::exists(tmpdir / file.filename().replace_extension(
"ast"))) {
return false; }
54 auto time_point_ast = std::filesystem::last_write_time(tmpdir / file.filename().replace_extension(
"ast"));
55 for(
const auto& dep : deps) {
56 std::filesystem::path p_dep(dep);
57 auto time_point_cpp = std::filesystem::last_write_time(p_dep);
58 if(time_point_ast <= time_point_cpp) {
return false; }
void parseOrLoadAST(std::unique_ptr< clang::ASTUnit > &AST, const clang::tooling::CompilationDatabase &db, const std::filesystem::path &filename, const std::filesystem::path &tmpdir)