@@ -73,6 +73,25 @@ cl::opt<std::string> Style("style",
73
73
cl::desc (" The style name used for reformatting." ),
74
74
cl::init(" LLVM" ), cl::cat(ChangeNamespaceCategory));
75
75
76
+ cl::opt<std::string> WhiteListFile (
77
+ " whitelist_file" ,
78
+ cl::desc (" A file containing regexes of symbol names that are not expected "
79
+ " to be updated when changing namespaces around them." ),
80
+ cl::init(" " ), cl::cat(ChangeNamespaceCategory));
81
+
82
+ llvm::ErrorOr<std::vector<std::string>> GetWhiteListedSymbolPatterns () {
83
+ llvm::SmallVector<StringRef, 8 > Lines;
84
+ if (!WhiteListFile.empty ()) {
85
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
86
+ llvm::MemoryBuffer::getFile (WhiteListFile);
87
+ if (!File)
88
+ return File.getError ();
89
+ llvm::StringRef Content = File.get ()->getBuffer ();
90
+ Content.split (Lines, ' \n ' , /* MaxSplit=*/ -1 , /* KeepEmpty=*/ false );
91
+ }
92
+ return std::vector<std::string>(Lines.begin (), Lines.end ());
93
+ }
94
+
76
95
} // anonymous namespace
77
96
78
97
int main (int argc, const char **argv) {
@@ -81,8 +100,16 @@ int main(int argc, const char **argv) {
81
100
ChangeNamespaceCategory);
82
101
const auto &Files = OptionsParser.getSourcePathList ();
83
102
tooling::RefactoringTool Tool (OptionsParser.getCompilations (), Files);
103
+ llvm::ErrorOr<std::vector<std::string>> WhiteListPatterns =
104
+ GetWhiteListedSymbolPatterns ();
105
+ if (!WhiteListPatterns) {
106
+ llvm::errs () << " Failed to open whitelist file " << WhiteListFile << " . "
107
+ << WhiteListPatterns.getError ().message () << " \n " ;
108
+ return 1 ;
109
+ }
84
110
change_namespace::ChangeNamespaceTool NamespaceTool (
85
- OldNamespace, NewNamespace, FilePattern, &Tool.getReplacements (), Style );
111
+ OldNamespace, NewNamespace, FilePattern, *WhiteListPatterns,
112
+ &Tool.getReplacements (), Style );
86
113
ast_matchers::MatchFinder Finder;
87
114
NamespaceTool.registerMatchers (&Finder);
88
115
std::unique_ptr<tooling::FrontendActionFactory> Factory =
0 commit comments