/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * Based on LLVM/Clang. * * This file is distributed under the University of Illinois Open Source * License. See LICENSE.TXT for details. *
*/
class UnusedVariablePlus : public loplugin::FilteringPlugin<UnusedVariablePlus>
{ public: explicit UnusedVariablePlus(loplugin::InstantiationData const& data)
: FilteringPlugin(data)
{
}
virtualbool preRun() override
{
std::string fn(handler.getMainFileName());
loplugin::normalizeDotDotInFilePath(fn); if (loplugin::hasPathnamePrefix(fn, SRCDIR "/canvas/workben/")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/vcl/source/uipreviewer/previewer.cxx")) returnfalse; if (loplugin::hasPathnamePrefix(fn, SRCDIR "/vcl/workben/")) returnfalse; if (loplugin::hasPathnamePrefix(fn, SRCDIR "/vcl/qa/")) returnfalse; if (loplugin::hasPathnamePrefix(fn, SRCDIR "/vcl/backendtest/")) returnfalse; if (loplugin::hasPathnamePrefix(fn, SRCDIR "/lotuswordpro/")) returnfalse; if (loplugin::hasPathnamePrefix(fn, SRCDIR "/salhelper/qa/")) returnfalse; if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sal/qa/")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/idl/source/prj/svidl.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/sot/source/unoolestorage/xolesimplestorage.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/core/tool/interpr7.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/ui/vba/vbaapplication.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/sw/source/core/doc/doccomp.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/sw/source/core/swg/SwXMLTextBlocks.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/sw/source/filter/ww8/wrtw8esh.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/shell/source/sessioninstall/SyncDbusSessionHelper.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/svl/qa/unit/items/test_IndexedStyleSheets.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/sd/qa/unit/export-tests-ooxml2.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/sc/qa/unit/subsequent_export-test.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/vcl/skia/SkiaHelper.cxx")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/svx/source/dialog/dlgctrl.cxx")) returnfalse;
// clang has a bug here, with vars in destructing assignments if (loplugin::hasPathnamePrefix(fn, SRCDIR "/binaryurp/")) returnfalse; if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/filter/excel/xestring.cxx")) returnfalse; returntrue;
}
virtualvoid run() override
{ if (preRun())
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
bool VisitVarDecl(const VarDecl* var)
{ if (ignoreLocation(var)) returntrue; if (var->isReferenced() || var->isUsed()) returntrue; if (var->isDefinedOutsideFunctionOrMethod()) returntrue; if (var->isExceptionVariable()) // not interesting returntrue; if (isa<DecompositionDecl>(var)) returntrue;
if (var->getIdentifier())
{ auto name = var->getName(); if (name == "aBroadcastGuard" || name == "aDeleteRef" || name == "aGuard"
|| name == "aGuard2" || name == "aHoldSelf" || name == "aKeepDoc"
|| name == "aAutoRegistration" || name == "aLoadContentIfExists"
|| name == "aOwnRef" || name == "createImpl" || name == "flyHolder"
|| name == "guard" || name == "ensureDelete" || name == "s_xTerminateListener"
|| name == "pThis" || name == "pOldViewShell" || name == "self"
|| name == "xDocStor" || name == "xDeleteUponLeaving" || name == "xDeleteRef"
|| name == "xHoldAlive" || name == "xHolder" || name == "xHoldRefForMethodAlive"
|| name == "xLock" || name == "xMutexGuard" || name == "xKeepAlive"
|| name == "xKeepContentHolderAlive" || name == "xKeepDocAlive"
|| name == "xKeepMeAlive" || name == "xKeepProviderAlive"
|| name == "xOperationHold" || name == "xPreventDelete" || name == "xSelf"
|| name == "xSelfHold" || name == "xTempHold" || name == "xDisposeAfterNewOne"
|| name == "xThis" || name == "xThisPackage" || name == "xTriggerInit"
|| name == "xLifeCycle" || name == "xAnotherLifeCycle") returntrue;
}
if (isa<ParmVarDecl>(var)) returntrue;
if (typeName.find("Reference") != std::string::npos && var->getInit())
{ if (auto cxxConstructExpr
= dyn_cast<CXXConstructExpr>(var->getInit()->IgnoreImplicit())) if (cxxConstructExpr->getNumArgs() == 2) if (auto param1 = dyn_cast<DeclRefExpr>(cxxConstructExpr->getArg(1))) if (auto enumDecl = dyn_cast<EnumConstantDecl>(param1->getDecl())) if (enumDecl->getName() == "UNO_QUERY_THROW"
|| enumDecl->getName() == "UNO_SET_THROW") returntrue;
}
report(DiagnosticsEngine::Warning, "unused variable %0 of type %1", var->getLocation())
<< var->getDeclName() << typeName;
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 ist noch experimentell.