/* -*- 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/.
*/
#include"clang/AST/Attr.h"
#include"config_clang.h"
#include"check.hxx" #include"plugin.hxx"
/* Look for member functions that can be static
*/ namespace {
class StaticMethods: public loplugin::FilteringPlugin<StaticMethods>
{ private: bool bVisitedThis; public: explicit StaticMethods(loplugin::InstantiationData const & data): FilteringPlugin(data), bVisitedThis(false) {}
bool isDerivedFromTestFixture(const CXXRecordDecl *decl) { if (!decl->hasDefinition()) returnfalse; if (// not sure what hasAnyDependentBases() does, // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() &&
!decl->forallBases(BaseCheckNotTestFixtureSubclass)) { returntrue;
} returnfalse;
}
bool StaticMethods::TraverseCXXMethodDecl(const CXXMethodDecl * pCXXMethodDecl) { if (ignoreLocation(pCXXMethodDecl)) { returntrue;
} if (!pCXXMethodDecl->isInstance() || pCXXMethodDecl->isVirtual() || !pCXXMethodDecl->doesThisDeclarationHaveABody() || pCXXMethodDecl->isLateTemplateParsed()) { returntrue;
} if (pCXXMethodDecl->getOverloadedOperator() != OverloadedOperatorKind::OO_None || pCXXMethodDecl->hasAttr<OverrideAttr>()) { returntrue;
} if (isa<CXXConstructorDecl>(pCXXMethodDecl) || isa<CXXDestructorDecl>(pCXXMethodDecl) || isa<CXXConversionDecl>(pCXXMethodDecl)) { returntrue;
} if (isInUnoIncludeFile(pCXXMethodDecl)) { returntrue;
} if (pCXXMethodDecl->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) returntrue;
// the CppUnit stuff uses macros and methods that can't be changed if (isDerivedFromTestFixture(pCXXMethodDecl->getParent())) { returntrue;
} // don't mess with the backwards compatibility stuff if (loplugin::isSamePathname(getFilename(pCXXMethodDecl->getBeginLoc()), SRCDIR "/cppuhelper/source/compat.cxx")) { returntrue;
} // the DDE has a dummy implementation on Linux and a real one on Windows auto aFilename = getFilename(pCXXMethodDecl->getCanonicalDecl()->getBeginLoc()); if (loplugin::isSamePathname(aFilename, SRCDIR "/include/svl/svdde.hxx")) { returntrue;
} auto cdc = loplugin::DeclCheck(pCXXMethodDecl->getParent()); // special case having something to do with static initialisation // sal/osl/all/utility.cxx if (cdc.Class("OGlobalTimer").Namespace("osl").GlobalNamespace()) { returntrue;
} // leave the TopLeft() method alone for consistency with the other "corner" methods if (cdc.Class("BitmapInfoAccess").GlobalNamespace()) { returntrue;
} // there is some odd stuff happening here I don't fully understand, leave it for now if (loplugin::hasPathnamePrefix(aFilename, SRCDIR "/include/canvas/") || loplugin::hasPathnamePrefix(aFilename, SRCDIR "/canvas/")) { returntrue;
} // classes that have static data and some kind of weird reference-counting trick in its constructor if (cdc.Class("LinguOptions").GlobalNamespace()
|| (cdc.Class("EditableExtendedColorConfig").Namespace("svtools")
.GlobalNamespace())
|| (cdc.Class("ExtendedColorConfig").Namespace("svtools")
.GlobalNamespace())
|| cdc.Class("SvtMiscOptions").GlobalNamespace()
|| cdc.Class("SvtAccessibilityOptions").GlobalNamespace()
|| cdc.Class("ColorConfig").Namespace("svtools").GlobalNamespace()
|| cdc.Class("SvtOptionsDrawinglayer").GlobalNamespace()
|| cdc.Class("SvtMenuOptions").GlobalNamespace()
|| cdc.Class("SvtToolPanelOptions").GlobalNamespace()
|| (cdc.Class("SharedResources").Namespace("connectivity")
.GlobalNamespace())
|| (cdc.Class("OParseContextClient").Namespace("svxform")
.GlobalNamespace())
|| cdc.Class("OLimitedFormats").Namespace("frm").GlobalNamespace())
{ returntrue;
}
auto fdc = loplugin::DeclCheck(pCXXMethodDecl);
// somebody has work-in-progress here if ((fdc.Function("getCurrZeroChar")
.Class("LocaleDataWrapper").GlobalNamespace())) returntrue;
// the unotools and svl config code stuff is doing weird stuff with a reference-counted statically allocated pImpl class if ((fdc.Function("getByName2")
.Class("GlobalEventConfig").GlobalNamespace())) returntrue; if ((cdc.Class("SvtLinguConfig").GlobalNamespace())) returntrue; if ((cdc.Class("SvtModuleOptions").GlobalNamespace())) returntrue;
// only empty on Linux, not on windows if ((fdc.Function("GetVisualRepresentationInNativeFormat_Impl")
.Class("OleEmbeddedObject").GlobalNamespace())
|| (fdc.Function("GetRidOfComponent").Class("OleEmbeddedObject")
.GlobalNamespace())
|| cdc.Class("SbxDecimal").GlobalNamespace()
|| fdc.Function("Call").Class("SbiDllMgr").GlobalNamespace()
|| fdc.Function("FreeDll").Class("SbiDllMgr").GlobalNamespace()
|| (fdc.Function("InitializeDde").Class("SfxApplication")
.GlobalNamespace())
|| (fdc.Function("RemoveDdeTopic").Class("SfxApplication")
.GlobalNamespace())
|| (fdc.Function("UpdateSkiaStatus").Class("OfaViewTabPage")
.GlobalNamespace())
|| (fdc.Function("ReleaseData").Class("ScannerManager")
.GlobalNamespace()))
{ returntrue;
} // debugging stuff if (fdc.Function("dump").Class("InternalData").Namespace("chart")
.GlobalNamespace())
{ returntrue;
} // used in a function-pointer-table if ((cdc.Class("SbiRuntime").GlobalNamespace()
&& startsWith(pCXXMethodDecl->getNameAsString(), "Step"))
|| (cdc.Class("OoxFormulaParserImpl").AnonymousNamespace().Namespace("xls").Namespace("oox")
.GlobalNamespace())
|| cdc.Class("SwTableFormula").GlobalNamespace()
|| (cdc.Class("BiffFormulaParserImpl").Namespace("xls").Namespace("oox")
.GlobalNamespace())
|| (fdc.Function("Read_F_Shape").Class("SwWW8ImplReader")
.GlobalNamespace())
|| (fdc.Function("Read_Majority").Class("SwWW8ImplReader")
.GlobalNamespace())
|| fdc.Function("Ignore").Class("SwWrtShell").GlobalNamespace()
|| (cdc.Class("AttributesChecker").AnonymousNamespace().GlobalNamespace()
&& startsWith(pCXXMethodDecl->getNameAsString(), "check")))
{ returntrue;
} // have no idea why this can't be static, but 'make check' fails with it so... if (fdc.Function("resolveRelationshipsOfTypeFromOfficeDoc").Class("Shape")
.Namespace("drawingml").Namespace("oox").GlobalNamespace())
{ returntrue;
} // template magic if (fdc.Function("getValue").Class("ColumnBatch").GlobalNamespace()
|| cdc.Class("TitleImpl").GlobalNamespace()
|| (fdc.Function("getDefaultPropertyName").Class("DefaultReturnHelper")
.Namespace("vba").Namespace("ooo").GlobalNamespace()))
{ returntrue;
} // depends on config options if ((fdc.Function("autoInstallFontLangSupport").Class("PrintFontManager")
.Namespace("psp").GlobalNamespace())
|| fdc.Function("AllocateFrame").Class("GtkSalFrame").GlobalNamespace()
|| (fdc.Function("TriggerPaintEvent").Class("GtkSalFrame")
.GlobalNamespace()))
{ returntrue;
}
bVisitedThis = false;
TraverseStmt(pCXXMethodDecl->getBody()); if (bVisitedThis) { returntrue;
}
if (containsPreprocessingConditionalInclusion((pCXXMethodDecl->getSourceRange()))) { returntrue;
}
report(
DiagnosticsEngine::Warning, "this member function can be declared static",
pCXXMethodDecl->getCanonicalDecl()->getLocation())
<< pCXXMethodDecl->getCanonicalDecl()->getSourceRange();
FunctionDecl const * def; if (pCXXMethodDecl->isDefined(def)
&& def != pCXXMethodDecl->getCanonicalDecl())
{
report(DiagnosticsEngine::Note, "defined here:", def->getLocation())
<< def->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.