summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/change-namespace/ChangeNamespace.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2017-03-01 10:29:39 +0000
committerEric Liu <ioeric@google.com>2017-03-01 10:29:39 +0000
commit413671507f593a7ce70a61db23e35387579d5f2a (patch)
tree2434f5f1bd608f6d9aba25e23eb8e4386c3d307d /clang-tools-extra/change-namespace/ChangeNamespace.cpp
parentded2306208d875ed38309cef6478b88f87a3ecd7 (diff)
downloadbcm5719-llvm-413671507f593a7ce70a61db23e35387579d5f2a.tar.gz
bcm5719-llvm-413671507f593a7ce70a61db23e35387579d5f2a.zip
[change-namespace] get insertion points of forward declarations correct.
Summary: Previously, the insertion points would conflict with the old namespace deletion. Reviewers: hokein Reviewed By: hokein Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D30490 llvm-svn: 296604
Diffstat (limited to 'clang-tools-extra/change-namespace/ChangeNamespace.cpp')
-rw-r--r--clang-tools-extra/change-namespace/ChangeNamespace.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/clang-tools-extra/change-namespace/ChangeNamespace.cpp b/clang-tools-extra/change-namespace/ChangeNamespace.cpp
index ad1c22afcdb..36f04243ce8 100644
--- a/clang-tools-extra/change-namespace/ChangeNamespace.cpp
+++ b/clang-tools-extra/change-namespace/ChangeNamespace.cpp
@@ -676,19 +676,18 @@ void ChangeNamespaceTool::moveClassForwardDeclaration(
const NamedDecl *FwdDecl) {
SourceLocation Start = FwdDecl->getLocStart();
SourceLocation End = FwdDecl->getLocEnd();
+ const SourceManager &SM = *Result.SourceManager;
SourceLocation AfterSemi = Lexer::findLocationAfterToken(
- End, tok::semi, *Result.SourceManager, Result.Context->getLangOpts(),
+ End, tok::semi, SM, Result.Context->getLangOpts(),
/*SkipTrailingWhitespaceAndNewLine=*/true);
if (AfterSemi.isValid())
End = AfterSemi.getLocWithOffset(-1);
// Delete the forward declaration from the code to be moved.
- addReplacementOrDie(Start, End, "", *Result.SourceManager,
- &FileToReplacements);
+ addReplacementOrDie(Start, End, "", SM, &FileToReplacements);
llvm::StringRef Code = Lexer::getSourceText(
- CharSourceRange::getTokenRange(
- Result.SourceManager->getSpellingLoc(Start),
- Result.SourceManager->getSpellingLoc(End)),
- *Result.SourceManager, Result.Context->getLangOpts());
+ CharSourceRange::getTokenRange(SM.getSpellingLoc(Start),
+ SM.getSpellingLoc(End)),
+ SM, Result.Context->getLangOpts());
// Insert the forward declaration back into the old namespace after moving the
// code from old namespace to new namespace.
// Insertion information is stored in `InsertFwdDecls` and actual
@@ -697,8 +696,9 @@ void ChangeNamespaceTool::moveClassForwardDeclaration(
const auto *NsDecl = Result.Nodes.getNodeAs<NamespaceDecl>("ns_decl");
// The namespace contains the forward declaration, so it must not be empty.
assert(!NsDecl->decls_empty());
- const auto Insertion = createInsertion(NsDecl->decls_begin()->getLocStart(),
- Code, *Result.SourceManager);
+ const auto Insertion = createInsertion(
+ getLocAfterNamespaceLBrace(NsDecl, SM, Result.Context->getLangOpts()),
+ Code, SM);
InsertForwardDeclaration InsertFwd;
InsertFwd.InsertionOffset = Insertion.getOffset();
InsertFwd.ForwardDeclText = Insertion.getReplacementText().str();
OpenPOWER on IntegriCloud