clang/qa/data/rename-cxx-destructor-decl.cxx | 16 ++++++++ clang/qa/data/rename-cxx-destructor-decl.cxx.expected | 16 ++++++++ clang/qa/test-rename.sh | 4 ++ clang/rename.cxx | 34 ++++++++++++++++-- 4 files changed, 67 insertions(+), 3 deletions(-)
New commits: commit 26667ea7490f9e21a859d33ca4efc87d328f8a1b Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Fri Jun 3 09:03:45 2016 +0200 clang: handle dtors in rename Use case: try to rename e.g. SvxFmTbxCtlRecText in core.git. diff --git a/clang/qa/data/rename-cxx-destructor-decl.cxx b/clang/qa/data/rename-cxx-destructor-decl.cxx new file mode 100644 index 0000000..6f4a772 --- /dev/null +++ b/clang/qa/data/rename-cxx-destructor-decl.cxx @@ -0,0 +1,16 @@ +class C +{ +public: + C(); + ~C(); +}; + +C::C() +{ +} + +C::~C() +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/clang/qa/data/rename-cxx-destructor-decl.cxx.expected b/clang/qa/data/rename-cxx-destructor-decl.cxx.expected new file mode 100644 index 0000000..ff5be6c --- /dev/null +++ b/clang/qa/data/rename-cxx-destructor-decl.cxx.expected @@ -0,0 +1,16 @@ +class D +{ +public: + D(); + ~D(); +}; + +D::D() +{ +} + +D::~D() +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/clang/qa/test-rename.sh b/clang/qa/test-rename.sh index 4cae9ef..6755779 100755 --- a/clang/qa/test-rename.sh +++ b/clang/qa/test-rename.sh @@ -95,6 +95,10 @@ declare_rename_test "testCXXStaticCastExpr" "rename-cxx-static-cast-expr.cxx" bin/rename -old-name=C -new-name=D $test_input -- test_assert_equal $test_expected $test_output +declare_rename_test "testCXXDestructorDecl" "rename-cxx-destructor-decl.cxx" +bin/rename -old-name=C -new-name=D $test_input -- +test_assert_equal $test_expected $test_output + echo "OK ($ok)" # vi:set shiftwidth=4 expandtab: diff --git a/clang/rename.cxx b/clang/rename.cxx index 05e4abc..892e33a 100644 --- a/clang/rename.cxx +++ b/clang/rename.cxx @@ -42,9 +42,13 @@ class RenameVisitor : public clang::RecursiveASTVisitor<RenameVisitor> // Otherwise an A -> BA replacement would be done twice. std::set<clang::SourceLocation> maHandledLocations; - void RewriteText(clang::SourceLocation aStart, unsigned nLength, const std::string& rOldName) + void RewriteText(clang::SourceLocation aStart, unsigned nLength, const std::string& rOldName, const std::string& rPrefix = std::string()) { - const std::map<std::string, std::string>::const_iterator it = mrRewriter.getNameMap().find(rOldName); + std::string aOldName = rOldName; + if (!rPrefix.empty()) + // E.g. rOldName is '~C' and rPrefix is '~', then check if 'C' is to be renamed. + aOldName = aOldName.substr(rPrefix.size()); + const std::map<std::string, std::string>::const_iterator it = mrRewriter.getNameMap().find(aOldName); if (it != mrRewriter.getNameMap().end()) { if (aStart.isMacroID()) @@ -56,7 +60,11 @@ class RenameVisitor : public clang::RecursiveASTVisitor<RenameVisitor> aStart = mrRewriter.getSourceMgr().getSpellingLoc(aStart); if (maHandledLocations.find(aStart) == maHandledLocations.end()) { - mrRewriter.ReplaceText(aStart, nLength, it->second); + std::string aNewName = it->second; + if (!rPrefix.empty()) + // E.g. aNewName is 'D' and rPrefix is '~', then rename to '~D'. + aNewName = rPrefix + aNewName; + mrRewriter.ReplaceText(aStart, nLength, aNewName); maHandledLocations.insert(aStart); } } @@ -150,6 +158,26 @@ public: return true; } + bool VisitCXXDestructorDecl(clang::CXXDestructorDecl* pDecl) + { + std::string aName = pDecl->getNameAsString(); + std::string aPrefix("~"); + if (pDecl->isThisDeclarationADefinition()) + /* + * Foo::~Foo(...) {} + * ^~~ Handles this. + */ + RewriteText(pDecl->getLocStart(), pDecl->getNameAsString().length() - aPrefix.size(), aName.substr(aPrefix.size())); + + /* + * Foo::~Foo(...) {} + * ^~~ Handles this. + */ + RewriteText(pDecl->getLocation(), pDecl->getNameAsString().length(), aName, aPrefix); + + return true; + } + /* * C aC; * aC.nX = 1; <- Handles e.g. this... _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits