#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"
}
}
}
+
+ clang::tooling::ClangTool Tool(OptionsParser->getCompilations(),
+ OptionsParser->getSourcePathList());
+ std::vector<std::unique_ptr<llvm::MemoryBuffer>> Buffers;
+ for (const auto &File : OptionsParser->getSourcePathList()) {
+ auto Content = llvm::MemoryBuffer::getFile(File);
+ if (!Content) {
+ llvm::errs() << "Error: can't read file '" << File
+ << "': " << Content.getError().message() << "\n";
+ return 1;
+ }
+ Buffers.push_back(std::move(Content.get()));
+ Tool.mapVirtualFile(File, Buffers.back()->getBuffer());
+ }
+
auto HeaderFilter = headerFilter();
if (!HeaderFilter)
return 1; // error already reported.
ActionFactory Factory(HeaderFilter);
- return clang::tooling::ClangTool(OptionsParser->getCompilations(),
- OptionsParser->getSourcePathList())
- .run(&Factory) ||
- Errors != 0;
+ return Tool.run(&Factory) || Errors != 0;
}