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 | |
parent | be4fe32eb8ad20e47fecf7e85e57c7e522ec5143 (diff) | |
download | bcm5719-llvm-8832c066a23eb7df33b025bcf7e8fe7199ad3aae.tar.gz bcm5719-llvm-8832c066a23eb7df33b025bcf7e8fe7199ad3aae.zip |
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')
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 35 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 29 | ||||
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 31 |
3 files changed, 62 insertions, 33 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index c4f7596e003..5035dac53cf 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -692,7 +692,8 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename, AST->OnlyLocalDecls = OnlyLocalDecls; AST->CaptureDiagnostics = CaptureDiagnostics; AST->Diagnostics = Diags; - AST->FileMgr = new FileManager(FileSystemOpts); + IntrusiveRefCntPtr<vfs::FileSystem> VFS = vfs::getRealFileSystem(); + AST->FileMgr = new FileManager(FileSystemOpts, VFS); AST->UserFilesAreVolatile = UserFilesAreVolatile; AST->SourceMgr = new SourceManager(AST->getDiagnostics(), AST->getFileManager(), @@ -1093,10 +1094,9 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) { "IR inputs not support here!"); // Configure the various subsystems. - // FIXME: Should we retain the previous file manager? LangOpts = &Clang->getLangOpts(); FileSystemOpts = Clang->getFileSystemOpts(); - FileMgr = new FileManager(FileSystemOpts); + // Re-use the existing FileManager SourceMgr = new SourceManager(getDiagnostics(), *FileMgr, UserFilesAreVolatile); TheSema.reset(); @@ -1598,9 +1598,14 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( TopLevelDecls.clear(); TopLevelDeclsInPreamble.clear(); PreambleDiagnostics.clear(); - + + IntrusiveRefCntPtr<vfs::FileSystem> VFS = + createVFSFromCompilerInvocation(Clang->getInvocation(), getDiagnostics()); + if (!VFS) + return nullptr; + // Create a file manager object to provide access to and cache the filesystem. - Clang->setFileManager(new FileManager(Clang->getFileSystemOpts())); + Clang->setFileManager(new FileManager(Clang->getFileSystemOpts(), VFS)); // Create the source manager. Clang->setSourceManager(new SourceManager(getDiagnostics(), @@ -1758,7 +1763,11 @@ ASTUnit *ASTUnit::create(CompilerInvocation *CI, AST->Diagnostics = Diags; AST->Invocation = CI; AST->FileSystemOpts = CI->getFileSystemOpts(); - AST->FileMgr = new FileManager(AST->FileSystemOpts); + IntrusiveRefCntPtr<vfs::FileSystem> VFS = + createVFSFromCompilerInvocation(*CI, *Diags); + if (!VFS) + return nullptr; + AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS); AST->UserFilesAreVolatile = UserFilesAreVolatile; AST->SourceMgr = new SourceManager(AST->getDiagnostics(), *AST->FileMgr, UserFilesAreVolatile); @@ -1781,6 +1790,8 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( // Create the AST unit. OwnAST.reset(create(CI, Diags, CaptureDiagnostics, UserFilesAreVolatile)); AST = OwnAST.get(); + if (!AST) + return nullptr; } if (!ResourceFilesPath.empty()) { @@ -1950,7 +1961,11 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI, = IncludeBriefCommentsInCodeCompletion; AST->Invocation = CI; AST->FileSystemOpts = CI->getFileSystemOpts(); - AST->FileMgr = new FileManager(AST->FileSystemOpts); + IntrusiveRefCntPtr<vfs::FileSystem> VFS = + createVFSFromCompilerInvocation(*CI, *Diags); + if (!VFS) + return nullptr; + AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS); AST->UserFilesAreVolatile = UserFilesAreVolatile; // Recover resources if we crash before exiting this method. @@ -2017,7 +2032,11 @@ ASTUnit *ASTUnit::LoadFromCommandLine( AST->Diagnostics = Diags; Diags = 0; // Zero out now to ease cleanup during crash recovery. AST->FileSystemOpts = CI->getFileSystemOpts(); - AST->FileMgr = new FileManager(AST->FileSystemOpts); + IntrusiveRefCntPtr<vfs::FileSystem> VFS = + createVFSFromCompilerInvocation(*CI, *Diags); + if (!VFS) + return nullptr; + AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS); AST->OnlyLocalDecls = OnlyLocalDecls; AST->CaptureDiagnostics = CaptureDiagnostics; AST->TUKind = TUKind; diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index b22ea9a07f6..6177a96fa7b 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 diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index dc4dd89371a..dfe3d85ba73 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -211,30 +211,13 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, return true; } - if (!CI.getHeaderSearchOpts().VFSOverlayFiles.empty()) { - IntrusiveRefCntPtr<vfs::OverlayFileSystem> - Overlay(new vfs::OverlayFileSystem(vfs::getRealFileSystem())); - // earlier vfs files are on the bottom - const std::vector<std::string> &Files = - CI.getHeaderSearchOpts().VFSOverlayFiles; - for (std::vector<std::string>::const_iterator I = Files.begin(), - E = Files.end(); - I != E; ++I) { - std::unique_ptr<llvm::MemoryBuffer> Buffer; - if (llvm::errc::success != llvm::MemoryBuffer::getFile(*I, Buffer)) { - CI.getDiagnostics().Report(diag::err_missing_vfs_overlay_file) << *I; - goto failure; - } - - IntrusiveRefCntPtr<vfs::FileSystem> FS = - vfs::getVFSFromYAML(Buffer.release(), /*DiagHandler*/ 0); - if (!FS.getPtr()) { - CI.getDiagnostics().Report(diag::err_invalid_vfs_overlay) << *I; - goto failure; - } - Overlay->pushOverlay(FS); - } - CI.setVirtualFileSystem(Overlay); + if (!CI.hasVirtualFileSystem()) { + if (IntrusiveRefCntPtr<vfs::FileSystem> VFS = + createVFSFromCompilerInvocation(CI.getInvocation(), + CI.getDiagnostics())) + CI.setVirtualFileSystem(VFS); + else + goto failure; } // Set up the file and source managers, if needed. |