From 8832c066a23eb7df33b025bcf7e8fe7199ad3aae Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Tue, 15 Apr 2014 18:16:25 +0000 Subject: 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 --- clang/lib/Frontend/CompilerInvocation.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') 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 +createVFSFromCompilerInvocation(const CompilerInvocation &CI, + DiagnosticsEngine &Diags) { + if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty()) + return vfs::getRealFileSystem(); + + IntrusiveRefCntPtr + Overlay(new vfs::OverlayFileSystem(vfs::getRealFileSystem())); + // earlier vfs files are on the bottom + for (const std::string &File : CI.getHeaderSearchOpts().VFSOverlayFiles) { + std::unique_ptr Buffer; + if (llvm::errc::success != llvm::MemoryBuffer::getFile(File, Buffer)) { + Diags.Report(diag::err_missing_vfs_overlay_file) << File; + return IntrusiveRefCntPtr(); + } + + IntrusiveRefCntPtr FS = + vfs::getVFSFromYAML(Buffer.release(), /*DiagHandler*/0); + if (!FS.getPtr()) { + Diags.Report(diag::err_invalid_vfs_overlay) << File; + return IntrusiveRefCntPtr(); + } + Overlay->pushOverlay(FS); + } + return Overlay; } +} // end namespace clang -- cgit v1.1