1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 #include <unordered_set>
17 #include <clang/AST/CXXInheritance.h>
19 #include "config_clang.h"
30 class PutPoolItem
: public loplugin::FilteringPlugin
<PutPoolItem
>
33 explicit PutPoolItem(loplugin::InstantiationData
const& data
)
34 : FilteringPlugin(data
)
38 virtual bool preRun() override
40 // StringRef fn(handler.getMainFileName());
41 // if (loplugin::isSamePathname(fn, WORKDIR "/YaccTarget/unoidl/source/sourceprovider-parser.cxx"))
45 virtual void run() override
48 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
51 bool VisitCXXMemberCallExpr(const CXXMemberCallExpr
*);
52 bool VisitFunctionDecl(const FunctionDecl
*)
54 // if (f->getIdentifier() && f->getName() == "foo")
60 bool PutPoolItem::VisitCXXMemberCallExpr(const CXXMemberCallExpr
* cxxCallExpr
)
62 if (ignoreLocation(cxxCallExpr
))
64 auto tc
= loplugin::TypeCheck(cxxCallExpr
->getObjectType());
65 if (!tc
.Class("SfxItemSet"))
67 if (!cxxCallExpr
->getMethodDecl()->getIdentifier()
68 || cxxCallExpr
->getMethodDecl()->getName() != "Put")
70 auto argExpr
= dyn_cast
<CXXOperatorCallExpr
>(cxxCallExpr
->getArg(0)->IgnoreImplicit());
73 if (argExpr
->getOperator() != OO_Star
)
75 auto ptrExpr
= argExpr
->getArg(0)->IgnoreImplicit();
76 auto tc2
= loplugin::TypeCheck(ptrExpr
->getType());
77 if (!tc2
.Class("unique_ptr"))
79 // ignore calls when we are passing a copy of a member field
80 if (isa
<MemberExpr
>(ptrExpr
))
83 StringRef fn
= getFilenameOfLocation(
84 compiler
.getSourceManager().getSpellingLoc(cxxCallExpr
->getBeginLoc()));
85 if (loplugin::isSamePathname(fn
, SRCDIR
"/sc/source/ui/app/inputwin.cxx")
86 || loplugin::isSamePathname(fn
, SRCDIR
"/sc/source/ui/dbgui/csvgrid.cxx")
87 || loplugin::isSamePathname(fn
, SRCDIR
"/sw/source/uibase/shells/basesh.cxx")
88 || loplugin::isSamePathname(fn
, SRCDIR
"/sw/source/uibase/shells/textsh.cxx")
89 || loplugin::isSamePathname(fn
, SRCDIR
"/sw/source/filter/xml/xmlimpit.cxx")
90 || loplugin::isSamePathname(fn
, SRCDIR
"/sw/source/uibase/shells/tabsh.cxx"))
95 report(DiagnosticsEngine::Warning
, "could use std::move?", cxxCallExpr
->getBeginLoc())
96 << cxxCallExpr
->getSourceRange();
100 loplugin::Plugin::Registration
<PutPoolItem
> putpoolitem("putpoolitem", true);
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */