[clang-tools-extra] r283553 - Revert "[clang-move] Support moving multiple classes in one run."

Renato Golin via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 7 06:58:11 PDT 2016


Author: rengolin
Date: Fri Oct  7 08:58:10 2016
New Revision: 283553

URL: http://llvm.org/viewvc/llvm-project?rev=283553&view=rev
Log:
Revert "[clang-move] Support moving multiple classes in one run."

This reverts commit r283526 et al as it keeps randomly breaking bots, even after
the commit has gone, on other people's commit ranges.

Revert "[clang-move] Simplify lint tests" (r283545).
Revert "Fix buildbot error." (r283534).
Revert "Revert "fix buildbot error" since it is not right fix." (r283538).

Added:
    clang-tools-extra/trunk/test/clang-move/Inputs/database_template.json
Removed:
    clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.cpp
    clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.h
    clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp
Modified:
    clang-tools-extra/trunk/clang-move/ClangMove.cpp
    clang-tools-extra/trunk/clang-move/ClangMove.h
    clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
    clang-tools-extra/trunk/test/clang-move/move-class.cpp
    clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=283553&r1=283552&r2=283553&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Fri Oct  7 08:58:10 2016
@@ -287,43 +287,31 @@ ClangMoveTool::ClangMoveTool(
     : Spec(MoveSpec), FileToReplacements(FileToReplacements),
       OriginalRunningDirectory(OriginalRunningDirectory),
       FallbackStyle(FallbackStyle) {
+  Spec.Name = llvm::StringRef(Spec.Name).ltrim(':');
   if (!Spec.NewHeader.empty())
     CCIncludes.push_back("#include \"" + Spec.NewHeader + "\"\n");
 }
 
 void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
-  SmallVector<StringRef, 4> ClassNames;
-  llvm::StringRef(Spec.Names).split(ClassNames, ',');
-  Optional<ast_matchers::internal::Matcher<NamedDecl>> InMovedClassNames;
-  for (StringRef ClassName : ClassNames) {
-    llvm::StringRef GlobalClassName = ClassName.trim().ltrim(':');
-    const auto HasName = hasName(("::" + GlobalClassName).str());
-    InMovedClassNames =
-        InMovedClassNames ? anyOf(*InMovedClassNames, HasName) : HasName;
-  }
-  if (!InMovedClassNames) {
-    llvm::errs() << "No classes being moved.\n";
-    return;
-  }
-
+  std::string FullyQualifiedName = "::" + Spec.Name;
   auto InOldHeader = isExpansionInFile(
       MakeAbsolutePath(OriginalRunningDirectory, Spec.OldHeader));
   auto InOldCC = isExpansionInFile(
       MakeAbsolutePath(OriginalRunningDirectory, Spec.OldCC));
   auto InOldFiles = anyOf(InOldHeader, InOldCC);
   auto InMovedClass =
-      hasDeclContext(cxxRecordDecl(*InMovedClassNames));
+      hasDeclContext(cxxRecordDecl(hasName(FullyQualifiedName)));
 
   // Match moved class declarations.
   auto MovedClass = cxxRecordDecl(
-      InOldFiles, *InMovedClassNames, isDefinition(),
+      InOldFiles, hasName(FullyQualifiedName), isDefinition(),
       hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl())));
   Finder->addMatcher(MovedClass.bind("moved_class"), this);
 
   // Match moved class methods (static methods included) which are defined
   // outside moved class declaration.
   Finder->addMatcher(cxxMethodDecl(InOldFiles,
-                                   ofClass(*InMovedClassNames),
+                                   ofClass(hasName(FullyQualifiedName)),
                                    isDefinition())
                          .bind("class_method"),
                      this);

