Remove exec bits from docx
[LibreOffice.git] / compilerplugins / clang / unoany.cxx
blob0ab5657c1d03ea4e406b3f99afbbf9d3013519e7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 #ifndef LO_CLANG_SHARED_PLUGINS
12 #include "config_clang.h"
14 #include "check.hxx"
15 #include "plugin.hxx"
17 namespace {
19 class UnoAny:
20 public loplugin::FilteringPlugin<UnoAny>
22 public:
23 explicit UnoAny(loplugin::InstantiationData const & data): FilteringPlugin(data) {}
25 bool preRun() override {
26 return compiler.getLangOpts().CPlusPlus;
29 void run() override {
30 if (preRun()) {
31 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
35 bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr);
38 bool UnoAny::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr)
40 if (ignoreLocation(expr)) {
41 return true;
43 StringRef aFileName = getFilenameOfLocation(
44 compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc()));
45 if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Any.hxx")) {
46 return true;
48 if (expr->getOperator() != OO_Equal) {
49 return true;
51 if (!loplugin::TypeCheck(expr->getArg(0)->getType()).Class("Any").
52 Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace())
54 return true;
56 if (auto expr2 = dyn_cast<MaterializeTemporaryExpr>(expr->getArg(1))) {
57 if (auto expr3 = dyn_cast<CXXBindTemporaryExpr>(expr2->getSubExpr())) {
58 if (auto expr4 = dyn_cast<CallExpr>(expr3->getSubExpr())) {
59 if (loplugin::DeclCheck(expr4->getDirectCallee()).Function("makeAny").
60 Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace()) {
61 report(
62 DiagnosticsEngine::Warning,
63 ("unnecessary copy, rather use <<= operator directly with the 'makeAny'"
64 " argument"),
65 expr->getOperatorLoc())
66 << expr->getSourceRange();
67 return true;
71 if (isa<CXXFunctionalCastExpr>(expr2->getSubExpr())) {
72 //expr->getArg(1)->dump();
73 report(
74 DiagnosticsEngine::Warning,
75 ("unnecessary copy, rather use <<= operator directly with the 'Any' constructor"
76 " argument"),
77 expr->getOperatorLoc())
78 << expr->getSourceRange();
79 return true;
82 //expr->getArg(1)->dump();
83 return true;
86 loplugin::Plugin::Registration<UnoAny> unoany("unoany");
88 } // namespace
90 #endif // LO_CLANG_SHARED_PLUGINS
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */