Author: hokein Date: Tue Jan 17 04:08:11 2017 New Revision: 292207 URL: http://llvm.org/viewvc/llvm-project?rev=292207&view=rev Log: [clang-move] Ignore using decls which are defined in macros.
Summary: Also ignore helpers which are defined in macro. Currently clang-move doesn't handle macro well enough, especiall for complex macros. This patch will ignore declarations in macros to make the behavior of clang-move more correct. Reviewers: ioeric Reviewed By: ioeric Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D28774 Added: clang-tools-extra/trunk/test/clang-move/Inputs/macro_helper_test.cpp clang-tools-extra/trunk/test/clang-move/Inputs/macro_helper_test.h clang-tools-extra/trunk/test/clang-move/no-move-macro-helpers.cpp Modified: clang-tools-extra/trunk/clang-move/ClangMove.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=292207&r1=292206&r2=292207&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original) +++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Tue Jan 17 04:08:11 2017 @@ -31,6 +31,8 @@ namespace { // FIXME: Move to ASTMatchers. AST_MATCHER(VarDecl, isStaticDataMember) { return Node.isStaticDataMember(); } +AST_MATCHER(NamedDecl, notInMacro) { return !Node.getLocation().isMacroID(); } + AST_MATCHER_P(Decl, hasOutermostEnclosingClass, ast_matchers::internal::Matcher<Decl>, InnerMatcher) { const auto *Context = Node.getDeclContext(); @@ -525,12 +527,12 @@ void ClangMoveTool::registerMatchers(ast // Matching using decls/type alias decls which are in named/anonymous/global // namespace, these decls are always copied to new.h/cc. Those in classes, // functions are covered in other matchers. - Finder->addMatcher( - namedDecl(anyOf(usingDecl(IsOldCCTopLevelDecl), - usingDirectiveDecl(IsOldCCTopLevelDecl), - typeAliasDecl(IsOldCCTopLevelDecl))) - .bind("using_decl"), - this); + Finder->addMatcher(namedDecl(anyOf(usingDecl(IsOldCCTopLevelDecl), + usingDirectiveDecl(IsOldCCTopLevelDecl), + typeAliasDecl(IsOldCCTopLevelDecl)), + notInMacro()) + .bind("using_decl"), + this); // Match static functions/variable definitions which are defined in named // namespaces. @@ -556,9 +558,11 @@ void ClangMoveTool::registerMatchers(ast allOf(DefinitionInOldCC, anyOf(isStaticStorageClass(), InAnonymousNS)); // Match helper classes separately with helper functions/variables since we // want to reuse these matchers in finding helpers usage below. - auto HelperFuncOrVar = namedDecl(anyOf(functionDecl(IsOldCCHelperDefinition), - varDecl(IsOldCCHelperDefinition))); - auto HelperClasses = cxxRecordDecl(DefinitionInOldCC, InAnonymousNS); + auto HelperFuncOrVar = + namedDecl(notInMacro(), anyOf(functionDecl(IsOldCCHelperDefinition), + varDecl(IsOldCCHelperDefinition))); + auto HelperClasses = + cxxRecordDecl(notInMacro(), DefinitionInOldCC, InAnonymousNS); // Save all helper declarations in old.cc. Finder->addMatcher( namedDecl(anyOf(HelperFuncOrVar, HelperClasses)).bind("helper_decls"), Added: clang-tools-extra/trunk/test/clang-move/Inputs/macro_helper_test.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/Inputs/macro_helper_test.cpp?rev=292207&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-move/Inputs/macro_helper_test.cpp (added) +++ clang-tools-extra/trunk/test/clang-move/Inputs/macro_helper_test.cpp Tue Jan 17 04:08:11 2017 @@ -0,0 +1,13 @@ +#include "macro_helper_test.h" + +#define DEFINE(name) \ + namespace ns { \ + static const bool t1 = false; \ + bool t2_##name = t1; \ + bool t3_##name = t1; \ + } \ + using ns::t2_##name; + +DEFINE(test) + +void f1() {} Added: clang-tools-extra/trunk/test/clang-move/Inputs/macro_helper_test.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/Inputs/macro_helper_test.h?rev=292207&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-move/Inputs/macro_helper_test.h (added) +++ clang-tools-extra/trunk/test/clang-move/Inputs/macro_helper_test.h Tue Jan 17 04:08:11 2017 @@ -0,0 +1,2 @@ +class A {}; +void f1(); Added: clang-tools-extra/trunk/test/clang-move/no-move-macro-helpers.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/no-move-macro-helpers.cpp?rev=292207&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-move/no-move-macro-helpers.cpp (added) +++ clang-tools-extra/trunk/test/clang-move/no-move-macro-helpers.cpp Tue Jan 17 04:08:11 2017 @@ -0,0 +1,43 @@ +// RUN: mkdir -p %T/no-move-macro-helper +// RUN: cp %S/Inputs/macro_helper_test.h %T/no-move-macro-helper/macro_helper_test.h +// RUN: cp %S/Inputs/macro_helper_test.cpp %T/no-move-macro-helper/macro_helper_test.cpp +// RUN: cd %T/no-move-macro-helper +// +// ----------------------------------------------------------------------------- +// Test no moving helpers in macro. +// ----------------------------------------------------------------------------- +// RUN: clang-move -names="A" -new_cc=%T/no-move-macro-helper/new_test.cpp -new_header=%T/no-move-macro-helper/new_test.h -old_cc=%T/no-move-macro-helper/macro_helper_test.cpp -old_header=%T/no-move-macro-helper/macro_helper_test.h %T/no-move-macro-helper/macro_helper_test.cpp -- -std=c++11 +// RUN: FileCheck -input-file=%T/no-move-macro-helper/new_test.h -check-prefix=CHECK-NEW-TEST-CASE1-H %s +// RUN: FileCheck -input-file=%T/no-move-macro-helper/new_test.cpp -check-prefix=CHECK-NEW-TEST-CASE1-CPP %s +// RUN: FileCheck -input-file=%T/no-move-macro-helper/macro_helper_test.h -check-prefix=CHECK-OLD-TEST-CASE1-H %s +// RUN: FileCheck -input-file=%T/no-move-macro-helper/macro_helper_test.cpp -check-prefix=CHECK-OLD-TEST-CASE1-CPP %s + +// CHECK-NEW-TEST-CASE1-H: class A {}; + +// CHECK-OLD-TEST-CASE1-H-NOT: class A {}; + +// CHECK-OLD-TEST-CASE1-CPP: DEFINE(test) + +// CHECK-NEW-TEST-CASE1-CPP-NOT: DEFINE(test) + + +// ----------------------------------------------------------------------------- +// Test moving all. +// ----------------------------------------------------------------------------- +// RUN: cp %S/Inputs/macro_helper_test.h %T/no-move-macro-helper/macro_helper_test.h +// RUN: cp %S/Inputs/macro_helper_test.cpp %T/no-move-macro-helper/macro_helper_test.cpp +// RUN: clang-move -names="A, f1" -new_cc=%T/no-move-macro-helper/new_test.cpp -new_header=%T/no-move-macro-helper/new_test.h -old_cc=%T/no-move-macro-helper/macro_helper_test.cpp -old_header=%T/no-move-macro-helper/macro_helper_test.h %T/no-move-macro-helper/macro_helper_test.cpp -- -std=c++11 +// +// RUN: FileCheck -input-file=%T/no-move-macro-helper/new_test.h -check-prefix=CHECK-NEW-TEST-CASE2-H %s +// RUN: FileCheck -input-file=%T/no-move-macro-helper/new_test.cpp -check-prefix=CHECK-NEW-TEST-CASE2-CPP %s +// RUN: FileCheck -input-file=%T/no-move-macro-helper/macro_helper_test.h -allow-empty -check-prefix=CHECK-EMPTY %s +// RUN: FileCheck -input-file=%T/no-move-macro-helper/macro_helper_test.cpp -allow-empty -check-prefix=CHECK-EMPTY %s + +// CHECK-NEW-TEST-CASE2-H: class A {}; +// CHECK-NEW-TEST-CASE2-H-NEXT:void f1(); + + +// CHECK-NEW-TEST-CASE2-CPP: DEFINE(test) +// CHECK-NEW-TEST-CASE2-CPP: void f1() {} + +// CHECK-EMPTY: {{^}}{{$}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits