Files
clice/include/Clang/CompileDatabase.h
2024-07-10 12:46:04 +08:00

31 lines
721 B
C++

#pragma once
#include <Clang/Clang.h>
namespace clice {
class CompileDatabase {
private:
std::unique_ptr<clang::tooling::CompilationDatabase> database;
public:
static auto& instance() {
static CompileDatabase instance;
return instance;
}
void load(std::string_view path);
auto lookup(std::string_view path) {
auto commands = database->getCompileCommands(path);
llvm::ArrayRef command = commands[0].CommandLine;
std::vector<const char*> args = {command.front().c_str(), "-Xclang", "-no-round-trip-args"};
for(auto& arg: command.drop_front()) {
args.push_back(arg.c_str());
}
return args;
}
};
} // namespace clice