LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / compilerplugins / clang / unoany.cxx
blobd44fce1d434cd4dd97cd845efe3a1e1fa104b282
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 */
10 #ifndef LO_CLANG_SHARED_PLUGINS
12 #include "check.hxx"
13 #include "compat.hxx"
14 #include "plugin.hxx"
16 namespace {
18 class UnoAny:
19 public loplugin::FilteringPlugin<UnoAny>
21 public:
22 explicit UnoAny(loplugin::InstantiationData const & data): FilteringPlugin(data) {}
24 bool preRun() override {
25 return compiler.getLangOpts().CPlusPlus;
28 void run() override {
29 if (preRun()) {
30 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
34 bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr);
37 bool UnoAny::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr)
39 if (ignoreLocation(expr)) {
40 return true;
42 StringRef aFileName = getFilenameOfLocation(
43 compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr)));
44 if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Any.hxx")) {
45 return true;
47 if (expr->getOperator() != OO_Equal) {
48 return true;
50 if (!loplugin::TypeCheck(expr->getArg(0)->getType()).Class("Any").
51 Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace())
53 return true;
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()) {
60 report(
61 DiagnosticsEngine::Warning,
62 ("unnecessary copy, rather use <<= operator directly with the 'makeAny'"
63 " argument"),
64 expr->getOperatorLoc())
65 << expr->getSourceRange();
66 return true;
70 if (isa<CXXFunctionalCastExpr>(compat::getSubExpr(expr2))) {
71 //expr->getArg(1)->dump();
72 report(
73 DiagnosticsEngine::Warning,
74 ("unnecessary copy, rather use <<= operator directly with the 'Any' constructor"
75 " argument"),
76 expr->getOperatorLoc())
77 << expr->getSourceRange();
78 return true;
81 //expr->getArg(1)->dump();
82 return true;
85 loplugin::Plugin::Registration<UnoAny> unoany("unoany");
87 } // namespace
89 #endif // LO_CLANG_SHARED_PLUGINS
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */