[clang-tools-extra] 25ed42f - [clang-change-namespace] As part of using inclusive language

Eric Christopher via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 19 23:02:32 PDT 2020


Author: Eric Christopher
Date: 2020-06-19T23:01:42-07:00
New Revision: 25ed42f05d07d3ad85c58ee001752338211c911c

URL: https://github.com/llvm/llvm-project/commit/25ed42f05d07d3ad85c58ee001752338211c911c
DIFF: https://github.com/llvm/llvm-project/commit/25ed42f05d07d3ad85c58ee001752338211c911c.diff

LOG: [clang-change-namespace] As part of using inclusive language
within the llvm project, migrate away from the use of blacklist
and whitelist.

Added: 
    clang-tools-extra/test/clang-change-namespace/allow-list.cpp

Modified: 
    clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
    clang-tools-extra/clang-change-namespace/ChangeNamespace.h
    clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp
    clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp

Removed: 
    clang-tools-extra/test/clang-change-namespace/white-list.cpp


################################################################################
diff  --git a/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp b/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
index 5f4a889cab9e..e2a70db4102b 100644
--- a/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
+++ b/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
@@ -347,7 +347,7 @@ bool isTemplateParameter(TypeLoc Type) {
 
 ChangeNamespaceTool::ChangeNamespaceTool(
     llvm::StringRef OldNs, llvm::StringRef NewNs, llvm::StringRef FilePattern,
-    llvm::ArrayRef<std::string> WhiteListedSymbolPatterns,
+    llvm::ArrayRef<std::string> AllowedSymbolPatterns,
     std::map<std::string, tooling::Replacements> *FileToReplacements,
     llvm::StringRef FallbackStyle)
     : FallbackStyle(FallbackStyle), FileToReplacements(*FileToReplacements),
@@ -365,8 +365,8 @@ ChangeNamespaceTool::ChangeNamespaceTool(
   DiffOldNamespace = joinNamespaces(OldNsSplitted);
   DiffNewNamespace = joinNamespaces(NewNsSplitted);
 
-  for (const auto &Pattern : WhiteListedSymbolPatterns)
-    WhiteListedSymbolRegexes.emplace_back(Pattern);
+  for (const auto &Pattern : AllowedSymbolPatterns)
+    AllowedSymbolRegexes.emplace_back(Pattern);
 }
 
 void ChangeNamespaceTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
@@ -800,7 +800,7 @@ void ChangeNamespaceTool::replaceQualifiedSymbolInDeclContext(
           Result.SourceManager->getSpellingLoc(End)),
       *Result.SourceManager, Result.Context->getLangOpts());
   std::string FromDeclName = FromDecl->getQualifiedNameAsString();
-  for (llvm::Regex &RE : WhiteListedSymbolRegexes)
+  for (llvm::Regex &RE : AllowedSymbolRegexes)
     if (RE.match(FromDeclName))
       return;
   std::string ReplaceName =

diff  --git a/clang-tools-extra/clang-change-namespace/ChangeNamespace.h b/clang-tools-extra/clang-change-namespace/ChangeNamespace.h
index 147675911941..d35119b70a69 100644
--- a/clang-tools-extra/clang-change-namespace/ChangeNamespace.h
+++ b/clang-tools-extra/clang-change-namespace/ChangeNamespace.h
@@ -49,7 +49,7 @@ class ChangeNamespaceTool : public ast_matchers::MatchFinder::MatchCallback {
   // files matching `FilePattern`.
   ChangeNamespaceTool(
       llvm::StringRef OldNs, llvm::StringRef NewNs, llvm::StringRef FilePattern,
-      llvm::ArrayRef<std::string> WhiteListedSymbolPatterns,
+      llvm::ArrayRef<std::string> AllowedSymbolPatterns,
       std::map<std::string, tooling::Replacements> *FileToReplacements,
       llvm::StringRef FallbackStyle = "LLVM");
 
@@ -166,7 +166,7 @@ class ChangeNamespaceTool : public ast_matchers::MatchFinder::MatchCallback {
   llvm::SmallPtrSet<const clang::DeclRefExpr*, 16> ProcessedFuncRefs;
   // Patterns of symbol names whose references are not expected to be updated
   // when changing namespaces around them.
-  std::vector<llvm::Regex> WhiteListedSymbolRegexes;
+  std::vector<llvm::Regex> AllowedSymbolRegexes;
 };
 
 } // namespace change_namespace

