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
18 #include "config_clang.h"
29 class ColorCheck
: public loplugin::FilteringPlugin
<ColorCheck
>
32 explicit ColorCheck(loplugin::InstantiationData
const& data
)
33 : FilteringPlugin(data
)
37 virtual void run() override
40 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
43 bool VisitCXXConstructExpr(const CXXConstructExpr
*);
46 bool ColorCheck::VisitCXXConstructExpr(const CXXConstructExpr
* constructExpr
)
48 if (ignoreLocation(constructExpr
))
51 if (constructExpr
->getNumArgs() != 1)
54 auto tc
= loplugin::TypeCheck(constructExpr
->getType());
55 if (!tc
.Class("Color").GlobalNamespace())
58 StringRef aFileName
= getFilenameOfLocation(
59 compiler
.getSourceManager().getSpellingLoc(constructExpr
->getBeginLoc()));
60 if (loplugin::isSamePathname(aFileName
, SRCDIR
"/include/tools/color.hxx"))
63 const CXXConstructorDecl
* constructorDecl
= constructExpr
->getConstructor();
64 constructorDecl
= constructorDecl
->getCanonicalDecl();
66 if (!loplugin::TypeCheck(constructorDecl
->getParamDecl(0)->getType())
67 .Typedef("sal_uInt32")
71 auto arg0
= constructExpr
->getArg(0);
72 if (arg0
->isCXX11ConstantExpr(compiler
.getASTContext()))
74 if (!arg0
->isValueDependent())
76 compat::optional
<llvm::APSInt
> xVal
77 = arg0
->getIntegerConstantExpr(compiler
.getASTContext());
78 if (xVal
&& *xVal
> 0xffffff)
79 report(DiagnosticsEngine::Warning
,
80 "Rather use the ColorTransparency or ColorAlpha version of this constructor",
85 report(DiagnosticsEngine::Warning
,
86 "Rather use the ColorTransparency or ColorAlpha version of this constructor",
92 loplugin::Plugin::Registration
<ColorCheck
> colorcheck("colorcheck");
96 #endif // LO_CLANG_SHARED_PLUGINS
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */