Skip to content

Commit 25ed42f

Browse files
committed
[clang-change-namespace] As part of using inclusive language
within the llvm project, migrate away from the use of blacklist and whitelist.
1 parent 8027f04 commit 25ed42f

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ bool isTemplateParameter(TypeLoc Type) {
347347

348348
ChangeNamespaceTool::ChangeNamespaceTool(
349349
llvm::StringRef OldNs, llvm::StringRef NewNs, llvm::StringRef FilePattern,
350-
llvm::ArrayRef<std::string> WhiteListedSymbolPatterns,
350+
llvm::ArrayRef<std::string> AllowedSymbolPatterns,
351351
std::map<std::string, tooling::Replacements> *FileToReplacements,
352352
llvm::StringRef FallbackStyle)
353353
: FallbackStyle(FallbackStyle), FileToReplacements(*FileToReplacements),
@@ -365,8 +365,8 @@ ChangeNamespaceTool::ChangeNamespaceTool(
365365
DiffOldNamespace = joinNamespaces(OldNsSplitted);
366366
DiffNewNamespace = joinNamespaces(NewNsSplitted);
367367

368-
for (const auto &Pattern : WhiteListedSymbolPatterns)
369-
WhiteListedSymbolRegexes.emplace_back(Pattern);
368+
for (const auto &Pattern : AllowedSymbolPatterns)
369+
AllowedSymbolRegexes.emplace_back(Pattern);
370370
}
371371

372372
void ChangeNamespaceTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
@@ -800,7 +800,7 @@ void ChangeNamespaceTool::replaceQualifiedSymbolInDeclContext(
800800
Result.SourceManager->getSpellingLoc(End)),
801801
*Result.SourceManager, Result.Context->getLangOpts());
802802
std::string FromDeclName = FromDecl->getQualifiedNameAsString();
803-
for (llvm::Regex &RE : WhiteListedSymbolRegexes)
803+
for (llvm::Regex &RE : AllowedSymbolRegexes)
804804
if (RE.match(FromDeclName))
805805
return;
806806
std::string ReplaceName =

clang-tools-extra/clang-change-namespace/ChangeNamespace.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ChangeNamespaceTool : public ast_matchers::MatchFinder::MatchCallback {
4949
// files matching `FilePattern`.
5050
ChangeNamespaceTool(
5151
llvm::StringRef OldNs, llvm::StringRef NewNs, llvm::StringRef FilePattern,
52-
llvm::ArrayRef<std::string> WhiteListedSymbolPatterns,
52+
llvm::ArrayRef<std::string> AllowedSymbolPatterns,
5353
std::map<std::string, tooling::Replacements> *FileToReplacements,
5454
llvm::StringRef FallbackStyle = "LLVM");
5555

@@ -166,7 +166,7 @@ class ChangeNamespaceTool : public ast_matchers::MatchFinder::MatchCallback {
166166
llvm::SmallPtrSet<const clang::DeclRefExpr*, 16> ProcessedFuncRefs;
167167
// Patterns of symbol names whose references are not expected to be updated
168168
// when changing namespaces around them.
169-
std::vector<llvm::Regex> WhiteListedSymbolRegexes;
169+
std::vector<llvm::Regex> AllowedSymbolRegexes;
170170
};
171171

172172
} // namespace change_namespace

clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ cl::opt<std::string> Style("style",
7272
cl::desc("The style name used for reformatting."),
7373
cl::init("LLVM"), cl::cat(ChangeNamespaceCategory));
7474

75-
cl::opt<std::string> WhiteListFile(
76-
"whitelist_file",
75+
cl::opt<std::string> AllowedFile(
76+
"allowed_file",
7777
cl::desc("A file containing regexes of symbol names that are not expected "
7878
"to be updated when changing namespaces around them."),
7979
cl::init(""), cl::cat(ChangeNamespaceCategory));
8080

81-
llvm::ErrorOr<std::vector<std::string>> GetWhiteListedSymbolPatterns() {
81+
llvm::ErrorOr<std::vector<std::string>> GetAllowedSymbolPatterns() {
8282
std::vector<std::string> Patterns;
83-
if (WhiteListFile.empty())
83+
if (AllowedFile.empty())
8484
return Patterns;
8585

8686
llvm::SmallVector<StringRef, 8> Lines;
8787
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
88-
llvm::MemoryBuffer::getFile(WhiteListFile);
88+
llvm::MemoryBuffer::getFile(AllowedFile);
8989
if (!File)
9090
return File.getError();
9191
llvm::StringRef Content = File.get()->getBuffer();
@@ -103,15 +103,15 @@ int main(int argc, const char **argv) {
103103
ChangeNamespaceCategory);
104104
const auto &Files = OptionsParser.getSourcePathList();
105105
tooling::RefactoringTool Tool(OptionsParser.getCompilations(), Files);
106-
llvm::ErrorOr<std::vector<std::string>> WhiteListPatterns =
107-
GetWhiteListedSymbolPatterns();
108-
if (!WhiteListPatterns) {
109-
llvm::errs() << "Failed to open whitelist file " << WhiteListFile << ". "
110-
<< WhiteListPatterns.getError().message() << "\n";
106+
llvm::ErrorOr<std::vector<std::string>> AllowedPatterns =
107+
GetAllowedSymbolPatterns();
108+
if (!AllowedPatterns) {
109+
llvm::errs() << "Failed to open Allowed file " << AllowedFile << ". "
110+
<< AllowedPatterns.getError().message() << "\n";
111111
return 1;
112112
}
113113
change_namespace::ChangeNamespaceTool NamespaceTool(
114-
OldNamespace, NewNamespace, FilePattern, *WhiteListPatterns,
114+
OldNamespace, NewNamespace, FilePattern, *AllowedPatterns,
115115
&Tool.getReplacements(), Style);
116116
ast_matchers::MatchFinder Finder;
117117
NamespaceTool.registerMatchers(&Finder);

clang-tools-extra/test/clang-change-namespace/white-list.cpp renamed to clang-tools-extra/test/clang-change-namespace/allow-list.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: echo "^std::.*$" > %T/white-list.txt
2-
// 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
1+
// RUN: echo "^std::.*$" > %T/allowed-list.txt
2+
// 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
33

44
#include "Inputs/fake-std.h"
55

clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ChangeNamespaceTest : public ::testing::Test {
3838
std::map<std::string, tooling::Replacements> FileToReplacements;
3939
change_namespace::ChangeNamespaceTool NamespaceTool(
4040
OldNamespace, NewNamespace, FilePattern,
41-
/*WhiteListedSymbolPatterns*/ {}, &FileToReplacements);
41+
/*AllowedSymbolPatterns*/ {}, &FileToReplacements);
4242
ast_matchers::MatchFinder Finder;
4343
NamespaceTool.registerMatchers(&Finder);
4444
std::unique_ptr<tooling::FrontendActionFactory> Factory =

0 commit comments

Comments
 (0)