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/StringRef.h"
|
2014-09-10 19:25:43 +08:00
|
|
|
#include <functional>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2013-07-29 16:19:24 +08:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
|
|
|
|
/// \brief A collection of \c ClangTidyCheckFactory instances.
|
|
|
|
///
|
|
|
|
/// All clang-tidy modules register their check factories with an instance of
|
|
|
|
/// this object.
|
|
|
|
class ClangTidyCheckFactories {
|
|
|
|
public:
|
2014-09-12 16:53:36 +08:00
|
|
|
typedef std::function<ClangTidyCheck *(
|
|
|
|
StringRef Name, ClangTidyContext *Context)> CheckFactory;
|
|
|
|
|
2014-09-10 19:25:43 +08:00
|
|
|
/// \brief Registers check \p Factory with name \p Name.
|
|
|
|
///
|
|
|
|
/// For all checks that have default constructors, use \c registerCheck.
|
2014-09-12 16:53:36 +08:00
|
|
|
void registerCheckFactory(StringRef Name, CheckFactory Factory);
|
2014-09-10 19:06:43 +08:00
|
|
|
|
2014-09-10 19:25:43 +08:00
|
|
|
/// \brief Registers the \c CheckType with the name \p Name.
|
|
|
|
///
|
|
|
|
/// This method 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 {
|
|
|
|
/// void registerMatchers(ast_matchers::MatchFinder *Finder) override {
|
|
|
|
/// ..
|
|
|
|
/// }
|
|
|
|
/// };
|
|
|
|
/// \endcode
|
|
|
|
/// you can register it with:
|
|
|
|
/// \code
|
|
|
|
/// class MyModule : public ClangTidyModule {
|
|
|
|
/// void addCheckFactories(ClangTidyCheckFactories &Factories) override {
|
|
|
|
/// Factories.registerCheck<MyTidyCheck>("myproject-my-check");
|
|
|
|
/// }
|
|
|
|
/// };
|
|
|
|
/// \endcode
|
2014-09-12 16:53:36 +08:00
|
|
|
template <typename CheckType> void registerCheck(StringRef CheckName) {
|
|
|
|
registerCheckFactory(CheckName,
|
|
|
|
[](StringRef Name, ClangTidyContext *Context) {
|
|
|
|
return new CheckType(Name, Context);
|
|
|
|
});
|
2014-09-10 19:06:43 +08:00
|
|
|
}
|
2013-07-29 16:19:24 +08:00
|
|
|
|
|
|
|
/// \brief Create instances of all checks matching \p CheckRegexString and
|
|
|
|
/// store them in \p Checks.
|
|
|
|
///
|
|
|
|
/// The caller takes ownership of the return \c ClangTidyChecks.
|
2014-09-12 16:53:36 +08:00
|
|
|
void createChecks(ClangTidyContext *Context,
|
2014-06-05 21:31:45 +08:00
|
|
|
std::vector<std::unique_ptr<ClangTidyCheck>> &Checks);
|
2013-07-29 16:19:24 +08:00
|
|
|
|
2014-09-12 16:53:36 +08:00
|
|
|
typedef std::map<std::string, CheckFactory> FactoryMap;
|
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::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
|
|
|
};
|
|
|
|
|
2014-09-10 19:25:43 +08:00
|
|
|
/// \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;
|
2014-10-16 19:27:57 +08:00
|
|
|
|
|
|
|
/// \brief Gets default options for checks defined in this module.
|
|
|
|
virtual ClangTidyOptions getModuleOptions();
|
2014-09-10 19:25:43 +08:00
|
|
|
};
|
|
|
|
|
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
|