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/.
10 #ifndef LO_CLANG_SHARED_PLUGINS
18 #include "clang/AST/CXXInheritance.h"
21 * Check for multiple copies of WeakBase in base classes
25 class WeakBase
: public loplugin::FilteringPlugin
<WeakBase
>
28 explicit WeakBase(loplugin::InstantiationData
const& data
)
29 : FilteringPlugin(data
)
33 bool preRun() override
{ return compiler
.getLangOpts().CPlusPlus
; }
39 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
43 bool VisitCXXRecordDecl(CXXRecordDecl
const*);
46 bool WeakBase::VisitCXXRecordDecl(CXXRecordDecl
const* recordDecl
)
48 if (ignoreLocation(recordDecl
))
52 // StringRef aFileName = getFilenameOfLocation(
53 // compiler.getSourceManager().getSpellingLoc(fieldDecl->getBeginLoc()));
55 // if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/chart2/source/"))
57 // if (loplugin::isSamePathname(aFileName, SRCDIR "/include/sfx2/recentdocsview.hxx"))
59 // if (loplugin::isSamePathname(aFileName, SRCDIR "/include/sfx2/templatelocalview.hxx"))
61 // if (loplugin::isSamePathname(aFileName, SRCDIR "/store/source/stortree.hxx")
62 // || loplugin::isSamePathname(aFileName, SRCDIR "/store/source/stordata.hxx"))
64 // if (loplugin::isSamePathname(aFileName, SRCDIR "/sw/source/uibase/inc/dbtree.hxx"))
67 recordDecl
= recordDecl
->getCanonicalDecl();
68 if (!recordDecl
->hasDefinition())
72 std::string basePaths
;
73 auto BaseMatchesCallback
= [&](const CXXBaseSpecifier
* cxxBaseSpecifier
, CXXBasePath
& Paths
) {
74 if (!cxxBaseSpecifier
->getType().getTypePtr())
76 const CXXRecordDecl
* baseCXXRecordDecl
= cxxBaseSpecifier
->getType()->getAsCXXRecordDecl();
77 if (!baseCXXRecordDecl
)
79 if (baseCXXRecordDecl
->isInvalidDecl())
81 if (baseCXXRecordDecl
->getName() != "WeakBase")
85 for (CXXBasePathElement
const& pathElement
: Paths
)
91 if (pathElement
.Class
->hasDefinition())
92 sPath
+= pathElement
.Class
->getNameAsString();
97 sPath
+= baseCXXRecordDecl
->getNameAsString();
98 if (!basePaths
.empty())
105 recordDecl
->lookupInBases(BaseMatchesCallback
, aPaths
);
109 report(DiagnosticsEngine::Warning
,
110 "multiple copies of WeakBase, through inheritance paths %0",
111 recordDecl
->getBeginLoc())
112 << basePaths
<< recordDecl
->getSourceRange();
117 loplugin::Plugin::Registration
<WeakBase
> weakbase("weakbase");
121 #endif // LO_CLANG_SHARED_PLUGINS
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */