|
39 | 39 | //
|
40 | 40 | // extern "C"
|
41 | 41 | // void clang_registerCheckers(CheckerRegistry &Registry) {
|
42 |
| -// Registry.addChecker( |
43 |
| -// registerMainCallChecker, |
44 |
| -// shouldRegisterMainCallChecker, |
| 42 | +// Registry.addChecker<MainCallChecker>( |
45 | 43 | // "example.MainCallChecker",
|
46 |
| -// "MainCallChecker", |
47 |
| -// "Example Description", |
48 |
| -// "example.mychecker.documentation.nonexistent.html", |
49 |
| -// /*isHidden=*/ false); |
| 44 | +// "Example Description"); |
50 | 45 | // }
|
51 | 46 | //
|
52 |
| -// The first two arguments are the registration handling functions, which |
53 |
| -// in a simple case look like |
| 47 | +// The first argument of this templated method is the full name of the checker |
| 48 | +// (including its package), while the second argument is a short description |
| 49 | +// that is printed by `-analyzer-checker-help`. |
54 | 50 | //
|
55 |
| -// void registerMainCallChecker(CheckerManager &Mgr) { |
56 |
| -// Mgr.registerChecker<MainCallChecker>(); |
57 |
| -// } |
58 |
| -// |
59 |
| -// bool shouldRegisterMainCallChecker(const CheckerManager &) { |
60 |
| -// return true; |
61 |
| -// } |
62 |
| -// |
63 |
| -// The third argument is the full name of the checker (including its package), |
64 |
| -// the fourth name is the internal DebugName (by convention, the name of the |
65 |
| -// class), the fifth argument is a short documentation, the sixth argument is |
66 |
| -// an url to a documentation page, and the seventh argument should be false for |
67 |
| -// normal user-facing checkers. |
| 51 | +// If a checker requires custom registration functions (e.g. checker option |
| 52 | +// handling) use the non-templated variant of `addChecker` that takes two |
| 53 | +// callback functions as the first two parameters. |
68 | 54 | //
|
69 | 55 | // To load a checker plugin, specify the full path to the dynamic library as
|
70 | 56 | // the argument to the -load option in the cc1 frontend. You can then enable
|
|
73 | 59 | // clang -cc1 -load </path/to/plugin.dylib> -analyze
|
74 | 60 | // -analyzer-checker=<example.MainCallChecker>
|
75 | 61 | //
|
76 |
| -// For a complete example, see clang/lib/Analysis/plugins/SampleAnalyzer |
| 62 | +// For complete examples, see clang/lib/Analysis/plugins/SampleAnalyzer |
77 | 63 |
|
78 | 64 | #ifndef CLANG_ANALYZER_API_VERSION_STRING
|
79 | 65 | // FIXME: The Clang version string is not particularly granular;
|
@@ -125,20 +111,34 @@ class CheckerRegistry {
|
125 | 111 | return true;
|
126 | 112 | }
|
127 | 113 |
|
128 |
| -public: |
129 |
| - /// Adds a checker to the registry. Use this non-templated overload when your |
130 |
| - /// checker requires custom initialization. |
| 114 | + /// Adds a checker to the registry. This private, most general variant is |
| 115 | + /// intended for loading the checker definitions from `Checkers.td`. |
| 116 | + /// FIXME: DocsUri is never loaded from the checker registry. |
131 | 117 | void addChecker(RegisterCheckerFn Fn, ShouldRegisterFunction Sfn,
|
132 | 118 | StringRef FullName, StringRef DebugName, StringRef Desc,
|
133 | 119 | StringRef DocsUri, bool IsHidden);
|
134 | 120 |
|
| 121 | +public: |
| 122 | + /// Adds a checker to the registry. Use this for a checker defined in a |
| 123 | + /// plugin if it requires custom registration functions. |
| 124 | + void addChecker(RegisterCheckerFn Fn, ShouldRegisterFunction Sfn, |
| 125 | + StringRef FullName, StringRef Desc, bool IsHidden = false) { |
| 126 | + addChecker(Fn, Sfn, FullName, "CheckerFromPlugin", Desc, "", IsHidden); |
| 127 | + } |
| 128 | + |
| 129 | + /// Adds a checker to the registry. Use this for a checker defined in a |
| 130 | + /// plugin if it doesn't require custom registration functions. |
| 131 | + template <class T> |
| 132 | + void addChecker(StringRef FullName, StringRef Desc, bool IsHidden = false) { |
| 133 | + addChecker(&CheckerRegistry::initializeManager<CheckerManager, T>, |
| 134 | + &CheckerRegistry::returnTrue<T>, FullName, Desc, |
| 135 | + /*IsHidden=*/IsHidden); |
| 136 | + } |
| 137 | + |
135 | 138 | /// Add a mock checker to the registry for testing purposes, without
|
136 | 139 | /// specifying metadata that is not relevant in simple tests.
|
137 | 140 | template <class T> void addMockChecker(StringRef FullName) {
|
138 |
| - addChecker(&CheckerRegistry::initializeManager<CheckerManager, T>, |
139 |
| - &CheckerRegistry::returnTrue<T>, FullName, |
140 |
| - /*DebugName=*/"TestChecker", /*Desc=*/"", /*DocsUri=*/"", |
141 |
| - /*IsHidden=*/false); |
| 141 | + addChecker<T>(FullName, ""); |
142 | 142 | }
|
143 | 143 |
|
144 | 144 | /// Makes the checker with the full name \p fullName depend on the checker
|
|
0 commit comments