From: Benjamin Kramer Date: Tue, 6 Oct 2015 14:45:20 +0000 (+0000) Subject: [Tooling] Reuse FileManager in ASTUnit. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b3ccc8051b30db4a341c23664cb2e5aac11063f;p=clang [Tooling] Reuse FileManager in ASTUnit. ASTUnit was creating multiple FileManagers and throwing them away. Reuse the one from Tooling. No functionality change now but necessary for VFSifying tooling. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249410 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index f977bfdd78..7d9d121038 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -805,9 +805,9 @@ public: static std::unique_ptr LoadFromCompilerInvocation( CompilerInvocation *CI, std::shared_ptr PCHContainerOps, - IntrusiveRefCntPtr Diags, bool OnlyLocalDecls = false, - bool CaptureDiagnostics = false, bool PrecompilePreamble = false, - TranslationUnitKind TUKind = TU_Complete, + IntrusiveRefCntPtr Diags, FileManager *FileMgr, + bool OnlyLocalDecls = false, bool CaptureDiagnostics = false, + bool PrecompilePreamble = false, TranslationUnitKind TUKind = TU_Complete, bool CacheCodeCompletionResults = false, bool IncludeBriefCommentsInCodeCompletion = false, bool UserFilesAreVolatile = false); diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 90161af26c..bac9c386a6 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -1076,11 +1076,10 @@ bool ASTUnit::Parse(std::shared_ptr PCHContainerOps, // Configure the various subsystems. LangOpts = Clang->getInvocation().LangOpts; FileSystemOpts = Clang->getFileSystemOpts(); - IntrusiveRefCntPtr VFS = - createVFSFromCompilerInvocation(Clang->getInvocation(), getDiagnostics()); - if (!VFS) - return true; - FileMgr = new FileManager(FileSystemOpts, VFS); + if (!FileMgr) { + Clang->createFileManager(); + FileMgr = &Clang->getFileManager(); + } SourceMgr = new SourceManager(getDiagnostics(), *FileMgr, UserFilesAreVolatile); TheSema.reset(); @@ -1892,8 +1891,8 @@ bool ASTUnit::LoadFromCompilerInvocation( std::unique_ptr ASTUnit::LoadFromCompilerInvocation( CompilerInvocation *CI, std::shared_ptr PCHContainerOps, - IntrusiveRefCntPtr Diags, bool OnlyLocalDecls, - bool CaptureDiagnostics, bool PrecompilePreamble, + IntrusiveRefCntPtr Diags, FileManager *FileMgr, + bool OnlyLocalDecls, bool CaptureDiagnostics, bool PrecompilePreamble, TranslationUnitKind TUKind, bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion, bool UserFilesAreVolatile) { // Create the AST unit. @@ -1907,12 +1906,8 @@ std::unique_ptr ASTUnit::LoadFromCompilerInvocation( AST->IncludeBriefCommentsInCodeCompletion = IncludeBriefCommentsInCodeCompletion; AST->Invocation = CI; - AST->FileSystemOpts = CI->getFileSystemOpts(); - IntrusiveRefCntPtr VFS = - createVFSFromCompilerInvocation(*CI, *Diags); - if (!VFS) - return nullptr; - AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS); + AST->FileSystemOpts = FileMgr->getFileSystemOpts(); + AST->FileMgr = FileMgr; AST->UserFilesAreVolatile = UserFilesAreVolatile; // Recover resources if we crash before exiting this method. @@ -2043,6 +2038,7 @@ bool ASTUnit::Reparse(std::shared_ptr PCHContainerOps, getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation); // Clear out the diagnostics state. + FileMgr.reset(); getDiagnostics().Reset(); ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts()); if (OverrideMainBuffer) diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index f361d1f411..8c7ed78d41 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -418,12 +418,12 @@ public: bool runInvocation(CompilerInvocation *Invocation, FileManager *Files, std::shared_ptr PCHContainerOps, DiagnosticConsumer *DiagConsumer) override { - // FIXME: This should use the provided FileManager. std::unique_ptr AST = ASTUnit::LoadFromCompilerInvocation( Invocation, PCHContainerOps, CompilerInstance::createDiagnostics(&Invocation->getDiagnosticOpts(), DiagConsumer, - /*ShouldOwnClient=*/false)); + /*ShouldOwnClient=*/false), + Files); if (!AST) return false;