Index: clang-move/ClangMove.cpp =================================================================== --- clang-move/ClangMove.cpp +++ clang-move/ClangMove.cpp @@ -522,18 +522,6 @@ //============================================================================ // Matchers for old cc //============================================================================ - auto IsOldCCTopLevelDecl = allOf( - hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl()))), InOldCC); - // Matching using decls/type alias decls which are in named/anonymous/global - // namespace, these decls are always copied to new.h/cc. Those in classes, - // functions are covered in other matchers. - Finder->addMatcher(namedDecl(anyOf(usingDecl(IsOldCCTopLevelDecl), - usingDirectiveDecl(IsOldCCTopLevelDecl), - typeAliasDecl(IsOldCCTopLevelDecl)), - notInMacro()) - .bind("using_decl"), - this); - // Match static functions/variable definitions which are defined in named // namespaces. Optional> HasAnySymbolNames; @@ -587,6 +575,21 @@ //============================================================================ // Matchers for old files, including old.h/old.cc //============================================================================ + auto IsTopLevelDecl = + hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl()))); + // Find using declarations which are defined in named/anonymous/global + // namespace of old.h/old.cc. All theses decls are always copied to + // new.h/new.cc. Besides, type aliaes which defined in old.cc will be + // included as type alias in old.h are the movable types in clang-move. + Finder->addMatcher( + namedDecl(anyOf(usingDecl(IsTopLevelDecl), + usingDirectiveDecl(IsTopLevelDecl), + // filter out type aliases defined in old.h. + typeAliasDecl(IsTopLevelDecl, InOldCC)), + notInMacro()) + .bind("using_decl"), + this); + // Create a MatchCallback for class declarations. MatchCallbacks.push_back(llvm::make_unique(this)); // Match moved class declarations. Index: test/clang-move/Inputs/multiple_class_test.h =================================================================== --- test/clang-move/Inputs/multiple_class_test.h +++ test/clang-move/Inputs/multiple_class_test.h @@ -13,6 +13,8 @@ } // namespace b namespace c { +using a::Move1; +using namespace a; class Move3 { public: int f(); Index: test/clang-move/move-multiple-classes.cpp =================================================================== --- test/clang-move/move-multiple-classes.cpp +++ test/clang-move/move-multiple-classes.cpp @@ -11,94 +11,128 @@ // CHECK-EMPTY: [{{[[:space:]]*}}] // // 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-H-NEXT: using a::Move1; +// CHECK-OLD-TEST-H-NEXT: using namespace a; +// CHECK-OLD-TEST-H-SAME: {{[[:space:]]}} +// CHECK-OLD-TEST-H-NEXT: class NoMove { +// CHECK-OLD-TEST-H-NEXT: public: +// CHECK-OLD-TEST-H-NEXT: int f(); +// CHECK-OLD-TEST-H-NEXT: }; +// CHECK-OLD-TEST-H-NEXT: } // namespace c // CHECK-OLD-TEST-CPP: #include "{{.*}}multiple_class_test.h" -// CHECK-OLD-TEST-CPP: using a::Move1; -// CHECK-OLD-TEST-CPP: using namespace a; -// CHECK-OLD-TEST-CPP: using A = a::Move1; -// CHECK-OLD-TEST-CPP: static int g = 0; -// CHECK-OLD-TEST-CPP: namespace { -// CHECK-OLD-TEST-CPP: using a::Move1; -// CHECK-OLD-TEST-CPP: using namespace a; -// CHECK-OLD-TEST-CPP: } // namespace -// CHECK-OLD-TEST-CPP: namespace b { -// CHECK-OLD-TEST-CPP: using a::Move1; -// CHECK-OLD-TEST-CPP: using namespace a; -// CHECK-OLD-TEST-CPP: using T = a::Move1; -// CHECK-OLD-TEST-CPP: } // namespace b -// CHECK-OLD-TEST-CPP: namespace c { -// CHECK-OLD-TEST-CPP: int NoMove::f() { -// CHECK-OLD-TEST-CPP: static int F = 0; -// CHECK-OLD-TEST-CPP: return g; -// CHECK-OLD-TEST-CPP: } -// CHECK-OLD-TEST-CPP: } // namespace c +// CHECK-OLD-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-OLD-TEST-CPP-NEXT: using a::Move1; +// CHECK-OLD-TEST-CPP-NEXT: using namespace a; +// CHECK-OLD-TEST-CPP-NEXT: using A = a::Move1; +// CHECK-OLD-TEST-CPP-NEXT: static int g = 0; +// CHECK-OLD-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-OLD-TEST-CPP-NEXT: namespace { +// CHECK-OLD-TEST-CPP-NEXT: using a::Move1; +// CHECK-OLD-TEST-CPP-NEXT: using namespace a; +// CHECK-OLD-TEST-CPP-NEXT: } // namespace +// CHECK-OLD-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-OLD-TEST-CPP-NEXT: namespace b { +// CHECK-OLD-TEST-CPP-NEXT: using a::Move1; +// CHECK-OLD-TEST-CPP-NEXT: using namespace a; +// CHECK-OLD-TEST-CPP-NEXT: using T = a::Move1; +// CHECK-OLD-TEST-CPP-NEXT: } // namespace b +// CHECK-OLD-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-OLD-TEST-CPP-NEXT: namespace c { +// CHECK-OLD-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-OLD-TEST-CPP-NEXT: int NoMove::f() { +// CHECK-OLD-TEST-CPP-NEXT: static int F = 0; +// CHECK-OLD-TEST-CPP-NEXT: return g; +// CHECK-OLD-TEST-CPP-NEXT: } +// CHECK-OLD-TEST-CPP-NEXT: } // namespace c // CHECK-NEW-TEST-H: #ifndef {{.*}}NEW_MULTIPLE_CLASS_TEST_H -// CHECK-NEW-TEST-H: #define {{.*}}NEW_MULTIPLE_CLASS_TEST_H -// 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: class EnclosingMove5 { -// CHECK-NEW-TEST-H: public: -// CHECK-NEW-TEST-H: class Nested { -// CHECK-NEW-TEST-H: int f(); -// CHECK-NEW-TEST-H: static int b; -// CHECK-NEW-TEST-H: }; -// CHECK-NEW-TEST-H: static int a; -// CHECK-NEW-TEST-H: }; -// CHECK-NEW-TEST-H: } // namespace c +// CHECK-NEW-TEST-H-NEXT: #define {{.*}}NEW_MULTIPLE_CLASS_TEST_H +// CHECK-NEW-TEST-H-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-H-NEXT: namespace a { +// CHECK-NEW-TEST-H-NEXT: class Move1 { +// CHECK-NEW-TEST-H-NEXT: public: +// CHECK-NEW-TEST-H-NEXT: int f(); +// CHECK-NEW-TEST-H-NEXT: }; +// CHECK-NEW-TEST-H-NEXT: } // namespace a +// CHECK-NEW-TEST-H-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-H-NEXT: namespace b { +// CHECK-NEW-TEST-H-NEXT: class Move2 { +// CHECK-NEW-TEST-H-NEXT: public: +// CHECK-NEW-TEST-H-NEXT: int f(); +// CHECK-NEW-TEST-H-NEXT: }; +// CHECK-NEW-TEST-H-NEXT: } // namespace b +// CHECK-NEW-TEST-H-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-H-NEXT: namespace c { +// CHECK-NEW-TEST-H-NEXT: using a::Move1; +// CHECK-NEW-TEST-H-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-H-NEXT: using namespace a; +// CHECK-NEW-TEST-H-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-H-NEXT: class Move3 { +// CHECK-NEW-TEST-H-NEXT: public: +// CHECK-NEW-TEST-H-NEXT: int f(); +// CHECK-NEW-TEST-H-NEXT: }; +// CHECK-NEW-TEST-H-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-H-NEXT: class Move4 { +// CHECK-NEW-TEST-H-NEXT: public: +// CHECK-NEW-TEST-H-NEXT: int f(); +// CHECK-NEW-TEST-H-NEXT: }; +// CHECK-NEW-TEST-H-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-H-NEXT: class EnclosingMove5 { +// CHECK-NEW-TEST-H-NEXT: public: +// CHECK-NEW-TEST-H-NEXT: class Nested { +// CHECK-NEW-TEST-H-NEXT: int f(); +// CHECK-NEW-TEST-H-NEXT: static int b; +// CHECK-NEW-TEST-H-NEXT: }; +// CHECK-NEW-TEST-H-NEXT: static int a; +// CHECK-NEW-TEST-H-NEXT: }; +// CHECK-NEW-TEST-H-NEXT: } // namespace c +// CHECK-NEW-TEST-H-SAME: {{[[:space:]]}} // CHECK-NEW-TEST-H: #endif // {{.*}}NEW_MULTIPLE_CLASS_TEST_H // CHECK-NEW-TEST-CPP: #include "{{.*}}new_multiple_class_test.h" -// CHECK-NEW-TEST-CPP: using a::Move1; -// CHECK-NEW-TEST-CPP: using namespace a; -// CHECK-NEW-TEST-CPP: using A = a::Move1; -// CHECK-NEW-TEST-CPP: static int g = 0; -// 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 { -// CHECK-NEW-TEST-CPP: using a::Move1; -// CHECK-NEW-TEST-CPP: using namespace a; -// CHECK-NEW-TEST-CPP: static int k = 0; -// CHECK-NEW-TEST-CPP: } // namespace -// CHECK-NEW-TEST-CPP: namespace b { -// CHECK-NEW-TEST-CPP: using a::Move1; -// CHECK-NEW-TEST-CPP: using namespace a; -// CHECK-NEW-TEST-CPP: using T = a::Move1; -// 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() { -// CHECK-NEW-TEST-CPP: using a::Move1; -// CHECK-NEW-TEST-CPP: using namespace b; -// CHECK-NEW-TEST-CPP: return 0; -// CHECK-NEW-TEST-CPP: } -// CHECK-NEW-TEST-CPP: int Move4::f() { return k; } -// CHECK-NEW-TEST-CPP: int EnclosingMove5::a = 1; -// CHECK-NEW-TEST-CPP: int EnclosingMove5::Nested::f() { return g; } -// CHECK-NEW-TEST-CPP: int EnclosingMove5::Nested::b = 1; -// CHECK-NEW-TEST-CPP: } // namespace c +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: using a::Move1; +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: using namespace a; +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: using A = a::Move1; +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: static int g = 0; +// CHECK-NEW-TEST-CPP-NEXT: namespace a { +// CHECK-NEW-TEST-CPP-NEXT: int Move1::f() { return 0; } +// CHECK-NEW-TEST-CPP-NEXT: } // namespace a +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: namespace { +// CHECK-NEW-TEST-CPP-NEXT: using a::Move1; +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: using namespace a; +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: static int k = 0; +// CHECK-NEW-TEST-CPP-NEXT: } // namespace +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: namespace b { +// CHECK-NEW-TEST-CPP-NEXT: using a::Move1; +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: using namespace a; +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: using T = a::Move1; +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: int Move2::f() { return 0; } +// CHECK-NEW-TEST-CPP-NEXT: } // namespace b +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: namespace c { +// CHECK-NEW-TEST-CPP-NEXT: int Move3::f() { +// CHECK-NEW-TEST-CPP-NEXT: using a::Move1; +// CHECK-NEW-TEST-CPP-NEXT: using namespace b; +// CHECK-NEW-TEST-CPP-NEXT: return 0; +// CHECK-NEW-TEST-CPP-NEXT: } +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: int Move4::f() { return k; } +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: int EnclosingMove5::a = 1; +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: int EnclosingMove5::Nested::f() { return g; } +// CHECK-NEW-TEST-CPP-SAME: {{[[:space:]]}} +// CHECK-NEW-TEST-CPP-NEXT: int EnclosingMove5::Nested::b = 1; +// CHECK-NEW-TEST-CPP-NEXT: } // namespace c