[PATCH] D26844: [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:29:02 PST 2016
hokein updated this revision to Diff 78491.
hokein marked an inline comment as done.
hokein added a comment.
Add FIXME.
https://reviews.llvm.org/D26844
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
@@ -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
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
@@ -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;
Index: clang-move/ClangMove.cpp
===================================================================
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -373,6 +373,7 @@
}
// 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 @@
//============================================================================
// 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 @@
// 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)))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26844.78491.patch
Type: text/x-patch
Size: 5922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161118/250e7869/attachment-0001.bin>
More information about the cfe-commits
mailing list