From: Benjamin Kramer Date: Tue, 6 Oct 2015 10:23:17 +0000 (+0000) Subject: [VFS] Port applyAllReplacements to InMemoryFileSystem. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=266e77f330d9b5d5d7833228d7436e349e919d72;p=clang [VFS] Port applyAllReplacements to InMemoryFileSystem. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249388 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Tooling/Core/Replacement.cpp b/lib/Tooling/Core/Replacement.cpp index 838b8042dc..5bea84fd44 100644 --- a/lib/Tooling/Core/Replacement.cpp +++ b/lib/Tooling/Core/Replacement.cpp @@ -265,19 +265,18 @@ bool applyAllReplacements(const std::vector &Replaces, } std::string applyAllReplacements(StringRef Code, const Replacements &Replaces) { - FileManager Files((FileSystemOptions())); + IntrusiveRefCntPtr InMemoryFileSystem( + new vfs::InMemoryFileSystem); + FileManager Files(FileSystemOptions(), InMemoryFileSystem); DiagnosticsEngine Diagnostics( IntrusiveRefCntPtr(new DiagnosticIDs), new DiagnosticOptions); SourceManager SourceMgr(Diagnostics, Files); Rewriter Rewrite(SourceMgr, LangOptions()); - std::unique_ptr Buf = - llvm::MemoryBuffer::getMemBuffer(Code, ""); - const clang::FileEntry *Entry = - Files.getVirtualFile("", Buf->getBufferSize(), 0); - SourceMgr.overrideFileContents(Entry, std::move(Buf)); - FileID ID = - SourceMgr.createFileID(Entry, SourceLocation(), clang::SrcMgr::C_User); + InMemoryFileSystem->addFile( + "", 0, llvm::MemoryBuffer::getMemBuffer(Code, "")); + FileID ID = SourceMgr.createFileID(Files.getFile(""), SourceLocation(), + clang::SrcMgr::C_User); for (Replacements::const_iterator I = Replaces.begin(), E = Replaces.end(); I != E; ++I) { Replacement Replace("", I->getOffset(), I->getLength(),