diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-03-06 14:39:13 +0100 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-03-11 11:53:50 +0100 |
commit | 990163534cb5bc63ac500d5204f4caeab056bdf3 (patch) | |
tree | f48378c04d3c0a4c55fc07290c2d09be2ddc1b16 /compilerplugins | |
parent | 803b43efe86b51366a516648015efd3b39255f75 (diff) |
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: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/check.cxx | 29 | ||||
-rw-r--r-- | compilerplugins/clang/check.hxx | 6 | ||||
-rw-r--r-- | compilerplugins/clang/refcounting.cxx | 33 |
3 files changed, 36 insertions, 32 deletions
diff --git a/compilerplugins/clang/check.cxx b/compilerplugins/clang/check.cxx index acda74adacd6..f2443e44a1f2 100644 --- a/compilerplugins/clang/check.cxx +++ b/compilerplugins/clang/check.cxx @@ -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: */ diff --git a/compilerplugins/clang/check.hxx b/compilerplugins/clang/check.hxx index 4ae65f139955..0d636636a81a 100644 --- a/compilerplugins/clang/check.hxx +++ b/compilerplugins/clang/check.hxx @@ -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( diff --git a/compilerplugins/clang/refcounting.cxx b/compilerplugins/clang/refcounting.cxx index 6ae861cfcad9..535808a3a0ca 100644 --- a/compilerplugins/clang/refcounting.cxx +++ b/compilerplugins/clang/refcounting.cxx @@ -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) { |