/* -*- 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/.
*/
// We use Traverse to set a flag so we can easily ignore certain method calls bool RenderContext::TraverseFunctionDecl(const FunctionDecl * pFunctionDecl)
{ if (ignoreLocation(pFunctionDecl)) { returntrue;
} if (!pFunctionDecl->hasBody()) { returntrue;
} if ( pFunctionDecl != pFunctionDecl->getCanonicalDecl() ) { returntrue;
} // Ignore methods inside the OutputDevice class const CXXMethodDecl *pCXXMethodDecl = dyn_cast<CXXMethodDecl>(pFunctionDecl); if (pCXXMethodDecl) { if (loplugin::TypeCheck(pCXXMethodDecl->getParent()).Class("OutputDevice").GlobalNamespace()) returntrue;
} // we are only currently interested in methods where the first parameter is RenderContext if (pFunctionDecl->getNumParams() == 0) returntrue; if ( loplugin::TypeCheck(pFunctionDecl->getParamDecl( 0 )->getType()).Class("RenderContext").GlobalNamespace() ) { returntrue;
}
mbChecking = true;
TraverseStmt(pFunctionDecl->getBody());
mbChecking = false; returntrue;
}
bool RenderContext::VisitCXXMemberCallExpr(const CXXMemberCallExpr* pCXXMemberCallExpr)
{ if (!mbChecking) returntrue; if (ignoreLocation(pCXXMemberCallExpr)) { returntrue;
} const CXXRecordDecl *pCXXRecordDecl = pCXXMemberCallExpr->getRecordDecl(); if (!loplugin::TypeCheck(pCXXRecordDecl).Class("OutputDevice").GlobalNamespace()) { returntrue;
} // 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")
{ returntrue;
}
} // for calling through a pointer const ImplicitCastExpr *pImplicitCastExpr = dyn_cast<ImplicitCastExpr>(pCXXMemberCallExpr->getImplicitObjectArgument()); if (pImplicitCastExpr) {
QualType aType = pImplicitCastExpr->getSubExpr()->getType(); if (aType->isPointerType())
aType = aType->getPointeeType();
std::string t2 = aType.getAsString(); if (t2 == "vcl::RenderContext" || t2 == "const vcl::RenderContext") returntrue;
} // for calling through a reference const DeclRefExpr *pDeclRefExpr = dyn_cast<DeclRefExpr>(pCXXMemberCallExpr->getImplicitObjectArgument()); if (pDeclRefExpr) {
QualType aType = pDeclRefExpr->getType();
std::string t2 = aType.getAsString(); if (t2 == "vcl::RenderContext" || t2 == "const vcl::RenderContext") returntrue;
} // for calling through a chain of methods const CXXMemberCallExpr *pMemberExpr = dyn_cast<CXXMemberCallExpr>(pCXXMemberCallExpr->getImplicitObjectArgument()); if (pMemberExpr) {
QualType aType = pMemberExpr->getType(); if (aType->isPointerType())
aType = aType->getPointeeType();
std::string t2 = aType.getAsString(); if (t2 == "vcl::RenderContext" || t2 == "const vcl::RenderContext") returntrue;
}
report(
DiagnosticsEngine::Warning, "Should be calling OutputDevice method through RenderContext.",
pCXXMemberCallExpr->getBeginLoc())
<< pCXXMemberCallExpr->getSourceRange(); returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.