Skip to content

Commit 03c8963

Browse files
committedMay 2, 2017
[clang-move] Find template class forward declarations more precisely.
Reviewers: ioeric Reviewed By: ioeric Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D32741 llvm-svn: 301914
1 parent a43a8f5 commit 03c8963

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed
 

‎clang-tools-extra/clang-move/ClangMove.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,11 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
504504
isExpansionInFile(makeAbsolutePath(Context->Spec.OldHeader));
505505
auto InOldCC = isExpansionInFile(makeAbsolutePath(Context->Spec.OldCC));
506506
auto InOldFiles = anyOf(InOldHeader, InOldCC);
507-
auto ForwardDecls =
508-
cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition())));
507+
auto classTemplateForwardDecls =
508+
classTemplateDecl(unless(has(cxxRecordDecl(isDefinition()))));
509+
auto ForwardClassDecls = namedDecl(
510+
anyOf(cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition()))),
511+
classTemplateForwardDecls));
509512
auto TopLevelDecl =
510513
hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl()));
511514

@@ -518,9 +521,8 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
518521
// We consider declarations inside a class belongs to the class. So these
519522
// declarations will be ignored.
520523
auto AllDeclsInHeader = namedDecl(
521-
unless(ForwardDecls), unless(namespaceDecl()),
522-
unless(usingDirectiveDecl()), // using namespace decl.
523-
unless(classTemplateDecl(has(ForwardDecls))), // template forward decl.
524+
unless(ForwardClassDecls), unless(namespaceDecl()),
525+
unless(usingDirectiveDecl()), // using namespace decl.
524526
InOldHeader,
525527
hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl()))),
526528
hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl()))));
@@ -531,7 +533,7 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
531533
return;
532534

533535
// Match forward declarations in old header.
534-
Finder->addMatcher(namedDecl(ForwardDecls, InOldHeader).bind("fwd_decl"),
536+
Finder->addMatcher(namedDecl(ForwardClassDecls, InOldHeader).bind("fwd_decl"),
535537
this);
536538

537539
//============================================================================

‎clang-tools-extra/unittests/clang-move/ClangMoveTests.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,15 @@ TEST(ClangMove, DumpDecls) {
531531
"void f2();\n"
532532
"} // namespace a\n"
533533
"\n"
534+
"class ForwardClass;\n"
534535
"namespace a {\n"
535536
"namespace b {\n"
536537
"class Move1 { public : void f(); };\n"
537538
"void f() {}\n"
538539
"enum E1 { Green };\n"
539540
"enum class E2 { Red };\n"
540541
"typedef int Int2;\n"
542+
"typedef A<double> A_d;"
541543
"using Int = int;\n"
542544
"extern int kGlobalInt;\n"
543545
"extern const char* const kGlobalStr;\n"
@@ -552,11 +554,20 @@ TEST(ClangMove, DumpDecls) {
552554
Spec.NewCC = "new_foo.cc";
553555
DeclarationReporter Reporter;
554556
std::set<DeclarationReporter::DeclarationPair> ExpectedDeclarations = {
555-
{"A", "Class"}, {"B", "Class"}, {"a::Move1", "Class"},
556-
{"a::f1", "Function"}, {"a::f2", "Function"}, {"a::b::Move1", "Class"},
557-
{"a::b::f", "Function"}, {"a::b::E1", "Enum"}, {"a::b::E2", "Enum"},
558-
{"a::b::Int2", "TypeAlias"}, {"a::b::Int", "TypeAlias"},
559-
{"a::b::kGlobalInt", "Variable"}, {"a::b::kGlobalStr", "Variable"}};
557+
{"A", "Class"},
558+
{"B", "Class"},
559+
{"a::Move1", "Class"},
560+
{"a::f1", "Function"},
561+
{"a::f2", "Function"},
562+
{"a::b::Move1", "Class"},
563+
{"a::b::f", "Function"},
564+
{"a::b::E1", "Enum"},
565+
{"a::b::E2", "Enum"},
566+
{"a::b::Int2", "TypeAlias"},
567+
{"a::b::A_d", "TypeAlias"},
568+
{"a::b::Int", "TypeAlias"},
569+
{"a::b::kGlobalInt", "Variable"},
570+
{"a::b::kGlobalStr", "Variable"}};
560571
runClangMoveOnCode(Spec, TestHeader, TestCode, &Reporter);
561572
std::set<DeclarationReporter::DeclarationPair> Results;
562573
for (const auto& DelPair : Reporter.getDeclarationList())

0 commit comments

Comments
 (0)
Please sign in to comment.