Tooling.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. =================================================
  2. Choosing the Right Interface for Your Application
  3. =================================================
  4. NOTE: this document applies to the original Clang project, not the DirectX
  5. Compiler. It's made available for informational purposes only. The recommended
  6. APIs for the library are available via dxcapi.h
  7. Clang provides infrastructure to write tools that need syntactic and semantic
  8. information about a program. This document will give a short introduction of
  9. the different ways to write clang tools, and their pros and cons.
  10. LibClang
  11. --------
  12. `LibClang <http://clang.llvm.org/doxygen/group__CINDEX.html>`_ is a stable high
  13. level C interface to clang. When in doubt LibClang is probably the interface
  14. you want to use. Consider the other interfaces only when you have a good
  15. reason not to use LibClang.
  16. Canonical examples of when to use LibClang:
  17. * Xcode
  18. * Clang Python Bindings
  19. Use LibClang when you...:
  20. * want to interface with clang from other languages than C++
  21. * need a stable interface that takes care to be backwards compatible
  22. * want powerful high-level abstractions, like iterating through an AST with a
  23. cursor, and don't want to learn all the nitty gritty details of Clang's AST.
  24. Do not use LibClang when you...:
  25. * want full control over the Clang AST
  26. Clang Plugins
  27. -------------
  28. :doc:`Clang Plugins <ClangPlugins>` allow you to run additional actions on the
  29. AST as part of a compilation. Plugins are dynamic libraries that are loaded at
  30. runtime by the compiler, and they're easy to integrate into your build
  31. environment.
  32. Canonical examples of when to use Clang Plugins:
  33. * special lint-style warnings or errors for your project
  34. * creating additional build artifacts from a single compile step
  35. Use Clang Plugins when you...:
  36. * need your tool to rerun if any of the dependencies change
  37. * want your tool to make or break a build
  38. * need full control over the Clang AST
  39. Do not use Clang Plugins when you...:
  40. * want to run tools outside of your build environment
  41. * want full control on how Clang is set up, including mapping of in-memory
  42. virtual files
  43. * need to run over a specific subset of files in your project which is not
  44. necessarily related to any changes which would trigger rebuilds
  45. LibTooling
  46. ----------
  47. :doc:`LibTooling <LibTooling>` is a C++ interface aimed at writing standalone
  48. tools, as well as integrating into services that run clang tools. Canonical
  49. examples of when to use LibTooling:
  50. * a simple syntax checker
  51. * refactoring tools
  52. Use LibTooling when you...:
  53. * want to run tools over a single file, or a specific subset of files,
  54. independently of the build system
  55. * want full control over the Clang AST
  56. * want to share code with Clang Plugins
  57. Do not use LibTooling when you...:
  58. * want to run as part of the build triggered by dependency changes
  59. * want a stable interface so you don't need to change your code when the AST API
  60. changes
  61. * want high level abstractions like cursors and code completion out of the box
  62. * do not want to write your tools in C++
  63. :doc:`Clang tools <ClangTools>` are a collection of specific developer tools
  64. built on top of the LibTooling infrastructure as part of the Clang project.
  65. They are targeted at automating and improving core development activities of
  66. C/C++ developers.
  67. Examples of tools we are building or planning as part of the Clang project:
  68. * Syntax checking (:program:`clang-check`)
  69. * Automatic fixing of compile errors (:program:`clang-fixit`)
  70. * Automatic code formatting (:program:`clang-format`)
  71. * Migration tools for new features in new language standards
  72. * Core refactoring tools