diff options
author | Jordy Rose <jediknil@belkadan.com> | 2011-08-17 02:15:41 +0000 |
---|---|---|
committer | Jordy Rose <jediknil@belkadan.com> | 2011-08-17 02:15:41 +0000 |
commit | 8e240498dfd4355849bcec943e97799f7f75d93d (patch) | |
tree | cade412359ea4bcbcfb8625ebdaa3dbd1c931884 | |
parent | 01a429a1029dd650ed11cc35160451664f664df3 (diff) |
[analyzer] Add some documentation for the new analyzer plugin infrastructure.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137805 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/StaticAnalyzer/Core/CheckerOptInfo.h | 4 | ||||
-rw-r--r-- | include/clang/StaticAnalyzer/Core/CheckerRegistry.h | 60 |
2 files changed, 64 insertions, 0 deletions
diff --git a/include/clang/StaticAnalyzer/Core/CheckerOptInfo.h b/include/clang/StaticAnalyzer/Core/CheckerOptInfo.h index b64fbf2c1f..6ce5b3c509 100644 --- a/include/clang/StaticAnalyzer/Core/CheckerOptInfo.h +++ b/include/clang/StaticAnalyzer/Core/CheckerOptInfo.h @@ -15,6 +15,10 @@ namespace clang { namespace ento { +/// Represents a request to include or exclude a checker or package from a +/// specific analysis run. +/// +/// \sa CheckerRegistry::initializeManager class CheckerOptInfo { StringRef Name; bool Enable; diff --git a/include/clang/StaticAnalyzer/Core/CheckerRegistry.h b/include/clang/StaticAnalyzer/Core/CheckerRegistry.h index 8bf0dd7052..b59c14d32f 100644 --- a/include/clang/StaticAnalyzer/Core/CheckerRegistry.h +++ b/include/clang/StaticAnalyzer/Core/CheckerRegistry.h @@ -14,6 +14,47 @@ #include "clang/Basic/LLVM.h" #include <vector> +// FIXME: move this information to an HTML file in docs/. +// At the very least, a checker plugin is a dynamic library that exports +// clang_analyzerAPIVersionString. This should be defined as follows: +// +// extern "C" +// const char clang_analyzerAPIVersionString[] = +// CLANG_ANALYZER_API_VERSION_STRING; +// +// This is used to check whether the current version of the analyzer is known to +// be incompatible with a plugin. Plugins with incompatible version strings, +// or without a version string at all, will not be loaded. +// +// To add a custom checker to the analyzer, the plugin must also define the +// function clang_registerCheckers. For example: +// +// extern "C" +// void clang_registerCheckers (CheckerRegistry ®istry) { +// registry.addChecker<MainCallChecker>("example.MainCallChecker", +// "Disallows calls to functions called main"); +// } +// +// The first method argument is the full name of the checker, including its +// enclosing package. By convention, the registered name of a checker is the +// name of the associated class (the template argument). +// The second method argument is a short human-readable description of the +// checker. +// +// The clang_registerCheckers function may add any number of checkers to the +// registry. If any checkers require additional initialization, use the three- +// argument form of CheckerRegistry::addChecker. +// +// To load a checker plugin, specify the full path to the dynamic library as +// the argument to the -load option in the cc1 frontend. You can then enable +// your custom checker using the -analyzer-checker: +// +// clang -cc1 -load </path/to/plugin.dylib> -analyze +// -analyzer-checker=<example.MainCallChecker> +// +// For a complete working example, see examples/analyzer-plugin. + + namespace clang { namespace ento { @@ -28,8 +69,16 @@ namespace ento { class CheckerOptInfo; +/// Manages a set of available checkers for running a static analysis. +/// The checkers are organized into packages by full name, where including +/// a package will recursively include all subpackages and checkers within it. +/// For example, the checker "core.builtin.NoReturnFunctionChecker" will be +/// included if initializeManager() is called with an option of "core", +/// "core.builtin", or the full name "core.builtin.NoReturnFunctionChecker". class CheckerRegistry { public: + /// Initialization functions perform any necessary setup for a checker. + /// They should include a call to CheckerManager::registerChecker. typedef void (*InitializationFunction)(CheckerManager &); struct CheckerInfo { InitializationFunction Initialize; @@ -49,16 +98,27 @@ private: } public: + /// Adds a checker to the registry. Use this non-templated overload when your + /// checker requires custom initialization. void addChecker(InitializationFunction fn, StringRef fullName, StringRef desc); + /// Adds a checker to the registry. Use this templated overload when your + /// checker does not require any custom initialization. template <class T> void addChecker(StringRef fullName, StringRef desc) { addChecker(&initializeManager<T>, fullName, desc); } + /// Initializes a CheckerManager by calling the initialization functions for + /// all checkers specified by the given CheckerOptInfo list. The order of this + /// list is significant; later options can be used to reverse earlier ones. + /// This can be used to exclude certain checkers in an included package. void initializeManager(CheckerManager &mgr, SmallVectorImpl<CheckerOptInfo> &opts) const; + + /// Prints the name and description of all checkers in this registry. + /// This output is not intended to be machine-parseable. void printHelp(raw_ostream &out, size_t maxNameChars = 30) const ; private: |