Lines Matching +full:clang +full:- +full:tools
5 LibTooling is a library to support writing standalone tools based on Clang.
9 For the information on how to setup Clang Tooling for LLVM see
13 ------------
15 Tools built with LibTooling, like Clang Plugins, run ``FrontendActions`` over
20 In this tutorial, we'll demonstrate the different ways of running Clang's
24 --------------------------------
27 example to unit test parts of the Clang AST, ``runToolOnCode`` is what you
30 .. code-block:: c++
32 #include "clang/Tooling/Tooling.h"
37 EXPECT_TRUE(runToolOnCode(new clang::SyntaxOnlyAction, "class X {};"));
41 -------------------------
45 to run clang, it first needs to figure out what command line arguments to use
48 of them depending on command-line options. There's the ``CommonOptionsParser``
49 class that takes the responsibility to parse command-line parameters related to
50 compilation databases and inputs, so that all tools share the implementation.
52 Parsing common tools options
57 command line, specification of build path using the ``-p`` command-line option,
60 .. code-block:: c++
62 #include "clang/Tooling/CommonOptionsParser.h"
65 using namespace clang::tooling;
67 // Apply a custom category to all command-line options so that they are the
69 static llvm::cl::OptionCategory MyToolCategory("my-tool options");
87 .. code-block:: c++
89 // A clang tool can run over a number of sources in the same process...
101 // newFrontendActionFactory<clang::SyntaxOnlyAction>().
102 int result = Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>().get());
104 Putting it together --- the first tool
108 version of this example tool is also checked into the clang tree at
109 ``tools/clang-check/ClangCheck.cpp``.
111 .. code-block:: c++
113 // Declares clang::SyntaxOnlyAction.
114 #include "clang/Frontend/FrontendActions.h"
115 #include "clang/Tooling/CommonOptionsParser.h"
116 #include "clang/Tooling/Tooling.h"
120 using namespace clang::tooling;
123 // Apply a custom category to all command-line options so that they are the
125 static cl::OptionCategory MyToolCategory("my-tool options");
128 // command-line options related to the compilation database and input files.
129 // It's nice to have this help message in all tools.
139 return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>().get());
145 When you check out and build clang, clang-check is already built and available
146 to you in bin/clang-check inside your build directory.
148 You can run clang-check on a file in the llvm repository by specifying all the
149 needed parameters after a "``--``" separator:
151 .. code-block:: bash
155 $ $BD/bin/clang-check tools/clang/tools/clang-check/ClangCheck.cpp -- \
156 clang++ -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS \
157 -Itools/clang/include -I$BD/include -Iinclude \
158 -Itools/clang/lib/Headers -c
163 .. code-block:: bash
167 $ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
170 Now you can run :program:`clang-check` over files in the project by specifying
174 .. code-block:: bash
178 $ $BD/bin/clang-check -p $BD tools/clang/tools/clang-check/ClangCheck.cpp
186 Clang tools need their builtin headers and search for them the same way Clang
188 ``$(dirname /path/to/tool)/../lib/clang/3.3/include`` relative to the tool
189 binary. This works out-of-the-box for tools running from llvm's toplevel
190 binary directory after building clang-headers, or if the tool is running from
191 the binary directory of a clang install next to the clang binary.
194 with ``-v`` and look at the search paths it looks through.
199 For a list of libraries to link, look at one of the tools' Makefiles (for
200 example `clang-check/Makefile
201 <http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-check/Makefile?view=markup>`_).