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
This commit is contained in:
@@ -9,8 +9,9 @@
|
|||||||
|
|
||||||
#include "clang/AST/Attr.h"
|
#include "clang/AST/Attr.h"
|
||||||
|
|
||||||
#include "plugin.hxx"
|
|
||||||
#include "compat.hxx"
|
#include "compat.hxx"
|
||||||
|
#include "plugin.hxx"
|
||||||
|
#include "typecheck.hxx"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Look for member functions that can be static
|
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
|
// can't change it because in debug mode it can't be static
|
||||||
// sal/cpprt/operators_new_delete.cxx
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
// in this case, the code is taking the address of the member function
|
// in this case, the code is taking the address of the member function
|
||||||
// shell/source/unix/sysshell/recently_used_file_handler.cxx
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
// the unotools and svl config code stuff is doing weird stuff with a reference-counted statically allocated pImpl class
|
// the unotools and svl config code stuff is doing weird stuff with a reference-counted statically allocated pImpl class
|
||||||
|
@@ -85,6 +85,12 @@ TerminalCheck NamespaceCheck::StdNamespace() const {
|
|||||||
context_ != nullptr && compat::isStdNamespace(*context_));
|
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: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -21,6 +21,13 @@ namespace loplugin {
|
|||||||
class NamespaceCheck;
|
class NamespaceCheck;
|
||||||
class TerminalCheck;
|
class TerminalCheck;
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<std::size_t N> NamespaceCheck checkRecordDecl(
|
||||||
|
clang::Decl const * decl, clang::TagTypeKind tag, char const (& id)[N]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class TypeCheck {
|
class TypeCheck {
|
||||||
public:
|
public:
|
||||||
explicit TypeCheck(clang::QualType type): type_(type) {}
|
explicit TypeCheck(clang::QualType type): type_(type) {}
|
||||||
@@ -59,8 +66,12 @@ public:
|
|||||||
|
|
||||||
TerminalCheck StdNamespace() const;
|
TerminalCheck StdNamespace() const;
|
||||||
|
|
||||||
|
NamespaceCheck AnonymousNamespace() const;
|
||||||
|
|
||||||
private:
|
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):
|
explicit NamespaceCheck(clang::DeclContext const * context = nullptr):
|
||||||
context_(context) {}
|
context_(context) {}
|
||||||
@@ -68,6 +79,19 @@ private:
|
|||||||
clang::DeclContext const * const context_;
|
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 {
|
class TerminalCheck {
|
||||||
public:
|
public:
|
||||||
explicit operator bool() const { return satisfied_; }
|
explicit operator bool() const { return satisfied_; }
|
||||||
@@ -81,19 +105,30 @@ private:
|
|||||||
bool const satisfied_;
|
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])
|
template<std::size_t N> NamespaceCheck TypeCheck::Class(char const (& id)[N])
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
if (!type_.isNull()) {
|
if (!type_.isNull()) {
|
||||||
auto const t = type_->getAs<clang::RecordType>();
|
auto const t = type_->getAs<clang::RecordType>();
|
||||||
if (t != nullptr) {
|
if (t != nullptr) {
|
||||||
auto const d = t->getDecl();
|
return detail::checkRecordDecl(t->getDecl(), clang::TTK_Class, id);
|
||||||
if (d->isClass()) {
|
|
||||||
auto const i = d->getIdentifier();
|
|
||||||
if (i != nullptr && i->isStr(id)) {
|
|
||||||
return NamespaceCheck(d->getDeclContext());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NamespaceCheck();
|
return NamespaceCheck();
|
||||||
@@ -114,6 +149,12 @@ template<std::size_t N> NamespaceCheck NamespaceCheck::Namespace(
|
|||||||
return NamespaceCheck();
|
return NamespaceCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<std::size_t N> NamespaceCheck DeclCheck::Struct(char const (& id)[N])
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return detail::checkRecordDecl(decl_, clang::TTK_Struct, id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user