Instantiator
Generate c++ template instantiations
Loading...
Searching...
No Matches
ASTCreation.cpp
Go to the documentation of this file.
1#include "ASTCreation.hpp"
2
3#include <chrono>
4#include <filesystem>
5#include <memory>
6#include <stdexcept>
7
8#include "spdlog/spdlog.h"
9
12
13void parseOrLoadAST(std::unique_ptr<clang::ASTUnit>& AST,
14 const clang::tooling::CompilationDatabase& db,
15 const std::filesystem::path& filename,
16 const std::filesystem::path& tmpdir)
17{
18 clang::tooling::ClangTool Tool(db, filename.string());
19 ASTBuilderAction ast_build_action(AST, db, filename, tmpdir);
20 int success = Tool.run(&ast_build_action);
21 if(success == 1) {
22 throw std::runtime_error("Error while creating the AST for " + filename.string() +
23 ". Check for issing includes due to generated instantiations.");
24 }
25}
26
27namespace internal {
28
29bool is_cached(const clang::tooling::CompilationDatabase& db, const std::filesystem::path& file, const std::filesystem::path& tmpdir)
30{
31 clang::tooling::ClangTool Tool(db, file.string());
32 std::vector<std::string> deps;
33 class SingleFrontendActionFactory : public clang::tooling::FrontendActionFactory
34 {
35 std::vector<std::string>* deps;
36
37 public:
38 SingleFrontendActionFactory(std::vector<std::string>* deps)
39 : deps(deps)
40 {}
41
42 std::unique_ptr<clang::FrontendAction> create() override
43 {
44 auto dep_action = std::make_unique<DependencyAction>();
45 dep_action->dependencies = deps;
46 return std::move(dep_action);
47 }
48 };
49
50 auto wrapper = std::make_unique<SingleFrontendActionFactory>(&deps);
51 [[maybe_unused]] int result = Tool.run(wrapper.get());
52
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; }
59 }
60 return true;
61}
62} // namespace internal
void parseOrLoadAST(std::unique_ptr< clang::ASTUnit > &AST, const clang::tooling::CompilationDatabase &db, const std::filesystem::path &filename, const std::filesystem::path &tmpdir)
Action to compute a single AST of file filename.
bool is_cached(const clang::tooling::CompilationDatabase &db, const std::filesystem::path &filename, const std::filesystem::path &tmpdir)