Changeset View
Changeset View
Standalone View
Standalone View
src/checkmanager.h
Show All 25 Lines | |||||
26 | #define CLANG_LAZY_CHECK_MANAGER_H | 26 | #define CLANG_LAZY_CHECK_MANAGER_H | ||
27 | 27 | | |||
28 | #include "clazy_export.h" | 28 | #include "clazy_export.h" | ||
29 | #include "checkbase.h" | 29 | #include "checkbase.h" | ||
30 | 30 | | |||
31 | #include <clang/Lex/PreprocessorOptions.h> | 31 | #include <clang/Lex/PreprocessorOptions.h> | ||
32 | 32 | | |||
33 | #include <functional> | 33 | #include <functional> | ||
34 | #include <mutex> | ||||
34 | #include <unordered_map> | 35 | #include <unordered_map> | ||
35 | 36 | | |||
36 | struct CLAZYLIB_EXPORT RegisteredFixIt { | 37 | struct CLAZYLIB_EXPORT RegisteredFixIt { | ||
37 | typedef std::vector<RegisteredFixIt> List; | 38 | typedef std::vector<RegisteredFixIt> List; | ||
38 | RegisteredFixIt() : id(-1) {} | 39 | RegisteredFixIt() : id(-1) {} | ||
39 | RegisteredFixIt(int id, const std::string &name) : id(id), name(name) {} | 40 | RegisteredFixIt(int id, const std::string &name) : id(id), name(name) {} | ||
40 | int id = -1; | 41 | int id = -1; | ||
41 | std::string name; | 42 | std::string name; | ||
Show All 30 Lines | 72 | if (c1.level == c2.level) | |||
72 | return checkLessThan(c1, c2); | 73 | return checkLessThan(c1, c2); | ||
73 | 74 | | |||
74 | return c1.level < c2.level; | 75 | return c1.level < c2.level; | ||
75 | } | 76 | } | ||
76 | 77 | | |||
77 | class CLAZYLIB_EXPORT CheckManager | 78 | class CLAZYLIB_EXPORT CheckManager | ||
78 | { | 79 | { | ||
79 | public: | 80 | public: | ||
81 | /** | ||||
82 | * @note You must hold the CheckManager lock when operating on the instance | ||||
83 | * | ||||
84 | * @sa lock() | ||||
85 | */ | ||||
80 | static CheckManager *instance(); | 86 | static CheckManager *instance(); | ||
81 | 87 | | |||
88 | static std::mutex &lock() { return m_lock; } | ||||
89 | | ||||
82 | int registerCheck(const std::string &name, const std::string &className, | 90 | int registerCheck(const std::string &name, const std::string &className, | ||
83 | CheckLevel level, const FactoryFunction &, RegisteredCheck::Options = RegisteredCheck::Option_None); | 91 | CheckLevel level, const FactoryFunction &, RegisteredCheck::Options = RegisteredCheck::Option_None); | ||
84 | int registerFixIt(int id, const std::string &fititName, const std::string &checkName); | 92 | int registerFixIt(int id, const std::string &fititName, const std::string &checkName); | ||
85 | 93 | | |||
86 | RegisteredCheck::List availableChecks(CheckLevel maxLevel) const; | 94 | RegisteredCheck::List availableChecks(CheckLevel maxLevel) const; | ||
87 | RegisteredCheck::List requestedChecksThroughEnv(const ClazyContext *context) const; | 95 | RegisteredCheck::List requestedChecksThroughEnv(const ClazyContext *context) const; | ||
88 | RegisteredCheck::List requestedChecksThroughEnv(const ClazyContext *context, std::vector<std::string> &userDisabledChecks) const; | 96 | RegisteredCheck::List requestedChecksThroughEnv(const ClazyContext *context, std::vector<std::string> &userDisabledChecks) const; | ||
89 | 97 | | |||
Show All 11 Lines | |||||
101 | RegisteredCheck::List requestedChecks(const ClazyContext *context, std::vector<std::string> &args); | 109 | RegisteredCheck::List requestedChecks(const ClazyContext *context, std::vector<std::string> &args); | ||
102 | CheckBase::List createChecks(const RegisteredCheck::List &requestedChecks, ClazyContext *context); | 110 | CheckBase::List createChecks(const RegisteredCheck::List &requestedChecks, ClazyContext *context); | ||
103 | 111 | | |||
104 | static void removeChecksFromList(RegisteredCheck::List &list, std::vector<std::string> &checkNames); | 112 | static void removeChecksFromList(RegisteredCheck::List &list, std::vector<std::string> &checkNames); | ||
105 | 113 | | |||
106 | private: | 114 | private: | ||
107 | CheckManager(); | 115 | CheckManager(); | ||
108 | 116 | | |||
117 | static std::mutex m_lock; | ||||
118 | | ||||
109 | bool checkExists(const std::string &name) const; | 119 | bool checkExists(const std::string &name) const; | ||
110 | RegisteredCheck::List checksForLevel(int level) const; | 120 | RegisteredCheck::List checksForLevel(int level) const; | ||
111 | bool isReservedCheckName(const std::string &name) const; | 121 | bool isReservedCheckName(const std::string &name) const; | ||
112 | CheckBase* createCheck(const std::string &name, ClazyContext *context); | 122 | CheckBase* createCheck(const std::string &name, ClazyContext *context); | ||
113 | std::string checkNameForFixIt(const std::string &) const; | 123 | std::string checkNameForFixIt(const std::string &) const; | ||
114 | RegisteredCheck::List m_registeredChecks; | 124 | RegisteredCheck::List m_registeredChecks; | ||
115 | std::unordered_map<std::string, std::vector<RegisteredFixIt> > m_fixitsByCheckName; | 125 | std::unordered_map<std::string, std::vector<RegisteredFixIt> > m_fixitsByCheckName; | ||
116 | std::unordered_map<std::string, RegisteredFixIt > m_fixitByName; | 126 | std::unordered_map<std::string, RegisteredFixIt > m_fixitByName; | ||
Show All 16 Lines |