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 | 426bfa0c4555cc2b415f1a607252c373a69f3197 (patch) | |
| tree | 23d5ae28c713f118b0b1000c7106816b3c05e5e8 /lib/Frontend/CompilerInvocation.cpp | |
| parent | 258f1c35116abc057b5cd8139736bdb385cc29c1 (diff) | |
| download | clang-426bfa0c4555cc2b415f1a607252c373a69f3197.tar.gz clang-426bfa0c4555cc2b415f1a607252c373a69f3197.tar.bz2 clang-426bfa0c4555cc2b415f1a607252c373a69f3197.tar.xz | |
Honour -ivfsoverlay in ASTUnit to match clang
This allows code indexing, etc. to use the VFS in the same way as the
compiler.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206309 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/CompilerInvocation.cpp')
| -rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index b22ea9a07f..6177a96fa7 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/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 |
