summaryrefslogtreecommitdiff
path: root/docs/LibTooling.rst
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2014-11-24 09:15:30 +0000
committerDimitry Andric <dim@FreeBSD.org>2014-11-24 09:15:30 +0000
commit9f4dbff6669c8037f3b036bcf580d14f1a4f12a5 (patch)
tree47df2c12b57214af6c31e47404b005675b8b7ffc /docs/LibTooling.rst
parentf73d5f23a889b93d89ddef61ac0995df40286bb8 (diff)
downloadsrc-test2-9f4dbff6669c8037f3b036bcf580d14f1a4f12a5.tar.gz
src-test2-9f4dbff6669c8037f3b036bcf580d14f1a4f12a5.zip
Notes
Diffstat (limited to 'docs/LibTooling.rst')
-rw-r--r--docs/LibTooling.rst25
1 files changed, 17 insertions, 8 deletions
diff --git a/docs/LibTooling.rst b/docs/LibTooling.rst
index 505865606433..75ef6a0fe7ea 100644
--- a/docs/LibTooling.rst
+++ b/docs/LibTooling.rst
@@ -60,13 +60,18 @@ and automatic location of the compilation database using source files paths.
.. code-block:: c++
#include "clang/Tooling/CommonOptionsParser.h"
+ #include "llvm/Support/CommandLine.h"
using namespace clang::tooling;
+ // Apply a custom category to all command-line options so that they are the
+ // only ones displayed.
+ static llvm::cl::OptionCategory MyToolCategory("my-tool options");
+
int main(int argc, const char **argv) {
// CommonOptionsParser constructor will parse arguments and create a
// CompilationDatabase. In case of error it will terminate the program.
- CommonOptionsParser OptionsParser(argc, argv);
+ CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
// Use OptionsParser.getCompilations() and OptionsParser.getSourcePathList()
// to retrieve CompilationDatabase and the list of input file paths.
@@ -94,13 +99,13 @@ our ``FrontendAction`` over some code. For example, to run the
// on. Thus, it takes a FrontendActionFactory as parameter. To create a
// FrontendActionFactory from a given FrontendAction type, we call
// newFrontendActionFactory<clang::SyntaxOnlyAction>().
- int result = Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>());
+ int result = Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>().get());
Putting it together --- the first tool
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Now we combine the two previous steps into our first real tool. This example
-tool is also checked into the clang tree at
+Now we combine the two previous steps into our first real tool. A more advanced
+version of this example tool is also checked into the clang tree at
``tools/clang-check/ClangCheck.cpp``.
.. code-block:: c++
@@ -115,6 +120,10 @@ tool is also checked into the clang tree at
using namespace clang::tooling;
using namespace llvm;
+ // Apply a custom category to all command-line options so that they are the
+ // only ones displayed.
+ static cl::OptionCategory MyToolCategory("my-tool options");
+
// CommonOptionsParser declares HelpMessage with a description of the common
// command-line options related to the compilation database and input files.
// It's nice to have this help message in all tools.
@@ -124,10 +133,10 @@ tool is also checked into the clang tree at
static cl::extrahelp MoreHelp("\nMore help text...");
int main(int argc, const char **argv) {
- CommonOptionsParser OptionsParser(argc, argv);
+ CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
ClangTool Tool(OptionsParser.getCompilations(),
- OptionsParser.getSourcePathList());
- return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>());
+ OptionsParser.getSourcePathList());
+ return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>().get());
}
Running the tool on some code
@@ -176,7 +185,7 @@ Builtin includes
Clang tools need their builtin headers and search for them the same way Clang
does. Thus, the default location to look for builtin headers is in a path
-``$(dirname /path/to/tool)/../lib/clang/3.4/include`` relative to the tool
+``$(dirname /path/to/tool)/../lib/clang/3.3/include`` relative to the tool
binary. This works out-of-the-box for tools running from llvm's toplevel
binary directory after building clang-headers, or if the tool is running from
the binary directory of a clang install next to the clang binary.