1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #ifndef LO_CLANG_SHARED_PLUGINS
12 #include "config_clang.h"
20 public loplugin::FilteringPlugin
<UnoAny
>
23 explicit UnoAny(loplugin::InstantiationData
const & data
): FilteringPlugin(data
) {}
25 bool preRun() override
{
26 return compiler
.getLangOpts().CPlusPlus
;
31 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
35 bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr
const * expr
);
38 bool UnoAny::VisitCXXOperatorCallExpr(CXXOperatorCallExpr
const * expr
)
40 if (ignoreLocation(expr
)) {
43 StringRef aFileName
= getFilenameOfLocation(
44 compiler
.getSourceManager().getSpellingLoc(expr
->getBeginLoc()));
45 if (loplugin::isSamePathname(aFileName
, SRCDIR
"/include/com/sun/star/uno/Any.hxx")) {
48 if (expr
->getOperator() != OO_Equal
) {
51 if (!loplugin::TypeCheck(expr
->getArg(0)->getType()).Class("Any").
52 Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace())
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()) {
62 DiagnosticsEngine::Warning
,
63 ("unnecessary copy, rather use <<= operator directly with the 'makeAny'"
65 expr
->getOperatorLoc())
66 << expr
->getSourceRange();
71 if (isa
<CXXFunctionalCastExpr
>(expr2
->getSubExpr())) {
72 //expr->getArg(1)->dump();
74 DiagnosticsEngine::Warning
,
75 ("unnecessary copy, rather use <<= operator directly with the 'Any' constructor"
77 expr
->getOperatorLoc())
78 << expr
->getSourceRange();
82 //expr->getArg(1)->dump();
86 loplugin::Plugin::Registration
<UnoAny
> unoany("unoany");
90 #endif // LO_CLANG_SHARED_PLUGINS
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */