diff options
author | Noel Grandin <noel@peralex.com> | 2015-05-11 08:37:50 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2015-05-11 09:17:41 +0200 |
commit | fc9e78c78864cbfa67ddea646da4aa4677d99b0c (patch) | |
tree | b04d03aa08ef442f456202d31ff9d9b13e8a1f0a /compilerplugins | |
parent | 80244bff5f1fb5cad4638ed0b661f0c0f7776b07 (diff) |
sw,sc,sd,starmath: convert to vcl::RenderContext
Change-Id: I5d0a3b8ed1c49ba2806e0fa528d908da45afd58c
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/rendercontext.cxx | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/compilerplugins/clang/rendercontext.cxx b/compilerplugins/clang/rendercontext.cxx index a1e7018d5fd1..bc34629613c2 100644 --- a/compilerplugins/clang/rendercontext.cxx +++ b/compilerplugins/clang/rendercontext.cxx @@ -16,7 +16,8 @@ // Check for calls to OutputDevice methods that are not passing through RenderContext -namespace { +namespace +{ class RenderContext: public RecursiveASTVisitor<RenderContext>, public loplugin::Plugin @@ -24,7 +25,9 @@ class RenderContext: public: explicit RenderContext(InstantiationData const & data): Plugin(data) {} - virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } + virtual void run() override { + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + } bool TraverseFunctionDecl(const FunctionDecl * decl); @@ -34,7 +37,8 @@ private: bool mbChecking = false; }; -bool RenderContext::TraverseFunctionDecl(const FunctionDecl * pFunctionDecl) { +bool RenderContext::TraverseFunctionDecl(const FunctionDecl * pFunctionDecl) +{ if (ignoreLocation(pFunctionDecl)) { return true; } @@ -67,22 +71,56 @@ bool RenderContext::VisitCXXMemberCallExpr(const CXXMemberCallExpr* pCXXMemberCa if (pCXXRecordDecl->getQualifiedNameAsString() != "OutputDevice") { return true; } + // ignore a handful of methods. They will most probably still be present in Window for use during processing outside of the Paint() + // method lifecycle + const CXXMethodDecl *pCXXMethodDecl = pCXXMemberCallExpr->getMethodDecl(); + if (pCXXMethodDecl->isInstance()) { + StringRef name = pCXXMethodDecl->getName(); + if (name == "LogicToPixel" || name == "GetMapMode" || name == "GetFontMetric" || name == "LogicToLogic" + || name == "PixelToLogic" || name == "SetDigitLanguage") + { + return true; + } + } + // for calling through a pointer const ImplicitCastExpr *pImplicitCastExpr = dyn_cast<ImplicitCastExpr>(pCXXMemberCallExpr->getImplicitObjectArgument()); - std::string t2 = "0"; + std::string x = "0"; // for debugging if (pImplicitCastExpr) { - t2 = "2"; + x += "1"; QualType aType = pImplicitCastExpr->getSubExpr()->getType(); if (aType->isPointerType()) aType = aType->getPointeeType(); - t2 = aType.getAsString(); - if (t2 == "vcl::RenderContext") + std::string t2 = aType.getAsString(); + if (t2 == "vcl::RenderContext" || t2 == "const vcl::RenderContext") + return true; + } + // for calling through a reference + const DeclRefExpr *pDeclRefExpr = dyn_cast<DeclRefExpr>(pCXXMemberCallExpr->getImplicitObjectArgument()); + if (pDeclRefExpr) { + x += "2"; + QualType aType = pDeclRefExpr->getType(); + std::string t2 = aType.getAsString(); + if (t2 == "vcl::RenderContext" || t2 == "const vcl::RenderContext") + return true; + } + // for calling through a chain of methods + const CXXMemberCallExpr *pMemberExpr = dyn_cast<CXXMemberCallExpr>(pCXXMemberCallExpr->getImplicitObjectArgument()); + if (pMemberExpr) { + x += "3"; + QualType aType = pMemberExpr->getType(); + if (aType->isPointerType()) + aType = aType->getPointeeType(); + std::string t2 = aType.getAsString(); + x += t2; + if (t2 == "vcl::RenderContext" || t2 == "const vcl::RenderContext") return true; } report( DiagnosticsEngine::Warning, + // + x + pCXXMemberCallExpr->getImplicitObjectArgument()->getStmtClassName() "Should be calling OutputDevice method through RenderContext.", pCXXMemberCallExpr->getLocStart()) - << pCXXMemberCallExpr->getSourceRange(); + << pCXXMemberCallExpr->getSourceRange(); return true; } |