[clang-tools-extra] r284592 - [clang-move] Move using-decl in old cc.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 19 07:13:22 PDT 2016
Author: hokein
Date: Wed Oct 19 09:13:21 2016
New Revision: 284592
URL: http://llvm.org/viewvc/llvm-project?rev=284592&view=rev
Log:
[clang-move] Move using-decl in old cc.
Summary:
Another fix is to move the whole anonymous namespace declaration
completely instead of moving fun/var declarations only.
Reviewers: ioeric
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D25762
Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/test/clang-move/Inputs/multiple_class_test.cpp
clang-tools-extra/trunk/test/clang-move/move-multiple-classes.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=284592&r1=284591&r2=284592&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Wed Oct 19 09:13:21 2016
@@ -351,21 +351,31 @@ void ClangMoveTool::registerMatchers(ast
.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/variable definitions which are defined in named
+ // namespaces.
+ 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 @@ void ClangMoveTool::run(const ast_matche
// 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());
}
}
Modified: 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=284592&r1=284591&r2=284592&view=diff
==============================================================================
--- 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 Wed Oct 19 09:13:21 2016
@@ -6,7 +6,16 @@ int Move1::f() {
}
} // 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;
}
@@ -14,6 +23,8 @@ int Move2::f() {
namespace c {
int Move3::f() {
+ using a::Move1;
+ using namespace b;
return 0;
}
@@ -30,6 +41,7 @@ int EnclosingMove5::Nested::f() {
int EnclosingMove5::Nested::b = 1;
int NoMove::f() {
+ static int F = 0;
return 0;
}
} // namespace c
Modified: 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=284592&r1=284591&r2=284592&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp (original)
+++ clang-tools-extra/trunk/test/clang-move/move-multiple-classes.cpp Wed Oct 19 09:13:21 2016
@@ -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; }
More information about the cfe-commits
mailing list