From ef858170ac4ee33edebe4afdadaec624325e7aa3 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 10 Oct 2018 13:27:25 +0000 Subject: Lift VFS from clang to llvm (NFC) This patch moves the virtual file system form clang to llvm so it can be used by more projects. Concretely the patch: - Moves VirtualFileSystem.{h|cpp} from clang/Basic to llvm/Support. - Moves the corresponding unit test from clang to llvm. - Moves the vfs namespace from clang::vfs to llvm::vfs. - Formats the lines affected by this change, mostly this is the result of the added llvm namespace. RFC on the mailing list: http://lists.llvm.org/pipermail/llvm-dev/2018-October/126657.html Differential revision: https://reviews.llvm.org/D52783 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@344140 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/ASTUnit.cpp | 26 ++++++++--------- lib/Frontend/CacheTokens.cpp | 4 +-- lib/Frontend/CompilerInstance.cpp | 12 ++++---- lib/Frontend/CompilerInvocation.cpp | 20 ++++++------- lib/Frontend/CreateInvocationFromCommandLine.cpp | 2 +- lib/Frontend/FrontendAction.cpp | 9 +++--- lib/Frontend/PrecompiledPreamble.cpp | 36 +++++++++++++----------- 7 files changed, 56 insertions(+), 53 deletions(-) (limited to 'lib/Frontend') diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index d72fc92cc9..c999458ee6 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -37,7 +37,6 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" -#include "clang/Basic/VirtualFileSystem.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendAction.h" @@ -88,6 +87,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/Timer.h" +#include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -155,9 +155,8 @@ static bool moveOnNoError(llvm::ErrorOr Val, T &Output) { /// and file-to-buffer remappings inside \p Invocation. static std::unique_ptr getBufferForFileHandlingRemapping(const CompilerInvocation &Invocation, - vfs::FileSystem *VFS, - StringRef FilePath, - bool isVolatile) { + llvm::vfs::FileSystem *VFS, + StringRef FilePath, bool isVolatile) { const auto &PreprocessorOpts = Invocation.getPreprocessorOpts(); // Try to determine if the main file has been remapped, either from the @@ -752,7 +751,8 @@ std::unique_ptr ASTUnit::LoadFromASTFile( AST->OnlyLocalDecls = OnlyLocalDecls; AST->CaptureDiagnostics = CaptureDiagnostics; AST->Diagnostics = Diags; - IntrusiveRefCntPtr VFS = vfs::getRealFileSystem(); + IntrusiveRefCntPtr VFS = + llvm::vfs::getRealFileSystem(); AST->FileMgr = new FileManager(FileSystemOpts, VFS); AST->UserFilesAreVolatile = UserFilesAreVolatile; AST->SourceMgr = new SourceManager(AST->getDiagnostics(), @@ -1074,7 +1074,7 @@ static void checkAndSanitizeDiags(SmallVectorImpl & /// contain any translation-unit information, false otherwise. bool ASTUnit::Parse(std::shared_ptr PCHContainerOps, std::unique_ptr OverrideMainBuffer, - IntrusiveRefCntPtr VFS) { + IntrusiveRefCntPtr VFS) { if (!Invocation) return true; @@ -1082,7 +1082,7 @@ bool ASTUnit::Parse(std::shared_ptr PCHContainerOps, if (OverrideMainBuffer) { assert(Preamble && "No preamble was built, but OverrideMainBuffer is not null"); - IntrusiveRefCntPtr OldVFS = VFS; + IntrusiveRefCntPtr OldVFS = VFS; Preamble->AddImplicitPreamble(*CCInvocation, VFS, OverrideMainBuffer.get()); if (OldVFS != VFS && FileMgr) { assert(OldVFS == FileMgr->getVirtualFileSystem() && @@ -1279,7 +1279,7 @@ std::unique_ptr ASTUnit::getMainBufferWithPrecompiledPreamble( std::shared_ptr PCHContainerOps, CompilerInvocation &PreambleInvocationIn, - IntrusiveRefCntPtr VFS, bool AllowRebuild, + IntrusiveRefCntPtr VFS, bool AllowRebuild, unsigned MaxLines) { auto MainFilePath = PreambleInvocationIn.getFrontendOpts().Inputs[0].getFile(); @@ -1468,7 +1468,7 @@ ASTUnit::create(std::shared_ptr CI, bool CaptureDiagnostics, bool UserFilesAreVolatile) { std::unique_ptr AST(new ASTUnit(false)); ConfigureDiags(Diags, *AST, CaptureDiagnostics); - IntrusiveRefCntPtr VFS = + IntrusiveRefCntPtr VFS = createVFSFromCompilerInvocation(*CI, *Diags); AST->Diagnostics = Diags; AST->FileSystemOpts = CI->getFileSystemOpts(); @@ -1630,7 +1630,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( bool ASTUnit::LoadFromCompilerInvocation( std::shared_ptr PCHContainerOps, unsigned PrecompilePreambleAfterNParses, - IntrusiveRefCntPtr VFS) { + IntrusiveRefCntPtr VFS) { if (!Invocation) return true; @@ -1709,7 +1709,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine( bool AllowPCHWithCompilerErrors, SkipFunctionBodiesScope SkipFunctionBodies, bool SingleFileParse, bool UserFilesAreVolatile, bool ForSerialization, llvm::Optional ModuleFormat, std::unique_ptr *ErrAST, - IntrusiveRefCntPtr VFS) { + IntrusiveRefCntPtr VFS) { assert(Diags.get() && "no DiagnosticsEngine was provided"); SmallVector StoredDiagnostics; @@ -1754,7 +1754,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine( AST->Diagnostics = Diags; AST->FileSystemOpts = CI->getFileSystemOpts(); if (!VFS) - VFS = vfs::getRealFileSystem(); + VFS = llvm::vfs::getRealFileSystem(); VFS = createVFSFromCompilerInvocation(*CI, *Diags, VFS); AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS); AST->PCMCache = new MemoryBufferCache; @@ -1794,7 +1794,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine( bool ASTUnit::Reparse(std::shared_ptr PCHContainerOps, ArrayRef RemappedFiles, - IntrusiveRefCntPtr VFS) { + IntrusiveRefCntPtr VFS) { if (!Invocation) return true; diff --git a/lib/Frontend/CacheTokens.cpp b/lib/Frontend/CacheTokens.cpp index c4504a1445..4d63afc1f2 100644 --- a/lib/Frontend/CacheTokens.cpp +++ b/lib/Frontend/CacheTokens.cpp @@ -556,8 +556,8 @@ public: ~StatListener() override {} LookupResult getStat(StringRef Path, FileData &Data, bool isFile, - std::unique_ptr *F, - vfs::FileSystem &FS) override { + std::unique_ptr *F, + llvm::vfs::FileSystem &FS) override { LookupResult Result = statChained(Path, Data, isFile, F, FS); if (Result == CacheMissing) // Failed 'stat'. diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 05ba3c0265..bba1ef1f4f 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -177,9 +177,9 @@ static void collectIncludePCH(CompilerInstance &CI, std::error_code EC; SmallString<128> DirNative; llvm::sys::path::native(PCHDir->getName(), DirNative); - vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); + llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); SimpleASTReaderListener Validator(CI.getPreprocessor()); - for (vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd; + for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { // Check whether this is an AST file. ASTReader::isAcceptableASTFile is not // used here since we're not interested in validating the PCH at this time, @@ -198,14 +198,14 @@ static void collectVFSEntries(CompilerInstance &CI, return; // Collect all VFS found. - SmallVector VFSEntries; + SmallVector VFSEntries; for (const std::string &VFSFile : CI.getHeaderSearchOpts().VFSOverlayFiles) { llvm::ErrorOr> Buffer = llvm::MemoryBuffer::getFile(VFSFile); if (!Buffer) return; - vfs::collectVFSFromYAML(std::move(Buffer.get()), /*DiagHandler*/ nullptr, - VFSFile, VFSEntries); + llvm::vfs::collectVFSFromYAML(std::move(Buffer.get()), + /*DiagHandler*/ nullptr, VFSFile, VFSEntries); } for (auto &E : VFSEntries) @@ -303,7 +303,7 @@ CompilerInstance::createDiagnostics(DiagnosticOptions *Opts, FileManager *CompilerInstance::createFileManager() { if (!hasVirtualFileSystem()) { - IntrusiveRefCntPtr VFS = + IntrusiveRefCntPtr VFS = createVFSFromCompilerInvocation(getInvocation(), getDiagnostics()); setVirtualFileSystem(VFS); } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 851fd49ce6..e848e50ced 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -23,7 +23,6 @@ #include "clang/Basic/SourceLocation.h" #include "clang/Basic/TargetOptions.h" #include "clang/Basic/Version.h" -#include "clang/Basic/VirtualFileSystem.h" #include "clang/Basic/Visibility.h" #include "clang/Basic/XRayInstr.h" #include "clang/Config/config.h" @@ -77,6 +76,7 @@ #include "llvm/Support/Process.h" #include "llvm/Support/Regex.h" #include "llvm/Support/VersionTuple.h" +#include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetOptions.h" #include @@ -3245,21 +3245,21 @@ void BuryPointer(const void *Ptr) { GraveYard[Idx] = Ptr; } -IntrusiveRefCntPtr +IntrusiveRefCntPtr createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags) { - return createVFSFromCompilerInvocation(CI, Diags, vfs::getRealFileSystem()); + return createVFSFromCompilerInvocation(CI, Diags, + llvm::vfs::getRealFileSystem()); } -IntrusiveRefCntPtr -createVFSFromCompilerInvocation(const CompilerInvocation &CI, - DiagnosticsEngine &Diags, - IntrusiveRefCntPtr BaseFS) { +IntrusiveRefCntPtr createVFSFromCompilerInvocation( + const CompilerInvocation &CI, DiagnosticsEngine &Diags, + IntrusiveRefCntPtr BaseFS) { if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty()) return BaseFS; - IntrusiveRefCntPtr Overlay( - new vfs::OverlayFileSystem(BaseFS)); + IntrusiveRefCntPtr Overlay( + new llvm::vfs::OverlayFileSystem(BaseFS)); // earlier vfs files are on the bottom for (const auto &File : CI.getHeaderSearchOpts().VFSOverlayFiles) { llvm::ErrorOr> Buffer = @@ -3269,7 +3269,7 @@ createVFSFromCompilerInvocation(const CompilerInvocation &CI, continue; } - IntrusiveRefCntPtr FS = vfs::getVFSFromYAML( + IntrusiveRefCntPtr FS = llvm::vfs::getVFSFromYAML( std::move(Buffer.get()), /*DiagHandler*/ nullptr, File); if (FS) Overlay->pushOverlay(FS); diff --git a/lib/Frontend/CreateInvocationFromCommandLine.cpp b/lib/Frontend/CreateInvocationFromCommandLine.cpp index c3ce7ce2b7..2d4c40f8b9 100644 --- a/lib/Frontend/CreateInvocationFromCommandLine.cpp +++ b/lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -32,7 +32,7 @@ using namespace llvm::opt; /// argument vector. std::unique_ptr clang::createInvocationFromCommandLine( ArrayRef ArgList, IntrusiveRefCntPtr Diags, - IntrusiveRefCntPtr VFS) { + IntrusiveRefCntPtr VFS) { if (!Diags.get()) { // No diagnostics engine was provided, so create our own diagnostics object // with the default options. diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index d24700535e..16c75648f3 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -342,8 +342,8 @@ static std::error_code collectModuleHeaderIncludes( SmallString<128> DirNative; llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative); - vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); - for (vfs::recursive_directory_iterator Dir(FS, DirNative, EC), End; + llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); + for (llvm::vfs::recursive_directory_iterator Dir(FS, DirNative, EC), End; Dir != End && !EC; Dir.increment(EC)) { // Check whether this entry has an extension typically associated with // headers. @@ -696,8 +696,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, SmallString<128> DirNative; llvm::sys::path::native(PCHDir->getName(), DirNative); bool Found = false; - vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); - for (vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd; + llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); + for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), + DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { // Check whether this is an acceptable AST file. if (ASTReader::isAcceptableASTFile( diff --git a/lib/Frontend/PrecompiledPreamble.cpp b/lib/Frontend/PrecompiledPreamble.cpp index c6dd89c05c..1930af187e 100644 --- a/lib/Frontend/PrecompiledPreamble.cpp +++ b/lib/Frontend/PrecompiledPreamble.cpp @@ -14,7 +14,6 @@ #include "clang/Frontend/PrecompiledPreamble.h" #include "clang/AST/DeclObjC.h" #include "clang/Basic/TargetInfo.h" -#include "clang/Basic/VirtualFileSystem.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendActions.h" @@ -30,6 +29,7 @@ #include "llvm/Support/Mutex.h" #include "llvm/Support/MutexGuard.h" #include "llvm/Support/Process.h" +#include "llvm/Support/VirtualFileSystem.h" #include #include @@ -48,17 +48,17 @@ StringRef getInMemoryPreamblePath() { #endif } -IntrusiveRefCntPtr +IntrusiveRefCntPtr createVFSOverlayForPreamblePCH(StringRef PCHFilename, std::unique_ptr PCHBuffer, - IntrusiveRefCntPtr VFS) { + IntrusiveRefCntPtr VFS) { // We want only the PCH file from the real filesystem to be available, // so we create an in-memory VFS with just that and overlay it on top. - IntrusiveRefCntPtr PCHFS( - new vfs::InMemoryFileSystem()); + IntrusiveRefCntPtr PCHFS( + new llvm::vfs::InMemoryFileSystem()); PCHFS->addFile(PCHFilename, 0, std::move(PCHBuffer)); - IntrusiveRefCntPtr Overlay( - new vfs::OverlayFileSystem(VFS)); + IntrusiveRefCntPtr Overlay( + new llvm::vfs::OverlayFileSystem(VFS)); Overlay->pushOverlay(PCHFS); return Overlay; } @@ -232,7 +232,8 @@ PreambleBounds clang::ComputePreambleBounds(const LangOptions &LangOpts, llvm::ErrorOr PrecompiledPreamble::Build( const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, - DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr VFS, + DiagnosticsEngine &Diagnostics, + IntrusiveRefCntPtr VFS, std::shared_ptr PCHContainerOps, bool StoreInMemory, PreambleCallbacks &Callbacks) { assert(VFS && "VFS is null"); @@ -410,7 +411,7 @@ std::size_t PrecompiledPreamble::getSize() const { bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, - vfs::FileSystem *VFS) const { + llvm::vfs::FileSystem *VFS) const { assert( Bounds.Size <= MainFileBuffer->getBufferSize() && @@ -437,7 +438,7 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation, // remapping or unsaved_files. std::map OverriddenFiles; for (const auto &R : PreprocessorOpts.RemappedFiles) { - vfs::Status Status; + llvm::vfs::Status Status; if (!moveOnNoError(VFS->status(R.second), Status)) { // If we can't stat the file we're remapping to, assume that something // horrible happened. @@ -449,7 +450,7 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation, } for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) { - vfs::Status Status; + llvm::vfs::Status Status; if (!moveOnNoError(VFS->status(RB.first), Status)) return false; @@ -459,7 +460,7 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation, // Check whether anything has changed. for (const auto &F : FilesInPreamble) { - vfs::Status Status; + llvm::vfs::Status Status; if (!moveOnNoError(VFS->status(F.first()), Status)) { // If we can't stat the file, assume that something horrible happened. return false; @@ -485,14 +486,14 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation, } void PrecompiledPreamble::AddImplicitPreamble( - CompilerInvocation &CI, IntrusiveRefCntPtr &VFS, + CompilerInvocation &CI, IntrusiveRefCntPtr &VFS, llvm::MemoryBuffer *MainFileBuffer) const { PreambleBounds Bounds(PreambleBytes.size(), PreambleEndsAtStartOfLine); configurePreamble(Bounds, CI, VFS, MainFileBuffer); } void PrecompiledPreamble::OverridePreamble( - CompilerInvocation &CI, IntrusiveRefCntPtr &VFS, + CompilerInvocation &CI, IntrusiveRefCntPtr &VFS, llvm::MemoryBuffer *MainFileBuffer) const { auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), MainFileBuffer, 0); configurePreamble(Bounds, CI, VFS, MainFileBuffer); @@ -680,7 +681,7 @@ PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer( void PrecompiledPreamble::configurePreamble( PreambleBounds Bounds, CompilerInvocation &CI, - IntrusiveRefCntPtr &VFS, + IntrusiveRefCntPtr &VFS, llvm::MemoryBuffer *MainFileBuffer) const { assert(VFS); @@ -701,13 +702,14 @@ void PrecompiledPreamble::configurePreamble( void PrecompiledPreamble::setupPreambleStorage( const PCHStorage &Storage, PreprocessorOptions &PreprocessorOpts, - IntrusiveRefCntPtr &VFS) { + IntrusiveRefCntPtr &VFS) { if (Storage.getKind() == PCHStorage::Kind::TempFile) { const TempPCHFile &PCHFile = Storage.asFile(); PreprocessorOpts.ImplicitPCHInclude = PCHFile.getFilePath(); // Make sure we can access the PCH file even if we're using a VFS - IntrusiveRefCntPtr RealFS = vfs::getRealFileSystem(); + IntrusiveRefCntPtr RealFS = + llvm::vfs::getRealFileSystem(); auto PCHPath = PCHFile.getFilePath(); if (VFS == RealFS || VFS->exists(PCHPath)) return; -- cgit v1.2.1