forked from amazingfate/loongoffice
loplugin:unusedfields
Change-Id: Ib574403a7f7f8b11c6263c9c19ec6b65c8374ddd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115753 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@ -165,6 +165,8 @@ public:
|
||||
|
||||
private:
|
||||
MyFieldInfo niceName(const FieldDecl*);
|
||||
bool ignoreLocation(SourceLocation loc);
|
||||
bool checkIgnoreLocation(SourceLocation loc);
|
||||
void checkTouchedFromOutside(const FieldDecl* fieldDecl, const Expr* memberExpr);
|
||||
void checkIfReadFrom(const FieldDecl* fieldDecl, const Expr* memberExpr);
|
||||
void checkIfWrittenTo(const FieldDecl* fieldDecl, const Expr* memberExpr);
|
||||
@ -281,10 +283,46 @@ MyFieldInfo UnusedFields::niceName(const FieldDecl* fieldDecl)
|
||||
return aInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Our need to see everything conflicts with the PCH code in pluginhandler::ignoreLocation,
|
||||
* so we have to do this ourselves.
|
||||
*/
|
||||
bool UnusedFields::ignoreLocation(SourceLocation loc)
|
||||
{
|
||||
static std::unordered_map<SourceLocation, bool> checkedMap;
|
||||
auto it = checkedMap.find(loc);
|
||||
if (it != checkedMap.end())
|
||||
return it->second;
|
||||
bool ignore = checkIgnoreLocation(loc);
|
||||
checkedMap.emplace(loc, ignore);
|
||||
return ignore;
|
||||
}
|
||||
|
||||
bool UnusedFields::checkIgnoreLocation(SourceLocation loc)
|
||||
{
|
||||
// simplified form of the code in PluginHandler::checkIgnoreLocation
|
||||
SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( loc );
|
||||
if( compiler.getSourceManager().isInSystemHeader( expansionLoc ))
|
||||
return true;
|
||||
PresumedLoc presumedLoc = compiler.getSourceManager().getPresumedLoc( expansionLoc );
|
||||
if( presumedLoc.isInvalid())
|
||||
return true;
|
||||
const char* bufferName = presumedLoc.getFilename();
|
||||
if (bufferName == NULL
|
||||
|| loplugin::hasPathnamePrefix(bufferName, SRCDIR "/external/")
|
||||
|| loplugin::hasPathnamePrefix(bufferName, WORKDIR "/"))
|
||||
return true;
|
||||
if( loplugin::hasPathnamePrefix(bufferName, BUILDDIR "/")
|
||||
|| loplugin::hasPathnamePrefix(bufferName, SRCDIR "/") )
|
||||
return false; // ok
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool UnusedFields::VisitFieldDecl( const FieldDecl* fieldDecl )
|
||||
{
|
||||
fieldDecl = fieldDecl->getCanonicalDecl();
|
||||
if (ignoreLocation( fieldDecl )) {
|
||||
if (ignoreLocation( compat::getBeginLoc(fieldDecl) )) {
|
||||
return true;
|
||||
}
|
||||
// ignore stuff that forms part of the stable URE interface
|
||||
@ -392,7 +430,7 @@ bool startswith(const std::string& rStr, const char* pSubStr)
|
||||
bool UnusedFields::TraverseCXXConstructorDecl(CXXConstructorDecl* cxxConstructorDecl)
|
||||
{
|
||||
auto copy = insideMoveOrCopyOrCloneDeclParent;
|
||||
if (!ignoreLocation(cxxConstructorDecl) && cxxConstructorDecl->isThisDeclarationADefinition())
|
||||
if (!ignoreLocation(compat::getBeginLoc(cxxConstructorDecl)) && cxxConstructorDecl->isThisDeclarationADefinition())
|
||||
{
|
||||
if (cxxConstructorDecl->isCopyOrMoveConstructor())
|
||||
insideMoveOrCopyOrCloneDeclParent = cxxConstructorDecl->getParent();
|
||||
@ -406,7 +444,7 @@ bool UnusedFields::TraverseCXXMethodDecl(CXXMethodDecl* cxxMethodDecl)
|
||||
{
|
||||
auto copy1 = insideMoveOrCopyOrCloneDeclParent;
|
||||
auto copy2 = insideFunctionDecl;
|
||||
if (!ignoreLocation(cxxMethodDecl) && cxxMethodDecl->isThisDeclarationADefinition())
|
||||
if (!ignoreLocation(compat::getBeginLoc(cxxMethodDecl)) && cxxMethodDecl->isThisDeclarationADefinition())
|
||||
{
|
||||
if (cxxMethodDecl->isCopyAssignmentOperator()
|
||||
|| cxxMethodDecl->isMoveAssignmentOperator()
|
||||
@ -433,7 +471,7 @@ bool UnusedFields::TraverseFunctionDecl(FunctionDecl* functionDecl)
|
||||
auto copy1 = insideStreamOutputOperator;
|
||||
auto copy2 = insideFunctionDecl;
|
||||
auto copy3 = insideMoveOrCopyOrCloneDeclParent;
|
||||
if (functionDecl->getLocation().isValid() && !ignoreLocation(functionDecl) && functionDecl->isThisDeclarationADefinition())
|
||||
if (functionDecl->getLocation().isValid() && !ignoreLocation(compat::getBeginLoc(functionDecl)) && functionDecl->isThisDeclarationADefinition())
|
||||
{
|
||||
auto op = functionDecl->getOverloadedOperator();
|
||||
if (op == OO_LessLess
|
||||
@ -500,7 +538,7 @@ bool UnusedFields::VisitMemberExpr( const MemberExpr* memberExpr )
|
||||
return true;
|
||||
}
|
||||
fieldDecl = fieldDecl->getCanonicalDecl();
|
||||
if (ignoreLocation(fieldDecl)) {
|
||||
if (ignoreLocation(compat::getBeginLoc(fieldDecl))) {
|
||||
return true;
|
||||
}
|
||||
// ignore stuff that forms part of the stable URE interface
|
||||
@ -1074,7 +1112,7 @@ bool UnusedFields::IsPassedByNonConst(const FieldDecl* fieldDecl, const Stmt * c
|
||||
// have to do it here
|
||||
bool UnusedFields::VisitCXXConstructorDecl( const CXXConstructorDecl* cxxConstructorDecl )
|
||||
{
|
||||
if (ignoreLocation( cxxConstructorDecl )) {
|
||||
if (ignoreLocation( compat::getBeginLoc(cxxConstructorDecl) )) {
|
||||
return true;
|
||||
}
|
||||
// ignore stuff that forms part of the stable URE interface
|
||||
@ -1107,7 +1145,7 @@ bool UnusedFields::VisitCXXConstructorDecl( const CXXConstructorDecl* cxxConstru
|
||||
// have to do it here.
|
||||
bool UnusedFields::VisitInitListExpr( const InitListExpr* initListExpr)
|
||||
{
|
||||
if (ignoreLocation( initListExpr ))
|
||||
if (ignoreLocation( compat::getBeginLoc(initListExpr) ))
|
||||
return true;
|
||||
|
||||
QualType varType = initListExpr->getType().getDesugaredType(compiler.getASTContext());
|
||||
@ -1133,7 +1171,7 @@ bool UnusedFields::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
|
||||
return true;
|
||||
}
|
||||
fieldDecl = fieldDecl->getCanonicalDecl();
|
||||
if (ignoreLocation(fieldDecl)) {
|
||||
if (ignoreLocation(compat::getBeginLoc(fieldDecl))) {
|
||||
return true;
|
||||
}
|
||||
// ignore stuff that forms part of the stable URE interface
|
||||
|
||||
@ -35,9 +35,6 @@ class VclMetaFileProcessor2DTest : public test::BootstrapFixture
|
||||
{
|
||||
VclPtr<VirtualDevice> mVclDevice;
|
||||
uno::Reference<rendering::XCanvas> mCanvas;
|
||||
rendering::ViewState mViewState;
|
||||
rendering::RenderState mRenderState;
|
||||
uno::Sequence<double> mColorBlack;
|
||||
|
||||
// if enabled - check the result images with:
|
||||
// "xdg-open ./workdir/CppunitTest/drawinglayer_processors.test.core/"
|
||||
@ -59,18 +56,6 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual void setUp() override
|
||||
{
|
||||
BootstrapFixture::setUp();
|
||||
mColorBlack = vcl::unotools::colorToStdColorSpaceSequence(COL_BLACK);
|
||||
// Geometry init
|
||||
com::sun::star::geometry::AffineMatrix2D aUnit(1, 0, 0, 0, 1, 0);
|
||||
mViewState.AffineTransform = aUnit;
|
||||
mRenderState.AffineTransform = aUnit;
|
||||
mRenderState.DeviceColor = mColorBlack;
|
||||
mRenderState.CompositeOperation = rendering::CompositeOperation::OVER;
|
||||
}
|
||||
|
||||
virtual void tearDown() override
|
||||
{
|
||||
mVclDevice.clear();
|
||||
|
||||
@ -808,7 +808,6 @@ class TransClipHandler
|
||||
bool mbWasCut;
|
||||
bool mbIncludeFiltered;
|
||||
InsertDeleteFlags mnFlags;
|
||||
std::vector<SCROW>& mrFilteredRows;
|
||||
|
||||
ScAddress getDestPos(size_t nRow) const
|
||||
{
|
||||
@ -851,7 +850,6 @@ public:
|
||||
, mbWasCut(bWasCut)
|
||||
, mbIncludeFiltered(bIncludeFiltered)
|
||||
, mnFlags(nFlags)
|
||||
, mrFilteredRows(rFilteredRows)
|
||||
{
|
||||
// Create list of filtered rows.
|
||||
if (!mbIncludeFiltered)
|
||||
@ -861,7 +859,7 @@ public:
|
||||
// maybe this loop could be optimized
|
||||
bool bFiltered = mrSrcTab.RowFiltered(curRow, nullptr, nullptr);
|
||||
if (bFiltered)
|
||||
mrFilteredRows.push_back(curRow);
|
||||
rFilteredRows.push_back(curRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +72,6 @@ private:
|
||||
std::unique_ptr<weld::TreeView> mpCommandTreeView;
|
||||
|
||||
std::vector<CurrentEntry> maCommandList;
|
||||
OUString m_PreviousText;
|
||||
std::unique_ptr<MenuContentHandler> mpMenuContentHandler;
|
||||
|
||||
DECL_LINK(QueryTooltip, const weld::TreeIter&, OUString);
|
||||
|
||||
@ -56,7 +56,6 @@ protected:
|
||||
std::unique_ptr<weld::Container> mxTitlebar;
|
||||
std::unique_ptr<weld::Image> mxAddonImage;
|
||||
std::unique_ptr<weld::Toolbar> mxToolBox;
|
||||
std::unique_ptr<ToolbarUnoDispatcher> mxToolBoxController;
|
||||
Theme::ThemeItem meThemeItem;
|
||||
|
||||
virtual void HandleToolBoxItemClick() = 0;
|
||||
|
||||
@ -201,7 +201,6 @@ class SwCalc
|
||||
sal_Int32 m_nCommandPos;
|
||||
|
||||
SwDoc& m_rDoc;
|
||||
SvtSysLocale m_aSysLocale;
|
||||
std::unique_ptr<LocaleDataWrapper> m_xLocaleDataWrapper;
|
||||
CharClass* m_pCharClass;
|
||||
|
||||
|
||||
@ -57,12 +57,10 @@ namespace sw {
|
||||
SwContentFrame*& m_rpContentFrame;
|
||||
const SwDoc& m_rDoc;
|
||||
const SwRootFrame& m_rLayout;
|
||||
const bool m_isReadOnlyAvailable;
|
||||
FindContentFrameHint(SwContentFrame*& rpContentFrame, const SwDoc& rDoc, const SwRootFrame& rLayout, const bool isReadOnlyAvailable)
|
||||
FindContentFrameHint(SwContentFrame*& rpContentFrame, const SwDoc& rDoc, const SwRootFrame& rLayout)
|
||||
: m_rpContentFrame(rpContentFrame)
|
||||
, m_rDoc(rDoc)
|
||||
, m_rLayout(rLayout)
|
||||
, m_isReadOnlyAvailable(isReadOnlyAvailable)
|
||||
{}
|
||||
};
|
||||
struct CollectTextTOXMarksForLayoutHint final : SfxHint {
|
||||
@ -188,10 +186,10 @@ public:
|
||||
SwDoc& GetDoc() const { return m_rDoc; }
|
||||
void CollectTextMarks(SwTOXMarks& rMarks) const
|
||||
{ const_cast<SwTOXType*>(this)->GetNotifier().Broadcast(sw::CollectTextMarksHint(rMarks)); }
|
||||
SwContentFrame* FindContentFrame(const SwDoc& rDoc, const SwRootFrame& rLayout, const bool isReadOnlyAvailable) const
|
||||
SwContentFrame* FindContentFrame(const SwDoc& rDoc, const SwRootFrame& rLayout) const
|
||||
{
|
||||
SwContentFrame* pContentFrame = nullptr;
|
||||
const_cast<SwTOXType*>(this)->GetNotifier().Broadcast(sw::FindContentFrameHint(pContentFrame, rDoc, rLayout, isReadOnlyAvailable));
|
||||
const_cast<SwTOXType*>(this)->GetNotifier().Broadcast(sw::FindContentFrameHint(pContentFrame, rDoc, rLayout));
|
||||
return pContentFrame;
|
||||
}
|
||||
void CollectTextTOXMarksForLayout(std::vector<std::reference_wrapper<SwTextTOXMark>>& rMarks, const SwRootFrame* pLayout) const
|
||||
|
||||
@ -375,7 +375,7 @@ void SwCursorShell::GotoTOXMarkBase()
|
||||
return;
|
||||
// Take the 1. and get the index type. Ask it for the actual index.
|
||||
const SwTOXType* pType = aMarks[0]->GetTOXType();
|
||||
auto pContentFrame = pType->FindContentFrame(*GetDoc(), *GetLayout(), IsReadOnlyAvailable());
|
||||
auto pContentFrame = pType->FindContentFrame(*GetDoc(), *GetLayout());
|
||||
SwCallLink aLk(*this); // watch Cursor-Moves
|
||||
SwCursorSaveState aSaveState(*m_pCurrentCursor);
|
||||
assert(pContentFrame->IsTextFrame());
|
||||
|
||||
@ -41,7 +41,6 @@ using namespace ::com::sun::star;
|
||||
/// Sample tests for import
|
||||
class XmlScriptTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools
|
||||
{
|
||||
uno::Reference<lang::XComponent> mxComponent;
|
||||
OUString maDataPath;
|
||||
|
||||
void testBasicElements();
|
||||
@ -53,7 +52,6 @@ class XmlScriptTest : public test::BootstrapFixture, public unotest::MacrosTest,
|
||||
|
||||
public:
|
||||
virtual void setUp() override;
|
||||
virtual void tearDown() override;
|
||||
|
||||
virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override
|
||||
{
|
||||
@ -76,14 +74,6 @@ void XmlScriptTest::setUp()
|
||||
mxDesktop.set(frame::Desktop::create(mxComponentContext));
|
||||
}
|
||||
|
||||
void XmlScriptTest::tearDown()
|
||||
{
|
||||
if (mxComponent.is())
|
||||
mxComponent->dispose();
|
||||
|
||||
test::BootstrapFixture::tearDown();
|
||||
}
|
||||
|
||||
Reference<container::XNameContainer> XmlScriptTest::importFile(std::u16string_view sFileName)
|
||||
{
|
||||
OUString sFullName = m_directories.getURLFromSrc(maDataPath) + sFileName;
|
||||
|
||||
Reference in New Issue
Block a user