diff options
author | Ben Langmuir <blangmuir@apple.com> | 2014-04-15 18:16:25 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2014-04-15 18:16:25 +0000 |
commit | 8832c066a23eb7df33b025bcf7e8fe7199ad3aae (patch) | |
tree | 923753afcf173f06cba5d014e2e8e1b51dda2b5d /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | be4fe32eb8ad20e47fecf7e85e57c7e522ec5143 (diff) | |
download | llvm-8832c066a23eb7df33b025bcf7e8fe7199ad3aae.zip llvm-8832c066a23eb7df33b025bcf7e8fe7199ad3aae.tar.gz llvm-8832c066a23eb7df33b025bcf7e8fe7199ad3aae.tar.bz2 |
Honour -ivfsoverlay in ASTUnit to match clang
This allows code indexing, etc. to use the VFS in the same way as the
compiler.
llvm-svn: 206309
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index b22ea9a..6177a96 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -8,12 +8,12 @@ //===----------------------------------------------------------------------===// #include "clang/Frontend/CompilerInvocation.h" -#include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/Version.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "clang/Driver/Util.h" +#include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/LangStandard.h" #include "clang/Frontend/Utils.h" #include "clang/Lex/HeaderSearchOptions.h" @@ -1907,4 +1907,31 @@ void BuryPointer(const void *Ptr) { return; GraveYard[Idx] = Ptr; } + +IntrusiveRefCntPtr<vfs::FileSystem> +createVFSFromCompilerInvocation(const CompilerInvocation &CI, + DiagnosticsEngine &Diags) { + if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty()) + return vfs::getRealFileSystem(); + + IntrusiveRefCntPtr<vfs::OverlayFileSystem> + Overlay(new vfs::OverlayFileSystem(vfs::getRealFileSystem())); + // earlier vfs files are on the bottom + for (const std::string &File : CI.getHeaderSearchOpts().VFSOverlayFiles) { + std::unique_ptr<llvm::MemoryBuffer> Buffer; + if (llvm::errc::success != llvm::MemoryBuffer::getFile(File, Buffer)) { + Diags.Report(diag::err_missing_vfs_overlay_file) << File; + return IntrusiveRefCntPtr<vfs::FileSystem>(); + } + + IntrusiveRefCntPtr<vfs::FileSystem> FS = + vfs::getVFSFromYAML(Buffer.release(), /*DiagHandler*/0); + if (!FS.getPtr()) { + Diags.Report(diag::err_invalid_vfs_overlay) << File; + return IntrusiveRefCntPtr<vfs::FileSystem>(); + } + Overlay->pushOverlay(FS); + } + return Overlay; } +} // end namespace clang |