Kaydet (Commit) 99016353 authored tarafından Luboš Luňák's avatar Luboš Luňák Kaydeden (comit) Noel Grandin

move isDerivedFrom() from a clang plugin to shared code, for reuse

Change-Id: I7b9b41a7081281214a387cdf02080866e9b9dfe7
Reviewed-on: https://gerrit.libreoffice.org/68873
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 803b43ef
......@@ -280,6 +280,35 @@ bool isOkToRemoveArithmeticCast(
return true;
}
static bool BaseCheckNotSubclass(const clang::CXXRecordDecl *BaseDefinition, void *p) {
if (!BaseDefinition)
return true;
auto const & base = *static_cast<const DeclChecker *>(p);
if (base(BaseDefinition)) {
return false;
}
return true;
}
bool isDerivedFrom(const clang::CXXRecordDecl *decl, DeclChecker base) {
if (!decl)
return false;
if (base(decl))
return true;
if (!decl->hasDefinition()) {
return false;
}
if (!decl->forallBases(
[&base](const clang::CXXRecordDecl *BaseDefinition) -> bool
{ return BaseCheckNotSubclass(BaseDefinition, &base); },
true))
{
return true;
}
return false;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -140,6 +140,12 @@ private:
bool const satisfied_;
};
typedef std::function<bool(clang::Decl const *)> DeclChecker;
// Returns true if the class has a base matching the checker, or if the class itself matches.
bool isDerivedFrom(const clang::CXXRecordDecl *decl, DeclChecker base);
namespace detail {
ContextCheck checkRecordDecl(
......
......@@ -35,7 +35,7 @@ not delete on last 'release'.
*/
namespace {
namespace loplugin {
class RefCounting:
public loplugin::FilteringPlugin<RefCounting>
......@@ -72,37 +72,6 @@ private:
bool visitTemporaryObjectExpr(Expr const * expr);
};
typedef std::function<bool(Decl const *)> DeclChecker;
bool BaseCheckNotSubclass(const CXXRecordDecl *BaseDefinition, void *p) {
if (!BaseDefinition)
return true;
auto const & base = *static_cast<const DeclChecker *>(p);
if (base(BaseDefinition)) {
return false;
}
return true;
}
bool isDerivedFrom(const CXXRecordDecl *decl, DeclChecker base) {
if (!decl)
return false;
if (base(decl))
return true;
if (!decl->hasDefinition()) {
return false;
}
if (!decl->forallBases(
[&base](const CXXRecordDecl *BaseDefinition) -> bool
{ return BaseCheckNotSubclass(BaseDefinition, &base); },
true))
{
return true;
}
return false;
}
bool containsXInterfaceSubclass(const clang::Type* pType0);
bool containsXInterfaceSubclass(const QualType& qType) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment