[clang-tools-extra] r214961 - Rename ChecksFilter to GlobList, as there's nothing specific to checks in it.

Alexander Kornienko alexfh at google.com
Wed Aug 6 04:49:10 PDT 2014


Author: alexfh
Date: Wed Aug  6 06:49:10 2014
New Revision: 214961

URL: http://llvm.org/viewvc/llvm-project?rev=214961&view=rev
Log:
Rename ChecksFilter to GlobList, as there's nothing specific to checks in it.

Summary:
Rename ChecksFilter to GlobList, as there's nothing specific to checks in it.
It's a rather generic way to represent sets of strings (or patterns), so it may
be used for something else in ClangTidy. The new name would not look strange
when used to filter other entities.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D4806

Modified:
    clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
    clang-tools-extra/trunk/clang-tidy/ClangTidy.h
    clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
    clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
    clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp
    clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
    clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=214961&r1=214960&r2=214961&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Wed Aug  6 06:49:10 2014
@@ -213,7 +213,7 @@ clang::ASTConsumer *ClangTidyASTConsumer
   Context.setASTContext(&Compiler.getASTContext());
 
   std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
-  ChecksFilter &Filter = Context.getChecksFilter();
+  GlobList &Filter = Context.getChecksFilter();
   CheckFactories->createChecks(Filter, Checks);
 
   std::unique_ptr<ast_matchers::MatchFinder> Finder(
@@ -252,10 +252,10 @@ clang::ASTConsumer *ClangTidyASTConsumer
 }
 
 std::vector<std::string>
-ClangTidyASTConsumerFactory::getCheckNames(ChecksFilter &Filter) {
+ClangTidyASTConsumerFactory::getCheckNames(GlobList &Filter) {
   std::vector<std::string> CheckNames;
   for (const auto &CheckFactory : *CheckFactories) {
-    if (Filter.isCheckEnabled(CheckFactory.first))
+    if (Filter.contains(CheckFactory.first))
       CheckNames.push_back(CheckFactory.first);
   }
 
@@ -267,7 +267,7 @@ ClangTidyASTConsumerFactory::getCheckNam
 }
 
 ClangTidyASTConsumerFactory::CheckersList
-ClangTidyASTConsumerFactory::getCheckersControlList(ChecksFilter &Filter) {
+ClangTidyASTConsumerFactory::getCheckersControlList(GlobList &Filter) {
   CheckersList List;
 
   bool AnalyzerChecksEnabled = false;
@@ -275,7 +275,7 @@ ClangTidyASTConsumerFactory::getCheckers
     std::string Checker((AnalyzerCheckNamePrefix + CheckName).str());
     AnalyzerChecksEnabled =
         AnalyzerChecksEnabled ||
-        (!CheckName.startswith("debug") && Filter.isCheckEnabled(Checker));
+        (!CheckName.startswith("debug") && Filter.contains(Checker));
   }
 
   if (AnalyzerChecksEnabled) {
@@ -290,7 +290,7 @@ ClangTidyASTConsumerFactory::getCheckers
       std::string Checker((AnalyzerCheckNamePrefix + CheckName).str());
 
       if (CheckName.startswith("core") ||
-          (!CheckName.startswith("debug") && Filter.isCheckEnabled(Checker)))
+          (!CheckName.startswith("debug") && Filter.contains(Checker)))
         List.push_back(std::make_pair(CheckName, true));
     }
   }

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.h?rev=214961&r1=214960&r2=214961&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.h Wed Aug  6 06:49:10 2014
@@ -103,11 +103,11 @@ public:
                                         StringRef File);
 
   /// \brief Get the list of enabled checks.
-  std::vector<std::string> getCheckNames(ChecksFilter &Filter);
+  std::vector<std::string> getCheckNames(GlobList &Filter);
 
 private:
   typedef std::vector<std::pair<std::string, bool> > CheckersList;
