Instantiator
Generate c++ template instantiations
Loading...
Searching...
No Matches
ASTBuilderAction.cpp
Go to the documentation of this file.
2
3#include <filesystem>
4
5#include "fmt/std.h"
6#include "spdlog/spdlog.h"
7
8#include "clang/Basic/FileManager.h"
9
10#include "ASTCreation.hpp"
11
12bool ASTBuilderAction::runInvocation(std::shared_ptr<clang::CompilerInvocation> Invocation,
13 clang::FileManager* Files,
14 std::shared_ptr<clang::PCHContainerOperations> PCHContainerOps,
15 clang::DiagnosticConsumer* DiagConsumer)
16{
17 spdlog::debug("Processing {}", file);
18 bool is_cached_on_disk = internal::is_cached(db, file, tmpdir);
19 spdlog::debug("cached={}", is_cached_on_disk);
20 if(is_cached_on_disk) {
21 clang::CompilerInstance CI;
22 CI.setInvocation(Invocation);
23 CI.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false);
24 clang::DiagnosticsEngine* DiagEngine = &CI.getDiagnostics();
25#if INSTANTIATOR_LLVM_MAJOR > 16
26 AST = clang::ASTUnit::LoadFromASTFile((tmpdir / file.filename().replace_extension("ast")).string(),
27 CI.getPCHContainerReader(),
28 clang::ASTUnit::WhatToLoad::LoadEverything,
29 llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>(DiagEngine),
30 CI.getFileSystemOpts(),
31 CI.getHeaderSearchOptsPtr());
32#else
33 AST = clang::ASTUnit::LoadFromASTFile((tmpdir / file.filename().replace_extension("ast")).string(),
34 CI.getPCHContainerReader(),
35 clang::ASTUnit::WhatToLoad::LoadEverything,
36 llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>(DiagEngine),
37 CI.getFileSystemOpts());
38#endif
39 } else {
40 AST = clang::ASTUnit::LoadFromCompilerInvocation(Invocation,
41 std::move(PCHContainerOps),
42 clang::CompilerInstance::createDiagnostics(&Invocation->getDiagnosticOpts(),
43 DiagConsumer,
44 /*ShouldOwnClient=*/false),
45 Files);
46 AST->Save((tmpdir / file.filename().replace_extension("ast")).string());
47 }
48 if(!AST or AST->getDiagnostics().hasUncompilableErrorOccurred()) return false;
49 return true;
50}
const clang::tooling::CompilationDatabase & db
std::filesystem::path file
std::filesystem::path tmpdir
std::unique_ptr< clang::ASTUnit > & AST
bool runInvocation(std::shared_ptr< clang::CompilerInvocation > Invocation, clang::FileManager *Files, std::shared_ptr< clang::PCHContainerOperations > PCHContainerOps, clang::DiagnosticConsumer *DiagConsumer) override
bool is_cached(const clang::tooling::CompilationDatabase &db, const std::filesystem::path &filename, const std::filesystem::path &tmpdir)