/* -*- 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/.
*/ #ifndef LO_CLANG_SHARED_PLUGINS
bool RedundantPointerOps::VisitFunctionDecl(FunctionDecl const * functionDecl)
{ if (ignoreLocation(functionDecl)) returntrue; // if (functionDecl->getIdentifier() && functionDecl->getName() == "function6b") // functionDecl->dump(); returntrue;
}
bool RedundantPointerOps::VisitMemberExpr(MemberExpr const * memberExpr)
{ if (ignoreLocation(memberExpr)) returntrue; if (memberExpr->getBeginLoc().isMacroID()) returntrue; auto base = memberExpr->getBase()->IgnoreParenImpCasts(); //parentStmt(parentStmt(memberExpr))->dump(); if (memberExpr->isArrow())
{ if (auto unaryOp = dyn_cast<UnaryOperator>(base))
{ if (unaryOp->getOpcode() == UO_AddrOf)
report(
DiagnosticsEngine::Warning, "'&' followed by '->' operating on %0, rather use '.'",
memberExpr->getBeginLoc())
<< memberExpr->getBase()->getType()->getPointeeType()
<< memberExpr->getSourceRange();
} elseif (auto operatorCallExpr = dyn_cast<CXXOperatorCallExpr>(base))
{ if (operatorCallExpr->getOperator() == OO_Amp)
report(
DiagnosticsEngine::Warning, "'&' followed by '->' operating on %0, rather use '.'",
memberExpr->getBeginLoc())
<< memberExpr->getBase()->getType()->getPointeeType()
<< memberExpr->getSourceRange();
} elseif (auto cxxMemberCallExpr = dyn_cast<CXXMemberCallExpr>(base))
{ auto methodDecl = cxxMemberCallExpr->getMethodDecl(); if (methodDecl->getIdentifier() && methodDecl->getName() == "get")
{ autoconst e = cxxMemberCallExpr->getImplicitObjectArgument(); if (loplugin::isSmartPointerType(e))
report(
DiagnosticsEngine::Warning, "'get()' followed by '->' operating on %0, just use '->'",
memberExpr->getBeginLoc())
<< e->IgnoreImpCasts()->getType().getLocalUnqualifiedType()
<< memberExpr->getSourceRange();
}
}
} // else // { // if (auto unaryOp = dyn_cast<UnaryOperator>(base)) // { // if (unaryOp->getOpcode() == UO_Deref) // report( // DiagnosticsEngine::Warning, "'*' followed by '.', rather use '->'", // memberExpr->getLocStart()) // << memberExpr->getSourceRange(); // // } // } returntrue;
}
bool RedundantPointerOps::VisitUnaryOperator(UnaryOperator const * unaryOperator)
{ if (ignoreLocation(unaryOperator)) returntrue; if (unaryOperator->getBeginLoc().isMacroID()) returntrue; if (unaryOperator->getOpcode() != UO_Deref) returntrue; auto subExpr = unaryOperator->getSubExpr()->IgnoreParenImpCasts(); auto innerOp = dyn_cast<UnaryOperator>(subExpr); if (innerOp && innerOp->getOpcode() == UO_AddrOf)
report(
DiagnosticsEngine::Warning, "'&' followed by '*' operating on %0, rather use '.'",
unaryOperator->getBeginLoc())
<< innerOp->getSubExpr()->getType() << unaryOperator->getSourceRange(); if (auto cxxMemberCallExpr = dyn_cast<CXXMemberCallExpr>(subExpr))
{ auto methodDecl = cxxMemberCallExpr->getMethodDecl(); if (methodDecl->getIdentifier() && methodDecl->getName() == "get")
{ autoconst e = cxxMemberCallExpr->getImplicitObjectArgument(); if (loplugin::isSmartPointerType(e))
report(
DiagnosticsEngine::Warning, "'*' followed by '.get()' operating on %0, just use '*'",
unaryOperator->getBeginLoc())
<< e->IgnoreImpCasts()->getType().getLocalUnqualifiedType()
<< unaryOperator->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.