[PATCH] D47074: [Tooling] Add an overload of runToolOnCodeWithArgs that takes VFS
This revision was automatically updated to reflect the committed changes. Closed by commit rC332731: [Tooling] Add an overload of runToolOnCodeWithArgs that takes VFS (authored by ioeric, committed by ). Changed prior to commit: https://reviews.llvm.org/D47074?vs=147526=147529#toc Repository: rC Clang https://reviews.llvm.org/D47074 Files: include/clang/Tooling/Tooling.h lib/Tooling/Tooling.cpp Index: include/clang/Tooling/Tooling.h === --- include/clang/Tooling/Tooling.h +++ include/clang/Tooling/Tooling.h @@ -187,6 +187,15 @@ std::make_shared(), const FileContentMappings = FileContentMappings()); +// Similar to the overload except this takes a VFS. +bool runToolOnCodeWithArgs( +FrontendAction *ToolAction, const Twine , +llvm::IntrusiveRefCntPtr VFS, +const std::vector , const Twine = "input.cc", +const Twine = "clang-tool", +std::shared_ptr PCHContainerOps = +std::make_shared()); + /// Builds an AST for 'Code'. /// /// \param Code C++ code. Index: lib/Tooling/Tooling.cpp === --- lib/Tooling/Tooling.cpp +++ lib/Tooling/Tooling.cpp @@ -155,27 +155,37 @@ bool runToolOnCodeWithArgs( FrontendAction *ToolAction, const Twine , +llvm::IntrusiveRefCntPtr VFS, const std::vector , const Twine , const Twine , -std::shared_ptr PCHContainerOps, -const FileContentMappings ) { +std::shared_ptr PCHContainerOps) { SmallString<16> FileNameStorage; StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage); - llvm::IntrusiveRefCntPtr OverlayFileSystem( - new vfs::OverlayFileSystem(vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr InMemoryFileSystem( - new vfs::InMemoryFileSystem); - OverlayFileSystem->pushOverlay(InMemoryFileSystem); + llvm::IntrusiveRefCntPtr 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 , +const std::vector , const Twine , +const Twine , +std::shared_ptr PCHContainerOps, +const FileContentMappings ) { + llvm::IntrusiveRefCntPtr OverlayFileSystem( + new vfs::OverlayFileSystem(vfs::getRealFileSystem())); + llvm::IntrusiveRefCntPtr 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 @@ llvm::MemoryBuffer::getMemBuffer(FilenameWithContent.second)); } - return Invocation.run(); + return runToolOnCodeWithArgs(ToolAction, Code, OverlayFileSystem, Args, + FileName, ToolName); } std::string getAbsolutePath(StringRef File) { Index: include/clang/Tooling/Tooling.h === --- include/clang/Tooling/Tooling.h +++ include/clang/Tooling/Tooling.h @@ -187,6 +187,15 @@ std::make_shared(), const FileContentMappings = FileContentMappings()); +// Similar to the overload except this takes a VFS. +bool runToolOnCodeWithArgs( +FrontendAction *ToolAction, const Twine , +llvm::IntrusiveRefCntPtr VFS, +const std::vector , const Twine = "input.cc", +const Twine = "clang-tool", +std::shared_ptr PCHContainerOps = +std::make_shared()); + /// Builds an AST for 'Code'. /// /// \param Code C++ code. Index: lib/Tooling/Tooling.cpp === --- lib/Tooling/Tooling.cpp +++ lib/Tooling/Tooling.cpp @@ -155,27 +155,37 @@ bool runToolOnCodeWithArgs( FrontendAction *ToolAction, const Twine , +llvm::IntrusiveRefCntPtr VFS, const std::vector , const Twine , const Twine , -std::shared_ptr PCHContainerOps, -const FileContentMappings ) { +std::shared_ptr PCHContainerOps) { SmallString<16> FileNameStorage; StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage); - llvm::IntrusiveRefCntPtr OverlayFileSystem( - new vfs::OverlayFileSystem(vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr InMemoryFileSystem( - new vfs::InMemoryFileSystem); - OverlayFileSystem->pushOverlay(InMemoryFileSystem); + llvm::IntrusiveRefCntPtr Files( - new FileManager(FileSystemOptions(), OverlayFileSystem)); +
[PATCH] D47074: [Tooling] Add an overload of runToolOnCodeWithArgs that takes VFS
bkramer accepted this revision. bkramer added a comment. This revision is now accepted and ready to land. lg Repository: rC Clang https://reviews.llvm.org/D47074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D47074: [Tooling] Add an overload of runToolOnCodeWithArgs that takes VFS
ioeric created this revision. ioeric added a reviewer: bkramer. Herald added subscribers: cfe-commits, klimek. ... to support purely VFS-based tools. Repository: rC Clang https://reviews.llvm.org/D47074 Files: include/clang/Tooling/Tooling.h lib/Tooling/Tooling.cpp Index: lib/Tooling/Tooling.cpp === --- lib/Tooling/Tooling.cpp +++ lib/Tooling/Tooling.cpp @@ -155,27 +155,37 @@ bool runToolOnCodeWithArgs( FrontendAction *ToolAction, const Twine , +llvm::IntrusiveRefCntPtr VFS, const std::vector , const Twine , const Twine , -std::shared_ptr PCHContainerOps, -const FileContentMappings ) { +std::shared_ptr PCHContainerOps) { SmallString<16> FileNameStorage; StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage); - llvm::IntrusiveRefCntPtr OverlayFileSystem( - new vfs::OverlayFileSystem(vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr InMemoryFileSystem( - new vfs::InMemoryFileSystem); - OverlayFileSystem->pushOverlay(InMemoryFileSystem); + llvm::IntrusiveRefCntPtr 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 , +const std::vector , const Twine , +const Twine , +std::shared_ptr PCHContainerOps, +const FileContentMappings ) { + llvm::IntrusiveRefCntPtr OverlayFileSystem( + new vfs::OverlayFileSystem(vfs::getRealFileSystem())); + llvm::IntrusiveRefCntPtr 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 @@ llvm::MemoryBuffer::getMemBuffer(FilenameWithContent.second)); } - return Invocation.run(); + return runToolOnCodeWithArgs(ToolAction, Code, OverlayFileSystem, Args, + FileName, ToolName); } std::string getAbsolutePath(StringRef File) { Index: include/clang/Tooling/Tooling.h === --- include/clang/Tooling/Tooling.h +++ include/clang/Tooling/Tooling.h @@ -187,6 +187,15 @@ std::make_shared(), const FileContentMappings = FileContentMappings()); +// Similar to the overload except this takes a VFS. +bool runToolOnCodeWithArgs( +FrontendAction *ToolAction, const Twine , +llvm::IntrusiveRefCntPtr VFS, +const std::vector , const Twine = "input.cc", +const Twine = "clang-tool", +std::shared_ptr PCHContainerOps = +std::make_shared()); + /// Builds an AST for 'Code'. /// /// \param Code C++ code. Index: lib/Tooling/Tooling.cpp === --- lib/Tooling/Tooling.cpp +++ lib/Tooling/Tooling.cpp @@ -155,27 +155,37 @@ bool runToolOnCodeWithArgs( FrontendAction *ToolAction, const Twine , +llvm::IntrusiveRefCntPtr VFS, const std::vector , const Twine , const Twine , -std::shared_ptr PCHContainerOps, -const FileContentMappings ) { +std::shared_ptr PCHContainerOps) { SmallString<16> FileNameStorage; StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage); - llvm::IntrusiveRefCntPtr OverlayFileSystem( - new vfs::OverlayFileSystem(vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr InMemoryFileSystem( - new vfs::InMemoryFileSystem); - OverlayFileSystem->pushOverlay(InMemoryFileSystem); + llvm::IntrusiveRefCntPtr 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 , +const std::vector , const Twine , +const Twine , +std::shared_ptr PCHContainerOps, +const FileContentMappings ) { + llvm::IntrusiveRefCntPtr OverlayFileSystem( + new vfs::OverlayFileSystem(vfs::getRealFileSystem())); + llvm::IntrusiveRefCntPtr InMemoryFileSystem( + new vfs::InMemoryFileSystem); + OverlayFileSystem->pushOverlay(InMemoryFileSystem);