185a77c16SDaniel Jasper========= 285a77c16SDaniel JasperLibFormat 385a77c16SDaniel Jasper========= 485a77c16SDaniel Jasper 585a77c16SDaniel JasperLibFormat is a library that implements automatic source code formatting based 685a77c16SDaniel Jasperon Clang. This documents describes the LibFormat interface and design as well 785a77c16SDaniel Jasperas some basic style discussions. 885a77c16SDaniel Jasper 985a77c16SDaniel JasperIf you just want to use `clang-format` as a tool or integrated into an editor, 1085a77c16SDaniel Jaspercheckout :doc:`ClangFormat`. 1185a77c16SDaniel Jasper 1285a77c16SDaniel JasperDesign 1385a77c16SDaniel Jasper------ 1485a77c16SDaniel Jasper 1585a77c16SDaniel JasperFIXME: Write up design. 1685a77c16SDaniel Jasper 1785a77c16SDaniel Jasper 1885a77c16SDaniel JasperInterface 1985a77c16SDaniel Jasper--------- 2085a77c16SDaniel Jasper 2185a77c16SDaniel JasperThe core routine of LibFormat is ``reformat()``: 2285a77c16SDaniel Jasper 2385a77c16SDaniel Jasper.. code-block:: c++ 2485a77c16SDaniel Jasper 2585a77c16SDaniel Jasper tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex, 2685a77c16SDaniel Jasper SourceManager &SourceMgr, 2785a77c16SDaniel Jasper std::vector<CharSourceRange> Ranges); 2885a77c16SDaniel Jasper 2985a77c16SDaniel JasperThis reads a token stream out of the lexer ``Lex`` and reformats all the code 3085a77c16SDaniel Jasperranges in ``Ranges``. The ``FormatStyle`` controls basic decisions made during 3185a77c16SDaniel Jasperformatting. A list of options can be found under :ref:`style-options`. 3269f49ce8SSylvestre Ledru 3369f49ce8SSylvestre LedruThe style options are described in :doc:`ClangFormatStyleOptions`. 3485a77c16SDaniel Jasper 3585a77c16SDaniel Jasper 3685a77c16SDaniel Jasper.. _style-options: 3785a77c16SDaniel Jasper 3885a77c16SDaniel JasperStyle Options 3985a77c16SDaniel Jasper------------- 4085a77c16SDaniel Jasper 4185a77c16SDaniel JasperThe style options describe specific formatting options that can be used in 4285a77c16SDaniel Jasperorder to make `ClangFormat` comply with different style guides. Currently, 4351dbda54SJake Merdichseveral style guides are hard-coded: 4485a77c16SDaniel Jasper 4585a77c16SDaniel Jasper.. code-block:: c++ 4685a77c16SDaniel Jasper 479fc8faf9SAdrian Prantl /// Returns a format style complying with the LLVM coding standards: 48bc5c3f57SSylvestre Ledru /// https://llvm.org/docs/CodingStandards.html. 4985a77c16SDaniel Jasper FormatStyle getLLVMStyle(); 5085a77c16SDaniel Jasper 519fc8faf9SAdrian Prantl /// Returns a format style complying with Google's C++ style guide: 5285a77c16SDaniel Jasper /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml. 5385a77c16SDaniel Jasper FormatStyle getGoogleStyle(); 5485a77c16SDaniel Jasper 5551dbda54SJake Merdich /// Returns a format style complying with Chromium's style guide: 56*c71fbdd8SQuinn Pham /// https://chromium.googlesource.com/chromium/src/+/refs/heads/main/styleguide/styleguide.md 5751dbda54SJake Merdich FormatStyle getChromiumStyle(); 5851dbda54SJake Merdich 5951dbda54SJake Merdich /// Returns a format style complying with the GNU coding standards: 6051dbda54SJake Merdich /// https://www.gnu.org/prep/standards/standards.html 6151dbda54SJake Merdich FormatStyle getGNUStyle(); 6251dbda54SJake Merdich 6351dbda54SJake Merdich /// Returns a format style complying with Mozilla's style guide 6451dbda54SJake Merdich /// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html 6551dbda54SJake Merdich FormatStyle getMozillaStyle(); 6651dbda54SJake Merdich 6751dbda54SJake Merdich /// Returns a format style complying with Webkit's style guide: 6851dbda54SJake Merdich /// https://webkit.org/code-style-guidelines/ 6951dbda54SJake Merdich FormatStyle getWebkitStyle(); 7051dbda54SJake Merdich 7151dbda54SJake Merdich /// Returns a format style complying with Microsoft's style guide: 7251dbda54SJake Merdich /// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference 7351dbda54SJake Merdich FormatStyle getMicrosoftStyle(); 7451dbda54SJake Merdich 7585a77c16SDaniel JasperThese options are also exposed in the :doc:`standalone tools <ClangFormat>` 7685a77c16SDaniel Jasperthrough the `-style` option. 7785a77c16SDaniel Jasper 7885a77c16SDaniel JasperIn the future, we plan on making this configurable. 79