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