2013-07-29 16:19:24 +08:00
|
|
|
//===--- ClangTidyModule.h - clang-tidy -------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANG_TIDY_MODULE_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANG_TIDY_MODULE_H
|
|
|
|
|
|
|
|
#include "ClangTidy.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
|
|
|
|
/// \brief A factory, that can instantiate a specific clang-tidy check for
|
|
|
|
/// processing a translation unit.
|
|
|
|
///
|
|
|
|
/// In order to register your check with the \c ClangTidyModule, create a
|
|
|
|
/// subclass of \c CheckFactoryBase and implement \c createCheck(). Then, use
|
|
|
|
/// this subclass in \c ClangTidyModule::addCheckFactories().
|
|
|
|
class CheckFactoryBase {
|
|
|
|
public:
|
Clang-tidy: added --disable-checks, --list-checks options.
Summary:
Allow disabling checks by regex. By default, disable alpha.* checks,
that are not particularly good tested (e.g. IdempotentOperationChecker, see
http://llvm-reviews.chandlerc.com/D2427).
Fixed a bug, that would disable all analyzer checks, when using a regex more
strict, than 'clang-analyzer-', for example --checks='clang-analyzer-deadcode-'.
Added --list-checks to list all enabled checks. This is useful to test specific
values in --checks/--disable-checks.
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2444
llvm-svn: 197717
2013-12-20 03:57:05 +08:00
|
|
|
virtual ~CheckFactoryBase() {}
|
2013-07-29 16:19:24 +08:00
|
|
|
virtual ClangTidyCheck *createCheck() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief A subclass of \c CheckFactoryBase that should be used for all
|
|
|
|
/// \c ClangTidyChecks that don't require constructor parameters.
|
|
|
|
///
|
|
|
|
/// For example, if have a clang-tidy check like:
|
|
|
|
/// \code
|
|
|
|
/// class MyTidyCheck : public ClangTidyCheck {
|
2014-03-02 18:20:11 +08:00
|
|
|
/// void registerMatchers(ast_matchers::MatchFinder *Finder) override {
|
2014-02-27 21:14:51 +08:00
|
|
|
/// ..
|
|
|
|
/// }
|
2013-07-29 16:19:24 +08:00
|
|
|
/// };
|
|
|
|
/// \endcode
|
|
|
|
/// you can register it with:
|
|
|
|
/// \code
|
|
|
|
/// class MyModule : public ClangTidyModule {
|
2014-02-27 21:14:51 +08:00
|
|
|
/// void
|
2014-03-02 18:20:11 +08:00
|
|
|
/// addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
|
2013-07-29 16:19:24 +08:00
|
|
|
/// CheckFactories.addCheckFactory(
|
|
|
|
/// "myproject-my-check", new ClangTidyCheckFactory<MyTidyCheck>());
|
|
|
|
/// }
|
|
|
|
/// };
|
|
|
|
/// \endcode
|
|
|
|
template <typename T> class ClangTidyCheckFactory : public CheckFactoryBase {
|
|
|
|
public:
|
2014-03-02 18:20:11 +08:00
|
|
|
ClangTidyCheck *createCheck() override { return new T; }
|
2013-07-29 16:19:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ClangTidyCheckFactories;
|
|
|
|
|
|
|
|
/// \brief A clang-tidy module groups a number of \c ClangTidyChecks and gives
|
|
|
|
/// them a prefixed name.
|
|
|
|
class ClangTidyModule {
|
|
|
|
public:
|
|
|
|
virtual ~ClangTidyModule() {}
|
|
|
|
|
|
|
|
/// \brief Implement this function in order to register all \c CheckFactories
|
|
|
|
/// belonging to this module.
|
|
|
|
virtual void addCheckFactories(ClangTidyCheckFactories &CheckFactories) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief A collection of \c ClangTidyCheckFactory instances.
|
|
|
|
///
|
|
|
|
/// All clang-tidy modules register their check factories with an instance of
|
|
|
|
/// this object.
|
|
|
|
class ClangTidyCheckFactories {
|
|
|
|
public:
|
|
|
|
ClangTidyCheckFactories() {}
|
|
|
|
~ClangTidyCheckFactories();
|
|
|
|
|
|
|
|
/// \brief Register \p Factory with the name \p Name.
|
|
|
|
///
|
|
|
|
/// The \c ClangTidyCheckFactories object takes ownership of the \p Factory.
|
|
|
|
void addCheckFactory(StringRef Name, CheckFactoryBase *Factory);
|
|
|
|
|
|
|
|
/// \brief Create instances of all checks matching \p CheckRegexString and
|
|
|
|
/// store them in \p Checks.
|
|
|
|
///
|
|
|
|
/// The caller takes ownership of the return \c ClangTidyChecks.
|
Clang-tidy: added --disable-checks, --list-checks options.
Summary:
Allow disabling checks by regex. By default, disable alpha.* checks,
that are not particularly good tested (e.g. IdempotentOperationChecker, see
http://llvm-reviews.chandlerc.com/D2427).
Fixed a bug, that would disable all analyzer checks, when using a regex more
strict, than 'clang-analyzer-', for example --checks='clang-analyzer-deadcode-'.
Added --list-checks to list all enabled checks. This is useful to test specific
values in --checks/--disable-checks.
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2444
llvm-svn: 197717
2013-12-20 03:57:05 +08:00
|
|
|
void createChecks(ChecksFilter &Filter,
|
2013-07-29 16:19:24 +08:00
|
|
|
SmallVectorImpl<ClangTidyCheck *> &Checks);
|
|
|
|
|
Clang-tidy: added --disable-checks, --list-checks options.
Summary:
Allow disabling checks by regex. By default, disable alpha.* checks,
that are not particularly good tested (e.g. IdempotentOperationChecker, see
http://llvm-reviews.chandlerc.com/D2427).
Fixed a bug, that would disable all analyzer checks, when using a regex more
strict, than 'clang-analyzer-', for example --checks='clang-analyzer-deadcode-'.
Added --list-checks to list all enabled checks. This is useful to test specific
values in --checks/--disable-checks.
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2444
llvm-svn: 197717
2013-12-20 03:57:05 +08:00
|
|
|
typedef std::map<std::string, CheckFactoryBase *> FactoryMap;
|
|
|
|
FactoryMap::const_iterator begin() const { return Factories.begin(); }
|
|
|
|
FactoryMap::const_iterator end() const { return Factories.end(); }
|
2014-02-14 00:10:47 +08:00
|
|
|
bool empty() const { return Factories.empty(); }
|
Clang-tidy: added --disable-checks, --list-checks options.
Summary:
Allow disabling checks by regex. By default, disable alpha.* checks,
that are not particularly good tested (e.g. IdempotentOperationChecker, see
http://llvm-reviews.chandlerc.com/D2427).
Fixed a bug, that would disable all analyzer checks, when using a regex more
strict, than 'clang-analyzer-', for example --checks='clang-analyzer-deadcode-'.
Added --list-checks to list all enabled checks. This is useful to test specific
values in --checks/--disable-checks.
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2444
llvm-svn: 197717
2013-12-20 03:57:05 +08:00
|
|
|
|
2013-07-29 16:19:24 +08:00
|
|
|
private:
|
Clang-tidy: added --disable-checks, --list-checks options.
Summary:
Allow disabling checks by regex. By default, disable alpha.* checks,
that are not particularly good tested (e.g. IdempotentOperationChecker, see
http://llvm-reviews.chandlerc.com/D2427).
Fixed a bug, that would disable all analyzer checks, when using a regex more
strict, than 'clang-analyzer-', for example --checks='clang-analyzer-deadcode-'.
Added --list-checks to list all enabled checks. This is useful to test specific
values in --checks/--disable-checks.
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2444
llvm-svn: 197717
2013-12-20 03:57:05 +08:00
|
|
|
FactoryMap Factories;
|
2013-07-29 16:19:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace tidy
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANG_TIDY_MODULE_H
|