1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "clang/Lex/Lexer.h"
18 * Rewrites all Paint method on subclasses of vcl::Window to include RenderContext& as parameter.
20 * run as: make COMPILER_PLUGIN_TOOL=paintmethodconversion UPDATE_FILES=all FORCE_COMPILE_ALL=1
26 bool baseCheckNotWindowSubclass(const CXXRecordDecl
* aBaseDefinition
, void* /*pInput*/)
28 if (aBaseDefinition
&& aBaseDefinition
->getQualifiedNameAsString() == "vcl::Window")
35 bool isDerivedFromWindow(const CXXRecordDecl
* decl
) {
39 if (decl
->getQualifiedNameAsString() == "vcl::Window")
41 if (!decl
->forallBases(baseCheckNotWindowSubclass
, nullptr, true))
47 class PaintMethodConversion
: public RecursiveASTVisitor
<PaintMethodConversion
>, public loplugin::RewritePlugin
50 explicit PaintMethodConversion(InstantiationData
const& data
):
54 virtual void run() override
56 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
59 bool TraverseCXXMethodDecl(const CXXMethodDecl
* methodDeclaration
)
64 if (methodDeclaration
->getNameAsString() != "Paint")
67 if (!isDerivedFromWindow(methodDeclaration
->getParent()))
72 unsigned int nNoOfParameters
= methodDeclaration
->getNumParams();
74 if (nNoOfParameters
== 1) // we expect only one parameter Paint(Rect&)
76 const ParmVarDecl
* parameterDecl
= methodDeclaration
->getParamDecl(0);
77 if (methodDeclaration
->hasBody())
79 rewriter
->InsertText(parameterDecl
->getLocStart(), "vcl::RenderContext& /*rRenderContext*/, ", true, true);
83 rewriter
->InsertText(parameterDecl
->getLocStart(), "vcl::RenderContext& rRenderContext, ", true, true);
91 loplugin::Plugin::Registration
<PaintMethodConversion
> X("paintmethodconversion", true);
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */