summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/change-namespace/ChangeNamespace.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2016-12-07 14:20:52 +0000
committerEric Liu <ioeric@google.com>2016-12-07 14:20:52 +0000
commit41552d6a37c8c9fb4a620b3a7164469a2cb914ac (patch)
treead2f3d0da9e320b6e782083ad083ad8c674d2e17 /clang-tools-extra/change-namespace/ChangeNamespace.cpp
parentb1332d8bf603216b34c250a1e72de51025b48819 (diff)
downloadbcm5719-llvm-41552d6a37c8c9fb4a620b3a7164469a2cb914ac.tar.gz
bcm5719-llvm-41552d6a37c8c9fb4a620b3a7164469a2cb914ac.zip
[change-namespace] move template class forward-declarations and don't move fwd-decls in classes.
Summary: Forward declarations in moved namespaces should be moved back to the old namespaces. We should also move template class forward declarations. Also fix a bug that moves forward declarations of nested classes. Reviewers: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D27515 llvm-svn: 288908
Diffstat (limited to 'clang-tools-extra/change-namespace/ChangeNamespace.cpp')
-rw-r--r--clang-tools-extra/change-namespace/ChangeNamespace.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/clang-tools-extra/change-namespace/ChangeNamespace.cpp b/clang-tools-extra/change-namespace/ChangeNamespace.cpp
index c0a8fe0370e..a18ad9b109c 100644
--- a/clang-tools-extra/change-namespace/ChangeNamespace.cpp
+++ b/clang-tools-extra/change-namespace/ChangeNamespace.cpp
@@ -303,10 +303,18 @@ void ChangeNamespaceTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
.bind("old_ns"),
this);
- // Match forward-declarations in the old namespace.
+ // Match class forward-declarations in the old namespace.
+ // Note that forward-declarations in classes are not matched.
+ Finder->addMatcher(cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition())),
+ IsInMovedNs, hasParent(namespaceDecl()))
+ .bind("class_fwd_decl"),
+ this);
+
+ // Match template class forward-declarations in the old namespace.
Finder->addMatcher(
- cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition())), IsInMovedNs)
- .bind("fwd_decl"),
+ classTemplateDecl(unless(hasDescendant(cxxRecordDecl(isDefinition()))),
+ IsInMovedNs, hasParent(namespaceDecl()))
+ .bind("template_class_fwd_decl"),
this);
// Match references to types that are not defined in the old namespace.
@@ -401,8 +409,12 @@ void ChangeNamespaceTool::run(
Result.Nodes.getNodeAs<NamespaceDecl>("old_ns")) {
moveOldNamespace(Result, NsDecl);
} else if (const auto *FwdDecl =
- Result.Nodes.getNodeAs<CXXRecordDecl>("fwd_decl")) {
- moveClassForwardDeclaration(Result, FwdDecl);
+ Result.Nodes.getNodeAs<CXXRecordDecl>("class_fwd_decl")) {
+ moveClassForwardDeclaration(Result, cast<NamedDecl>(FwdDecl));
+ } else if (const auto *TemplateFwdDecl =
+ Result.Nodes.getNodeAs<ClassTemplateDecl>(
+ "template_class_fwd_decl")) {
+ moveClassForwardDeclaration(Result, cast<NamedDecl>(TemplateFwdDecl));
} else if (const auto *UsingWithShadow =
Result.Nodes.getNodeAs<UsingDecl>("using_with_shadow")) {
fixUsingShadowDecl(Result, UsingWithShadow);
@@ -539,7 +551,7 @@ void ChangeNamespaceTool::moveOldNamespace(
// } // x
void ChangeNamespaceTool::moveClassForwardDeclaration(
const ast_matchers::MatchFinder::MatchResult &Result,
- const CXXRecordDecl *FwdDecl) {
+ const NamedDecl *FwdDecl) {
SourceLocation Start = FwdDecl->getLocStart();
SourceLocation End = FwdDecl->getLocEnd();
SourceLocation AfterSemi = Lexer::findLocationAfterToken(
OpenPOWER on IntegriCloud