10 #include "llvm/ADT/StringRef.h" 11 #include "llvm/ADT/Triple.h" 12 #include "llvm/Support/CommandLine.h" 13 #include "llvm/Support/ConvertUTF.h" 14 #include "llvm/Support/ErrorOr.h" 15 #include "llvm/Support/MemoryBuffer.h" 16 #include "llvm/Support/Path.h" 17 #include "llvm/Support/StringSaver.h" 23 class ExpandResponseFilesDatabase :
public CompilationDatabase {
25 ExpandResponseFilesDatabase(
26 std::unique_ptr<CompilationDatabase>
Base,
27 llvm::cl::TokenizerCallback Tokenizer,
29 : Base(
std::move(Base)), Tokenizer(Tokenizer), FS(
std::move(FS)) {
30 assert(this->Base !=
nullptr);
31 assert(this->Tokenizer !=
nullptr);
32 assert(this->FS !=
nullptr);
35 std::vector<std::string> getAllFiles()
const override {
36 return Base->getAllFiles();
39 std::vector<CompileCommand>
40 getCompileCommands(StringRef FilePath)
const override {
41 return expand(
Base->getCompileCommands(FilePath));
44 std::vector<CompileCommand> getAllCompileCommands()
const override {
45 return expand(
Base->getAllCompileCommands());
49 std::vector<CompileCommand> expand(std::vector<CompileCommand> Cmds)
const {
50 for (
auto &
Cmd : Cmds) {
51 bool SeenRSPFile =
false;
53 Argv.reserve(
Cmd.CommandLine.size());
54 for (
auto &Arg :
Cmd.CommandLine) {
55 Argv.push_back(Arg.c_str());
56 SeenRSPFile |= Arg.front() ==
'@';
60 llvm::BumpPtrAllocator Alloc;
61 llvm::StringSaver Saver(Alloc);
62 llvm::cl::ExpandResponseFiles(Saver, Tokenizer, Argv,
false,
false, *FS,
63 llvm::StringRef(
Cmd.Directory));
65 std::vector<std::string> ExpandedArgv(Argv.begin(), Argv.end());
66 Cmd.CommandLine = std::move(ExpandedArgv);
72 std::unique_ptr<CompilationDatabase>
Base;
73 llvm::cl::TokenizerCallback Tokenizer;
79 std::unique_ptr<CompilationDatabase>
82 auto Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
83 ? llvm::cl::TokenizeWindowsCommandLine
84 : llvm::cl::TokenizeGNUCommandLine;
85 return std::make_unique<ExpandResponseFilesDatabase>(
86 std::move(Base), Tokenizer, std::move(FS));
Dataflow Directional Tag Classes.