LibFormat.rst 1.6 KB

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