Modified: clang-tools-extra/trunk/clang-move/ClangMove.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.h?rev=283553&r1=283552&r2=283553&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-move/ClangMove.h (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.h Fri Oct  7 08:58:10 2016
@@ -37,9 +37,8 @@ public:
   };
 
   struct MoveDefinitionSpec {
-    // A comma-separated list of fully qualified names, e.g. "Foo",
-    // "a::Foo, b::Foo".
-    std::string Names;
+    // A fully qualified name, e.g. "X", "a::X".
+    std::string Name;
     // The file path of old header, can be relative path and absolute path.
     std::string OldHeader;
     // The file path of old cc, can be relative path and absolute path.

Modified: clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp?rev=283553&r1=283552&r2=283553&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp (original)
+++ clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp Fri Oct  7 08:58:10 2016
@@ -37,10 +37,8 @@ std::error_code CreateNewFile(const llvm
 
 cl::OptionCategory ClangMoveCategory("clang-move options");
 
-cl::opt<std::string>
-    Names("names", cl::desc("A comma-separated list of the names of classes "
-                            "being moved, e.g. \"Foo\", \"a::Foo, b::Foo\"."),
-          cl::cat(ClangMoveCategory));
+cl::opt<std::string> Name("name", cl::desc("The name of class being moved."),
+                          cl::cat(ClangMoveCategory));
 
 cl::opt<std::string>
     OldHeader("old_header",
@@ -88,7 +86,7 @@ int main(int argc, const char **argv) {
   tooling::RefactoringTool Tool(OptionsParser.getCompilations(),
                                 OptionsParser.getSourcePathList());
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = Names;
+  Spec.Name = Name;
   Spec.OldHeader = OldHeader;
   Spec.NewHeader = NewHeader;
   Spec.OldCC = OldCC;

Added: clang-tools-extra/trunk/test/clang-move/Inputs/database_template.json
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/Inputs/database_template.json?rev=283553&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-move/Inputs/database_template.json (added)
+++ clang-tools-extra/trunk/test/clang-move/Inputs/database_template.json Fri Oct  7 08:58:10 2016
@@ -0,0 +1,7 @@
+[
+{
+  "directory": "$test_dir/build",
+  "command": "clang++ -o test.o $test_dir/test.cpp",
+  "file": "$test_dir/test.cpp"
+}
+]

Removed: clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.cpp?rev=283552&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.cpp (original)
+++ clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.cpp (removed)
@@ -1,27 +0,0 @@
-#include "multiple_class_test.h"
-
-namespace a {
-int Move1::f() {
-  return 0;
-}
-} // namespace a
-
-namespace b {
-int Move2::f() {
-  return 0;
-}
-} // namespace b
-
-namespace c {
-int Move3::f() {
-  return 0;
-}
-
-int Move4::f() {
-  return 0;
-}
-
-int NoMove::f() {
-  return 0;
-}
-} // namespace c

Removed: clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.h?rev=283552&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.h (original)
+++ clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.h (removed)
@@ -1,30 +0,0 @@
-namespace a {
-class Move1 {
-public:
-  int f();
-};
-} // namespace a
-
-namespace b {
-class Move2 {
-public:
-  int f();
-};
-} // namespace b
-
-namespace c {
-class Move3 {
-public:
-  int f();
-};
-
-class Move4 {
-public:
-  int f();
-};
-
-class NoMove {
-public:
-  int f();
-};
-} // namespace c

Modified: clang-tools-extra/trunk/test/clang-move/move-class.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/move-class.cpp?rev=283553&r1=283552&r2=283553&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-move/move-class.cpp (original)
+++ clang-tools-extra/trunk/test/clang-move/move-class.cpp Fri Oct  7 08:58:10 2016
@@ -1,8 +1,9 @@
-// RUN: mkdir -p %T/clang-move
+// RUN: mkdir -p %T/clang-move/build
+// RUN: sed 's|$test_dir|%/T/clang-move|g' %S/Inputs/database_template.json > %T/clang-move/compile_commands.json
 // RUN: cp %S/Inputs/test*  %T/clang-move/
 // RUN: touch %T/clang-move/test2.h
 // RUN: cd %T/clang-move
-// RUN: clang-move -names="a::Foo" -new_cc=%T/clang-move/new_test.cpp -new_header=%T/clang-move/new_test.h -old_cc=../clang-move/test.cpp -old_header=../clang-move/test.h %T/clang-move/test.cpp --
+// RUN: clang-move -name="a::Foo" -new_cc=%T/clang-move/new_test.cpp -new_header=%T/clang-move/new_test.h -old_cc=../clang-move/test.cpp -old_header=../clang-move/test.h %T/clang-move/test.cpp
 // RUN: FileCheck -input-file=%T/clang-move/new_test.cpp -check-prefix=CHECK-NEW-TEST-CPP %s
 // RUN: FileCheck -input-file=%T/clang-move/new_test.h -check-prefix=CHECK-NEW-TEST-H %s
 // RUN: FileCheck -input-file=%T/clang-move/test.cpp -check-prefix=CHECK-OLD-TEST-CPP %s
@@ -10,7 +11,7 @@
 //
 // RUN: cp %S/Inputs/test*  %T/clang-move/
 // RUN: cd %T/clang-move
-// RUN: clang-move -names="a::Foo" -new_cc=%T/clang-move/new_test.cpp -new_header=%T/clang-move/new_test.h -old_cc=%T/clang-move/test.cpp -old_header=%T/clang-move/test.h %T/clang-move/test.cpp --
+// RUN: clang-move -name="a::Foo" -new_cc=%T/clang-move/new_test.cpp -new_header=%T/clang-move/new_test.h -old_cc=%T/clang-move/test.cpp -old_header=%T/clang-move/test.h %T/clang-move/test.cpp
 // RUN: FileCheck -input-file=%T/clang-move/new_test.cpp -check-prefix=CHECK-NEW-TEST-CPP %s
 // RUN: FileCheck -input-file=%T/clang-move/new_test.h -check-prefix=CHECK-NEW-TEST-H %s
 // RUN: FileCheck -input-file=%T/clang-move/test.cpp -check-prefix=CHECK-OLD-TEST-CPP %s

Removed: clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp?rev=283552&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp (original)
+++ clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp (removed)
@@ -1,57 +0,0 @@
-// RUN: mkdir -p %T/clang-move
-// RUN: cp %S/Inputs/multiple_class_test*  %T/clang-move/
-// RUN: cd %T/clang-move
-// RUN: clang-move -names="a::Move1, b::Move2,c::Move3,c::Move4" -new_cc=%T/clang-move/new_multiple_class_test.cpp -new_header=%T/clang-move/new_multiple_class_test.h -old_cc=%T/clang-move/multiple_class_test.cpp -old_header=../clang-move/multiple_class_test.h %T/clang-move/multiple_class_test.cpp --
-// RUN: FileCheck -input-file=%T/clang-move/new_multiple_class_test.cpp -check-prefix=CHECK-NEW-TEST-CPP %s
-// RUN: FileCheck -input-file=%T/clang-move/new_multiple_class_test.h -check-prefix=CHECK-NEW-TEST-H %s
-// RUN: FileCheck -input-file=%T/clang-move/multiple_class_test.cpp -check-prefix=CHECK-OLD-TEST-CPP %s
-// RUN: FileCheck -input-file=%T/clang-move/multiple_class_test.h -check-prefix=CHECK-OLD-TEST-H %s
-//
-// CHECK-OLD-TEST-H: namespace c {
-// CHECK-OLD-TEST-H: class NoMove {
-// CHECK-OLD-TEST-H: public:
-// CHECK-OLD-TEST-H:   int f();
-// CHECK-OLD-TEST-H: };
-// CHECK-OLD-TEST-H: } // namespace c
-
-// CHECK-OLD-TEST-CPP: #include "{{.*}}multiple_class_test.h"
-// CHECK-OLD-TEST-CPP: namespace c {
-// CHECK-OLD-TEST-CPP: int NoMove::f() {
-// CHECK-OLD-TEST-CPP:   return 0;
-// CHECK-OLD-TEST-CPP: }
-// CHECK-OLD-TEST-CPP: } // namespace c
-
-// CHECK-NEW-TEST-H: namespace a {
-// CHECK-NEW-TEST-H: class Move1 {
-// CHECK-NEW-TEST-H: public:
-// CHECK-NEW-TEST-H:   int f();
-// CHECK-NEW-TEST-H: };
-// CHECK-NEW-TEST-H: } // namespace a
-// CHECK-NEW-TEST-H: namespace b {
-// CHECK-NEW-TEST-H: class Move2 {
-// CHECK-NEW-TEST-H: public:
-// CHECK-NEW-TEST-H:   int f();
-// CHECK-NEW-TEST-H: };
-// CHECK-NEW-TEST-H: } // namespace b
-// CHECK-NEW-TEST-H: namespace c {
-// CHECK-NEW-TEST-H: class Move3 {
-// CHECK-NEW-TEST-H: public:
-// CHECK-NEW-TEST-H:   int f();
-// CHECK-NEW-TEST-H: };
-// CHECK-NEW-TEST-H: class Move4 {
-// CHECK-NEW-TEST-H: public:
-// CHECK-NEW-TEST-H:   int f();
-// CHECK-NEW-TEST-H: };
-// CHECK-NEW-TEST-H: } // namespace c
-
-// CHECK-NEW-TEST-CPP: #include "{{.*}}new_multiple_class_test.h"
-// CHECK-NEW-TEST-CPP: namespace a {
-// CHECK-NEW-TEST-CPP: int Move1::f() { return 0; }
-// CHECK-NEW-TEST-CPP: } // namespace a
-// CHECK-NEW-TEST-CPP: namespace b {
-// CHECK-NEW-TEST-CPP: int Move2::f() { return 0; }
-// CHECK-NEW-TEST-CPP: } // namespace b
-// CHECK-NEW-TEST-CPP: namespace c {
-// CHECK-NEW-TEST-CPP: int Move3::f() { return 0; }
-// CHECK-NEW-TEST-CPP: int Move4::f() { return 0; }
-// CHECK-NEW-TEST-CPP: } // namespace c

Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=283553&r1=283552&r2=283553&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Fri Oct  7 08:58:10 2016
@@ -210,7 +210,7 @@ runClangMoveOnCode(const move::ClangMove
 
 TEST(ClangMove, MoveHeaderAndCC) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = "a::b::Foo";
+  Spec.Name = "a::b::Foo";
   Spec.OldHeader = "foo.h";
   Spec.OldCC = "foo.cc";
   Spec.NewHeader = "new_foo.h";
@@ -225,7 +225,7 @@ TEST(ClangMove, MoveHeaderAndCC) {
 
 TEST(ClangMove, MoveHeaderOnly) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = "a::b::Foo";
+  Spec.Name = "a::b::Foo";
   Spec.OldHeader = "foo.h";
   Spec.NewHeader = "new_foo.h";
   auto Results = runClangMoveOnCode(Spec);
@@ -236,7 +236,7 @@ TEST(ClangMove, MoveHeaderOnly) {
 
 TEST(ClangMove, MoveCCOnly) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = "a::b::Foo";
+  Spec.Name = "a::b::Foo";
   Spec.OldCC = "foo.cc";
   Spec.NewCC = "new_foo.cc";
   std::string ExpectedHeader = "#include \"foo.h\"\n\n";
@@ -248,7 +248,7 @@ TEST(ClangMove, MoveCCOnly) {
 
 TEST(ClangMove, MoveNonExistClass) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = "NonExistFoo";
+  Spec.Name = "NonExistFoo";
   Spec.OldHeader = "foo.h";
   Spec.OldCC = "foo.cc";
   Spec.NewHeader = "new_foo.h";




More information about the cfe-commits mailing list