1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* Based on LLVM/Clang.
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include "plugin.hxx"
#include "check.hxx"
#include "config_clang.h"
#include <iostream>
/*
This is a compile-time checker.
Check for cases where we have
- two IDL interfaces A and B,
- B extends A
- we are converting a Reference<B> to a Reference<A> using UNO_QUERY
This makes the code simpler and cheaper, because UNO_QUERY can be surprisingly expensive if used a lot.
*/
namespace
{
class RtlRef : public loplugin::FilteringPlugin<RtlRef>
{
public:
explicit RtlRef(loplugin::InstantiationData const& data)
: FilteringPlugin(data)
{
}
bool preRun() override
{
std::string fn(handler.getMainFileName());
loplugin::normalizeDotDotInFilePath(fn);
if (fn == SRCDIR "/ucb/source/ucp/ext/ucpext_provider.cxx")
return false;
if (fn == SRCDIR "/ucb/source/ucp/hierarchy/hierarchyprovider.cxx")
return false;
if (fn == SRCDIR "/ucb/source/ucp/cmis/cmis_provider.cxx")
return false;
if (fn == SRCDIR "/ucb/source/ucp/webdav-curl/webdavprovider.cxx")
return false;
if (fn == SRCDIR "/ucb/source/ucp/webdav-curl/webdavresponseparser.cxx")
return false;
if (fn == SRCDIR "/ucb/source/cacher/dynamicresultsetwrapper.cxx")
return false;
if (fn == SRCDIR "/sax/source/fastparser/fastparser.cxx")
return false;
if (fn == SRCDIR "/chart2/source/controller/main/ObjectHierarchy.cxx")
return false;
if (fn == SRCDIR "/chart2/source/controller/main/ShapeController.cxx")
return false;
if (fn == SRCDIR "/chart2/source/view/axes/VCartesianAxis.cxx")
return false;
if (fn == SRCDIR "/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx")
return false;
if (fn == SRCDIR "/chart2/source/view/main/DataTableView.cxx")
return false;
if (fn == SRCDIR "/svx/source/form/datanavi.cxx")
return false;
if (fn == SRCDIR "/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx")
return false;
if (fn == SRCDIR "/sd/source/ui/annotations/annotationwindow.cxx")
return false;
if (fn == SRCDIR "/sd/source/ui/unoidl/unopage.cxx")
return false;
if (fn == SRCDIR "/xmlsecurity/source/helper/xsecsign.cxx")
return false;
if (fn == SRCDIR "/xmlsecurity/source/helper/xsecctl.cxx")
return false;
if (fn == SRCDIR "/unoxml/source/events/eventdispatcher.cxx")
return false;
if (fn == SRCDIR "/unoxml/source/dom/element.cxx")
return false;
return true;
}
void run() override
{
if (preRun())
{
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
}
bool VisitVarDecl(const VarDecl*);
};
bool RtlRef::VisitVarDecl(const VarDecl* varDecl)
{
if (ignoreLocation(varDecl))
return true;
// don't bother processing anything in the Reference.h file. Makes my life easier when debugging this.
StringRef aFileName
= getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(varDecl->getBeginLoc()));
if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.h"))
return true;
if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.hxx"))
return true;
if (!loplugin::TypeCheck(varDecl->getType()).Class("Reference").Namespace("uno"))
return true;
if (varDecl->isStaticLocal())
return true;
auto init = varDecl->getInit();
if (!init)
return true;
init = init->IgnoreImpCasts();
auto memberCall = dyn_cast<CXXMemberCallExpr>(init);
if (!memberCall)
return true;
if (memberCall->getNumArgs() > 1)
return true;
auto innerExpr = memberCall->getImplicitObjectArgument()->IgnoreImpCasts();
if (!loplugin::TypeCheck(innerExpr->getType()).Class("Reference").Namespace("rtl"))
return true;
report(DiagnosticsEngine::Warning, "cast from %0", varDecl->getBeginLoc())
<< innerExpr->getType() << varDecl->getSourceRange();
return true;
}
loplugin::Plugin::Registration<RtlRef> rtlref("rtlref");
} // namespace
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|