[index] Fix methods that take a shared_ptr to just take a reference.

There is no ownership here, passing a shared_ptr just adds confusion. No
functionality change intended.

llvm-svn: 330595
This commit is contained in:
Benjamin Kramer 2018-04-23 14:30:21 +00:00
parent 6978db7800
commit 6f33fca7ec
6 changed files with 47 additions and 52 deletions

View File

@ -182,9 +182,9 @@ std::vector<Location> findDefinitions(ParsedAST &AST, Position Pos) {
if (!Result.empty()) if (!Result.empty())
return Result; return Result;
auto DeclMacrosFinder = std::make_shared<DeclarationAndMacrosFinder>( DeclarationAndMacrosFinder DeclMacrosFinder(llvm::errs(), SourceLocationBeg,
llvm::errs(), SourceLocationBeg, AST.getASTContext(), AST.getASTContext(),
AST.getPreprocessor()); AST.getPreprocessor());
index::IndexingOptions IndexOpts; index::IndexingOptions IndexOpts;
IndexOpts.SystemSymbolFilter = IndexOpts.SystemSymbolFilter =
index::IndexingOptions::SystemSymbolFilterKind::All; index::IndexingOptions::SystemSymbolFilterKind::All;
@ -193,8 +193,8 @@ std::vector<Location> findDefinitions(ParsedAST &AST, Position Pos) {
indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(), indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(),
DeclMacrosFinder, IndexOpts); DeclMacrosFinder, IndexOpts);
std::vector<const Decl *> Decls = DeclMacrosFinder->takeDecls(); std::vector<const Decl *> Decls = DeclMacrosFinder.takeDecls();
std::vector<MacroDecl> MacroInfos = DeclMacrosFinder->takeMacroInfos(); std::vector<MacroDecl> MacroInfos = DeclMacrosFinder.takeMacroInfos();
for (auto D : Decls) { for (auto D : Decls) {
auto Loc = findNameLoc(D); auto Loc = findNameLoc(D);
@ -286,9 +286,9 @@ std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE); SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE);
auto DeclMacrosFinder = std::make_shared<DeclarationAndMacrosFinder>( DeclarationAndMacrosFinder DeclMacrosFinder(llvm::errs(), SourceLocationBeg,
llvm::errs(), SourceLocationBeg, AST.getASTContext(), AST.getASTContext(),
AST.getPreprocessor()); AST.getPreprocessor());
index::IndexingOptions IndexOpts; index::IndexingOptions IndexOpts;
IndexOpts.SystemSymbolFilter = IndexOpts.SystemSymbolFilter =
index::IndexingOptions::SystemSymbolFilterKind::All; index::IndexingOptions::SystemSymbolFilterKind::All;
@ -298,15 +298,15 @@ std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(), indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(),
DeclMacrosFinder, IndexOpts); 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); llvm::errs(), AST.getASTContext(), AST.getPreprocessor(), SelectedDecls);
indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(), indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(),
DocHighlightsFinder, IndexOpts); DocHighlightsFinder, IndexOpts);
return DocHighlightsFinder->takeHighlights(); return DocHighlightsFinder.takeHighlights();
} }
static PrintingPolicy PrintingPolicyForDecls(PrintingPolicy Base) { static PrintingPolicy PrintingPolicyForDecls(PrintingPolicy Base) {
@ -418,9 +418,9 @@ Hover getHover(ParsedAST &AST, Position Pos) {
return Hover(); return Hover();
SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE); SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE);
auto DeclMacrosFinder = std::make_shared<DeclarationAndMacrosFinder>( DeclarationAndMacrosFinder DeclMacrosFinder(llvm::errs(), SourceLocationBeg,
llvm::errs(), SourceLocationBeg, AST.getASTContext(), AST.getASTContext(),
AST.getPreprocessor()); AST.getPreprocessor());
index::IndexingOptions IndexOpts; index::IndexingOptions IndexOpts;
IndexOpts.SystemSymbolFilter = IndexOpts.SystemSymbolFilter =
@ -430,11 +430,11 @@ Hover getHover(ParsedAST &AST, Position Pos) {
indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(), indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(),
DeclMacrosFinder, IndexOpts); DeclMacrosFinder, IndexOpts);
std::vector<MacroDecl> Macros = DeclMacrosFinder->takeMacroInfos(); std::vector<MacroDecl> Macros = DeclMacrosFinder.takeMacroInfos();
if (!Macros.empty()) if (!Macros.empty())
return getHoverContents(Macros[0].Name); return getHoverContents(Macros[0].Name);
std::vector<const Decl *> Decls = DeclMacrosFinder->takeDecls(); std::vector<const Decl *> Decls = DeclMacrosFinder.takeDecls();
if (!Decls.empty()) if (!Decls.empty())
return getHoverContents(Decls[0]); return getHoverContents(Decls[0]);

