[Libreoffice-commits] core.git: Branch 'feature/rendercontext' - 2 commits - compilerplugins/clang include/vcl vcl/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Mon Apr 27 16:17:01 PDT 2015


 compilerplugins/clang/paintmethodconversion.cxx |   95 ++++++++++++++++++++++++
 include/vcl/window.hxx                          |    4 -
 vcl/source/window/window.cxx                    |    2 
 3 files changed, 98 insertions(+), 3 deletions(-)

New commits:
commit 217c76f72256076e0e125580e8d1b781828456e6
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Apr 28 08:14:47 2015 +0900

    Paint method clang rewriter plugin
    
    Change-Id: Ib66089f43b1df19a4c726f3cf198e8a4c4b101b6

diff --git a/compilerplugins/clang/paintmethodconversion.cxx b/compilerplugins/clang/paintmethodconversion.cxx
new file mode 100644
index 0000000..47e4108
--- /dev/null
+++ b/compilerplugins/clang/paintmethodconversion.cxx
@@ -0,0 +1,95 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "clang/Lex/Lexer.h"
+
+#include "compat.hxx"
+#include "plugin.hxx"
+#include <iostream>
+#include <fstream>
+
+/**
+ * Rewrites all Paint method on subclasses of vcl::Window to include RenderContext& as parameter.
+ *
+ * run as: make COMPILER_PLUGIN_TOOL=paintmethodconversion UPDATE_FILES=all FORCE_COMPILE_ALL=1
+ */
+
+namespace
+{
+
+bool baseCheckNotWindowSubclass(const CXXRecordDecl* aBaseDefinition, void* /*pInput*/)
+{
+    if (aBaseDefinition && aBaseDefinition->getQualifiedNameAsString() == "vcl::Window")
+    {
+        return false;
+    }
+    return true;
+}
+
+bool isDerivedFromWindow(const CXXRecordDecl* decl) {
+    if (!decl)
+        return false;
+    // skip vcl::Window
+    if (decl->getQualifiedNameAsString() == "vcl::Window")
+        return false;
+    if (!decl->forallBases(baseCheckNotWindowSubclass, nullptr, true))
+        return true;
+
+    return false;
+}
+
+class PaintMethodConversion: public RecursiveASTVisitor<PaintMethodConversion>, public loplugin::RewritePlugin
+{
+public:
+    explicit PaintMethodConversion(InstantiationData const& data):
+        RewritePlugin(data)
+    {}
+
+    virtual void run() override
+    {
+        TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
+    }
+
+    bool TraverseCXXMethodDecl(const CXXMethodDecl* methodDeclaration)
+    {
+        if (!rewriter)
+            return true;
+
+        if (methodDeclaration->getNameAsString() != "Paint")
+            return true;
+
+        if (!isDerivedFromWindow(methodDeclaration->getParent()))
+        {
+            return true;
+        }
+
+        unsigned int nNoOfParameters = methodDeclaration->getNumParams();
+
+        if (nNoOfParameters == 1) // we expect only one parameter Paint(Rect&)
+        {
+            const ParmVarDecl* parameterDecl = methodDeclaration->getParamDecl(0);
+            if (methodDeclaration->hasBody())
+            {
+                rewriter->InsertText(parameterDecl->getLocStart(), "vcl::RenderContext& /*rRenderContext*/, ", true, true);
+            }
+            else
+            {
+                rewriter->InsertText(parameterDecl->getLocStart(), "vcl::RenderContext& rRenderContext, ", true, true);
+            }
+        }
+        return true;
+    }
+
+};
+
+loplugin::Plugin::Registration<PaintMethodConversion> X("paintmethodconversion", true);
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit fc6719f6ad0c9c23f28de2af9453b5bcca3badc1
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Apr 28 08:11:44 2015 +0900

    change Paint input parameter to ref
    
    Change-Id: I4bf97d46736ce8186c3699c9a861e44103ab0d4b

diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index d11067d..59c27ef 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+y/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
  * This file is part of the LibreOffice project.
  *
@@ -718,7 +718,7 @@ public:
     virtual void                        KeyInput( const KeyEvent& rKEvt );
     virtual void                        KeyUp( const KeyEvent& rKEvt );
     virtual void                        PrePaint();
-    virtual void                        Paint(vcl::RenderContext* pRenderContext, const Rectangle& rRect);
+    virtual void                        Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
     virtual void                        Paint(const Rectangle& rRect);
     virtual void                        Erase() SAL_OVERRIDE;
     virtual void                        Erase( const Rectangle& rRect ) SAL_OVERRIDE { ::OutputDevice::Erase( rRect ); }
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 0be526f..7b90e8a 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -3893,7 +3893,7 @@ Any Window::GetSystemDataAny() const
     return aRet;
 }
 
-void Window::Paint(vcl::RenderContext* /*pRenderContext*/, const Rectangle& rRect)
+void Window::Paint(vcl::RenderContext& /*rRenderContext*/, const Rectangle& rRect)
 {
     Paint(rRect);
 }


More information about the Libreoffice-commits mailing list