blob: 340abf68933a20f1472c46428910ffc95dd4d4ef [file] [log] [blame]
Manuel Klimek9771a9e2012-04-25 13:57:00 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
5<title>Writing Clang Tools</title>
6<link type="text/css" rel="stylesheet" href="../menu.css">
7<link type="text/css" rel="stylesheet" href="../content.css">
8</head>
9<body>
10<div id="content">
11
12<h1>Writing Clang Tools</h1>
13<p>Clang provides infrastructure to write tools that need syntactic and semantic
14information about a program. This document will give a short introduction of the
15different ways to write clang tools, and their pros and cons.</p>
16
17<!-- ======================================================================= -->
18<h2 id="libclang"><a href="http://clang.llvm.org/doxygen/group__CINDEX.html">LibClang</a></h2>
19<!-- ======================================================================= -->
20
21<p>LibClang is a stable high level C interface to clang. When in doubt LibClang
22is probably the interface you want to use. Consider the other interfaces only
23when you have a good reason not to use LibClang.</p>
24<p>Canonical examples of when to use LibClang:</p>
25<ul>
Jean-Daniel Dupas332f9aa2012-05-13 14:32:11 +000026 <li>Xcode</li>
Manuel Klimek9771a9e2012-04-25 13:57:00 +000027 <li>Clang Python Bindings</li>
28</ul>
29<p>Use LibClang when you...</p>
30<ul>
31 <li>want to interface with clang from other languages than C++</li>
32 <li>need a stable interface that takes care to be backwards compatible</li>
33 <li>want powerful high-level abstractions, like iterating throught an AST
34with a cursor, and don't want to learn all the nitty gritty details of Clang's
35AST.</li>
36</ul>
37<p>Do not use LibClang when you...</p>
38<ul>
39 <li>want full control over the Clang AST</li>
40</ul>
41
42<!-- ======================================================================= -->
43<h2 id="clang-plugins"><a href="http://clang.llvm.org/doxygen/classclang_1_1PluginASTAction.html">Clang Plugins</a></h2>
44<!-- ======================================================================= -->
45
46<p>Clang Plugins allow you to run additional actions on the AST as part of
47a compilation. Plugins are dynamic libraries that are loaded at runtime by
48the compiler, and they're easy to integrate into your build environment.</p>
49<p>Canonical examples of when to use Clang Plugins:</p>
50<ul>
51 <li>special lint-style warnings or errors for your project</li>
52 <li>creating additional build artifacts from a single compile step</li>
53</ul>
54<p>Use Clang Plugins when you...</p>
55<ul>
56 <li>need your tool to rerun if any of the dependencies change</li>
57 <li>want your tool to make or break a build</li>
58 <li>need full control over the Clang AST</li>
59</ul>
60<p>Do not use Clang Plugins when you...</p>
61<ul>
62 <li>want to run tools outside of your build environment</li>
63 <li>want full control on how Clang is set up, including mapping of in-memory
64 virtual files</li>
65 <li>need to run over a specific subset of files in your project which is not
66 necessarily related to any changes which would trigger rebuilds</li>
67</ul>
68
69<!-- ======================================================================= -->
70<h2 id="libtooling"><a href="http://clang.llvm.org/doxygen/namespaceclang_1_1tooling.html">LibTooling</a></h2>
71<!-- ======================================================================= -->
72
73<p>LibTooling is a C++ interface aimed at writing standalone tools, as well as
74integrating into services that run clang tools.</p>
75<p>Canonical examples of when to use LibTooling:</p>
76<ul>
77 <li>a simple syntax checker</li>
78 <li>refactoring tools</li>
79</ul>
80<p>Use LibTooling when you...</p>
81<ul>
82 <li>want to run tools over a single file, or a specific subset of files,
83 independently of the build system</li>
84 <li>want full control over the Clang AST</li>
85 <li>want to share code with Clang Plugins</li>
86</ul>
87<p>Do not use LibTooling when you...</p>
88<ul>
89 <li>want to run as part of the build triggered by dependency changes</li>
90 <li>want a stable interface so you don't need to change your code when the
91 AST API changes</li>
92 <li>want high level abstractions like cursors and code completion out of the
93 box</li>
94 <li>do not want to write your tools in C++</li>
95</ul>
96
97</div>
98</body>
99</html>
100