[PATCH] D32741: [clang-move] Find template class forward declarations more precisely.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 2 05:28:22 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301914: [clang-move] Find template class forward declarations more precisely. (authored by hokein).
Changed prior to commit:
https://reviews.llvm.org/D32741?vs=97427&id=97434#toc
Repository:
rL LLVM
https://reviews.llvm.org/D32741
Files:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
Index: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
===================================================================
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
@@ -531,13 +531,15 @@
"void f2();\n"
"} // namespace a\n"
"\n"
+ "class ForwardClass;\n"
"namespace a {\n"
"namespace b {\n"
"class Move1 { public : void f(); };\n"
"void f() {}\n"
"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 @@
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())
Index: clang-tools-extra/trunk/clang-move/ClangMove.cpp
===================================================================
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp
@@ -504,8 +504,11 @@
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 @@
// 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 @@
return;
// Match forward declarations in old header.
- Finder->addMatcher(namedDecl(ForwardDecls, InOldHeader).bind("fwd_decl"),
+ Finder->addMatcher(namedDecl(ForwardClassDecls, InOldHeader).bind("fwd_decl"),
this);
//============================================================================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32741.97434.patch
Type: text/x-patch
Size: 4155 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170502/08e2b004/attachment.bin>
More information about the cfe-commits
mailing list