File indexing completed on 2026-05-10 08:36:23
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYMODULE_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYMODULE_H
0011
0012 #include "ClangTidyOptions.h"
0013 #include "llvm/ADT/StringMap.h"
0014 #include "llvm/ADT/StringRef.h"
0015 #include <functional>
0016 #include <memory>
0017
0018 namespace clang::tidy {
0019
0020 class ClangTidyCheck;
0021 class ClangTidyContext;
0022
0023
0024
0025
0026
0027 class ClangTidyCheckFactories {
0028 public:
0029 using CheckFactory = std::function<std::unique_ptr<ClangTidyCheck>(
0030 llvm::StringRef Name, ClangTidyContext *Context)>;
0031
0032
0033
0034
0035 void registerCheckFactory(llvm::StringRef Name, CheckFactory Factory);
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 template <typename CheckType> void registerCheck(llvm::StringRef CheckName) {
0059 registerCheckFactory(CheckName,
0060 [](llvm::StringRef Name, ClangTidyContext *Context) {
0061 return std::make_unique<CheckType>(Name, Context);
0062 });
0063 }
0064
0065
0066 std::vector<std::unique_ptr<ClangTidyCheck>>
0067 createChecks(ClangTidyContext *Context) const;
0068
0069
0070 std::vector<std::unique_ptr<ClangTidyCheck>>
0071 createChecksForLanguage(ClangTidyContext *Context) const;
0072
0073 using FactoryMap = llvm::StringMap<CheckFactory>;
0074 FactoryMap::const_iterator begin() const { return Factories.begin(); }
0075 FactoryMap::const_iterator end() const { return Factories.end(); }
0076 bool empty() const { return Factories.empty(); }
0077
0078 private:
0079 FactoryMap Factories;
0080 };
0081
0082
0083
0084 class ClangTidyModule {
0085 public:
0086 virtual ~ClangTidyModule() {}
0087
0088
0089
0090 virtual void addCheckFactories(ClangTidyCheckFactories &CheckFactories) = 0;
0091
0092
0093 virtual ClangTidyOptions getModuleOptions();
0094 };
0095
0096 }
0097
0098 #endif