diff options
-rw-r--r-- | clang/include/clang/Tooling/Tooling.h | 3 | ||||
-rw-r--r-- | clang/lib/Tooling/Tooling.cpp | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/clang/include/clang/Tooling/Tooling.h b/clang/include/clang/Tooling/Tooling.h index 19421f0a39f..f759789170d 100644 --- a/clang/include/clang/Tooling/Tooling.h +++ b/clang/include/clang/Tooling/Tooling.h @@ -224,7 +224,8 @@ std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs( StringRef FileName = "input.cc", StringRef ToolName = "clang-tool", std::shared_ptr<PCHContainerOperations> PCHContainerOps = std::make_shared<PCHContainerOperations>(), - ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster()); + ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(), + const FileContentMappings &VirtualMappedFiles = FileContentMappings()); /// Utility to run a FrontendAction in a single clang invocation. class ToolInvocation { diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp index 1d6a968331b..4a0618c50e4 100644 --- a/clang/lib/Tooling/Tooling.cpp +++ b/clang/lib/Tooling/Tooling.cpp @@ -619,7 +619,7 @@ buildASTFromCode(StringRef Code, StringRef FileName, std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs( StringRef Code, const std::vector<std::string> &Args, StringRef FileName, StringRef ToolName, std::shared_ptr<PCHContainerOperations> PCHContainerOps, - ArgumentsAdjuster Adjuster) { + ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles) { std::vector<std::unique_ptr<ASTUnit>> ASTs; ASTBuilderAction Action(ASTs); llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem( @@ -636,6 +636,12 @@ std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs( InMemoryFileSystem->addFile(FileName, 0, llvm::MemoryBuffer::getMemBufferCopy(Code)); + for (auto &FilenameWithContent : VirtualMappedFiles) { + InMemoryFileSystem->addFile( + FilenameWithContent.first, 0, + llvm::MemoryBuffer::getMemBuffer(FilenameWithContent.second)); + } + if (!Invocation.run()) return nullptr; |