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
19 public loplugin::FilteringPlugin
<UnoAny
>
22 explicit UnoAny(loplugin::InstantiationData
const & data
): FilteringPlugin(data
) {}
24 bool preRun() override
{
25 return compiler
.getLangOpts().CPlusPlus
;
30 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
34 bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr
const * expr
);
37 bool UnoAny::VisitCXXOperatorCallExpr(CXXOperatorCallExpr
const * expr
)
39 if (ignoreLocation(expr
)) {
42 StringRef aFileName
= getFilenameOfLocation(
43 compiler
.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr
)));
44 if (loplugin::isSamePathname(aFileName
, SRCDIR
"/include/com/sun/star/uno/Any.hxx")) {
47 if (expr
->getOperator() != OO_Equal
) {
50 if (!loplugin::TypeCheck(expr
->getArg(0)->getType()).Class("Any").
51 Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace())
55 if (auto expr2
= dyn_cast
<MaterializeTemporaryExpr
>(expr
->getArg(1))) {
56 if (auto expr3
= dyn_cast
<CXXBindTemporaryExpr
>(compat::getSubExpr(expr2
))) {
57 if (auto expr4
= dyn_cast
<CallExpr
>(expr3
->getSubExpr())) {
58 if (loplugin::DeclCheck(expr4
->getDirectCallee()).Function("makeAny").
59 Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace()) {
61 DiagnosticsEngine::Warning
,
62 ("unnecessary copy, rather use <<= operator directly with the 'makeAny'"
64 expr
->getOperatorLoc())
65 << expr
->getSourceRange();
70 if (isa
<CXXFunctionalCastExpr
>(compat::getSubExpr(expr2
))) {
71 //expr->getArg(1)->dump();
73 DiagnosticsEngine::Warning
,
74 ("unnecessary copy, rather use <<= operator directly with the 'Any' constructor"
76 expr
->getOperatorLoc())
77 << expr
->getSourceRange();
81 //expr->getArg(1)->dump();
85 loplugin::Plugin::Registration
<UnoAny
> unoany("unoany");
89 #endif // LO_CLANG_SHARED_PLUGINS
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */