1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 #ifndef LO_CLANG_SHARED_PLUGINS
26 class ColorCheck
: public loplugin::FilteringPlugin
<ColorCheck
>
29 explicit ColorCheck(loplugin::InstantiationData
const& data
)
30 : FilteringPlugin(data
)
34 virtual void run() override
37 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
40 bool VisitCXXConstructExpr(const CXXConstructExpr
*);
43 bool ColorCheck::VisitCXXConstructExpr(const CXXConstructExpr
* constructExpr
)
45 if (ignoreLocation(constructExpr
))
48 if (constructExpr
->getNumArgs() != 1)
51 auto tc
= loplugin::TypeCheck(constructExpr
->getType());
52 if (!tc
.Class("Color").GlobalNamespace())
55 StringRef aFileName
= getFilenameOfLocation(
56 compiler
.getSourceManager().getSpellingLoc(compat::getBeginLoc(constructExpr
)));
57 if (loplugin::isSamePathname(aFileName
, SRCDIR
"/include/tools/color.hxx"))
60 const CXXConstructorDecl
* constructorDecl
= constructExpr
->getConstructor();
61 constructorDecl
= constructorDecl
->getCanonicalDecl();
63 if (!loplugin::TypeCheck(constructorDecl
->getParamDecl(0)->getType())
64 .Typedef("sal_uInt32")
68 auto arg0
= constructExpr
->getArg(0);
69 if (arg0
->isCXX11ConstantExpr(compiler
.getASTContext()))
71 if (!arg0
->isValueDependent())
73 llvm::Optional
<llvm::APSInt
> xVal
74 = compat::getIntegerConstantExpr(arg0
, compiler
.getASTContext());
75 if (xVal
&& *xVal
> 0xffffff)
76 report(DiagnosticsEngine::Warning
,
77 "Rather use the ColorTransparency or ColorAlpha version of this constructor",
82 report(DiagnosticsEngine::Warning
,
83 "Rather use the ColorTransparency or ColorAlpha version of this constructor",
89 loplugin::Plugin::Registration
<ColorCheck
> colorcheck("colorcheck");
93 #endif // LO_CLANG_SHARED_PLUGINS
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */