2013-07-29 16:19:24 +08:00
|
|
|
//===--- ClangTidyModule.h - clang-tidy -------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-07-29 16:19:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-03-10 00:52:33 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYMODULE_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYMODULE_H
|
2013-07-29 16:19:24 +08:00
|
|
|
|
|
|
|
#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:
|
2016-11-08 15:50:19 +08:00
|
|
|
typedef std::function<ClangTidyCheck *(StringRef Name,
|
|
|
|
ClangTidyContext *Context)>
|
|
|
|
CheckFactory;
|
2014-09-12 16:53:36 +08:00
|
|
|
|
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) {
|
2016-11-08 15:50:19 +08:00
|
|
|
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:
|
2015-10-21 05:45:52 +08:00
|
|
|
virtual ~ClangTidyModule() {}
|
2014-09-10 19:25:43 +08:00
|
|
|
|
|
|
|
/// \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
|
|
|
|
|
2015-03-10 00:52:33 +08:00
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYMODULE_H
|