View File

@ -28,8 +28,8 @@ std::unique_ptr<SymbolSlab> indexAST(ASTContext &Ctx,
CollectorOpts.CollectIncludePath = false; CollectorOpts.CollectIncludePath = false;
CollectorOpts.CountReferences = false; CollectorOpts.CountReferences = false;
auto Collector = std::make_shared<SymbolCollector>(std::move(CollectorOpts)); SymbolCollector Collector(std::move(CollectorOpts));
Collector->setPreprocessor(std::move(PP)); Collector.setPreprocessor(std::move(PP));
index::IndexingOptions IndexOpts; index::IndexingOptions IndexOpts;
// We only need declarations, because we don't count references. // We only need declarations, because we don't count references.
IndexOpts.SystemSymbolFilter = IndexOpts.SystemSymbolFilter =
@ -38,7 +38,7 @@ std::unique_ptr<SymbolSlab> indexAST(ASTContext &Ctx,
index::indexTopLevelDecls(Ctx, Decls, Collector, IndexOpts); index::indexTopLevelDecls(Ctx, Decls, Collector, IndexOpts);
auto Symbols = llvm::make_unique<SymbolSlab>(); auto Symbols = llvm::make_unique<SymbolSlab>();
*Symbols = Collector->takeSymbols(); *Symbols = Collector.takeSymbols();
return Symbols; return Symbols;
} }

View File

@ -46,17 +46,14 @@ createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
IndexingOptions Opts, IndexingOptions Opts,
std::unique_ptr<FrontendAction> WrappedAction); std::unique_ptr<FrontendAction> WrappedAction);
void indexASTUnit(ASTUnit &Unit, void indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
std::shared_ptr<IndexDataConsumer> DataConsumer,
IndexingOptions Opts); IndexingOptions Opts);
void indexTopLevelDecls(ASTContext &Ctx, ArrayRef<const Decl *> Decls, void indexTopLevelDecls(ASTContext &Ctx, ArrayRef<const Decl *> Decls,
std::shared_ptr<IndexDataConsumer> DataConsumer, IndexDataConsumer &DataConsumer, IndexingOptions Opts);
IndexingOptions Opts);
void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader, void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader,
std::shared_ptr<IndexDataConsumer> DataConsumer, IndexDataConsumer &DataConsumer, IndexingOptions Opts);
IndexingOptions Opts);
} // namespace index } // namespace index
} // namespace clang } // namespace clang

View File

@ -173,40 +173,38 @@ static void indexTranslationUnit(ASTUnit &Unit, IndexingContext &IndexCtx) {
Unit.visitLocalTopLevelDecls(&IndexCtx, topLevelDeclVisitor); Unit.visitLocalTopLevelDecls(&IndexCtx, topLevelDeclVisitor);
} }
void index::indexASTUnit(ASTUnit &Unit, void index::indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
std::shared_ptr<IndexDataConsumer> DataConsumer,
IndexingOptions Opts) { IndexingOptions Opts) {
IndexingContext IndexCtx(Opts, *DataConsumer); IndexingContext IndexCtx(Opts, DataConsumer);
IndexCtx.setASTContext(Unit.getASTContext()); IndexCtx.setASTContext(Unit.getASTContext());
DataConsumer->initialize(Unit.getASTContext()); DataConsumer.initialize(Unit.getASTContext());
DataConsumer->setPreprocessor(Unit.getPreprocessorPtr()); DataConsumer.setPreprocessor(Unit.getPreprocessorPtr());
indexTranslationUnit(Unit, IndexCtx); indexTranslationUnit(Unit, IndexCtx);
DataConsumer->finish(); DataConsumer.finish();
} }
void index::indexTopLevelDecls(ASTContext &Ctx, ArrayRef<const Decl *> Decls, void index::indexTopLevelDecls(ASTContext &Ctx, ArrayRef<const Decl *> Decls,
std::shared_ptr<IndexDataConsumer> DataConsumer, IndexDataConsumer &DataConsumer,
IndexingOptions Opts) { IndexingOptions Opts) {
IndexingContext IndexCtx(Opts, *DataConsumer); IndexingContext IndexCtx(Opts, DataConsumer);
IndexCtx.setASTContext(Ctx); IndexCtx.setASTContext(Ctx);
DataConsumer->initialize(Ctx); DataConsumer.initialize(Ctx);
for (const Decl *D : Decls) for (const Decl *D : Decls)
IndexCtx.indexTopLevelDecl(D); IndexCtx.indexTopLevelDecl(D);
DataConsumer->finish(); DataConsumer.finish();
} }
void index::indexModuleFile(serialization::ModuleFile &Mod, void index::indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader,
ASTReader &Reader, IndexDataConsumer &DataConsumer,
std::shared_ptr<IndexDataConsumer> DataConsumer,
IndexingOptions Opts) { IndexingOptions Opts) {
ASTContext &Ctx = Reader.getContext(); ASTContext &Ctx = Reader.getContext();
IndexingContext IndexCtx(Opts, *DataConsumer); IndexingContext IndexCtx(Opts, DataConsumer);
IndexCtx.setASTContext(Ctx); IndexCtx.setASTContext(Ctx);
DataConsumer->initialize(Ctx); DataConsumer.initialize(Ctx);
for (const Decl *D : Reader.getModuleFileLevelDecls(Mod)) { for (const Decl *D : Reader.getModuleFileLevelDecls(Mod)) {
IndexCtx.indexTopLevelDecl(D); IndexCtx.indexTopLevelDecl(D);
} }
DataConsumer->finish(); DataConsumer.finish();
} }

View File

@ -195,7 +195,7 @@ static bool printSourceSymbols(ArrayRef<const char *> Args,
if (auto Reader = Unit->getASTReader()) { if (auto Reader = Unit->getASTReader()) {
Reader->getModuleManager().visit([&](serialization::ModuleFile &Mod) -> bool { Reader->getModuleManager().visit([&](serialization::ModuleFile &Mod) -> bool {
OS << "==== Module " << Mod.ModuleName << " ====\n"; OS << "==== Module " << Mod.ModuleName << " ====\n";
indexModuleFile(Mod, *Reader, DataConsumer, IndexOpts); indexModuleFile(Mod, *Reader, *DataConsumer, IndexOpts);
dumpModuleFileInputs(Mod, *Reader, OS); dumpModuleFileInputs(Mod, *Reader, OS);
return true; // skip module dependencies. return true; // skip module dependencies.
}); });
@ -231,7 +231,7 @@ static bool printSourceSymbolsFromModule(StringRef modulePath,
return true; return true;
} }
auto DataConsumer = std::make_shared<PrintIndexDataConsumer>(outs()); PrintIndexDataConsumer DataConsumer(outs());
IndexingOptions IndexOpts; IndexingOptions IndexOpts;
indexASTUnit(*AU, DataConsumer, IndexOpts); indexASTUnit(*AU, DataConsumer, IndexOpts);

View File

@ -659,8 +659,7 @@ static CXErrorCode clang_indexTranslationUnit_Impl(
? index_callbacks_size : sizeof(CB); ? index_callbacks_size : sizeof(CB);
memcpy(&CB, client_index_callbacks, ClientCBSize); memcpy(&CB, client_index_callbacks, ClientCBSize);
auto DataConsumer = std::make_shared<CXIndexDataConsumer>(client_data, CB, CXIndexDataConsumer DataConsumer(client_data, CB, index_options, TU);
index_options, TU);
ASTUnit *Unit = cxtu::getASTUnit(TU); ASTUnit *Unit = cxtu::getASTUnit(TU);
if (!Unit) if (!Unit)
@ -669,21 +668,22 @@ static CXErrorCode clang_indexTranslationUnit_Impl(
ASTUnit::ConcurrencyCheck Check(*Unit); ASTUnit::ConcurrencyCheck Check(*Unit);
if (const FileEntry *PCHFile = Unit->getPCHFile()) if (const FileEntry *PCHFile = Unit->getPCHFile())
DataConsumer->importedPCH(PCHFile); DataConsumer.importedPCH(PCHFile);
FileManager &FileMgr = Unit->getFileManager(); FileManager &FileMgr = Unit->getFileManager();
if (Unit->getOriginalSourceFileName().empty()) if (Unit->getOriginalSourceFileName().empty())
DataConsumer->enteredMainFile(nullptr); DataConsumer.enteredMainFile(nullptr);
else else
DataConsumer->enteredMainFile(FileMgr.getFile(Unit->getOriginalSourceFileName())); DataConsumer.enteredMainFile(
FileMgr.getFile(Unit->getOriginalSourceFileName()));
DataConsumer->setASTContext(Unit->getASTContext()); DataConsumer.setASTContext(Unit->getASTContext());
DataConsumer->startedTranslationUnit(); DataConsumer.startedTranslationUnit();
indexPreprocessingRecord(*Unit, *DataConsumer); indexPreprocessingRecord(*Unit, DataConsumer);
indexASTUnit(*Unit, DataConsumer, getIndexingOptionsFromCXOptions(index_options)); indexASTUnit(*Unit, DataConsumer, getIndexingOptionsFromCXOptions(index_options));
DataConsumer->indexDiagnostics(); DataConsumer.indexDiagnostics();
return CXError_Success; return CXError_Success;
} }