Change getChecksFilter() interface to hide implementation details.
authorAlexander Kornienko <alexfh@google.com>
Wed, 17 May 2017 14:39:47 +0000 (14:39 +0000)
committerAlexander Kornienko <alexfh@google.com>
Wed, 17 May 2017 14:39:47 +0000 (14:39 +0000)
llvm-svn: 303264

clang-tools-extra/clang-tidy/ClangTidy.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/clang-tidy/ClangTidyModule.cpp

index 511cbb8..c3ddc45 100644 (file)
@@ -302,7 +302,7 @@ static void setStaticAnalyzerCheckerOpts(const ClangTidyOptions &Opts,
 
 typedef std::vector<std::pair<std::string, bool>> CheckersList;
 
-static CheckersList getCheckersControlList(GlobList &Filter) {
+static CheckersList getCheckersControlList(ClangTidyContext &Context) {
   CheckersList List;
 
   const auto &RegisteredCheckers =
@@ -310,7 +310,7 @@ static CheckersList getCheckersControlList(GlobList &Filter) {
   bool AnalyzerChecksEnabled = false;
   for (StringRef CheckName : RegisteredCheckers) {
     std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str());
-    AnalyzerChecksEnabled |= Filter.contains(ClangTidyCheckName);
+    AnalyzerChecksEnabled |= Context.isCheckEnabled(ClangTidyCheckName);
   }
 
   if (!AnalyzerChecksEnabled)
@@ -324,8 +324,10 @@ static CheckersList getCheckersControlList(GlobList &Filter) {
   for (StringRef CheckName : RegisteredCheckers) {
     std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str());
 
-    if (CheckName.startswith("core") || Filter.contains(ClangTidyCheckName))
+    if (CheckName.startswith("core") ||
+        Context.isCheckEnabled(ClangTidyCheckName)) {
       List.emplace_back(CheckName, true);
+    }
   }
   return List;
 }
@@ -371,8 +373,7 @@ ClangTidyASTConsumerFactory::CreateASTConsumer(
   AnalyzerOptions->Config["cfg-temporary-dtors"] =
       Context.getOptions().AnalyzeTemporaryDtors ? "true" : "false";
 
-  GlobList &Filter = Context.getChecksFilter();
-  AnalyzerOptions->CheckersControlList = getCheckersControlList(Filter);
+  AnalyzerOptions->CheckersControlList = getCheckersControlList(Context);
   if (!AnalyzerOptions->CheckersControlList.empty()) {
     setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
     AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
@@ -391,13 +392,12 @@ ClangTidyASTConsumerFactory::CreateASTConsumer(
 
 std::vector<std::string> ClangTidyASTConsumerFactory::getCheckNames() {
   std::vector<std::string> CheckNames;
-  GlobList &Filter = Context.getChecksFilter();
   for (const auto &CheckFactory : *CheckFactories) {
-    if (Filter.contains(CheckFactory.first))
+    if (Context.isCheckEnabled(CheckFactory.first))
       CheckNames.push_back(CheckFactory.first);
   }
 
-  for (const auto &AnalyzerCheck : getCheckersControlList(Filter))
+  for (const auto &AnalyzerCheck : getCheckersControlList(Context))
     CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first);
 
   std::sort(CheckNames.begin(), CheckNames.end());
index ca3494f..741bac6 100644 (file)
@@ -214,14 +214,14 @@ ClangTidyOptions ClangTidyContext::getOptionsForFile(StringRef File) const {
 
 void ClangTidyContext::setCheckProfileData(ProfileData *P) { Profile = P; }
 
-GlobList &ClangTidyContext::getChecksFilter() {
+bool ClangTidyContext::isCheckEnabled(StringRef CheckName) const {
   assert(CheckFilter != nullptr);
-  return *CheckFilter;
+  return CheckFilter->contains(CheckName);
 }
 
-GlobList &ClangTidyContext::getWarningAsErrorFilter() {
+bool ClangTidyContext::treatAsError(StringRef CheckName) const {
   assert(WarningAsErrorFilter != nullptr);
-  return *WarningAsErrorFilter;
+  return WarningAsErrorFilter->contains(CheckName);
 }
 
 /// \brief Store a \c ClangTidyError.
@@ -252,7 +252,7 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(
 void ClangTidyDiagnosticConsumer::finalizeLastError() {
   if (!Errors.empty()) {
     ClangTidyError &Error = Errors.back();
-    if (!Context.getChecksFilter().contains(Error.DiagnosticName) &&
+    if (!Context.isCheckEnabled(Error.DiagnosticName) &&
         Error.DiagLevel != ClangTidyError::Error) {
       ++Context.Stats.ErrorsIgnoredCheckFilter;
       Errors.pop_back();
@@ -384,9 +384,8 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
       LastErrorRelatesToUserCode = true;
       LastErrorPassesLineFilter = true;
     }
-    bool IsWarningAsError =
-        DiagLevel == DiagnosticsEngine::Warning &&
-        Context.getWarningAsErrorFilter().contains(CheckName);
+    bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
+                            Context.treatAsError(CheckName);
     Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),
                         IsWarningAsError);
   }
index ad447fd..19dd6f2 100644 (file)
@@ -136,14 +136,14 @@ public:
   /// diagnostic ID.
   StringRef getCheckName(unsigned DiagnosticID) const;
 
-  /// \brief Returns check filter for the \c CurrentFile.
+  /// \brief Returns \c true if the check is enabled for the \c CurrentFile.
   ///
   /// The \c CurrentFile can be changed using \c setCurrentFile.
-  GlobList &getChecksFilter();
+  bool isCheckEnabled(StringRef CheckName) const;
 
-  /// \brief Returns check filter for the \c CurrentFile which
-  /// selects checks for upgrade to error.
-  GlobList &getWarningAsErrorFilter();
+  /// \brief Returns \c true if the check should be upgraded to error for the
+  /// \c CurrentFile.
+  bool treatAsError(StringRef CheckName) const;
 
   /// \brief Returns global options.
   const ClangTidyGlobalOptions &getGlobalOptions() const;
index 3a3ae82..9dbf016 100644 (file)
@@ -24,9 +24,8 @@ void ClangTidyCheckFactories::registerCheckFactory(StringRef Name,
 void ClangTidyCheckFactories::createChecks(
     ClangTidyContext *Context,
     std::vector<std::unique_ptr<ClangTidyCheck>> &Checks) {
-  GlobList &Filter = Context->getChecksFilter();
   for (const auto &Factory : Factories) {
-    if (Filter.contains(Factory.first))
+    if (Context->isCheckEnabled(Factory.first))
       Checks.emplace_back(Factory.second(Factory.first, Context));
   }
 }