[PATCH] D124320: [clang-tidy] Add createChecks method that also checks for LangaugeOptions

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 23 01:01:07 PDT 2022


njames93 updated this revision to Diff 424694.
njames93 added a comment.

Remove unnecessary copy of LanguageOptions.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124320/new/

https://reviews.llvm.org/D124320

Files:
  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


Index: clang-tools-extra/clangd/ParsedAST.cpp
===================================================================
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -413,10 +413,7 @@
     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);
Index: clang-tools-extra/clang-tidy/ClangTidyModule.h
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyModule.h
+++ clang-tools-extra/clang-tidy/ClangTidyModule.h
@@ -67,6 +67,10 @@
   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(); }
Index: clang-tools-extra/clang-tidy/ClangTidyModule.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyModule.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyModule.cpp
@@ -31,6 +31,21 @@
   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();
 }
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -402,11 +402,7 @@
     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;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124320.424694.patch
Type: text/x-patch
Size: 3126 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220423/4bb9efae/attachment-0001.bin>


More information about the cfe-commits mailing list