compilerplugins/clang/staticmethods.cxx | 9 +++-- compilerplugins/clang/typecheck.cxx | 6 +++ compilerplugins/clang/typecheck.hxx | 57 +++++++++++++++++++++++++++----- 3 files changed, 61 insertions(+), 11 deletions(-)
New commits: commit c1ab6613ae7b45f2d90aafd6c6a829a471ceca55 Author: Stephan Bergmann <sberg...@redhat.com> Date: Tue Jun 28 17:48:22 2016 +0200 More adaption to Clang 3.4 ...where NmaedDecl::getQualifiedNameAsString (which is expensive and bad, anyway) apparently returns something other than "(anonymous namespace)" Change-Id: I05ef96665c48f8f596dd0d317388e91a75b8307b diff --git a/compilerplugins/clang/staticmethods.cxx b/compilerplugins/clang/staticmethods.cxx index be014fd..9108e02 100644 --- a/compilerplugins/clang/staticmethods.cxx +++ b/compilerplugins/clang/staticmethods.cxx @@ -9,8 +9,9 @@ #include "clang/AST/Attr.h" -#include "plugin.hxx" #include "compat.hxx" +#include "plugin.hxx" +#include "typecheck.hxx" /* Look for member functions that can be static @@ -118,12 +119,14 @@ bool StaticMethods::TraverseCXXMethodDecl(const CXXMethodDecl * pCXXMethodDecl) } // can't change it because in debug mode it can't be static // sal/cpprt/operators_new_delete.cxx - if (aParentName == "(anonymous namespace)::AllocatorTraits") { + auto dc = loplugin::DeclCheck(pCXXMethodDecl->getParent()); + if (dc.Struct("AllocatorTraits").AnonymousNamespace().GlobalNamespace()) { return true; } // in this case, the code is taking the address of the member function // shell/source/unix/sysshell/recently_used_file_handler.cxx - if (aParentName == "(anonymous namespace)::recently_used_item") { + if (dc.Struct("recently_used_item").AnonymousNamespace().GlobalNamespace()) + { return true; } // the unotools and svl config code stuff is doing weird stuff with a reference-counted statically allocated pImpl class diff --git a/compilerplugins/clang/typecheck.cxx b/compilerplugins/clang/typecheck.cxx index d7bccfd..c293b57 100644 --- a/compilerplugins/clang/typecheck.cxx +++ b/compilerplugins/clang/typecheck.cxx @@ -85,6 +85,12 @@ TerminalCheck NamespaceCheck::StdNamespace() const { context_ != nullptr && compat::isStdNamespace(*context_)); } +NamespaceCheck NamespaceCheck::AnonymousNamespace() const { + auto n = llvm::dyn_cast_or_null<clang::NamespaceDecl>(context_); + return NamespaceCheck( + n != nullptr && n->isAnonymousNamespace() ? n->getParent() : nullptr); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/typecheck.hxx b/compilerplugins/clang/typecheck.hxx index 9862890..b3417bf 100644 --- a/compilerplugins/clang/typecheck.hxx +++ b/compilerplugins/clang/typecheck.hxx @@ -21,6 +21,13 @@ namespace loplugin { class NamespaceCheck; class TerminalCheck; +namespace detail { + +template<std::size_t N> NamespaceCheck checkRecordDecl( + clang::Decl const * decl, clang::TagTypeKind tag, char const (& id)[N]); + +} + class TypeCheck { public: explicit TypeCheck(clang::QualType type): type_(type) {} @@ -59,8 +66,12 @@ public: TerminalCheck StdNamespace() const; + NamespaceCheck AnonymousNamespace() const; + private: - friend class TypeCheck; + friend TypeCheck; + template<std::size_t N> friend NamespaceCheck detail::checkRecordDecl( + clang::Decl const * decl, clang::TagTypeKind tag, char const (& id)[N]); explicit NamespaceCheck(clang::DeclContext const * context = nullptr): context_(context) {} @@ -68,6 +79,19 @@ private: clang::DeclContext const * const context_; }; +class DeclCheck { +public: + explicit DeclCheck(clang::Decl const * decl): decl_(decl) {} + + explicit operator bool() const { return decl_ != nullptr; } + + template<std::size_t N> inline NamespaceCheck Struct(char const (& id)[N]) + const; + +private: + clang::Decl const * const decl_; +}; + class TerminalCheck { public: explicit operator bool() const { return satisfied_; } @@ -81,19 +105,30 @@ private: bool const satisfied_; }; +namespace detail { + +template<std::size_t N> NamespaceCheck checkRecordDecl( + clang::Decl const * decl, clang::TagTypeKind tag, char const (& id)[N]) +{ + auto r = llvm::dyn_cast_or_null<clang::RecordDecl>(decl); + if (r != nullptr && r->getTagKind() == tag) { + auto const i = r->getIdentifier(); + if (i != nullptr && i->isStr(id)) { + return NamespaceCheck(r->getDeclContext()); + } + } + return NamespaceCheck(); +} + +} + template<std::size_t N> NamespaceCheck TypeCheck::Class(char const (& id)[N]) const { if (!type_.isNull()) { auto const t = type_->getAs<clang::RecordType>(); if (t != nullptr) { - auto const d = t->getDecl(); - if (d->isClass()) { - auto const i = d->getIdentifier(); - if (i != nullptr && i->isStr(id)) { - return NamespaceCheck(d->getDeclContext()); - } - } + return detail::checkRecordDecl(t->getDecl(), clang::TTK_Class, id); } } return NamespaceCheck(); @@ -114,6 +149,12 @@ template<std::size_t N> NamespaceCheck NamespaceCheck::Namespace( return NamespaceCheck(); } +template<std::size_t N> NamespaceCheck DeclCheck::Struct(char const (& id)[N]) + const +{ + return detail::checkRecordDecl(decl_, clang::TTK_Struct, id); +} + } #endif _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits