xref: /llvm-project/clang/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp (revision bda3dd0d986b33c3a327c0ee0eb8ba43aa140699)
1ccbda6b0SDon Hinton #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
2ccbda6b0SDon Hinton #include "clang/StaticAnalyzer/Core/Checker.h"
3ccbda6b0SDon Hinton #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
4ccbda6b0SDon Hinton #include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
5ccbda6b0SDon Hinton 
6ccbda6b0SDon Hinton using namespace clang;
7ccbda6b0SDon Hinton using namespace ento;
8ccbda6b0SDon Hinton 
9ccbda6b0SDon Hinton namespace {
10ccbda6b0SDon Hinton struct MyChecker : public Checker<check::BeginFunction> {
checkBeginFunction__anonbc30f2660111::MyChecker11ccbda6b0SDon Hinton   void checkBeginFunction(CheckerContext &Ctx) const {}
12ccbda6b0SDon Hinton };
13ccbda6b0SDon Hinton 
registerMyChecker(CheckerManager & Mgr)14ccbda6b0SDon Hinton void registerMyChecker(CheckerManager &Mgr) {
15ccbda6b0SDon Hinton   MyChecker *Checker = Mgr.registerChecker<MyChecker>();
16ccbda6b0SDon Hinton   llvm::outs() << "Example option is set to "
17ccbda6b0SDon Hinton                << (Mgr.getAnalyzerOptions().getCheckerBooleanOption(
18ccbda6b0SDon Hinton                        Checker, "ExampleOption")
19ccbda6b0SDon Hinton                        ? "true"
20ccbda6b0SDon Hinton                        : "false")
21ccbda6b0SDon Hinton                << '\n';
22ccbda6b0SDon Hinton }
23ccbda6b0SDon Hinton 
shouldRegisterMyChecker(const CheckerManager & mgr)24*bda3dd0dSKirstóf Umann bool shouldRegisterMyChecker(const CheckerManager &mgr) { return true; }
25ccbda6b0SDon Hinton 
26ccbda6b0SDon Hinton } // end anonymous namespace
27ccbda6b0SDon Hinton 
28ccbda6b0SDon Hinton // Register plugin!
clang_registerCheckers(CheckerRegistry & registry)29ccbda6b0SDon Hinton extern "C" void clang_registerCheckers(CheckerRegistry &registry) {
30ccbda6b0SDon Hinton   registry.addChecker(registerMyChecker, shouldRegisterMyChecker,
31ccbda6b0SDon Hinton                       "example.MyChecker", "Example Description",
32ccbda6b0SDon Hinton                       "example.mychecker.documentation.nonexistent.html",
33ccbda6b0SDon Hinton                       /*isHidden*/false);
34ccbda6b0SDon Hinton 
35ccbda6b0SDon Hinton   registry.addCheckerOption(/*OptionType*/ "bool",
36ccbda6b0SDon Hinton                             /*CheckerFullName*/ "example.MyChecker",
37ccbda6b0SDon Hinton                             /*OptionName*/ "ExampleOption",
38ccbda6b0SDon Hinton                             /*DefaultValStr*/ "false",
39ccbda6b0SDon Hinton                             /*Description*/ "This is an example checker opt.",
40ccbda6b0SDon Hinton                             /*DevelopmentStage*/ "released");
41ccbda6b0SDon Hinton }
42ccbda6b0SDon Hinton 
43ccbda6b0SDon Hinton extern "C" const char clang_analyzerAPIVersionString[] =
44ccbda6b0SDon Hinton     CLANG_ANALYZER_API_VERSION_STRING;
45