diff options
-rw-r--r-- | clang-tools-extra/clangd/XRefs.cpp | 32 | ||||
-rw-r--r-- | clang-tools-extra/clangd/index/FileIndex.cpp | 6 | ||||
-rw-r--r-- | clang/include/clang/Index/IndexingAction.h | 9 | ||||
-rw-r--r-- | clang/lib/Index/IndexingAction.cpp | 30 | ||||
-rw-r--r-- | clang/tools/c-index-test/core_main.cpp | 4 | ||||
-rw-r--r-- | clang/tools/libclang/Indexing.cpp | 18 |
6 files changed, 47 insertions, 52 deletions
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp index 6628c40ea40..01d4e952355 100644 --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -182,9 +182,9 @@ std::vector<Location> findDefinitions(ParsedAST &AST, Position Pos) { if (!Result.empty()) return Result; - auto DeclMacrosFinder = std::make_shared<DeclarationAndMacrosFinder>( - llvm::errs(), SourceLocationBeg, AST.getASTContext(), - AST.getPreprocessor()); + DeclarationAndMacrosFinder DeclMacrosFinder(llvm::errs(), SourceLocationBeg, + AST.getASTContext(), + AST.getPreprocessor()); index::IndexingOptions IndexOpts; IndexOpts.SystemSymbolFilter = index::IndexingOptions::SystemSymbolFilterKind::All; @@ -193,8 +193,8 @@ std::vector<Location> findDefinitions(ParsedAST &AST, Position Pos) { indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(), DeclMacrosFinder, IndexOpts); - std::vector<const Decl *> Decls = DeclMacrosFinder->takeDecls(); - std::vector<MacroDecl> MacroInfos = DeclMacrosFinder->takeMacroInfos(); + std::vector<const Decl *> Decls = DeclMacrosFinder.takeDecls(); + std::vector<MacroDecl> MacroInfos = DeclMacrosFinder.takeMacroInfos(); for (auto D : Decls) { auto Loc = findNameLoc(D); @@ -286,9 +286,9 @@ std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST, SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE); - auto DeclMacrosFinder = std::make_shared<DeclarationAndMacrosFinder>( - llvm::errs(), SourceLocationBeg, AST.getASTContext(), - AST.getPreprocessor()); + DeclarationAndMacrosFinder DeclMacrosFinder(llvm::errs(), SourceLocationBeg, + AST.getASTContext(), + AST.getPreprocessor()); index::IndexingOptions IndexOpts; IndexOpts.SystemSymbolFilter = index::IndexingOptions::SystemSymbolFilterKind::All; @@ -298,15 +298,15 @@ std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST, indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(), DeclMacrosFinder, IndexOpts); - std::vector<const Decl *> SelectedDecls = DeclMacrosFinder->takeDecls(); + std::vector<const Decl *> SelectedDecls = DeclMacrosFinder.takeDecls(); - auto DocHighlightsFinder = std::make_shared<DocumentHighlightsFinder>( + DocumentHighlightsFinder DocHighlightsFinder( llvm::errs(), AST.getASTContext(), AST.getPreprocessor(), SelectedDecls); indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(), DocHighlightsFinder, IndexOpts); - return DocHighlightsFinder->takeHighlights(); + return DocHighlightsFinder.takeHighlights(); } static PrintingPolicy PrintingPolicyForDecls(PrintingPolicy Base) { @@ -418,9 +418,9 @@ Hover getHover(ParsedAST &AST, Position Pos) { return Hover(); SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE); - auto DeclMacrosFinder = std::make_shared<DeclarationAndMacrosFinder>( - llvm::errs(), SourceLocationBeg, AST.getASTContext(), - AST.getPreprocessor()); + DeclarationAndMacrosFinder DeclMacrosFinder(llvm::errs(), SourceLocationBeg, + AST.getASTContext(), + AST.getPreprocessor()); index::IndexingOptions IndexOpts; IndexOpts.SystemSymbolFilter = @@ -430,11 +430,11 @@ Hover getHover(ParsedAST &AST, Position Pos) { indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(), DeclMacrosFinder, IndexOpts); - std::vector<MacroDecl> Macros = DeclMacrosFinder->takeMacroInfos(); + std::vector<MacroDecl> Macros = DeclMacrosFinder.takeMacroInfos(); if (!Macros.empty()) return getHoverContents(Macros[0].Name); - std::vector<const Decl *> Decls = DeclMacrosFinder->takeDecls(); + std::vector<const Decl *> Decls = DeclMacrosFinder.takeDecls(); if (!Decls.empty()) return getHoverContents(Decls[0]); diff --git a/clang-tools-extra/clangd/index/FileIndex.cpp b/clang-tools-extra/clangd/index/FileIndex.cpp index 2cf8b12739d..3f09c258fd0 100644 --- a/clang-tools-extra/clangd/index/FileIndex.cpp +++ b/clang-tools-extra/clangd/index/FileIndex.cpp @@ -28,8 +28,8 @@ std::unique_ptr<SymbolSlab> indexAST(ASTContext &Ctx, CollectorOpts.CollectIncludePath = false; CollectorOpts.CountReferences = false; - auto Collector = std::make_shared<SymbolCollector>(std::move(CollectorOpts)); - Collector->setPreprocessor(std::move(PP)); + SymbolCollector Collector(std::move(CollectorOpts)); + Collector.setPreprocessor(std::move(PP)); index::IndexingOptions IndexOpts; // We only need declarations, because we don't count references. IndexOpts.SystemSymbolFilter = @@ -38,7 +38,7 @@ std::unique_ptr<SymbolSlab> indexAST(ASTContext &Ctx, index::indexTopLevelDecls(Ctx, Decls, Collector, IndexOpts); auto Symbols = llvm::make_unique<SymbolSlab>(); - *Symbols = Collector->takeSymbols(); + *Symbols = Collector.takeSymbols(); return Symbols; } diff --git a/clang/include/clang/Index/IndexingAction.h b/clang/include/clang/Index/IndexingAction.h index fb703be4e5f..98e24554170 100644 --- a/clang/include/clang/Index/IndexingAction.h +++ b/clang/include/clang/Index/IndexingAction.h @@ -46,17 +46,14 @@ createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer, IndexingOptions Opts, std::unique_ptr<FrontendAction> WrappedAction); -void indexASTUnit(ASTUnit &Unit, - std::shared_ptr<IndexDataConsumer> DataConsumer, +void indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer, IndexingOptions Opts); void indexTopLevelDecls(ASTContext &Ctx, ArrayRef<const Decl *> Decls, - std::shared_ptr<IndexDataConsumer> DataConsumer, - IndexingOptions Opts); + IndexDataConsumer &DataConsumer, IndexingOptions Opts); void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader, - std::shared_ptr<IndexDataConsumer> DataConsumer, - IndexingOptions Opts); + IndexDataConsumer &DataConsumer, IndexingOptions Opts); } // namespace index } // namespace clang diff --git a/clang/lib/Index/IndexingAction.cpp b/clang/lib/Index/IndexingAction.cpp index fc718b0c0d9..c8f65804b0d 100644 --- a/clang/lib/Index/IndexingAction.cpp +++ b/clang/lib/Index/IndexingAction.cpp @@ -173,40 +173,38 @@ static void indexTranslationUnit(ASTUnit &Unit, IndexingContext &IndexCtx) { Unit.visitLocalTopLevelDecls(&IndexCtx, topLevelDeclVisitor); } -void index::indexASTUnit(ASTUnit &Unit, - std::shared_ptr<IndexDataConsumer> DataConsumer, +void index::indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer, IndexingOptions Opts) { - IndexingContext IndexCtx(Opts, *DataConsumer); + IndexingContext IndexCtx(Opts, DataConsumer); IndexCtx.setASTContext(Unit.getASTContext()); - DataConsumer->initialize(Unit.getASTContext()); - DataConsumer->setPreprocessor(Unit.getPreprocessorPtr()); + DataConsumer.initialize(Unit.getASTContext()); + DataConsumer.setPreprocessor(Unit.getPreprocessorPtr()); indexTranslationUnit(Unit, IndexCtx); - DataConsumer->finish(); + DataConsumer.finish(); } void index::indexTopLevelDecls(ASTContext &Ctx, ArrayRef<const Decl *> Decls, - std::shared_ptr<IndexDataConsumer> DataConsumer, + IndexDataConsumer &DataConsumer, IndexingOptions Opts) { - IndexingContext IndexCtx(Opts, *DataConsumer); + IndexingContext IndexCtx(Opts, DataConsumer); IndexCtx.setASTContext(Ctx); - DataConsumer->initialize(Ctx); + DataConsumer.initialize(Ctx); for (const Decl *D : Decls) IndexCtx.indexTopLevelDecl(D); - DataConsumer->finish(); + DataConsumer.finish(); } -void index::indexModuleFile(serialization::ModuleFile &Mod, - ASTReader &Reader, - std::shared_ptr<IndexDataConsumer> DataConsumer, +void index::indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader, + IndexDataConsumer &DataConsumer, IndexingOptions Opts) { ASTContext &Ctx = Reader.getContext(); - IndexingContext IndexCtx(Opts, *DataConsumer); + IndexingContext IndexCtx(Opts, DataConsumer); IndexCtx.setASTContext(Ctx); - DataConsumer->initialize(Ctx); + DataConsumer.initialize(Ctx); for (const Decl *D : Reader.getModuleFileLevelDecls(Mod)) { IndexCtx.indexTopLevelDecl(D); } - DataConsumer->finish(); + DataConsumer.finish(); } diff --git a/clang/tools/c-index-test/core_main.cpp b/clang/tools/c-index-test/core_main.cpp index 98658baaa1a..6093df5285e 100644 --- a/clang/tools/c-index-test/core_main.cpp +++ b/clang/tools/c-index-test/core_main.cpp @@ -195,7 +195,7 @@ static bool printSourceSymbols(ArrayRef<const char *> Args, if (auto Reader = Unit->getASTReader()) { Reader->getModuleManager().visit([&](serialization::ModuleFile &Mod) -> bool { OS << "==== Module " << Mod.ModuleName << " ====\n"; - indexModuleFile(Mod, *Reader, DataConsumer, IndexOpts); + indexModuleFile(Mod, *Reader, *DataConsumer, IndexOpts); dumpModuleFileInputs(Mod, *Reader, OS); return true; // skip module dependencies. }); @@ -231,7 +231,7 @@ static bool printSourceSymbolsFromModule(StringRef modulePath, return true; } - auto DataConsumer = std::make_shared<PrintIndexDataConsumer>(outs()); + PrintIndexDataConsumer DataConsumer(outs()); IndexingOptions IndexOpts; indexASTUnit(*AU, DataConsumer, IndexOpts); diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index 021ebcfcfe4..5722e915207 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -659,8 +659,7 @@ static CXErrorCode clang_indexTranslationUnit_Impl( ? index_callbacks_size : sizeof(CB); memcpy(&CB, client_index_callbacks, ClientCBSize); - auto DataConsumer = std::make_shared<CXIndexDataConsumer>(client_data, CB, - index_options, TU); + CXIndexDataConsumer DataConsumer(client_data, CB, index_options, TU); ASTUnit *Unit = cxtu::getASTUnit(TU); if (!Unit) @@ -669,21 +668,22 @@ static CXErrorCode clang_indexTranslationUnit_Impl( ASTUnit::ConcurrencyCheck Check(*Unit); if (const FileEntry *PCHFile = Unit->getPCHFile()) - DataConsumer->importedPCH(PCHFile); + DataConsumer.importedPCH(PCHFile); FileManager &FileMgr = Unit->getFileManager(); if (Unit->getOriginalSourceFileName().empty()) - DataConsumer->enteredMainFile(nullptr); + DataConsumer.enteredMainFile(nullptr); else - DataConsumer->enteredMainFile(FileMgr.getFile(Unit->getOriginalSourceFileName())); + DataConsumer.enteredMainFile( + FileMgr.getFile(Unit->getOriginalSourceFileName())); - DataConsumer->setASTContext(Unit->getASTContext()); - DataConsumer->startedTranslationUnit(); + DataConsumer.setASTContext(Unit->getASTContext()); + DataConsumer.startedTranslationUnit(); - indexPreprocessingRecord(*Unit, *DataConsumer); + indexPreprocessingRecord(*Unit, DataConsumer); indexASTUnit(*Unit, DataConsumer, getIndexingOptionsFromCXOptions(index_options)); - DataConsumer->indexDiagnostics(); + DataConsumer.indexDiagnostics(); return CXError_Success; } |