1*f4a2713aSLionel Sambuc========= 2*f4a2713aSLionel SambucLibFormat 3*f4a2713aSLionel Sambuc========= 4*f4a2713aSLionel Sambuc 5*f4a2713aSLionel SambucLibFormat is a library that implements automatic source code formatting based 6*f4a2713aSLionel Sambucon Clang. This documents describes the LibFormat interface and design as well 7*f4a2713aSLionel Sambucas some basic style discussions. 8*f4a2713aSLionel Sambuc 9*f4a2713aSLionel SambucIf you just want to use `clang-format` as a tool or integrated into an editor, 10*f4a2713aSLionel Sambuccheckout :doc:`ClangFormat`. 11*f4a2713aSLionel Sambuc 12*f4a2713aSLionel SambucDesign 13*f4a2713aSLionel Sambuc------ 14*f4a2713aSLionel Sambuc 15*f4a2713aSLionel SambucFIXME: Write up design. 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambuc 18*f4a2713aSLionel SambucInterface 19*f4a2713aSLionel Sambuc--------- 20*f4a2713aSLionel Sambuc 21*f4a2713aSLionel SambucThe core routine of LibFormat is ``reformat()``: 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc.. code-block:: c++ 24*f4a2713aSLionel Sambuc 25*f4a2713aSLionel Sambuc tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex, 26*f4a2713aSLionel Sambuc SourceManager &SourceMgr, 27*f4a2713aSLionel Sambuc std::vector<CharSourceRange> Ranges); 28*f4a2713aSLionel Sambuc 29*f4a2713aSLionel SambucThis reads a token stream out of the lexer ``Lex`` and reformats all the code 30*f4a2713aSLionel Sambucranges in ``Ranges``. The ``FormatStyle`` controls basic decisions made during 31*f4a2713aSLionel Sambucformatting. A list of options can be found under :ref:`style-options`. 32*f4a2713aSLionel Sambuc 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambuc.. _style-options: 35*f4a2713aSLionel Sambuc 36*f4a2713aSLionel SambucStyle Options 37*f4a2713aSLionel Sambuc------------- 38*f4a2713aSLionel Sambuc 39*f4a2713aSLionel SambucThe style options describe specific formatting options that can be used in 40*f4a2713aSLionel Sambucorder to make `ClangFormat` comply with different style guides. Currently, 41*f4a2713aSLionel Sambuctwo style guides are hard-coded: 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambuc.. code-block:: c++ 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambuc /// \brief Returns a format style complying with the LLVM coding standards: 46*f4a2713aSLionel Sambuc /// http://llvm.org/docs/CodingStandards.html. 47*f4a2713aSLionel Sambuc FormatStyle getLLVMStyle(); 48*f4a2713aSLionel Sambuc 49*f4a2713aSLionel Sambuc /// \brief Returns a format style complying with Google's C++ style guide: 50*f4a2713aSLionel Sambuc /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml. 51*f4a2713aSLionel Sambuc FormatStyle getGoogleStyle(); 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel SambucThese options are also exposed in the :doc:`standalone tools <ClangFormat>` 54*f4a2713aSLionel Sambucthrough the `-style` option. 55*f4a2713aSLionel Sambuc 56*f4a2713aSLionel SambucIn the future, we plan on making this configurable. 57