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
18 public loplugin::FilteringPlugin
<UnoAny
>
21 explicit UnoAny(loplugin::InstantiationData
const & data
): FilteringPlugin(data
) {}
23 bool preRun() override
{
24 return compiler
.getLangOpts().CPlusPlus
;
29 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
33 bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr
const * expr
);
36 bool UnoAny::VisitCXXOperatorCallExpr(CXXOperatorCallExpr
const * expr
)
38 if (ignoreLocation(expr
)) {
41 StringRef aFileName
= getFilenameOfLocation(
42 compiler
.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr
)));
43 if (loplugin::isSamePathname(aFileName
, SRCDIR
"/include/com/sun/star/uno/Any.hxx")) {
46 if (expr
->getOperator() != OO_Equal
) {
49 if (!loplugin::TypeCheck(expr
->getArg(0)->getType()).Class("Any").
50 Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace())
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()) {
60 DiagnosticsEngine::Warning
,
61 ("unnecessary copy, rather use <<= operator directly with the 'makeAny'"
63 expr
->getOperatorLoc())
64 << expr
->getSourceRange();
69 if (isa
<CXXFunctionalCastExpr
>(expr2
->GetTemporaryExpr())) {
70 //expr->getArg(1)->dump();
72 DiagnosticsEngine::Warning
,
73 ("unnecessary copy, rather use <<= operator directly with the 'Any' constructor"
75 expr
->getOperatorLoc())
76 << expr
->getSourceRange();
80 //expr->getArg(1)->dump();
84 loplugin::Plugin::Registration
<UnoAny
> unoany("unoany");
88 #endif // LO_CLANG_SHARED_PLUGINS
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */