[clang-tools-extra] r287330 - [clang-move] Fix not moving using-decls in global namespace in old.cc
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 18 02:51:16 PST 2016
Author: hokein
Date: Fri Nov 18 04:51:16 2016
New Revision: 287330
URL: http://llvm.org/viewvc/llvm-project?rev=287330&view=rev
Log:
[clang-move] Fix not moving using-decls in global namespace in old.cc
Reviewers: ioeric
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D26844
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=287330&r1=287329&r2=287330&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Fri Nov 18 04:51:16 2016
@@ -373,6 +373,7 @@ createInsertedReplacements(const std::ve
}
// If the moved declaration is in same namespace CurrentNamespace, add
// a preceeding `\n' before the moved declaration.
+ // FIXME: Don't add empty lines between using declarations.
if (!IsInNewNamespace)
NewCode += "\n";
NewCode += getDeclarationSourceText(MovedDecl.Decl, MovedDecl.SM);
@@ -453,15 +454,17 @@ void ClangMoveTool::registerMatchers(ast
//============================================================================
// Matchers for 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.
+ auto InOldCCNamedOrGlobalNamespace =
+ allOf(hasParent(decl(anyOf(namespaceDecl(unless(isAnonymous())),
+ translationUnitDecl()))),
+ InOldCC);
+ // Matching using decls/type alias decls which are in named namespace or
+ // global namespace. Those in classes, functions and anonymous namespaces are
+ // covered in other matchers.
Finder->addMatcher(
- namedDecl(anyOf(usingDecl(InOldCCNamedNamespace),
- usingDirectiveDecl(InOldCC, InOldCCNamedNamespace),
- typeAliasDecl(InOldCC, InOldCCNamedNamespace)))
+ namedDecl(anyOf(usingDecl(InOldCCNamedOrGlobalNamespace),
+ usingDirectiveDecl(InOldCCNamedOrGlobalNamespace),
+ typeAliasDecl( InOldCCNamedOrGlobalNamespace)))
.bind("using_decl"),
this);
@@ -472,7 +475,7 @@ void ClangMoveTool::registerMatchers(ast
// Match static functions/variable definitions which are defined in named
// namespaces.
auto IsOldCCStaticDefinition =
- allOf(isDefinition(), unless(InMovedClass), InOldCCNamedNamespace,
+ allOf(isDefinition(), unless(InMovedClass), InOldCCNamedOrGlobalNamespace,
isStaticStorageClass());
Finder->addMatcher(namedDecl(anyOf(functionDecl(IsOldCCStaticDefinition),
varDecl(IsOldCCStaticDefinition)))
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=287330&r1=287329&r2=287330&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 Fri Nov 18 04:51:16 2016
@@ -1,5 +1,10 @@
#include "multiple_class_test.h"
+using a::Move1;
+using namespace a;
+using A = a::Move1;
+static int g = 0;
+
namespace a {
int Move1::f() {
return 0;
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=287330&r1=287329&r2=287330&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 Fri Nov 18 04:51:16 2016
@@ -1,8 +1,8 @@
// RUN: mkdir -p %T/move-multiple-classes
// RUN: cp %S/Inputs/multiple_class_test* %T/move-multiple-classes/
// RUN: cd %T/move-multiple-classes
-// RUN: clang-move -names="c::EnclosingMove5::Nested" -new_cc=%T/move-multiple-classes/new_multiple_class_test.cpp -new_header=%T/move-multiple-classes/new_multiple_class_test.h -old_cc=%T/move-multiple-classes/multiple_class_test.cpp -old_header=../move-multiple-classes/multiple_class_test.h -dump_result %T/move-multiple-classes/multiple_class_test.cpp -- | FileCheck %s -check-prefix=CHECK-EMPTY
-// RUN: clang-move -names="a::Move1, b::Move2,c::Move3,c::Move4,c::EnclosingMove5" -new_cc=%T/move-multiple-classes/new_multiple_class_test.cpp -new_header=%T/move-multiple-classes/new_multiple_class_test.h -old_cc=%T/move-multiple-classes/multiple_class_test.cpp -old_header=../move-multiple-classes/multiple_class_test.h %T/move-multiple-classes/multiple_class_test.cpp --
+// RUN: clang-move -names="c::EnclosingMove5::Nested" -new_cc=%T/move-multiple-classes/new_multiple_class_test.cpp -new_header=%T/move-multiple-classes/new_multiple_class_test.h -old_cc=%T/move-multiple-classes/multiple_class_test.cpp -old_header=../move-multiple-classes/multiple_class_test.h -dump_result %T/move-multiple-classes/multiple_class_test.cpp -- -std=c++11| FileCheck %s -check-prefix=CHECK-EMPTY
+// RUN: clang-move -names="a::Move1, b::Move2,c::Move3,c::Move4,c::EnclosingMove5" -new_cc=%T/move-multiple-classes/new_multiple_class_test.cpp -new_header=%T/move-multiple-classes/new_multiple_class_test.h -old_cc=%T/move-multiple-classes/multiple_class_test.cpp -old_header=../move-multiple-classes/multiple_class_test.h %T/move-multiple-classes/multiple_class_test.cpp -- -std=c++11
// RUN: FileCheck -input-file=%T/move-multiple-classes/new_multiple_class_test.cpp -check-prefix=CHECK-NEW-TEST-CPP %s
// RUN: FileCheck -input-file=%T/move-multiple-classes/new_multiple_class_test.h -check-prefix=CHECK-NEW-TEST-H %s
// RUN: FileCheck -input-file=%T/move-multiple-classes/multiple_class_test.cpp -check-prefix=CHECK-OLD-TEST-CPP %s
@@ -18,6 +18,10 @@
// CHECK-OLD-TEST-H: } // 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;
@@ -70,6 +74,10 @@
// 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
More information about the cfe-commits
mailing list