2015-11-17 21:50:45 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_COMPILERPLUGINS_CLANG_TYPECHECK_HXX
|
|
|
|
#define INCLUDED_COMPILERPLUGINS_CLANG_TYPECHECK_HXX
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
#include <clang/AST/DeclBase.h>
|
2015-12-08 22:56:02 +01:00
|
|
|
#include <clang/AST/Decl.h>
|
2015-11-17 21:50:45 +01:00
|
|
|
#include <clang/AST/Type.h>
|
|
|
|
|
|
|
|
namespace loplugin {
|
|
|
|
|
|
|
|
class NamespaceCheck;
|
2015-12-08 22:56:02 +01:00
|
|
|
class TerminalCheck;
|
2015-11-17 21:50:45 +01:00
|
|
|
|
|
|
|
class TypeCheck {
|
|
|
|
public:
|
|
|
|
explicit TypeCheck(clang::QualType type): type_(type) {}
|
|
|
|
|
|
|
|
explicit operator bool() const { return !type_.isNull(); }
|
|
|
|
|
2015-12-08 22:56:02 +01:00
|
|
|
TypeCheck Const() const;
|
2015-11-17 21:50:45 +01:00
|
|
|
|
2015-12-08 22:56:02 +01:00
|
|
|
TerminalCheck Char() const;
|
|
|
|
|
2016-06-03 10:58:26 +02:00
|
|
|
TypeCheck Pointer() const;
|
|
|
|
|
2015-12-08 22:56:02 +01:00
|
|
|
TypeCheck LvalueReference() const;
|
2015-11-17 21:50:45 +01:00
|
|
|
|
|
|
|
template<std::size_t N> inline NamespaceCheck Class(char const (& id)[N])
|
|
|
|
const;
|
|
|
|
|
2015-12-08 22:56:02 +01:00
|
|
|
TypeCheck NotSubstTemplateTypeParmType() const;
|
|
|
|
|
2015-11-17 21:50:45 +01:00
|
|
|
private:
|
|
|
|
TypeCheck() = default;
|
|
|
|
|
|
|
|
clang::QualType const type_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NamespaceCheck {
|
|
|
|
public:
|
|
|
|
explicit operator bool() const { return context_ != nullptr; }
|
|
|
|
|
2015-12-08 22:56:02 +01:00
|
|
|
TerminalCheck GlobalNamespace() const;
|
2015-11-17 21:50:45 +01:00
|
|
|
|
2015-12-08 22:56:02 +01:00
|
|
|
template<std::size_t N> inline NamespaceCheck Namespace(
|
|
|
|
char const (& id)[N]) const;
|
2015-11-17 21:50:45 +01:00
|
|
|
|
2015-12-08 22:56:02 +01:00
|
|
|
TerminalCheck StdNamespace() const;
|
2015-11-17 21:50:45 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class TypeCheck;
|
|
|
|
|
|
|
|
explicit NamespaceCheck(clang::DeclContext const * context = nullptr):
|
|
|
|
context_(context) {}
|
|
|
|
|
|
|
|
clang::DeclContext const * const context_;
|
|
|
|
};
|
|
|
|
|
2015-12-08 22:56:02 +01:00
|
|
|
class TerminalCheck {
|
|
|
|
public:
|
|
|
|
explicit operator bool() const { return satisfied_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend TypeCheck;
|
|
|
|
friend NamespaceCheck;
|
|
|
|
|
|
|
|
explicit TerminalCheck(bool satisfied): satisfied_(satisfied) {}
|
|
|
|
|
|
|
|
bool const satisfied_;
|
|
|
|
};
|
|
|
|
|
2015-11-17 21:50:45 +01:00
|
|
|
template<std::size_t N> NamespaceCheck TypeCheck::Class(char const (& id)[N])
|
|
|
|
const
|
|
|
|
{
|
|
|
|
if (!type_.isNull()) {
|
2015-12-08 22:56:02 +01:00
|
|
|
auto const t = type_->getAs<clang::RecordType>();
|
2015-11-17 21:50:45 +01:00
|
|
|
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 NamespaceCheck();
|
|
|
|
}
|
|
|
|
|
2015-12-08 22:56:02 +01:00
|
|
|
template<std::size_t N> NamespaceCheck NamespaceCheck::Namespace(
|
|
|
|
char const (& id)[N]) const
|
|
|
|
{
|
|
|
|
if (context_) {
|
|
|
|
auto n = llvm::dyn_cast<clang::NamespaceDecl>(context_);
|
|
|
|
if (n != nullptr) {
|
|
|
|
auto const i = n->getIdentifier();
|
|
|
|
if (i != nullptr && i->isStr(id)) {
|
|
|
|
return NamespaceCheck(n->getParent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NamespaceCheck();
|
|
|
|
}
|
|
|
|
|
2015-11-17 21:50:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|