Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / compilerplugins / clang / store / putpoolitem.cxx
blob8080599973bd7b56a0ecd3fb6ef47acdb9a099fe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <cassert>
11 #include <string>
12 #include <iostream>
13 #include <fstream>
14 #include <set>
15 #include <unordered_set>
17 #include <clang/AST/CXXInheritance.h>
19 #include "config_clang.h"
21 #include "plugin.hxx"
22 #include "check.hxx"
24 /**
28 namespace
30 class PutPoolItem : public loplugin::FilteringPlugin<PutPoolItem>
32 public:
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"))
42 // return false;
43 return true;
45 virtual void run() override
47 if (preRun())
48 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
51 bool VisitCXXMemberCallExpr(const CXXMemberCallExpr*);
52 bool VisitFunctionDecl(const FunctionDecl*)
54 // if (f->getIdentifier() && f->getName() == "foo")
55 // f->dump();
56 return true;
60 bool PutPoolItem::VisitCXXMemberCallExpr(const CXXMemberCallExpr* cxxCallExpr)
62 if (ignoreLocation(cxxCallExpr))
63 return true;
64 auto tc = loplugin::TypeCheck(cxxCallExpr->getObjectType());
65 if (!tc.Class("SfxItemSet"))
66 return true;
67 if (!cxxCallExpr->getMethodDecl()->getIdentifier()
68 || cxxCallExpr->getMethodDecl()->getName() != "Put")
69 return true;
70 auto argExpr = dyn_cast<CXXOperatorCallExpr>(cxxCallExpr->getArg(0)->IgnoreImplicit());
71 if (!argExpr)
72 return true;
73 if (argExpr->getOperator() != OO_Star)
74 return true;
75 auto ptrExpr = argExpr->getArg(0)->IgnoreImplicit();
76 auto tc2 = loplugin::TypeCheck(ptrExpr->getType());
77 if (!tc2.Class("unique_ptr"))
78 return true;
79 // ignore calls when we are passing a copy of a member field
80 if (isa<MemberExpr>(ptrExpr))
81 return true;
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"))
91 return true;
93 // argExpr->dump();
95 report(DiagnosticsEngine::Warning, "could use std::move?", cxxCallExpr->getBeginLoc())
96 << cxxCallExpr->getSourceRange();
97 return true;
100 loplugin::Plugin::Registration<PutPoolItem> putpoolitem("putpoolitem", true);
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */