<div dir="ltr">Hello Eric,<br><br>This commit broke test on one of our builders:<br><br>    Clang Tools :: change-namespace/white-list.cpp<br><br><a href="http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/6153/steps/test/logs/stdio">http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/6153/steps/test/logs/stdio</a><br><br>Please have a look.<br><br>Thanks<br><br>Galina<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 24, 2017 at 3:54 AM, Eric Liu via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ioeric<br>
Date: Fri Feb 24 05:54:45 2017<br>
New Revision: 296110<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=296110&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=296110&view=rev</a><br>
Log:<br>
[change-namepsace] make it possible to whitelist symbols so they don't get updated.<br>
<br>
Reviewers: hokein<br>
<br>
Reviewed By: hokein<br>
<br>
Subscribers: cfe-commits<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D30328" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D30328</a><br>
<br>
Added:<br>
    clang-tools-extra/trunk/test/<wbr>change-namespace/Inputs/<br>
    clang-tools-extra/trunk/test/<wbr>change-namespace/Inputs/fake-<wbr>std.h<br>
    clang-tools-extra/trunk/test/<wbr>change-namespace/white-list.<wbr>cpp<br>
Modified:<br>
    clang-tools-extra/trunk/<wbr>change-namespace/<wbr>ChangeNamespace.cpp<br>
    clang-tools-extra/trunk/<wbr>change-namespace/<wbr>ChangeNamespace.h<br>
    clang-tools-extra/trunk/<wbr>change-namespace/tool/<wbr>ClangChangeNamespace.cpp<br>
    clang-tools-extra/trunk/<wbr>unittests/change-namespace/<wbr>ChangeNamespaceTests.cpp<br>
<br>
Modified: clang-tools-extra/trunk/<wbr>change-namespace/<wbr>ChangeNamespace.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=296110&r1=296109&r2=296110&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/change-namespace/<wbr>ChangeNamespace.cpp?rev=<wbr>296110&r1=296109&r2=296110&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/<wbr>change-namespace/<wbr>ChangeNamespace.cpp (original)<br>
+++ clang-tools-extra/trunk/<wbr>change-namespace/<wbr>ChangeNamespace.cpp Fri Feb 24 05:54:45 2017<br>
@@ -290,6 +290,7 @@ AST_MATCHER(EnumDecl, isScoped) {<br>
<br>
 ChangeNamespaceTool::<wbr>ChangeNamespaceTool(<br>
     llvm::StringRef OldNs, llvm::StringRef NewNs, llvm::StringRef FilePattern,<br>
+    llvm::ArrayRef<std::string> WhiteListedSymbolPatterns,<br>
     std::map<std::string, tooling::Replacements> *FileToReplacements,<br>
     llvm::StringRef FallbackStyle)<br>
     : FallbackStyle(FallbackStyle), FileToReplacements(*<wbr>FileToReplacements),<br>
@@ -308,6 +309,9 @@ ChangeNamespaceTool::<wbr>ChangeNamespaceTool<br>
   }<br>
   DiffOldNamespace = joinNamespaces(OldNsSplitted);<br>
   DiffNewNamespace = joinNamespaces(NewNsSplitted);<br>
+<br>
+  for (const auto &Pattern : WhiteListedSymbolPatterns)<br>
+    WhiteListedSymbolRegexes.<wbr>emplace_back(Pattern);<br>
 }<br>
<br>
 void ChangeNamespaceTool::<wbr>registerMatchers(ast_matchers:<wbr>:MatchFinder *Finder) {<br>
@@ -736,6 +740,9 @@ void ChangeNamespaceTool::<wbr>replaceQualifi<br>
           Result.SourceManager-><wbr>getSpellingLoc(End)),<br>
       *Result.SourceManager, Result.Context->getLangOpts())<wbr>;<br>
   std::string FromDeclName = FromDecl-><wbr>getQualifiedNameAsString();<br>
+  for (llvm::Regex &RE : WhiteListedSymbolRegexes)<br>
+    if (RE.match(FromDeclName))<br>
+      return;<br>
   std::string ReplaceName =<br>
       getShortestQualifiedNameInName<wbr>space(FromDeclName, NewNs);<br>
   // Checks if there is any using namespace declarations that can shorten the<br>
