|
| 1 | +//===--- Format.h - Format C++ code -----------------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// The LLVM Compiler Infrastructure |
| 4 | +// |
| 5 | +// This file is distributed under the University of Illinois Open Source |
| 6 | +// License. See LICENSE.TXT for details. |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | +/// |
| 10 | +/// \file |
| 11 | +/// Various functions to configurably format source code. |
| 12 | +/// |
| 13 | +/// This is EXPERIMENTAL code under heavy development. It is not in a state yet, |
| 14 | +/// where it can be used to format real code. |
| 15 | +/// |
| 16 | +//===----------------------------------------------------------------------===// |
| 17 | + |
| 18 | +#ifndef LLVM_CLANG_FORMAT_FORMAT_H_ |
| 19 | +#define LLVM_CLANG_FORMAT_FORMAT_H |
| 20 | + |
| 21 | +#include "clang/Frontend/FrontendAction.h" |
| 22 | +#include "clang/Tooling/Refactoring.h" |
| 23 | + |
| 24 | +namespace clang { |
| 25 | + |
| 26 | +class Lexer; |
| 27 | +class SourceManager; |
| 28 | + |
| 29 | +namespace format { |
| 30 | + |
| 31 | +/// \brief The \c FormatStyle is used to configure the formatting to follow |
| 32 | +/// specific guidelines. |
| 33 | +struct FormatStyle { |
| 34 | + /// \brief The column limit. |
| 35 | + unsigned ColumnLimit; |
| 36 | + |
| 37 | + /// \brief The maximum number of consecutive empty lines to keep. |
| 38 | + unsigned MaxEmptyLinesToKeep; |
| 39 | + |
| 40 | + /// \brief Set whether & and * bind to the type as opposed to the variable. |
| 41 | + bool PointerAndReferenceBindToType; |
| 42 | + |
| 43 | + /// \brief The extra indent or outdent of access modifiers (e.g.: public:). |
| 44 | + int AccessModifierOffset; |
| 45 | + |
| 46 | + /// \brief Split two consecutive closing '>' by a space, i.e. use |
| 47 | + /// A<A<int> > instead of A<A<int>>. |
| 48 | + bool SplitTemplateClosingGreater; |
| 49 | +}; |
| 50 | + |
| 51 | +/// \brief Returns a format style complying with the LLVM coding standards: |
| 52 | +/// http://llvm.org/docs/CodingStandards.html. |
| 53 | +FormatStyle getLLVMStyle(); |
| 54 | + |
| 55 | +/// \brief Returns a format style complying with Google's C++ style guide: |
| 56 | +/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml. |
| 57 | +FormatStyle getGoogleStyle(); |
| 58 | + |
| 59 | +/// \brief Reformats the given \p Ranges in the token stream coming out of |
| 60 | +/// \c Lex. |
| 61 | +/// |
| 62 | +/// Each range is extended on either end to its next bigger logic unit, i.e. |
| 63 | +/// everything that might influence its formatting or might be influenced by its |
| 64 | +/// formatting. |
| 65 | +/// |
| 66 | +/// Returns the \c Replacements necessary to make all \p Ranges comply with |
| 67 | +/// \p Style. |
| 68 | +tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex, |
| 69 | + SourceManager &SourceMgr, |
| 70 | + std::vector<CharSourceRange> Ranges); |
| 71 | + |
| 72 | +} // end namespace format |
| 73 | +} // end namespace clang |
| 74 | + |
| 75 | +#endif // LLVM_CLANG_FORMAT_FORMAT_H |
0 commit comments