[clang-tidy][NFC] Add createChecks method that also checks for LangaugeOptions

This method won't add a check if it isn't supported in the Contexts current LanguageOptions.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D124320
This commit is contained in:
Nathan James 2022-05-06 17:30:30 +01:00
parent 76f90a9d71
commit dd87aceb51
No known key found for this signature in database
GPG Key ID: CC007AFCDA90AA5F
4 changed files with 21 additions and 9 deletions

View File

@ -402,11 +402,7 @@ ClangTidyASTConsumerFactory::createASTConsumer(
Context.setCurrentBuildDirectory(WorkingDir.get());
std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
CheckFactories->createChecks(&Context);
llvm::erase_if(Checks, [&](std::unique_ptr<ClangTidyCheck> &Check) {
return !Check->isLanguageVersionSupported(Context.getLangOpts());
});
CheckFactories->createChecksForLanguage(&Context);
ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;

View File

@ -31,6 +31,21 @@ ClangTidyCheckFactories::createChecks(ClangTidyContext *Context) {
return Checks;
}
std::vector<std::unique_ptr<ClangTidyCheck>>
ClangTidyCheckFactories::createChecksForLanguage(ClangTidyContext *Context) {
std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
const LangOptions &LO = Context->getLangOpts();
for (const auto &Factory : Factories) {
if (!Context->isCheckEnabled(Factory.getKey()))
continue;
std::unique_ptr<ClangTidyCheck> Check =
Factory.getValue()(Factory.getKey(), Context);
if (Check->isLanguageVersionSupported(LO))
Checks.push_back(std::move(Check));
}
return Checks;
}
ClangTidyOptions ClangTidyModule::getModuleOptions() {
return ClangTidyOptions();
}

View File

@ -67,6 +67,10 @@ public:
std::vector<std::unique_ptr<ClangTidyCheck>>
createChecks(ClangTidyContext *Context);
/// Create instances of checks that are enabled for the current Language.
std::vector<std::unique_ptr<ClangTidyCheck>>
createChecksForLanguage(ClangTidyContext *Context);
typedef llvm::StringMap<CheckFactory> FactoryMap;
FactoryMap::const_iterator begin() const { return Factories.begin(); }
FactoryMap::const_iterator end() const { return Factories.end(); }

View File

@ -480,10 +480,7 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
CTContext->setASTContext(&Clang->getASTContext());
CTContext->setCurrentFile(Filename);
CTContext->setSelfContainedDiags(true);
CTChecks = CTFactories.createChecks(CTContext.getPointer());
llvm::erase_if(CTChecks, [&](const auto &Check) {
return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
});
CTChecks = CTFactories.createChecksForLanguage(CTContext.getPointer());
Preprocessor *PP = &Clang->getPreprocessor();
for (const auto &Check : CTChecks) {
Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);