<br>
Modified: clang-tools-extra/trunk/<wbr>change-namespace/<wbr>ChangeNamespace.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.h?rev=296110&r1=296109&r2=296110&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/change-namespace/<wbr>ChangeNamespace.h?rev=296110&<wbr>r1=296109&r2=296110&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/<wbr>change-namespace/<wbr>ChangeNamespace.h (original)<br>
+++ clang-tools-extra/trunk/<wbr>change-namespace/<wbr>ChangeNamespace.h Fri Feb 24 05:54:45 2017<br>
@@ -50,6 +50,7 @@ public:<br>
   // files matching `FilePattern`.<br>
   ChangeNamespaceTool(<br>
       llvm::StringRef OldNs, llvm::StringRef NewNs, llvm::StringRef FilePattern,<br>
+      llvm::ArrayRef<std::string> WhiteListedSymbolPatterns,<br>
       std::map<std::string, tooling::Replacements> *FileToReplacements,<br>
       llvm::StringRef FallbackStyle = "LLVM");<br>
<br>
@@ -164,6 +165,9 @@ private:<br>
   // CallExpr and one as DeclRefExpr), we record all DeclRefExpr's that have<br>
   // been processed so that we don't handle them twice.<br>
   llvm::SmallPtrSet<const clang::DeclRefExpr*, 16> ProcessedFuncRefs;<br>
+  // Patterns of symbol names whose references are not expected to be updated<br>
+  // when changing namespaces around them.<br>
+  std::vector<llvm::Regex> WhiteListedSymbolRegexes;<br>
 };<br>
<br>
 } // namespace change_namespace<br>
<br>
Modified: clang-tools-extra/trunk/<wbr>change-namespace/tool/<wbr>ClangChangeNamespace.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/tool/ClangChangeNamespace.cpp?rev=296110&r1=296109&r2=296110&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/change-namespace/tool/<wbr>ClangChangeNamespace.cpp?rev=<wbr>296110&r1=296109&r2=296110&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/<wbr>change-namespace/tool/<wbr>ClangChangeNamespace.cpp (original)<br>
+++ clang-tools-extra/trunk/<wbr>change-namespace/tool/<wbr>ClangChangeNamespace.cpp Fri Feb 24 05:54:45 2017<br>
@@ -73,6 +73,25 @@ cl::opt<std::string> Style("style",<br>
                            cl::desc("The style name used for reformatting."),<br>
                            cl::init("LLVM"), cl::cat(<wbr>ChangeNamespaceCategory));<br>
<br>
+cl::opt<std::string> WhiteListFile(<br>
+    "whitelist_file",<br>
+    cl::desc("A file containing regexes of symbol names that are not expected "<br>
+             "to be updated when changing namespaces around them."),<br>
+    cl::init(""), cl::cat(<wbr>ChangeNamespaceCategory));<br>
+<br>
+llvm::ErrorOr<std::vector<<wbr>std::string>> GetWhiteListedSymbolPatterns() {<br>
+  llvm::SmallVector<StringRef, 8> Lines;<br>
+  if (!WhiteListFile.empty()) {<br>
+    llvm::ErrorOr<std::unique_ptr<<wbr>llvm::MemoryBuffer>> File =<br>
+        llvm::MemoryBuffer::getFile(<wbr>WhiteListFile);<br>
+    if (!File)<br>
+      return File.getError();<br>
+    llvm::StringRef Content = File.get()->getBuffer();<br>
+    Content.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);<br>
+  }<br>
+  return std::vector<std::string>(<wbr>Lines.begin(), Lines.end());<br>
+}<br>
+<br>
 } // anonymous namespace<br>
