[clang-change-namespace] As part of using inclusive language
within the llvm project, migrate away from the use of blacklist and whitelist.
This commit is contained in:
parent
8027f04a6d
commit
25ed42f05d
|
@ -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 =
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
// 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 @@ private:
|
|||
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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
|
|
@ -38,7 +38,7 @@ public:
|
|||
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 =
|
||||
|
|
Loading…
Reference in a new issue