]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/llvm/tools/clang/include/clang/Format/Format.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / llvm / tools / clang / include / clang / Format / Format.h
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 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_FORMAT_FORMAT_H
16 #define LLVM_CLANG_FORMAT_FORMAT_H
17
18 #include "clang/Frontend/FrontendAction.h"
19 #include "clang/Tooling/Refactoring.h"
20
21 namespace clang {
22
23 class Lexer;
24 class SourceManager;
25 class DiagnosticConsumer;
26
27 namespace format {
28
29 /// \brief The \c FormatStyle is used to configure the formatting to follow
30 /// specific guidelines.
31 struct FormatStyle {
32   /// \brief The column limit.
33   unsigned ColumnLimit;
34
35   /// \brief The penalty for each character outside of the column limit.
36   unsigned PenaltyExcessCharacter;
37
38   /// \brief The maximum number of consecutive empty lines to keep.
39   unsigned MaxEmptyLinesToKeep;
40
41   /// \brief Set whether & and * bind to the type as opposed to the variable.
42   bool PointerBindsToType;
43
44   /// \brief If \c true, analyze the formatted file for the most common binding.
45   bool DerivePointerBinding;
46
47   /// \brief The extra indent or outdent of access modifiers (e.g.: public:).
48   int AccessModifierOffset;
49
50   enum LanguageStandard {
51     LS_Cpp03,
52     LS_Cpp11,
53     LS_Auto
54   };
55
56   /// \brief Format compatible with this standard, e.g. use \c A<A<int> >
57   /// instead of \c A<A<int>> for LS_Cpp03.
58   LanguageStandard Standard;
59
60   /// \brief Indent case labels one level from the switch statement.
61   ///
62   /// When false, use the same indentation level as for the switch statement.
63   /// Switch statement body is always indented one level more than case labels.
64   bool IndentCaseLabels;
65
66   /// \brief The number of spaces to before trailing line comments.
67   unsigned SpacesBeforeTrailingComments;
68
69   /// \brief If false, a function call's or function definition's parameters
70   /// will either all be on the same line or will have one line each.
71   bool BinPackParameters;
72
73   /// \brief Allow putting all parameters of a function declaration onto
74   /// the next line even if \c BinPackParameters is \c false.
75   bool AllowAllParametersOfDeclarationOnNextLine;
76
77   /// \brief Penalty for putting the return type of a function onto its own
78   /// line.
79   unsigned PenaltyReturnTypeOnItsOwnLine;
80
81   /// \brief If the constructor initializers don't fit on a line, put each
82   /// initializer on its own line.
83   bool ConstructorInitializerAllOnOneLineOrOnePerLine;
84
85   /// \brief If true, "if (a) return;" can be put on a single line.
86   bool AllowShortIfStatementsOnASingleLine;
87
88   /// \brief Add a space in front of an Objective-C protocol list, i.e. use
89   /// Foo <Protocol> instead of Foo<Protocol>.
90   bool ObjCSpaceBeforeProtocolList;
91
92   /// \brief If \c true, aligns escaped newlines as far left as possible.
93   /// Otherwise puts them into the right-most column.
94   bool AlignEscapedNewlinesLeft;
95 };
96
97 /// \brief Returns a format style complying with the LLVM coding standards:
98 /// http://llvm.org/docs/CodingStandards.html.
99 FormatStyle getLLVMStyle();
100
101 /// \brief Returns a format style complying with Google's C++ style guide:
102 /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
103 FormatStyle getGoogleStyle();
104
105 /// \brief Returns a format style complying with Chromium's style guide:
106 /// http://www.chromium.org/developers/coding-style.
107 FormatStyle getChromiumStyle();
108
109 /// \brief Returns a format style complying with Mozilla's style guide:
110 /// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
111 FormatStyle getMozillaStyle();
112
113 /// \brief Reformats the given \p Ranges in the token stream coming out of
114 /// \c Lex.
115 ///
116 /// Each range is extended on either end to its next bigger logic unit, i.e.
117 /// everything that might influence its formatting or might be influenced by its
118 /// formatting.
119 ///
120 /// \param DiagClient A custom DiagnosticConsumer. Can be 0, in this case
121 /// diagnostic is output to llvm::errs().
122 ///
123 /// Returns the \c Replacements necessary to make all \p Ranges comply with
124 /// \p Style.
125 tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
126                                SourceManager &SourceMgr,
127                                std::vector<CharSourceRange> Ranges,
128                                DiagnosticConsumer *DiagClient = 0);
129
130 /// \brief Returns the \c LangOpts that the formatter expects you to set.
131 LangOptions getFormattingLangOpts();
132
133 } // end namespace format
134 } // end namespace clang
135
136 #endif // LLVM_CLANG_FORMAT_FORMAT_H