[Libreoffice-commits] dev-tools.git: clang/README clang/rename.cxx clang/testmemberfunction.cxx

Miklos Vajna vmiklos at collabora.co.uk
Mon Jan 11 00:09:38 PST 2016


 clang/README                 |    2 +-
 clang/rename.cxx             |   35 +++++++++++++++++++++++++++++++++++
 clang/testmemberfunction.cxx |   20 ++++++++++++++++++++
 3 files changed, 56 insertions(+), 1 deletion(-)

New commits:
commit cd61d6342eea3b028d13670962327af698b5317f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Jan 11 09:08:59 2016 +0100

    clang: also handle member functions

diff --git a/clang/README b/clang/README
index fc7cd31..948e223 100644
--- a/clang/README
+++ b/clang/README
@@ -14,7 +14,7 @@ Pros:
 
 Cons:
 
-- handles only rename of class members so far
+- handles only rename of data members and member functions so far
 - only tested with clang 3.5/3.7
 
 == Hello world
diff --git a/clang/rename.cxx b/clang/rename.cxx
index 60bcce7..352a90b 100644
--- a/clang/rename.cxx
+++ b/clang/rename.cxx
@@ -48,6 +48,8 @@ public:
     {
     }
 
+    // Data member names.
+
     /*
      * class C
      * {
@@ -172,6 +174,39 @@ public:
         }
         return true;
     }
+
+    // Member function names.
+
+    /*
+     * class C
+     * {
+     * public:
+     *     foo(); <- Handles this.
+     * };
+     *
+     * C::foo() <- And this.
+     * {
+     * }
+     *
+     * ...
+     *
+     * aC.foo(); <- And this.
+     */
+    bool VisitCXXMethodDecl(const clang::CXXMethodDecl* pDecl)
+    {
+        std::string aName = pDecl->getQualifiedNameAsString();
+        const std::map<std::string, std::string>::const_iterator it = mrRewriter.getNameMap().find(aName);
+        if (it != mrRewriter.getNameMap().end())
+        {
+            clang::SourceLocation aLocation = pDecl->getLocation();
+            if (maHandledLocations.find(aLocation) == maHandledLocations.end())
+            {
+                mrRewriter.ReplaceText(aLocation, pDecl->getNameAsString().length(), it->second);
+                maHandledLocations.insert(aLocation);
+            }
+        }
+        return true;
+    }
 };
 
 class RenameASTConsumer : public clang::ASTConsumer
diff --git a/clang/testmemberfunction.cxx b/clang/testmemberfunction.cxx
new file mode 100644
index 0000000..e307304
--- /dev/null
+++ b/clang/testmemberfunction.cxx
@@ -0,0 +1,20 @@
+namespace ns
+{
+class C
+{
+public:
+    void foo(int x);
+};
+}
+
+void ns::C::foo(int /*x*/)
+{
+}
+
+int main(int /*argc*/, char** /*argv*/)
+{
+    ns::C aC;
+    aC.foo(0);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list