Return results by value from ClangTidyCheckFactories::createChecks

llvm-svn: 372979
This commit is contained in:
Dmitri Gribenko 2019-09-26 13:55:01 +00:00
parent 5338ffcfa1
commit bb7a9dcd42
4 changed files with 12 additions and 14 deletions

View File

@ -384,8 +384,8 @@ ClangTidyASTConsumerFactory::CreateASTConsumer(
if (WorkingDir)
Context.setCurrentBuildDirectory(WorkingDir.get());
std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
CheckFactories->createChecks(&Context, Checks);
std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
CheckFactories->createChecks(&Context);
ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
@ -459,8 +459,8 @@ std::vector<std::string> ClangTidyASTConsumerFactory::getCheckNames() {
ClangTidyOptions::OptionMap ClangTidyASTConsumerFactory::getCheckOptions() {
ClangTidyOptions::OptionMap Options;
std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
CheckFactories->createChecks(&Context, Checks);
std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
CheckFactories->createChecks(&Context);
for (const auto &Check : Checks)
Check->storeOptions(Options);
return Options;

View File

@ -20,13 +20,14 @@ void ClangTidyCheckFactories::registerCheckFactory(StringRef Name,
Factories[Name] = std::move(Factory);
}
void ClangTidyCheckFactories::createChecks(
ClangTidyContext *Context,
std::vector<std::unique_ptr<ClangTidyCheck>> &Checks) {
std::vector<std::unique_ptr<ClangTidyCheck>>
ClangTidyCheckFactories::createChecks(ClangTidyContext *Context) {
std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
for (const auto &Factory : Factories) {
if (Context->isCheckEnabled(Factory.first))
Checks.emplace_back(Factory.second(Factory.first, Context));
}
return Checks;
}
ClangTidyOptions ClangTidyModule::getModuleOptions() {

View File

@ -62,12 +62,9 @@ public:
});
}
/// Create instances of all checks matching \p CheckRegexString and
/// store them in \p Checks.
///
/// The caller takes ownership of the return \c ClangTidyChecks.
void createChecks(ClangTidyContext *Context,
std::vector<std::unique_ptr<ClangTidyCheck>> &Checks);
/// Create instances of checks that are enabled.
std::vector<std::unique_ptr<ClangTidyCheck>>
createChecks(ClangTidyContext *Context);
typedef std::map<std::string, CheckFactory> FactoryMap;
FactoryMap::const_iterator begin() const { return Factories.begin(); }

View File

@ -261,7 +261,7 @@ ParsedAST::build(std::unique_ptr<clang::CompilerInvocation> CI,
CTContext->setDiagnosticsEngine(&Clang->getDiagnostics());
CTContext->setASTContext(&Clang->getASTContext());
CTContext->setCurrentFile(Filename);
CTFactories.createChecks(CTContext.getPointer(), CTChecks);
CTChecks = CTFactories.createChecks(CTContext.getPointer());
ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic &Info) {
if (CTContext) {