annotate clang/docs/Tooling.rst @ 221:79ff65ed7e25

LLVM12 Original
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:15:29 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 =================================================
anatofuz
parents:
diff changeset
2 Choosing the Right Interface for Your Application
anatofuz
parents:
diff changeset
3 =================================================
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 Clang provides infrastructure to write tools that need syntactic and semantic
anatofuz
parents:
diff changeset
6 information about a program. This document will give a short introduction of
anatofuz
parents:
diff changeset
7 the different ways to write clang tools, and their pros and cons.
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 LibClang
anatofuz
parents:
diff changeset
10 --------
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 `LibClang <https://clang.llvm.org/doxygen/group__CINDEX.html>`_ is a stable high
anatofuz
parents:
diff changeset
13 level C interface to clang. When in doubt LibClang is probably the interface
anatofuz
parents:
diff changeset
14 you want to use. Consider the other interfaces only when you have a good
anatofuz
parents:
diff changeset
15 reason not to use LibClang.
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 Canonical examples of when to use LibClang:
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 * Xcode
anatofuz
parents:
diff changeset
20 * Clang Python Bindings
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 Use LibClang when you...:
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 * want to interface with clang from other languages than C++
anatofuz
parents:
diff changeset
25 * need a stable interface that takes care to be backwards compatible
anatofuz
parents:
diff changeset
26 * want powerful high-level abstractions, like iterating through an AST with a
anatofuz
parents:
diff changeset
27 cursor, and don't want to learn all the nitty gritty details of Clang's AST.
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 Do not use LibClang when you...:
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 * want full control over the Clang AST
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 Clang Plugins
anatofuz
parents:
diff changeset
34 -------------
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 :doc:`Clang Plugins <ClangPlugins>` allow you to run additional actions on the
anatofuz
parents:
diff changeset
37 AST as part of a compilation. Plugins are dynamic libraries that are loaded at
anatofuz
parents:
diff changeset
38 runtime by the compiler, and they're easy to integrate into your build
anatofuz
parents:
diff changeset
39 environment.
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 Canonical examples of when to use Clang Plugins:
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 * special lint-style warnings or errors for your project
anatofuz
parents:
diff changeset
44 * creating additional build artifacts from a single compile step
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 Use Clang Plugins when you...:
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 * need your tool to rerun if any of the dependencies change
anatofuz
parents:
diff changeset
49 * want your tool to make or break a build
anatofuz
parents:
diff changeset
50 * need full control over the Clang AST
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 Do not use Clang Plugins when you...:
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 * want to run tools outside of your build environment
anatofuz
parents:
diff changeset
55 * want full control on how Clang is set up, including mapping of in-memory
anatofuz
parents:
diff changeset
56 virtual files
anatofuz
parents:
diff changeset
57 * need to run over a specific subset of files in your project which is not
anatofuz
parents:
diff changeset
58 necessarily related to any changes which would trigger rebuilds
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 LibTooling
anatofuz
parents:
diff changeset
61 ----------
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 :doc:`LibTooling <LibTooling>` is a C++ interface aimed at writing standalone
anatofuz
parents:
diff changeset
64 tools, as well as integrating into services that run clang tools. Canonical
anatofuz
parents:
diff changeset
65 examples of when to use LibTooling:
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 * a simple syntax checker
anatofuz
parents:
diff changeset
68 * refactoring tools
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 Use LibTooling when you...:
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 * want to run tools over a single file, or a specific subset of files,
anatofuz
parents:
diff changeset
73 independently of the build system
anatofuz
parents:
diff changeset
74 * want full control over the Clang AST
anatofuz
parents:
diff changeset
75 * want to share code with Clang Plugins
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 Do not use LibTooling when you...:
anatofuz
parents:
diff changeset
78
anatofuz
parents:
diff changeset
79 * want to run as part of the build triggered by dependency changes
anatofuz
parents:
diff changeset
80 * want a stable interface so you don't need to change your code when the AST API
anatofuz
parents:
diff changeset
81 changes
anatofuz
parents:
diff changeset
82 * want high level abstractions like cursors and code completion out of the box
anatofuz
parents:
diff changeset
83 * do not want to write your tools in C++
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 :doc:`Clang tools <ClangTools>` are a collection of specific developer tools
anatofuz
parents:
diff changeset
86 built on top of the LibTooling infrastructure as part of the Clang project.
anatofuz
parents:
diff changeset
87 They are targeted at automating and improving core development activities of
anatofuz
parents:
diff changeset
88 C/C++ developers.
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 Examples of tools we are building or planning as part of the Clang project:
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 * Syntax checking (:program:`clang-check`)
anatofuz
parents:
diff changeset
93 * Automatic fixing of compile errors (:program:`clang-fixit`)
anatofuz
parents:
diff changeset
94 * Automatic code formatting (:program:`clang-format`)
anatofuz
parents:
diff changeset
95 * Migration tools for new features in new language standards
anatofuz
parents:
diff changeset
96 * Core refactoring tools
anatofuz
parents:
diff changeset
97