-  CheckersList getCheckersControlList(ChecksFilter &Filter);
+  CheckersList getCheckersControlList(GlobList &Filter);
 
   ClangTidyContext &Context;
   std::unique_ptr<ClangTidyCheckFactories> CheckFactories;

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=214961&r1=214960&r2=214961&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Wed Aug  6 06:49:10 2014
@@ -146,18 +146,18 @@ static llvm::Regex ConsumeGlob(StringRef
   return llvm::Regex(RegexText);
 }
 
-ChecksFilter::ChecksFilter(StringRef GlobList)
-    : Positive(!ConsumeNegativeIndicator(GlobList)),
-      Regex(ConsumeGlob(GlobList)),
-      NextFilter(GlobList.empty() ? nullptr : new ChecksFilter(GlobList)) {}
-
-bool ChecksFilter::isCheckEnabled(StringRef Name, bool Enabled) {
-  if (Regex.match(Name))
-    Enabled = Positive;
-
-  if (NextFilter)
-    Enabled = NextFilter->isCheckEnabled(Name, Enabled);
-  return Enabled;
+GlobList::GlobList(StringRef Globs)
+    : Positive(!ConsumeNegativeIndicator(Globs)),
+      Regex(ConsumeGlob(Globs)),
+      NextGlob(Globs.empty() ? nullptr : new GlobList(Globs)) {}
+
+bool GlobList::contains(StringRef S, bool Contains) {
+  if (Regex.match(S))
+    Contains = Positive;
+
+  if (NextGlob)
+    Contains = NextGlob->contains(S, Contains);
+  return Contains;
 }
 
 ClangTidyContext::ClangTidyContext(ClangTidyOptionsProvider *OptionsProvider)
@@ -202,7 +202,7 @@ void ClangTidyContext::setSourceManager(
 
 void ClangTidyContext::setCurrentFile(StringRef File) {
   CurrentFile = File;
-  CheckFilter.reset(new ChecksFilter(getOptions().Checks));
+  CheckFilter.reset(new GlobList(getOptions().Checks));
 }
 
 void ClangTidyContext::setASTContext(ASTContext *Context) {
@@ -217,7 +217,7 @@ const ClangTidyOptions &ClangTidyContext
   return OptionsProvider->getOptions(CurrentFile);
 }
 
-ChecksFilter &ClangTidyContext::getChecksFilter() {
+GlobList &ClangTidyContext::getChecksFilter() {
   assert(CheckFilter != nullptr);
   return *CheckFilter;
 }
@@ -248,7 +248,7 @@ ClangTidyDiagnosticConsumer::ClangTidyDi
 void ClangTidyDiagnosticConsumer::finalizeLastError() {
   if (!Errors.empty()) {
     ClangTidyError &Error = Errors.back();
-    if (!Context.getChecksFilter().isCheckEnabled(Error.CheckName) &&
+    if (!Context.getChecksFilter().contains(Error.CheckName) &&
         Error.DiagLevel != ClangTidyError::Error) {
       ++Context.Stats.ErrorsIgnoredCheckFilter;
       Errors.pop_back();

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h?rev=214961&r1=214960&r2=214961&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h Wed Aug  6 06:49:10 2014
@@ -65,24 +65,25 @@ struct ClangTidyError {
   Level DiagLevel;
 };
 
-/// \brief Filters checks by name.
-class ChecksFilter {
+/// \brief Read-only set of strings represented as a list of positive and
+/// negative globs. Positive globs add all matched strings to the set, negative
+/// globs remove them in the order of appearance in the list.
+class GlobList {
 public:
   /// \brief \p GlobList is a comma-separated list of globs (only '*'
   /// metacharacter is supported) with optional '-' prefix to denote exclusion.
-  ChecksFilter(StringRef GlobList);
+  GlobList(StringRef Globs);
 
-  /// \brief Returns \c true if the check with the specified \p Name should be
-  /// enabled. The result is the last matching glob's Positive flag. If \p Name
-  /// is not matched by any globs, the check is not enabled.
-  bool isCheckEnabled(StringRef Name) { return isCheckEnabled(Name, false); }
+  /// \brief Returns \c true if the pattern matches \p S. The result is the last
+  /// matching glob's Positive flag.
+  bool contains(StringRef S) { return contains(S, false); }
 
 private:
-  bool isCheckEnabled(StringRef Name, bool Enabled);
+  bool contains(StringRef S, bool Contains);
 
   bool Positive;
   llvm::Regex Regex;
-  std::unique_ptr<ChecksFilter> NextFilter;
+  std::unique_ptr<GlobList> NextGlob;
 };
 
 /// \brief Contains displayed and ignored diagnostic counters for a ClangTidy
@@ -145,7 +146,7 @@ public:
   StringRef getCheckName(unsigned DiagnosticID) const;
 
   /// \brief Returns check filter for the \c CurrentFile.
-  ChecksFilter &getChecksFilter();
+  GlobList &getChecksFilter();
 
   /// \brief Returns global options.
   const ClangTidyGlobalOptions &getGlobalOptions() const;
@@ -179,7 +180,7 @@ private:
   std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
 
   std::string CurrentFile;
-  std::unique_ptr<ChecksFilter> CheckFilter;
+  std::unique_ptr<GlobList> CheckFilter;
 
   ClangTidyStats Stats;
 

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp?rev=214961&r1=214960&r2=214961&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp Wed Aug  6 06:49:10 2014
@@ -27,10 +27,9 @@ void ClangTidyCheckFactories::addCheckFa
 }
 
 void ClangTidyCheckFactories::createChecks(
-    ChecksFilter &Filter,
-    std::vector<std::unique_ptr<ClangTidyCheck>> &Checks) {
+    GlobList &Filter, std::vector<std::unique_ptr<ClangTidyCheck>> &Checks) {
   for (const auto &Factory : Factories) {
-    if (Filter.isCheckEnabled(Factory.first)) {
+    if (Filter.contains(Factory.first)) {
       ClangTidyCheck *Check = Factory.second->createCheck();
       Check->setName(Factory.first);
       Checks.emplace_back(Check);

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h?rev=214961&r1=214960&r2=214961&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h Wed Aug  6 06:49:10 2014
@@ -86,7 +86,7 @@ public:
   /// store them in \p Checks.
   ///
   /// The caller takes ownership of the return \c ClangTidyChecks.
-  void createChecks(ChecksFilter &Filter,
+  void createChecks(GlobList &Filter,
                     std::vector<std::unique_ptr<ClangTidyCheck>> &Checks);
 
   typedef std::map<std::string, CheckFactoryBase *> FactoryMap;

Modified: clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp?rev=214961&r1=214960&r2=214961&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp Wed Aug  6 06:49:10 2014
@@ -28,57 +28,57 @@ TEST(ClangTidyDiagnosticConsumer, SortsE
   EXPECT_EQ("variable []", Errors[1].Message.Message);
 }
 
-TEST(ChecksFilter, Empty) {
-  ChecksFilter Filter("");
+TEST(GlobList, Empty) {
+  GlobList Filter("");
 
-  EXPECT_TRUE(Filter.isCheckEnabled(""));
-  EXPECT_FALSE(Filter.isCheckEnabled("aaa"));
+  EXPECT_TRUE(Filter.contains(""));
+  EXPECT_FALSE(Filter.contains("aaa"));
 }
 
-TEST(ChecksFilter, Nothing) {
-  ChecksFilter Filter("-*");
+TEST(GlobList, Nothing) {
+  GlobList Filter("-*");
 
-  EXPECT_FALSE(Filter.isCheckEnabled(""));
-  EXPECT_FALSE(Filter.isCheckEnabled("a"));
-  EXPECT_FALSE(Filter.isCheckEnabled("-*"));
-  EXPECT_FALSE(Filter.isCheckEnabled("-"));
-  EXPECT_FALSE(Filter.isCheckEnabled("*"));
+  EXPECT_FALSE(Filter.contains(""));
+  EXPECT_FALSE(Filter.contains("a"));
+  EXPECT_FALSE(Filter.contains("-*"));
+  EXPECT_FALSE(Filter.contains("-"));
+  EXPECT_FALSE(Filter.contains("*"));
 }
 
-TEST(ChecksFilter, Everything) {
-  ChecksFilter Filter("*");
+TEST(GlobList, Everything) {
+  GlobList Filter("*");
 
-  EXPECT_TRUE(Filter.isCheckEnabled(""));
-  EXPECT_TRUE(Filter.isCheckEnabled("aaaa"));
-  EXPECT_TRUE(Filter.isCheckEnabled("-*"));
-  EXPECT_TRUE(Filter.isCheckEnabled("-"));
-  EXPECT_TRUE(Filter.isCheckEnabled("*"));
+  EXPECT_TRUE(Filter.contains(""));
+  EXPECT_TRUE(Filter.contains("aaaa"));
+  EXPECT_TRUE(Filter.contains("-*"));
+  EXPECT_TRUE(Filter.contains("-"));
+  EXPECT_TRUE(Filter.contains("*"));
 }
 
-TEST(ChecksFilter, Simple) {
-  ChecksFilter Filter("aaa");
+TEST(GlobList, Simple) {
+  GlobList Filter("aaa");
 
-  EXPECT_TRUE(Filter.isCheckEnabled("aaa"));
-  EXPECT_FALSE(Filter.isCheckEnabled(""));
-  EXPECT_FALSE(Filter.isCheckEnabled("aa"));
-  EXPECT_FALSE(Filter.isCheckEnabled("aaaa"));
-  EXPECT_FALSE(Filter.isCheckEnabled("bbb"));
+  EXPECT_TRUE(Filter.contains("aaa"));
+  EXPECT_FALSE(Filter.contains(""));
+  EXPECT_FALSE(Filter.contains("aa"));
+  EXPECT_FALSE(Filter.contains("aaaa"));
+  EXPECT_FALSE(Filter.contains("bbb"));
 }
 
-TEST(ChecksFilter, Complex) {
-  ChecksFilter Filter("*,-a.*,-b.*,a.1.*,-a.1.A.*,-..,-...,-..+,-*$,-*qwe*");
+TEST(GlobList, Complex) {
+  GlobList Filter("*,-a.*,-b.*,a.1.*,-a.1.A.*,-..,-...,-..+,-*$,-*qwe*");
 
-  EXPECT_TRUE(Filter.isCheckEnabled("aaa"));
-  EXPECT_TRUE(Filter.isCheckEnabled("qqq"));
-  EXPECT_FALSE(Filter.isCheckEnabled("a."));
-  EXPECT_FALSE(Filter.isCheckEnabled("a.b"));
-  EXPECT_FALSE(Filter.isCheckEnabled("b."));
-  EXPECT_FALSE(Filter.isCheckEnabled("b.b"));
-  EXPECT_TRUE(Filter.isCheckEnabled("a.1.b"));
-  EXPECT_FALSE(Filter.isCheckEnabled("a.1.A.a"));
-  EXPECT_FALSE(Filter.isCheckEnabled("qwe"));
-  EXPECT_FALSE(Filter.isCheckEnabled("asdfqweasdf"));
-  EXPECT_TRUE(Filter.isCheckEnabled("asdfqwEasdf"));
+  EXPECT_TRUE(Filter.contains("aaa"));
+  EXPECT_TRUE(Filter.contains("qqq"));
+  EXPECT_FALSE(Filter.contains("a."));
+  EXPECT_FALSE(Filter.contains("a.b"));
+  EXPECT_FALSE(Filter.contains("b."));
+  EXPECT_FALSE(Filter.contains("b.b"));
+  EXPECT_TRUE(Filter.contains("a.1.b"));
+  EXPECT_FALSE(Filter.contains("a.1.A.a"));
+  EXPECT_FALSE(Filter.contains("qwe"));
+  EXPECT_FALSE(Filter.contains("asdfqweasdf"));
+  EXPECT_TRUE(Filter.contains("asdfqwEasdf"));
 }
 
 } // namespace test





More information about the cfe-commits mailing list