Source code

Revision control

Other Tools

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#ifndef BaseCheck_h__
6
#define BaseCheck_h__
7
8
class MozContext {};
9
typedef MozContext ContextType;
10
11
class BaseCheck : public MatchFinder::MatchCallback {
12
public:
13
BaseCheck(StringRef CheckName, ContextType *Context) {}
14
virtual void registerMatchers(MatchFinder *Finder) {}
15
virtual void registerPPCallbacks(CompilerInstance &CI) {}
16
virtual void check(const MatchFinder::MatchResult &Result) {}
17
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description,
18
DiagnosticIDs::Level Level = DiagnosticIDs::Warning) {
19
DiagnosticsEngine &Diag = Context->getDiagnostics();
20
unsigned ID = Diag.getDiagnosticIDs()->getCustomDiagID(Level, Description);
21
return Diag.Report(Loc, ID);
22
}
23
24
private:
25
void run(const MatchFinder::MatchResult &Result) override {
26
Context = Result.Context;
27
check(Result);
28
}
29
30
private:
31
ASTContext *Context;
32
};
33
34
#endif