hokein updated this revision to Diff 75139.
hokein marked 2 inline comments as done.
hokein added a comment.
Address comments.
- Cover type alias declarations.
- Fix an issue of moving function-scope static definitions in non-moved classes.
https://reviews.llvm.org/D25762
Files:
clang-move/ClangMove.cpp
test/clang-move/Inputs/multiple_class_test.cpp
test/clang-move/move-multiple-classes.cpp
Index: test/clang-move/move-multiple-classes.cpp
===================================================================
--- test/clang-move/move-multiple-classes.cpp
+++ test/clang-move/move-multiple-classes.cpp
@@ -18,8 +18,19 @@
// CHECK-OLD-TEST-H: } // namespace c
// CHECK-OLD-TEST-CPP: #include "{{.*}}multiple_class_test.h"
+// CHECK-OLD-TEST-CPP: namespace {
+// CHECK-OLD-TEST-CPP: using a::Move1;
+// CHECK-OLD-TEST-CPP: using namespace a;
+// CHECK-OLD-TEST-CPP: static int k = 0;
+// CHECK-OLD-TEST-CPP: } // anonymous 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 0;
// CHECK-OLD-TEST-CPP: }
// CHECK-OLD-TEST-CPP: } // namespace c
@@ -62,11 +73,23 @@
// 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: } // anonymous 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() { return 0; }
+// 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 0; }
// CHECK-NEW-TEST-CPP: int EnclosingMove5::a = 1;
// CHECK-NEW-TEST-CPP: int EnclosingMove5::Nested::f() { return 0; }
Index: test/clang-move/Inputs/multiple_class_test.cpp
===================================================================
--- test/clang-move/Inputs/multiple_class_test.cpp
+++ test/clang-move/Inputs/multiple_class_test.cpp
@@ -6,14 +6,25 @@
}
} // namespace a
+namespace {
+using a::Move1;
+using namespace a;
+static int k = 0;
+} // anonymous namespace
+
namespace b {
+using a::Move1;
+using namespace a;
+using T = a::Move1;
int Move2::f() {
return 0;
}
} // namespace b
namespace c {
int Move3::f() {
+ using a::Move1;
+ using namespace b;
return 0;
}
@@ -30,6 +41,7 @@
int EnclosingMove5::Nested::b = 1;
int NoMove::f() {
+ static int F = 0;
return 0;
}
} // namespace c
Index: clang-move/ClangMove.cpp
===================================================================
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -351,21 +351,31 @@
.bind("class_static_var_decl"),
this);
- auto inAnonymousNamespace = hasParent(namespaceDecl(isAnonymous()));
- // Match functions/variables definitions which are defined in anonymous
- // namespace in old cc.
+ auto InOldCCNamedNamespace =
+ allOf(hasParent(namespaceDecl(unless(isAnonymous()))), InOldCC);
+ // Matching using decls/type alias decls which are in named namespace. Those
+ // in classes, functions and anonymous namespaces are covered in other
+ // matchers.
Finder->addMatcher(
- namedDecl(anyOf(functionDecl(isDefinition()), varDecl(isDefinition())),
- inAnonymousNamespace)
- .bind("decls_in_anonymous_ns"),
+ namedDecl(
+ anyOf(usingDecl(InOldCCNamedNamespace),
+ usingDirectiveDecl(InOldCC, InOldCCNamedNamespace),
+ typeAliasDecl(InOldCC, InOldCCNamedNamespace)))
+ .bind("using_decl"),
this);
- // Match static functions/variabale definitions in old cc.
+ // Match anonymous namespace decl in old cc.
+ Finder->addMatcher(namespaceDecl(isAnonymous(), InOldCC).bind("anonymous_ns"),
+ this);
+
+ // Match static functions/variabale definitions which are defined in named
+ // spaces.
+ auto IsOldCCStaticDefinition =
+ allOf(isDefinition(), unless(InMovedClass), InOldCCNamedNamespace,
+ isStaticStorageClass());
Finder->addMatcher(
- namedDecl(anyOf(functionDecl(isDefinition(), unless(InMovedClass),
- isStaticStorageClass(), InOldCC),
- varDecl(isDefinition(), unless(InMovedClass),
- isStaticStorageClass(), InOldCC)))
+ namedDecl(anyOf(functionDecl(IsOldCCStaticDefinition),
+ varDecl(IsOldCCStaticDefinition)))
.bind("static_decls"),
this);
@@ -398,12 +408,15 @@
// Skip all forwad declarations which appear after moved class declaration.
if (RemovedDecls.empty())
MovedDecls.emplace_back(FWD, &Result.Context->getSourceManager());
- } else if (const auto *FD = Result.Nodes.getNodeAs<clang::NamedDecl>(
- "decls_in_anonymous_ns")) {
- MovedDecls.emplace_back(FD, &Result.Context->getSourceManager());
+ } else if (const auto *ANS = Result.Nodes.getNodeAs<clang::NamespaceDecl>(
+ "anonymous_ns")) {
+ MovedDecls.emplace_back(ANS, &Result.Context->getSourceManager());
} else if (const auto *ND =
Result.Nodes.getNodeAs<clang::NamedDecl>("static_decls")) {
MovedDecls.emplace_back(ND, &Result.Context->getSourceManager());
+ } else if (const auto *UD =
+ Result.Nodes.getNodeAs<clang::NamedDecl>("using_decl")) {
+ MovedDecls.emplace_back(UD, &Result.Context->getSourceManager());
}
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits