LibFormat.rst 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. =========
  2. LibFormat
  3. =========
  4. NOTE: this document applies to the original Clang project, not the DirectX
  5. Compiler. It's made available for informational purposes only.
  6. LibFormat is a library that implements automatic source code formatting based
  7. on Clang. This documents describes the LibFormat interface and design as well
  8. as some basic style discussions.
  9. If you just want to use `clang-format` as a tool or integrated into an editor,
  10. checkout :doc:`ClangFormat`.
  11. Design
  12. ------
  13. FIXME: Write up design.
  14. Interface
  15. ---------
  16. The core routine of LibFormat is ``reformat()``:
  17. .. code-block:: c++
  18. tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
  19. SourceManager &SourceMgr,
  20. std::vector<CharSourceRange> Ranges);
  21. This reads a token stream out of the lexer ``Lex`` and reformats all the code
  22. ranges in ``Ranges``. The ``FormatStyle`` controls basic decisions made during
  23. formatting. A list of options can be found under :ref:`style-options`.
  24. .. _style-options:
  25. Style Options
  26. -------------
  27. The style options describe specific formatting options that can be used in
  28. order to make `ClangFormat` comply with different style guides. Currently,
  29. two style guides are hard-coded:
  30. .. code-block:: c++
  31. /// \brief Returns a format style complying with the LLVM coding standards:
  32. /// http://llvm.org/docs/CodingStandards.html.
  33. FormatStyle getLLVMStyle();
  34. /// \brief Returns a format style complying with Google's C++ style guide:
  35. /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
  36. FormatStyle getGoogleStyle();
  37. These options are also exposed in the :doc:`standalone tools <ClangFormat>`
  38. through the `-style` option.
  39. In the future, we plan on making this configurable.