[clang-tools-extra] r301914 - [clang-move] Find template class forward declarations more precisely.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue May 2 05:15:11 PDT 2017
Author: hokein
Date: Tue May 2 07:15:11 2017
New Revision: 301914
URL: http://llvm.org/viewvc/llvm-project?rev=301914&view=rev
Log:
[clang-move] Find template class forward declarations more precisely.
Reviewers: ioeric
Reviewed By: ioeric
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D32741
Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.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=301914&r1=301913&r2=301914&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Tue May 2 07:15:11 2017
@@ -504,8 +504,11 @@ void ClangMoveTool::registerMatchers(ast
isExpansionInFile(makeAbsolutePath(Context->Spec.OldHeader));
auto InOldCC = isExpansionInFile(makeAbsolutePath(Context->Spec.OldCC));
auto InOldFiles = anyOf(InOldHeader, InOldCC);
- auto ForwardDecls =
- cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition())));
+ auto classTemplateForwardDecls =
+ classTemplateDecl(unless(has(cxxRecordDecl(isDefinition()))));
+ auto ForwardClassDecls = namedDecl(
+ anyOf(cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition()))),
+ classTemplateForwardDecls));
auto TopLevelDecl =
hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl()));
@@ -518,9 +521,8 @@ void ClangMoveTool::registerMatchers(ast
// We consider declarations inside a class belongs to the class. So these
// declarations will be ignored.
auto AllDeclsInHeader = namedDecl(
- unless(ForwardDecls), unless(namespaceDecl()),
- unless(usingDirectiveDecl()), // using namespace decl.
- unless(classTemplateDecl(has(ForwardDecls))), // template forward decl.
+ unless(ForwardClassDecls), unless(namespaceDecl()),
+ unless(usingDirectiveDecl()), // using namespace decl.
InOldHeader,
hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl()))),
hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl()))));
@@ -531,7 +533,7 @@ void ClangMoveTool::registerMatchers(ast
return;
// Match forward declarations in old header.
- Finder->addMatcher(namedDecl(ForwardDecls, InOldHeader).bind("fwd_decl"),
+ Finder->addMatcher(namedDecl(ForwardClassDecls, InOldHeader).bind("fwd_decl"),
this);
//============================================================================
Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=301914&r1=301913&r2=301914&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Tue May 2 07:15:11 2017
@@ -531,6 +531,7 @@ TEST(ClangMove, DumpDecls) {
"void f2();\n"
"} // namespace a\n"
"\n"
+ "class ForwardClass;\n"
"namespace a {\n"
"namespace b {\n"
"class Move1 { public : void f(); };\n"
@@ -538,6 +539,7 @@ TEST(ClangMove, DumpDecls) {
"enum E1 { Green };\n"
"enum class E2 { Red };\n"
"typedef int Int2;\n"
+ "typedef A<double> A_d;"
"using Int = int;\n"
"extern int kGlobalInt;\n"
"extern const char* const kGlobalStr;\n"
@@ -552,11 +554,20 @@ TEST(ClangMove, DumpDecls) {
Spec.NewCC = "new_foo.cc";
DeclarationReporter Reporter;
std::set<DeclarationReporter::DeclarationPair> ExpectedDeclarations = {
- {"A", "Class"}, {"B", "Class"}, {"a::Move1", "Class"},
- {"a::f1", "Function"}, {"a::f2", "Function"}, {"a::b::Move1", "Class"},
- {"a::b::f", "Function"}, {"a::b::E1", "Enum"}, {"a::b::E2", "Enum"},
- {"a::b::Int2", "TypeAlias"}, {"a::b::Int", "TypeAlias"},
- {"a::b::kGlobalInt", "Variable"}, {"a::b::kGlobalStr", "Variable"}};
+ {"A", "Class"},
+ {"B", "Class"},
+ {"a::Move1", "Class"},
+ {"a::f1", "Function"},
+ {"a::f2", "Function"},
+ {"a::b::Move1", "Class"},
+ {"a::b::f", "Function"},
+ {"a::b::E1", "Enum"},
+ {"a::b::E2", "Enum"},
+ {"a::b::Int2", "TypeAlias"},
+ {"a::b::A_d", "TypeAlias"},
+ {"a::b::Int", "TypeAlias"},
+ {"a::b::kGlobalInt", "Variable"},
+ {"a::b::kGlobalStr", "Variable"}};
runClangMoveOnCode(Spec, TestHeader, TestCode, &Reporter);
std::set<DeclarationReporter::DeclarationPair> Results;
for (const auto& DelPair : Reporter.getDeclarationList())
More information about the cfe-commits
mailing list