diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-10-06 10:04:08 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-10-06 10:04:08 +0000 |
| commit | 2e2351adce3dcd2c180442ce1d6c1163cbf7c380 (patch) | |
| tree | 4d0080cc3017f5d279877047afd33fbd7085179c /clang/lib/Format | |
| parent | d245267be0e885ebf3d40e1decfc74ee881cb278 (diff) | |
| download | bcm5719-llvm-2e2351adce3dcd2c180442ce1d6c1163cbf7c380.tar.gz bcm5719-llvm-2e2351adce3dcd2c180442ce1d6c1163cbf7c380.zip | |
[VFS] Transition clang-format to use an in-memory FS.
Apart from being cleaner this also means that clang-format no longer has
access to the host file system. This isn't necessary because clang-format
never reads includes :)
Includes minor tweaks and bugfixes found in the VFS implementation while
running clang-format tests.
llvm-svn: 249385
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index fffd80cb682..62f94b8f99f 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1792,18 +1792,17 @@ tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, if (Style.DisableFormat) return tooling::Replacements(); - FileManager Files((FileSystemOptions())); + IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem( + new vfs::InMemoryFileSystem); + FileManager Files(FileSystemOptions(), InMemoryFileSystem); DiagnosticsEngine Diagnostics( IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), new DiagnosticOptions); SourceManager SourceMgr(Diagnostics, Files); - std::unique_ptr<llvm::MemoryBuffer> Buf = - llvm::MemoryBuffer::getMemBuffer(Code, FileName); - const clang::FileEntry *Entry = - Files.getVirtualFile(FileName, Buf->getBufferSize(), 0); - SourceMgr.overrideFileContents(Entry, std::move(Buf)); - FileID ID = - SourceMgr.createFileID(Entry, SourceLocation(), clang::SrcMgr::C_User); + InMemoryFileSystem->addFile(FileName, 0, + llvm::MemoryBuffer::getMemBuffer(Code, FileName)); + FileID ID = SourceMgr.createFileID(Files.getFile(FileName), SourceLocation(), + clang::SrcMgr::C_User); SourceLocation StartOfFile = SourceMgr.getLocForStartOfFile(ID); std::vector<CharSourceRange> CharRanges; for (const tooling::Range &Range : Ranges) { |

