bump product version to 7.2.5.1
[LibreOffice.git] / compilerplugins / clang / colorcheck.cxx
blob83f9a9688381f3f2d9a19ed7129649ba73ebebd0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
9 #ifndef LO_CLANG_SHARED_PLUGINS
11 #include <memory>
12 #include <cassert>
13 #include <string>
14 #include <iostream>
15 #include <fstream>
16 #include <set>
18 #include "check.hxx"
19 #include "plugin.hxx"
21 /**
24 namespace
26 class ColorCheck : public loplugin::FilteringPlugin<ColorCheck>
28 public:
29 explicit ColorCheck(loplugin::InstantiationData const& data)
30 : FilteringPlugin(data)
34 virtual void run() override
36 if (preRun())
37 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
40 bool VisitCXXConstructExpr(const CXXConstructExpr*);
43 bool ColorCheck::VisitCXXConstructExpr(const CXXConstructExpr* constructExpr)
45 if (ignoreLocation(constructExpr))
46 return true;
48 if (constructExpr->getNumArgs() != 1)
49 return true;
51 auto tc = loplugin::TypeCheck(constructExpr->getType());
52 if (!tc.Class("Color").GlobalNamespace())
53 return true;
55 StringRef aFileName = getFilenameOfLocation(
56 compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(constructExpr)));
57 if (loplugin::isSamePathname(aFileName, SRCDIR "/include/tools/color.hxx"))
58 return true;
60 const CXXConstructorDecl* constructorDecl = constructExpr->getConstructor();
61 constructorDecl = constructorDecl->getCanonicalDecl();
63 if (!loplugin::TypeCheck(constructorDecl->getParamDecl(0)->getType())
64 .Typedef("sal_uInt32")
65 .GlobalNamespace())
66 return true;
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",
78 arg0->getExprLoc());
79 return true;
82 report(DiagnosticsEngine::Warning,
83 "Rather use the ColorTransparency or ColorAlpha version of this constructor",
84 arg0->getExprLoc());
86 return true;
89 loplugin::Plugin::Registration<ColorCheck> colorcheck("colorcheck");
91 } // namespace
93 #endif // LO_CLANG_SHARED_PLUGINS
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */