[PATCH] D25762: [clang-move] Move using-decl in old cc.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 19 02:06:07 PDT 2016


hokein created this revision.
hokein added a reviewer: ioeric.
hokein added a subscriber: cfe-commits.

Another fix is to move the whole anonymous namespace declaration
completely instead of moving fun/var declarations only.


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,6 +18,10 @@
 // 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: static int k = 0;
+// CHECK-OLD-TEST-CPP: }
 // CHECK-OLD-TEST-CPP: namespace c {
 // CHECK-OLD-TEST-CPP: int NoMove::f() {
 // CHECK-OLD-TEST-CPP:   return 0;
@@ -62,7 +66,12 @@
 // 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: static int k = 0;
+// CHECK-NEW-TEST-CPP: }
 // CHECK-NEW-TEST-CPP: namespace b {
+// CHECK-NEW-TEST-CPP: using a::Move1;
 // CHECK-NEW-TEST-CPP: int Move2::f() { return 0; }
 // CHECK-NEW-TEST-CPP: } // namespace b
 // CHECK-NEW-TEST-CPP: namespace c {
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,7 +6,13 @@
 }
 } // namespace a
 
+namespace {
+using a::Move1;
+static int k = 0;
+}
+
 namespace b {
+using a::Move1;
 int Move2::f() {
   return 0;
 }
Index: clang-move/ClangMove.cpp
===================================================================
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -351,20 +351,22 @@
                          .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 InAnonymousNamespace = hasParent(namespaceDecl(isAnonymous()));
   Finder->addMatcher(
-      namedDecl(anyOf(functionDecl(isDefinition()), varDecl(isDefinition())),
-                inAnonymousNamespace)
-          .bind("decls_in_anonymous_ns"),
+      usingDecl(InOldCC, unless(InAnonymousNamespace)).bind("using_decl"),
       this);
 
+  // Match anonymous namespace decl in old cc.
+  Finder->addMatcher(namespaceDecl(isAnonymous(), InOldCC).bind("anonymous_ns"),
+                     this);
+
   // Match static functions/variabale definitions in old cc.
   Finder->addMatcher(
       namedDecl(anyOf(functionDecl(isDefinition(), unless(InMovedClass),
+                                   unless(InAnonymousNamespace),
                                    isStaticStorageClass(), InOldCC),
                       varDecl(isDefinition(), unless(InMovedClass),
+                              unless(InAnonymousNamespace),
                               isStaticStorageClass(), InOldCC)))
           .bind("static_decls"),
       this);
@@ -398,12 +400,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::UsingDecl>("using_decl")) {
+    MovedDecls.emplace_back(UD, &Result.Context->getSourceManager());
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25762.75120.patch
Type: text/x-patch
Size: 3925 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161019/7cf7d1b2/attachment-0001.bin>


More information about the cfe-commits mailing list