<br>
 int main(int argc, const char **argv) {<br>
@@ -81,8 +100,16 @@ int main(int argc, const char **argv) {<br>
                                              ChangeNamespaceCategory);<br>
   const auto &Files = OptionsParser.<wbr>getSourcePathList();<br>
   tooling::RefactoringTool Tool(OptionsParser.<wbr>getCompilations(), Files);<br>
+  llvm::ErrorOr<std::vector<std:<wbr>:string>> WhiteListPatterns =<br>
+      GetWhiteListedSymbolPatterns()<wbr>;<br>
+  if (!WhiteListPatterns) {<br>
+    llvm::errs() << "Failed to open whitelist file " << WhiteListFile << ". "<br>
+                 << WhiteListPatterns.getError().<wbr>message() << "\n";<br>
+    return 1;<br>
+  }<br>
   change_namespace::<wbr>ChangeNamespaceTool NamespaceTool(<br>
-      OldNamespace, NewNamespace, FilePattern, &Tool.getReplacements(), Style);<br>
+      OldNamespace, NewNamespace, FilePattern, *WhiteListPatterns,<br>
+      &Tool.getReplacements(), Style);<br>
   ast_matchers::MatchFinder Finder;<br>
   NamespaceTool.<wbr>registerMatchers(&Finder);<br>
   std::unique_ptr<tooling::<wbr>FrontendActionFactory> Factory =<br>
<br>
Added: clang-tools-extra/trunk/test/<wbr>change-namespace/Inputs/fake-<wbr>std.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/change-namespace/Inputs/fake-std.h?rev=296110&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/test/change-namespace/<wbr>Inputs/fake-std.h?rev=296110&<wbr>view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/test/<wbr>change-namespace/Inputs/fake-<wbr>std.h (added)<br>
+++ clang-tools-extra/trunk/test/<wbr>change-namespace/Inputs/fake-<wbr>std.h Fri Feb 24 05:54:45 2017<br>
@@ -0,0 +1,5 @@<br>
+namespace std {<br>
+  class STD {};<br>
+}<br>
+<br>
+using namespace std;<br>
<br>
Added: clang-tools-extra/trunk/test/<wbr>change-namespace/white-list.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/change-namespace/white-list.cpp?rev=296110&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/test/change-namespace/<wbr>white-list.cpp?rev=296110&<wbr>view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/test/<wbr>change-namespace/white-list.<wbr>cpp (added)<br>
+++ clang-tools-extra/trunk/test/<wbr>change-namespace/white-list.<wbr>cpp Fri Feb 24 05:54:45 2017<br>
@@ -0,0 +1,19 @@<br>
+// RUN: echo "^std::.*$" > %T/white-list.txt<br>
+// 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<br>
+<br>
+#include "Inputs/fake-std.h"<br>
+<br>
+// CHECK: namespace x {<br>
+// CHECK-NEXT: namespace y {<br>
+namespace na {<br>
+namespace nb {<br>
+void f() {<br>
+  std::STD x1;<br>
+  STD x2;<br>
+// CHECK: {{^}}  std::STD x1;{{$}}<br>
+// CHECK-NEXT: {{^}}  STD x2;{{$}}<br>
+}<br>
+// CHECK: } // namespace y<br>
+// CHECK-NEXT: } // namespace x<br>
+}<br>
+}<br>
<br>
Modified: clang-tools-extra/trunk/<wbr>unittests/change-namespace/<wbr>ChangeNamespaceTests.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp?rev=296110&r1=296109&r2=296110&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/unittests/change-<wbr>namespace/<wbr>ChangeNamespaceTests.cpp?rev=<wbr>296110&r1=296109&r2=296110&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/<wbr>unittests/change-namespace/<wbr>ChangeNamespaceTests.cpp (original)<br>
+++ clang-tools-extra/trunk/<wbr>unittests/change-namespace/<wbr>ChangeNamespaceTests.cpp Fri Feb 24 05:54:45 2017<br>
@@ -38,7 +38,8 @@ public:<br>
<br>
     std::map<std::string, tooling::Replacements> FileToReplacements;<br>
     change_namespace::<wbr>ChangeNamespaceTool NamespaceTool(<br>
-        OldNamespace, NewNamespace, FilePattern, &FileToReplacements);<br>
+        OldNamespace, NewNamespace, FilePattern,<br>
+        /*WhiteListedSymbolPatterns*/ {}, &FileToReplacements);<br>
     ast_matchers::MatchFinder Finder;<br>
     NamespaceTool.<wbr>registerMatchers(&Finder);<br>
     std::unique_ptr<tooling::<wbr>FrontendActionFactory> Factory =<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>