summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2018-05-18 16:06:19 +0000
committerEric Liu <ioeric@google.com>2018-05-18 16:06:19 +0000
commit8992d27caa775535dfbbbec8b71c38eed13f17de (patch)
tree2924b8283c4c4b9f5f228dbb1d7b42bacf5f23e4 /clang/lib/Tooling
parent29b8df607e9ce8b59fb6ab91a4289bd32063de2c (diff)
downloadbcm5719-llvm-8992d27caa775535dfbbbec8b71c38eed13f17de.tar.gz
bcm5719-llvm-8992d27caa775535dfbbbec8b71c38eed13f17de.zip
[Tooling] Add an overload of runToolOnCodeWithArgs that takes VFS
Summary: ... to support purely VFS-based tools. Reviewers: bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D47074 llvm-svn: 332731
Diffstat (limited to 'clang/lib/Tooling')
-rw-r--r--clang/lib/Tooling/Tooling.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 9ef578b3629..c22ad93c760 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -155,27 +155,37 @@ namespace tooling {
bool runToolOnCodeWithArgs(
FrontendAction *ToolAction, const Twine &Code,
+ llvm::IntrusiveRefCntPtr<vfs::FileSystem> VFS,
const std::vector<std::string> &Args, const Twine &FileName,
const Twine &ToolName,
- std::shared_ptr<PCHContainerOperations> PCHContainerOps,
- const FileContentMappings &VirtualMappedFiles) {
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps) {
SmallString<16> FileNameStorage;
StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage);
- llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem(
- new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
- llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
- new vfs::InMemoryFileSystem);
- OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+
llvm::IntrusiveRefCntPtr<FileManager> Files(
- new FileManager(FileSystemOptions(), OverlayFileSystem));
+ new FileManager(FileSystemOptions(), VFS));
ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster();
ToolInvocation Invocation(
getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileNameRef), FileNameRef),
ToolAction, Files.get(),
std::move(PCHContainerOps));
+ return Invocation.run();
+}
+
+bool runToolOnCodeWithArgs(
+ FrontendAction *ToolAction, const Twine &Code,
+ const std::vector<std::string> &Args, const Twine &FileName,
+ const Twine &ToolName,
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps,
+ const FileContentMappings &VirtualMappedFiles) {
+ llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem(
+ new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
+ llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
+ new vfs::InMemoryFileSystem);
+ OverlayFileSystem->pushOverlay(InMemoryFileSystem);
SmallString<1024> CodeStorage;
- InMemoryFileSystem->addFile(FileNameRef, 0,
+ InMemoryFileSystem->addFile(FileName, 0,
llvm::MemoryBuffer::getMemBuffer(
Code.toNullTerminatedStringRef(CodeStorage)));
@@ -185,7 +195,8 @@ bool runToolOnCodeWithArgs(
llvm::MemoryBuffer::getMemBuffer(FilenameWithContent.second));
}
- return Invocation.run();
+ return runToolOnCodeWithArgs(ToolAction, Code, OverlayFileSystem, Args,
+ FileName, ToolName);
}
std::string getAbsolutePath(StringRef File) {
OpenPOWER on IntegriCloud