bump product version to 6.4.0.3
[LibreOffice.git] / compilerplugins / clang / unoany.cxx
blobe0360c6cd2deca6264ae3871ba4d6b316449a5c2
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 "check.hxx"
13 #include "plugin.hxx"
15 namespace {
17 class UnoAny:
18 public loplugin::FilteringPlugin<UnoAny>
20 public:
21 explicit UnoAny(loplugin::InstantiationData const & data): FilteringPlugin(data) {}
23 bool preRun() override {
24 return compiler.getLangOpts().CPlusPlus;
27 void run() override {
28 if (preRun()) {
29 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
33 bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr);
36 bool UnoAny::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr)
38 if (ignoreLocation(expr)) {
39 return true;
41 StringRef aFileName = getFilenameOfLocation(
42 compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr)));
43 if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Any.hxx")) {
44 return true;
46 if (expr->getOperator() != OO_Equal) {
47 return true;
49 if (!loplugin::TypeCheck(expr->getArg(0)->getType()).Class("Any").
50 Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace())
52 return true;
54 if (auto expr2 = dyn_cast<MaterializeTemporaryExpr>(expr->getArg(1))) {
55 if (auto expr3 = dyn_cast<CXXBindTemporaryExpr>(expr2->GetTemporaryExpr())) {
56 if (auto expr4 = dyn_cast<CallExpr>(expr3->getSubExpr())) {
57 if (loplugin::DeclCheck(expr4->getDirectCallee()).Function("makeAny").
58 Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace()) {
59 report(
60 DiagnosticsEngine::Warning,
61 ("unnecessary copy, rather use <<= operator directly with the 'makeAny'"
62 " argument"),
63 expr->getOperatorLoc())
64 << expr->getSourceRange();
65 return true;
69 if (isa<CXXFunctionalCastExpr>(expr2->GetTemporaryExpr())) {
70 //expr->getArg(1)->dump();
71 report(
72 DiagnosticsEngine::Warning,
73 ("unnecessary copy, rather use <<= operator directly with the 'Any' constructor"
74 " argument"),
75 expr->getOperatorLoc())
76 << expr->getSourceRange();
77 return true;
80 //expr->getArg(1)->dump();
81 return true;
84 loplugin::Plugin::Registration<UnoAny> unoany("unoany");
86 } // namespace
88 #endif // LO_CLANG_SHARED_PLUGINS
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */