[clang-tools-extra] dd87ace - [clang-tidy][NFC] Add createChecks method that also checks for LangaugeOptions
Nathan James via cfe-commits
cfe-commits at lists.llvm.org
Fri May 6 09:30:41 PDT 2022
Author: Nathan James
Date: 2022-05-06T17:30:34+01:00
New Revision: dd87aceb514d1c2b9c3e48854100df8b036d718a
URL: https://github.com/llvm/llvm-project/commit/dd87aceb514d1c2b9c3e48854100df8b036d718a
DIFF: https://github.com/llvm/llvm-project/commit/dd87aceb514d1c2b9c3e48854100df8b036d718a.diff
LOG: [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
Added:
Modified:
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang-tools-extra/clang-tidy/ClangTidyModule.cpp
clang-tools-extra/clang-tidy/ClangTidyModule.h
clang-tools-extra/clangd/ParsedAST.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 7de313ad4da6a..cd0cbfda3dc5a 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -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;
diff --git a/clang-tools-extra/clang-tidy/ClangTidyModule.cpp b/clang-tools-extra/clang-tidy/ClangTidyModule.cpp
index c72bcd3e188ce..e31252687adb3 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyModule.cpp
@@ -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();
}
diff --git a/clang-tools-extra/clang-tidy/ClangTidyModule.h b/clang-tools-extra/clang-tidy/ClangTidyModule.h
index dd21a8dbc6a43..f44457d3ae8f8 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyModule.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyModule.h
@@ -67,6 +67,10 @@ class ClangTidyCheckFactories {
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(); }
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp
index 54d8e391cd94a..8bb426d78f367 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -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);
More information about the cfe-commits
mailing list