diff  --git a/clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp b/clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp
index d54fe7347cf3..61754fe41bc1 100644
--- a/clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp
+++ b/clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp
@@ -72,20 +72,20 @@ cl::opt<std::string> Style("style",
                            cl::desc("The style name used for reformatting."),
                            cl::init("LLVM"), cl::cat(ChangeNamespaceCategory));
 
-cl::opt<std::string> WhiteListFile(
-    "whitelist_file",
+cl::opt<std::string> AllowedFile(
+    "allowed_file",
     cl::desc("A file containing regexes of symbol names that are not expected "
              "to be updated when changing namespaces around them."),
     cl::init(""), cl::cat(ChangeNamespaceCategory));
 
-llvm::ErrorOr<std::vector<std::string>> GetWhiteListedSymbolPatterns() {
+llvm::ErrorOr<std::vector<std::string>> GetAllowedSymbolPatterns() {
   std::vector<std::string> Patterns;
-  if (WhiteListFile.empty())
+  if (AllowedFile.empty())
     return Patterns;
 
   llvm::SmallVector<StringRef, 8> Lines;
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
-      llvm::MemoryBuffer::getFile(WhiteListFile);
+      llvm::MemoryBuffer::getFile(AllowedFile);
   if (!File)
     return File.getError();
   llvm::StringRef Content = File.get()->getBuffer();
@@ -103,15 +103,15 @@ int main(int argc, const char **argv) {
                                              ChangeNamespaceCategory);
   const auto &Files = OptionsParser.getSourcePathList();
   tooling::RefactoringTool Tool(OptionsParser.getCompilations(), Files);
-  llvm::ErrorOr<std::vector<std::string>> WhiteListPatterns =
-      GetWhiteListedSymbolPatterns();
-  if (!WhiteListPatterns) {
-    llvm::errs() << "Failed to open whitelist file " << WhiteListFile << ". "
-                 << WhiteListPatterns.getError().message() << "\n";
+  llvm::ErrorOr<std::vector<std::string>> AllowedPatterns =
+      GetAllowedSymbolPatterns();
+  if (!AllowedPatterns) {
+    llvm::errs() << "Failed to open Allowed file " << AllowedFile << ". "
+                 << AllowedPatterns.getError().message() << "\n";
     return 1;
   }
   change_namespace::ChangeNamespaceTool NamespaceTool(
-      OldNamespace, NewNamespace, FilePattern, *WhiteListPatterns,
+      OldNamespace, NewNamespace, FilePattern, *AllowedPatterns,
       &Tool.getReplacements(), Style);
   ast_matchers::MatchFinder Finder;
   NamespaceTool.registerMatchers(&Finder);

diff  --git a/clang-tools-extra/test/clang-change-namespace/white-list.cpp b/clang-tools-extra/test/clang-change-namespace/allow-list.cpp
similarity index 68%
rename from clang-tools-extra/test/clang-change-namespace/white-list.cpp
rename to clang-tools-extra/test/clang-change-namespace/allow-list.cpp
index 48e3a78a0e05..07abd8b247d1 100644
--- a/clang-tools-extra/test/clang-change-namespace/white-list.cpp
+++ b/clang-tools-extra/test/clang-change-namespace/allow-list.cpp
@@ -1,5 +1,5 @@
-// RUN: echo "^std::.*$" > %T/white-list.txt
-// RUN: clang-change-namespace -old_namespace "na::nb" -new_namespace "x::y" --file_pattern ".*" --whitelist_file %T/white-list.txt %s -- | sed 's,// CHECK.*,,' | FileCheck %s
+// RUN: echo "^std::.*$" > %T/allowed-list.txt
+// RUN: clang-change-namespace -old_namespace "na::nb" -new_namespace "x::y" --file_pattern ".*" --allowed_file %T/white-list.txt %s -- | sed 's,// CHECK.*,,' | FileCheck %s
 
 #include "Inputs/fake-std.h"
 

diff  --git a/clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp b/clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp
index d66fede29450..a8fbf3b7fe25 100644
--- a/clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp
+++ b/clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp
@@ -38,7 +38,7 @@ class ChangeNamespaceTest : public ::testing::Test {
     std::map<std::string, tooling::Replacements> FileToReplacements;
     change_namespace::ChangeNamespaceTool NamespaceTool(
         OldNamespace, NewNamespace, FilePattern,
-        /*WhiteListedSymbolPatterns*/ {}, &FileToReplacements);
+        /*AllowedSymbolPatterns*/ {}, &FileToReplacements);
     ast_matchers::MatchFinder Finder;
     NamespaceTool.registerMatchers(&Finder);
     std::unique_ptr<tooling::FrontendActionFactory> Factory =


        


More information about the cfe-commits mailing list