dexonsmith created this revision. dexonsmith added reviewers: JDevlieghere, arphaman, jansvoboda11, akyrtzi. Herald added a subscriber: ributzka. dexonsmith requested review of this revision.
The filesystem underneath it may have changed. This matches other `ASTUnit` entry points like `Reparse`, and unblocks implementing remapped files in a VFS layer underneath the `FileManager` in a future patch. https://reviews.llvm.org/D91298 Files: clang/include/clang/Frontend/ASTUnit.h clang/lib/Frontend/ASTUnit.cpp clang/tools/libclang/CIndexCodeCompletion.cpp Index: clang/tools/libclang/CIndexCodeCompletion.cpp =================================================================== --- clang/tools/libclang/CIndexCodeCompletion.cpp +++ clang/tools/libclang/CIndexCodeCompletion.cpp @@ -359,8 +359,6 @@ : CXCodeCompleteResults(), DiagOpts(new DiagnosticOptions), Diag(new DiagnosticsEngine( IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts)), - FileMgr(std::move(FileMgr)), - SourceMgr(new SourceManager(*Diag, *this->FileMgr)), CodeCompletionAllocator( std::make_shared<clang::GlobalCodeCompletionAllocator>()), Contexts(CXCompletionContext_Unknown), @@ -755,14 +753,15 @@ LibclangInvocationReporter InvocationReporter( *CXXIdx, LibclangInvocationReporter::OperationKind::CompletionOperation, TU->ParsingOptions, CArgs, CompletionInvocation, unsaved_files); - AST->CodeComplete(complete_filename, complete_line, complete_column, - RemappedFiles, (options & CXCodeComplete_IncludeMacros), - (options & CXCodeComplete_IncludeCodePatterns), - IncludeBriefComments, Capture, - CXXIdx->getPCHContainerOperations(), *Results->Diag, - Results->LangOpts, *Results->SourceMgr, *Results->FileMgr, - Results->Diagnostics, Results->TemporaryBuffers); - + AST->CodeComplete( + complete_filename, complete_line, complete_column, RemappedFiles, + (options & CXCodeComplete_IncludeMacros), + (options & CXCodeComplete_IncludeCodePatterns), IncludeBriefComments, + Capture, CXXIdx->getPCHContainerOperations(), *Results->Diag, + Results->LangOpts, Results->Diagnostics, Results->TemporaryBuffers); + + Results->FileMgr = &AST->getFileManager(); + Results->SourceMgr = &AST->getSourceManager(); Results->DiagnosticsWrappers.resize(Results->Diagnostics.size()); // Keep a reference to the allocator used for cached global completions, so Index: clang/lib/Frontend/ASTUnit.cpp =================================================================== --- clang/lib/Frontend/ASTUnit.cpp +++ clang/lib/Frontend/ASTUnit.cpp @@ -2132,8 +2132,8 @@ bool IncludeCodePatterns, bool IncludeBriefComments, CodeCompleteConsumer &Consumer, std::shared_ptr<PCHContainerOperations> PCHContainerOps, - DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr, - FileManager &FileMgr, SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics, + DiagnosticsEngine &Diag, LangOptions &LangOpts, + SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics, SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers) { if (!Invocation) return; @@ -2211,9 +2211,12 @@ Language::LLVM_IR && "IR inputs not support here!"); - // Use the source and file managers that we were given. - Clang->setFileManager(&FileMgr); - Clang->setSourceManager(&SourceMgr); + // Initialize file and source managers up front so that the caller can access + // them after. + Clang->createFileManager(FS); + FileMgr = &Clang->getFileManager(); + Clang->createSourceManager(*FileMgr); + SourceMgr = &Clang->getSourceManager(); // Remap files. PreprocessorOpts.clearRemappedFiles(); Index: clang/include/clang/Frontend/ASTUnit.h =================================================================== --- clang/include/clang/Frontend/ASTUnit.h +++ clang/include/clang/Frontend/ASTUnit.h @@ -876,7 +876,6 @@ CodeCompleteConsumer &Consumer, std::shared_ptr<PCHContainerOperations> PCHContainerOps, DiagnosticsEngine &Diag, LangOptions &LangOpts, - SourceManager &SourceMgr, FileManager &FileMgr, SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics, SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers);
Index: clang/tools/libclang/CIndexCodeCompletion.cpp =================================================================== --- clang/tools/libclang/CIndexCodeCompletion.cpp +++ clang/tools/libclang/CIndexCodeCompletion.cpp @@ -359,8 +359,6 @@ : CXCodeCompleteResults(), DiagOpts(new DiagnosticOptions), Diag(new DiagnosticsEngine( IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts)), - FileMgr(std::move(FileMgr)), - SourceMgr(new SourceManager(*Diag, *this->FileMgr)), CodeCompletionAllocator( std::make_shared<clang::GlobalCodeCompletionAllocator>()), Contexts(CXCompletionContext_Unknown), @@ -755,14 +753,15 @@ LibclangInvocationReporter InvocationReporter( *CXXIdx, LibclangInvocationReporter::OperationKind::CompletionOperation, TU->ParsingOptions, CArgs, CompletionInvocation, unsaved_files); - AST->CodeComplete(complete_filename, complete_line, complete_column, - RemappedFiles, (options & CXCodeComplete_IncludeMacros), - (options & CXCodeComplete_IncludeCodePatterns), - IncludeBriefComments, Capture, - CXXIdx->getPCHContainerOperations(), *Results->Diag, - Results->LangOpts, *Results->SourceMgr, *Results->FileMgr, - Results->Diagnostics, Results->TemporaryBuffers); - + AST->CodeComplete( + complete_filename, complete_line, complete_column, RemappedFiles, + (options & CXCodeComplete_IncludeMacros), + (options & CXCodeComplete_IncludeCodePatterns), IncludeBriefComments, + Capture, CXXIdx->getPCHContainerOperations(), *Results->Diag, + Results->LangOpts, Results->Diagnostics, Results->TemporaryBuffers); + + Results->FileMgr = &AST->getFileManager(); + Results->SourceMgr = &AST->getSourceManager(); Results->DiagnosticsWrappers.resize(Results->Diagnostics.size()); // Keep a reference to the allocator used for cached global completions, so Index: clang/lib/Frontend/ASTUnit.cpp =================================================================== --- clang/lib/Frontend/ASTUnit.cpp +++ clang/lib/Frontend/ASTUnit.cpp @@ -2132,8 +2132,8 @@ bool IncludeCodePatterns, bool IncludeBriefComments, CodeCompleteConsumer &Consumer, std::shared_ptr<PCHContainerOperations> PCHContainerOps, - DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr, - FileManager &FileMgr, SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics, + DiagnosticsEngine &Diag, LangOptions &LangOpts, + SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics, SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers) { if (!Invocation) return; @@ -2211,9 +2211,12 @@ Language::LLVM_IR && "IR inputs not support here!"); - // Use the source and file managers that we were given. - Clang->setFileManager(&FileMgr); - Clang->setSourceManager(&SourceMgr); + // Initialize file and source managers up front so that the caller can access + // them after. + Clang->createFileManager(FS); + FileMgr = &Clang->getFileManager(); + Clang->createSourceManager(*FileMgr); + SourceMgr = &Clang->getSourceManager(); // Remap files. PreprocessorOpts.clearRemappedFiles(); Index: clang/include/clang/Frontend/ASTUnit.h =================================================================== --- clang/include/clang/Frontend/ASTUnit.h +++ clang/include/clang/Frontend/ASTUnit.h @@ -876,7 +876,6 @@ CodeCompleteConsumer &Consumer, std::shared_ptr<PCHContainerOperations> PCHContainerOps, DiagnosticsEngine &Diag, LangOptions &LangOpts, - SourceManager &SourceMgr, FileManager &FileMgr, SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics, SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits