clang  3.7.0
Format.h
Go to the documentation of this file.
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 
20 #include "llvm/ADT/ArrayRef.h"
21 #include <system_error>
22 
23 namespace clang {
24 
25 class Lexer;
26 class SourceManager;
27 class DiagnosticConsumer;
28 
29 namespace format {
30 
31 enum class ParseError { Success = 0, Error, Unsuitable };
32 class ParseErrorCategory final : public std::error_category {
33 public:
34  const char *name() const LLVM_NOEXCEPT override;
35  std::string message(int EV) const override;
36 };
37 const std::error_category &getParseCategory();
38 std::error_code make_error_code(ParseError e);
39 
40 /// \brief The \c FormatStyle is used to configure the formatting to follow
41 /// specific guidelines.
42 struct FormatStyle {
43  /// \brief The extra indent or outdent of access modifiers, e.g. \c public:.
45 
46  /// \brief If \c true, horizontally aligns arguments after an open bracket.
47  ///
48  /// This applies to round brackets (parentheses), angle brackets and square
49  /// brackets. This will result in formattings like
50  /// \code
51  /// someLongFunction(argument1,
52  /// argument2);
53  /// \endcode
55 
56  /// \brief If \c true, aligns consecutive assignments.
57  ///
58  /// This will align the assignment operators of consecutive lines. This
59  /// will result in formattings like
60  /// \code
61  /// int aaaa = 12;
62  /// int b = 23;
63  /// int ccc = 23;
64  /// \endcode
66 
67  /// \brief If \c true, aligns escaped newlines as far left as possible.
68  /// Otherwise puts them into the right-most column.
70 
71  /// \brief If \c true, horizontally align operands of binary and ternary
72  /// expressions.
74 
75  /// \brief If \c true, aligns trailing comments.
77 
78  /// \brief Allow putting all parameters of a function declaration onto
79  /// the next line even if \c BinPackParameters is \c false.
81 
82  /// \brief Allows contracting simple braced statements to a single line.
83  ///
84  /// E.g., this allows <tt>if (a) { return; }</tt> to be put on a single line.
86 
87  /// \brief If \c true, short case labels will be contracted to a single line.
89 
90  /// \brief Different styles for merging short functions containing at most one
91  /// statement.
93  /// \brief Never merge functions into a single line.
95  /// \brief Only merge empty functions.
97  /// \brief Only merge functions defined inside a class. Implies "empty".
99  /// \brief Merge all functions fitting on a single line.
101  };
102 
103  /// \brief Dependent on the value, <tt>int f() { return 0; }</tt> can be put
104  /// on a single line.
106 
107  /// \brief If \c true, <tt>if (a) return;</tt> can be put on a single
108  /// line.
110 
111  /// \brief If \c true, <tt>while (true) continue;</tt> can be put on a
112  /// single line.
114 
115  /// \brief Different ways to break after the function definition return type.
117  /// Break after return type automatically.
118  /// \c PenaltyReturnTypeOnItsOwnLine is taken into account.
120  /// Always break after the return type.
122  /// Always break after the return types of top level functions.
124  };
125 
126  /// \brief The function definition return type breaking style to use.
128 
129  /// \brief If \c true, always break before multiline string literals.
130  ///
131  /// This flag is mean to make cases where there are multiple multiline strings
132  /// in a file look more consistent. Thus, it will only take effect if wrapping
133  /// the string at that point leads to it being indented
134  /// \c ContinuationIndentWidth spaces from the start of the line.
136 
137  /// \brief If \c true, always break after the <tt>template<...></tt> of a
138  /// template declaration.
140 
141  /// \brief If \c false, a function call's arguments will either be all on the
142  /// same line or will have one line each.
144 
145  /// \brief If \c false, a function declaration's or function definition's
146  /// parameters will either all be on the same line or will have one line each.
148 
149  /// \brief The style of breaking before or after binary operators.
151  /// Break after operators.
153  /// Break before operators that aren't assignments.
155  /// Break before operators.
157  };
158 
159  /// \brief The way to wrap binary operators.
161 
162  /// \brief Different ways to attach braces to their surrounding context.
164  /// Always attach braces to surrounding context.
166  /// Like \c Attach, but break before braces on function, namespace and
167  /// class definitions.
169  /// Like ``Attach``, but break before braces on enum, function, and record
170  /// definitions.
172  /// Like \c Attach, but break before function definitions, and 'else'.
174  /// Always break before braces.
176  /// Always break before braces and add an extra level of indentation to
177  /// braces of control statements, not to those of class, function
178  /// or other definitions.
180  };
181 
182  /// \brief The brace breaking style to use.
184 
185  /// \brief If \c true, ternary operators will be placed after line breaks.
187 
188  /// \brief Always break constructor initializers before commas and align
189  /// the commas with the colon.
191 
192  /// \brief The column limit.
193  ///
194  /// A column limit of \c 0 means that there is no column limit. In this case,
195  /// clang-format will respect the input's line breaking decisions within
196  /// statements unless they contradict other rules.
197  unsigned ColumnLimit;
198 
199  /// \brief A regular expression that describes comments with special meaning,
200  /// which should not be split into lines or otherwise changed.
201  std::string CommentPragmas;
202 
203  /// \brief If the constructor initializers don't fit on a line, put each
204  /// initializer on its own line.
206 
207  /// \brief The number of characters to use for indentation of constructor
208  /// initializer lists.
210 
211  /// \brief Indent width for line continuations.
213 
214  /// \brief If \c true, format braced lists as best suited for C++11 braced
215  /// lists.
216  ///
217  /// Important differences:
218  /// - No spaces inside the braced list.
219  /// - No line break before the closing brace.
220  /// - Indentation with the continuation indent, not with the block indent.
221  ///
222  /// Fundamentally, C++11 braced lists are formatted exactly like function
223  /// calls would be formatted in their place. If the braced list follows a name
224  /// (e.g. a type or variable name), clang-format formats as if the \c {} were
225  /// the parentheses of a function call with that name. If there is no name,
226  /// a zero-length name is assumed.
228 
229  /// \brief If \c true, analyze the formatted file for the most common
230  /// alignment of & and *. \c PointerAlignment is then used only as fallback.
232 
233  /// \brief Disables formatting completely.
235 
236  /// \brief If \c true, clang-format detects whether function calls and
237  /// definitions are formatted with one parameter per line.
238  ///
239  /// Each call can be bin-packed, one-per-line or inconclusive. If it is
240  /// inconclusive, e.g. completely on one line, but a decision needs to be
241  /// made, clang-format analyzes whether there are other bin-packed cases in
242  /// the input file and act accordingly.
243  ///
244  /// NOTE: This is an experimental flag, that might go away or be renamed. Do
245  /// not use this in config files, etc. Use at your own risk.
247 
248  /// \brief A vector of macros that should be interpreted as foreach loops
249  /// instead of as function calls.
250  ///
251  /// These are expected to be macros of the form:
252  /// \code
253  /// FOREACH(<variable-declaration>, ...)
254  /// <loop-body>
255  /// \endcode
256  ///
257  /// For example: BOOST_FOREACH.
258  std::vector<std::string> ForEachMacros;
259 
260  /// \brief Indent case labels one level from the switch statement.
261  ///
262  /// When \c false, use the same indentation level as for the switch statement.
263  /// Switch statement body is always indented one level more than case labels.
265 
266  /// \brief The number of columns to use for indentation.
267  unsigned IndentWidth;
268 
269  /// \brief Indent if a function definition or declaration is wrapped after the
270  /// type.
272 
273  /// \brief If true, empty lines at the start of blocks are kept.
275 
276  /// \brief Supported languages. When stored in a configuration file, specifies
277  /// the language, that the configuration targets. When passed to the
278  /// reformat() function, enables syntax features specific to the language.
280  /// Do not use.
282  /// Should be used for C, C++, ObjectiveC, ObjectiveC++.
284  /// Should be used for Java.
286  /// Should be used for JavaScript.
288  /// Should be used for Protocol Buffers
289  /// (https://developers.google.com/protocol-buffers/).
291  };
292 
293  /// \brief Language, this format style is targeted at.
295 
296  /// \brief A regular expression matching macros that start a block.
297  std::string MacroBlockBegin;
298 
299  /// \brief A regular expression matching macros that end a block.
300  std::string MacroBlockEnd;
301 
302  /// \brief The maximum number of consecutive empty lines to keep.
304 
305  /// \brief Different ways to indent namespace contents.
307  /// Don't indent in namespaces.
309  /// Indent only in inner namespaces (nested in other namespaces).
311  /// Indent in all namespaces.
313  };
314 
315  /// \brief The indentation used for namespaces.
317 
318  /// \brief The number of characters to use for indentation of ObjC blocks.
320 
321  /// \brief Add a space after \c @property in Objective-C, i.e. use
322  /// <tt>\@property (readonly)</tt> instead of <tt>\@property(readonly)</tt>.
324 
325  /// \brief Add a space in front of an Objective-C protocol list, i.e. use
326  /// <tt>Foo <Protocol></tt> instead of \c Foo<Protocol>.
328 
329  /// \brief The penalty for breaking a function call after "call(".
331 
332  /// \brief The penalty for each line break introduced inside a comment.
334 
335  /// \brief The penalty for breaking before the first \c <<.
337 
338  /// \brief The penalty for each line break introduced inside a string literal.
340 
341  /// \brief The penalty for each character outside of the column limit.
343 
344  /// \brief Penalty for putting the return type of a function onto its own
345  /// line.
347 
348  /// \brief The & and * alignment style.
350  /// Align pointer to the left.
352  /// Align pointer to the right.
354  /// Align pointer in the middle.
356  };
357 
358  /// Pointer and reference alignment style.
360 
361  /// \brief If \c true, a space may be inserted after C style casts.
363 
364  /// \brief If \c false, spaces will be removed before assignment operators.
366 
367  /// \brief Different ways to put a space before opening parentheses.
369  /// Never put a space before opening parentheses.
371  /// Put a space before opening parentheses only after control statement
372  /// keywords (<tt>for/if/while...</tt>).
374  /// Always put a space before opening parentheses, except when it's
375  /// prohibited by the syntax rules (in function-like macro definitions) or
376  /// when determined by other style rules (after unary operators, opening
377  /// parentheses, etc.)
379  };
380 
381  /// \brief Defines in which cases to put a space before opening parentheses.
383 
384  /// \brief If \c true, spaces may be inserted into '()'.
386 
387  /// \brief The number of spaces before trailing line comments
388  /// (\c // - comments).
389  ///
390  /// This does not affect trailing block comments (\c /**/ - comments) as those
391  /// commonly have different usage patterns and a number of special cases.
393 
394  /// \brief If \c true, spaces will be inserted after '<' and before '>' in
395  /// template argument lists
397 
398  /// \brief If \c true, spaces are inserted inside container literals (e.g.
399  /// ObjC and Javascript array and dict literals).
401 
402  /// \brief If \c true, spaces may be inserted into C style casts.
404 
405  /// \brief If \c true, spaces will be inserted after '(' and before ')'.
407 
408  /// \brief If \c true, spaces will be inserted after '[' and before ']'.
410 
411  /// \brief Supported language standards.
413  /// Use C++03-compatible syntax.
415  /// Use features of C++11 (e.g. \c A<A<int>> instead of
416  /// <tt>A<A<int> ></tt>).
418  /// Automatic detection based on the input.
420  };
421 
422  /// \brief Format compatible with this standard, e.g. use
423  /// <tt>A<A<int> ></tt> instead of \c A<A<int>> for LS_Cpp03.
425 
426  /// \brief The number of columns used for tab stops.
427  unsigned TabWidth;
428 
429  /// \brief Different ways to use tab in formatting.
430  enum UseTabStyle {
431  /// Never use tab.
433  /// Use tabs only for indentation.
435  /// Use tabs whenever we need to fill whitespace that spans at least from
436  /// one tab stop to the next one.
438  };
439 
440  /// \brief The way to use tab characters in the resulting file.
442 
443  bool operator==(const FormatStyle &R) const {
473  ColumnLimit == R.ColumnLimit &&
487  IndentWidth == R.IndentWidth && Language == R.Language &&
516  Standard == R.Standard &&
517  TabWidth == R.TabWidth &&
518  UseTab == R.UseTab;
519  }
520 };
521 
522 /// \brief Returns a format style complying with the LLVM coding standards:
523 /// http://llvm.org/docs/CodingStandards.html.
524 FormatStyle getLLVMStyle();
525 
526 /// \brief Returns a format style complying with one of Google's style guides:
527 /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
528 /// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
529 /// https://developers.google.com/protocol-buffers/docs/style.
530 FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
531 
532 /// \brief Returns a format style complying with Chromium's style guide:
533 /// http://www.chromium.org/developers/coding-style.
534 FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
535 
536 /// \brief Returns a format style complying with Mozilla's style guide:
537 /// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
538 FormatStyle getMozillaStyle();
539 
540 /// \brief Returns a format style complying with Webkit's style guide:
541 /// http://www.webkit.org/coding/coding-style.html
542 FormatStyle getWebKitStyle();
543 
544 /// \brief Returns a format style complying with GNU Coding Standards:
545 /// http://www.gnu.org/prep/standards/standards.html
546 FormatStyle getGNUStyle();
547 
548 /// \brief Returns style indicating formatting should be not applied at all.
549 FormatStyle getNoStyle();
550 
551 /// \brief Gets a predefined style for the specified language by name.
552 ///
553 /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
554 /// compared case-insensitively.
555 ///
556 /// Returns \c true if the Style has been set.
557 bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
558  FormatStyle *Style);
559 
560 /// \brief Parse configuration from YAML-formatted text.
561 ///
562 /// Style->Language is used to get the base style, if the \c BasedOnStyle
563 /// option is present.
564 ///
565 /// When \c BasedOnStyle is not present, options not present in the YAML
566 /// document, are retained in \p Style.
567 std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
568 
569 /// \brief Gets configuration in a YAML string.
570 std::string configurationAsText(const FormatStyle &Style);
571 
572 /// \brief Reformats the given \p Ranges in the file \p ID.
573 ///
574 /// Each range is extended on either end to its next bigger logic unit, i.e.
575 /// everything that might influence its formatting or might be influenced by its
576 /// formatting.
577 ///
578 /// Returns the \c Replacements necessary to make all \p Ranges comply with
579 /// \p Style.
580 ///
581 /// If \c IncompleteFormat is non-null, its value will be set to true if any
582 /// of the affected ranges were not formatted due to a non-recoverable syntax
583 /// error.
584 tooling::Replacements reformat(const FormatStyle &Style,
587  bool *IncompleteFormat = nullptr);
588 
589 /// \brief Reformats the given \p Ranges in \p Code.
590 ///
591 /// Otherwise identical to the reformat() function using a file ID.
592 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
594  StringRef FileName = "<stdin>",
595  bool *IncompleteFormat = nullptr);
596 
597 /// \brief Returns the \c LangOpts that the formatter expects you to set.
598 ///
599 /// \param Style determines specific settings for lexing mode.
600 LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle());
601 
602 /// \brief Description to be used for help text for a llvm::cl option for
603 /// specifying format style. The description is closely related to the operation
604 /// of getStyle().
605 extern const char *StyleOptionHelpDescription;
606 
607 /// \brief Construct a FormatStyle based on \c StyleName.
608 ///
609 /// \c StyleName can take several forms:
610 /// \li "{<key>: <value>, ...}" - Set specic style parameters.
611 /// \li "<style name>" - One of the style names supported by
612 /// getPredefinedStyle().
613 /// \li "file" - Load style configuration from a file called '.clang-format'
614 /// located in one of the parent directories of \c FileName or the current
615 /// directory if \c FileName is empty.
616 ///
617 /// \param[in] StyleName Style name to interpret according to the description
618 /// above.
619 /// \param[in] FileName Path to start search for .clang-format if \c StyleName
620 /// == "file".
621 /// \param[in] FallbackStyle The name of a predefined style used to fallback to
622 /// in case the style can't be determined from \p StyleName.
623 ///
624 /// \returns FormatStyle as specified by \c StyleName. If no style could be
625 /// determined, the default is LLVM Style (see getLLVMStyle()).
626 FormatStyle getStyle(StringRef StyleName, StringRef FileName,
627  StringRef FallbackStyle);
628 
629 } // end namespace format
630 } // end namespace clang
631 
632 namespace std {
633 template <>
634 struct is_error_code_enum<clang::format::ParseError> : std::true_type {};
635 }
636 
637 #endif // LLVM_CLANG_FORMAT_FORMAT_H
Use tabs only for indentation.
Definition: Format.h:434
PointerAlignmentStyle
The & and * alignment style.
Definition: Format.h:349
Indent in all namespaces.
Definition: Format.h:312
bool AlwaysBreakBeforeMultilineStrings
If true, always break before multiline string literals.
Definition: Format.h:135
unsigned PenaltyBreakBeforeFirstCallParameter
The penalty for breaking a function call after "call(".
Definition: Format.h:330
bool AlignEscapedNewlinesLeft
If true, aligns escaped newlines as far left as possible. Otherwise puts them into the right-most col...
Definition: Format.h:69
comments as those *commonly have different usage patterns and a number of special cases *unsigned SpacesBeforeTrailingComments
The number of spaces before trailing line comments (// - comments).
Definition: Format.h:392
std::set< Replacement > Replacements
A set of Replacements. FIXME: Change to a vector and deduplicate in the RefactoringTool.
Definition: Replacement.h:141
bool IndentCaseLabels
Indent case labels one level from the switch statement.
Definition: Format.h:264
unsigned IndentWidth
The number of columns to use for indentation.
Definition: Format.h:267
bool DisableFormat
Disables formatting completely.
Definition: Format.h:234
FormatStyle getMozillaStyle()
Returns a format style complying with Mozilla's style guide: https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
Definition: Format.cpp:480
DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType
The function definition return type breaking style to use.
Definition: Format.h:127
bool AlignAfterOpenBracket
If true, horizontally aligns arguments after an open bracket.
Definition: Format.h:54
PointerAlignmentStyle PointerAlignment
Pointer and reference alignment style.
Definition: Format.h:359
std::error_code make_error_code(ParseError e)
Definition: Format.cpp:322
Align pointer to the left.
Definition: Format.h:351
Should be used for C, C++, ObjectiveC, ObjectiveC++.
Definition: Format.h:283
unsigned PenaltyBreakFirstLessLess
The penalty for breaking before the first <<.
Definition: Format.h:336
LanguageKind
Supported languages. When stored in a configuration file, specifies the language, that the configurat...
Definition: Format.h:279
Break after operators.
Definition: Format.h:152
FormatStyle getWebKitStyle()
Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style...
Definition: Format.cpp:500
const char * name() const LLVM_NOEXCEPT override
Definition: Format.cpp:326
bool DerivePointerAlignment
If true, analyze the formatted file for the most common alignment of & and *. PointerAlignment is the...
Definition: Format.h:231
bool ExperimentalAutoDetectBinPacking
If true, clang-format detects whether function calls and definitions are formatted with one parameter...
Definition: Format.h:246
bool SpaceInEmptyParentheses
If true, spaces may be inserted into '()'.
Definition: Format.h:385
std::string message(int EV) const override
Definition: Format.cpp:330
Should be used for Java.
Definition: Format.h:285
NamespaceIndentationKind
Different ways to indent namespace contents.
Definition: Format.h:306
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
Always break after the return types of top level functions.
Definition: Format.h:123
bool ConstructorInitializerAllOnOneLineOrOnePerLine
If the constructor initializers don't fit on a line, put each initializer on its own line...
Definition: Format.h:205
unsigned PenaltyBreakComment
The penalty for each line break introduced inside a comment.
Definition: Format.h:333
bool IndentWrappedFunctionNames
Indent if a function definition or declaration is wrapped after the type.
Definition: Format.h:271
bool SpacesInParentheses
If true, spaces will be inserted after '(' and before ')'.
Definition: Format.h:406
SmallVector< CharSourceRange, 8 > Ranges
Definition: Format.cpp:1554
NamespaceIndentationKind NamespaceIndentation
The indentation used for namespaces.
Definition: Format.h:316
bool BreakConstructorInitializersBeforeComma
Always break constructor initializers before commas and align the commas with the colon...
Definition: Format.h:190
bool BinPackArguments
If false, a function call's arguments will either be all on the same line or will have one line each...
Definition: Format.h:143
unsigned ObjCBlockIndentWidth
The number of characters to use for indentation of ObjC blocks.
Definition: Format.h:319
bool SpaceBeforeAssignmentOperators
If false, spaces will be removed before assignment operators.
Definition: Format.h:365
FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Chromium's style guide: http://www.chromium.org/developers/coding-style.
Definition: Format.cpp:461
SpaceBeforeParensOptions SpaceBeforeParens
Defines in which cases to put a space before opening parentheses.
Definition: Format.h:382
FormatStyle getGNUStyle()
Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standar...
Definition: Format.cpp:520
bool AlignConsecutiveAssignments
If true, aligns consecutive assignments.
Definition: Format.h:65
unsigned ColumnLimit
The column limit.
Definition: Format.h:197
Never merge functions into a single line.
Definition: Format.h:94
bool AllowShortCaseLabelsOnASingleLine
If true, short case labels will be contracted to a single line.
Definition: Format.h:88
bool KeepEmptyLinesAtTheStartOfBlocks
If true, empty lines at the start of blocks are kept.
Definition: Format.h:274
std::vector< std::string > ForEachMacros
A vector of macros that should be interpreted as foreach loops instead of as function calls...
Definition: Format.h:258
SpaceBeforeParensOptions
Different ways to put a space before opening parentheses.
Definition: Format.h:368
Break before operators that aren't assignments.
Definition: Format.h:154
UseTabStyle UseTab
The way to use tab characters in the resulting file.
Definition: Format.h:441
std::string MacroBlockEnd
A regular expression matching macros that end a block.
Definition: Format.h:300
FormatStyle getLLVMStyle()
Returns a format style complying with the LLVM coding standards: http://llvm.org/docs/CodingStandards...
Definition: Format.cpp:342
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
std::string CommentPragmas
A regular expression that describes comments with special meaning, which should not be split into lin...
Definition: Format.h:201
Only merge empty functions.
Definition: Format.h:96
Defines the clang::LangOptions interface.
std::string MacroBlockBegin
A regular expression matching macros that start a block.
Definition: Format.h:297
Should be used for JavaScript.
Definition: Format.h:287
SourceManager & SourceMgr
Definition: Format.cpp:1205
LangOptions getFormattingLangOpts(const FormatStyle &Style=getLLVMStyle())
Returns the LangOpts that the formatter expects you to set.
Definition: Format.cpp:1601
bool SpacesInContainerLiterals
If true, spaces are inserted inside container literals (e.g. ObjC and Javascript array and dict liter...
Definition: Format.h:400
bool SpacesInAngles
If true, spaces will be inserted after '<' and before '>' in template argument lists...
Definition: Format.h:396
bool AlignOperands
If true, horizontally align operands of binary and ternary expressions.
Definition: Format.h:73
FormatStyle getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle)
Construct a FormatStyle based on StyleName.
Definition: Format.cpp:1640
int AccessModifierOffset
The extra indent or outdent of access modifiers, e.g. public:.
Definition: Format.h:44
FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with one of Google's style guides: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml. http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml. https://developers.google.com/protocol-buffers/docs/style.
Definition: Format.cpp:413
Don't indent in namespaces.
Definition: Format.h:308
BinaryOperatorStyle
The style of breaking before or after binary operators.
Definition: Format.h:150
BraceBreakingStyle BreakBeforeBraces
The brace breaking style to use.
Definition: Format.h:183
unsigned PenaltyBreakString
The penalty for each line break introduced inside a string literal.
Definition: Format.h:339
LanguageStandard
Supported language standards.
Definition: Format.h:412
Always attach braces to surrounding context.
Definition: Format.h:165
Align pointer in the middle.
Definition: Format.h:355
unsigned PenaltyExcessCharacter
The penalty for each character outside of the column limit.
Definition: Format.h:342
Automatic detection based on the input.
Definition: Format.h:419
bool BreakBeforeTernaryOperators
If true, ternary operators will be placed after line breaks.
Definition: Format.h:186
unsigned ContinuationIndentWidth
Indent width for line continuations.
Definition: Format.h:212
bool AlwaysBreakTemplateDeclarations
If true, always break after the template<...> of a template declaration.
Definition: Format.h:139
bool AllowShortLoopsOnASingleLine
If true, while (true) continue; can be put on a single line.
Definition: Format.h:113
bool SpacesInCStyleCastParentheses
If true, spaces may be inserted into C style casts.
Definition: Format.h:403
bool SpacesInSquareBrackets
If true, spaces will be inserted after '[' and before ']'.
Definition: Format.h:409
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition: Format.h:42
Never put a space before opening parentheses.
Definition: Format.h:370
unsigned PenaltyReturnTypeOnItsOwnLine
Penalty for putting the return type of a function onto its own line.
Definition: Format.h:346
Indent only in inner namespaces (nested in other namespaces).
Definition: Format.h:310
std::string configurationAsText(const FormatStyle &Style)
Gets configuration in a YAML string.
Definition: Format.cpp:609
LanguageKind Language
Language, this format style is targeted at.
Definition: Format.h:294
Always break before braces.
Definition: Format.h:175
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
const char * StyleOptionHelpDescription
Description to be used for help text for a llvm::cl option for specifying format style. The description is closely related to the operation of getStyle().
Definition: Format.cpp:1616
ShortFunctionStyle AllowShortFunctionsOnASingleLine
Dependent on the value, int f() { return 0; } can be put on a single line.
Definition: Format.h:105
Use C++03-compatible syntax.
Definition: Format.h:414
bool Cpp11BracedListStyle
If true, format braced lists as best suited for C++11 braced lists.
Definition: Format.h:227
BraceBreakingStyle
Different ways to attach braces to their surrounding context.
Definition: Format.h:163
FormatStyle & Style
Definition: Format.cpp:1207
Merge all functions fitting on a single line.
Definition: Format.h:100
bool operator==(const FormatStyle &R) const
Definition: Format.h:443
bool AllowAllParametersOfDeclarationOnNextLine
Allow putting all parameters of a function declaration onto the next line even if BinPackParameters i...
Definition: Format.h:80
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
Gets a predefined style for the specified language by name.
Definition: Format.cpp:539
unsigned TabWidth
The number of columns used for tab stops.
Definition: Format.h:427
UseTabStyle
Different ways to use tab in formatting.
Definition: Format.h:430
bool SpaceAfterCStyleCast
If true, a space may be inserted after C style casts.
Definition: Format.h:362
bool AllowShortIfStatementsOnASingleLine
If true, if (a) return; can be put on a single line.
Definition: Format.h:109
Like Attach, but break before function definitions, and 'else'.
Definition: Format.h:173
FormatStyle getNoStyle()
Returns style indicating formatting should be not applied at all.
Definition: Format.cpp:533
Only merge functions defined inside a class. Implies "empty".
Definition: Format.h:98
LanguageStandard Standard
Format compatible with this standard, e.g. use A<A<int> > instead of A<A<int>> for LS_Cpp03...
Definition: Format.h:424
unsigned ConstructorInitializerIndentWidth
The number of characters to use for indentation of constructor initializer lists. ...
Definition: Format.h:209
const std::error_category & getParseCategory()
Definition: Format.cpp:318
BinaryOperatorStyle BreakBeforeBinaryOperators
The way to wrap binary operators.
Definition: Format.h:160
Break before operators.
Definition: Format.h:156
bool ObjCSpaceBeforeProtocolList
Add a space in front of an Objective-C protocol list, i.e. use Foo <Protocol> instead of Foo<Protocol...
Definition: Format.h:327
bool AllowShortBlocksOnASingleLine
Allows contracting simple braced statements to a single line.
Definition: Format.h:85
bool AlignTrailingComments
If true, aligns trailing comments.
Definition: Format.h:76
ShortFunctionStyle
Different styles for merging short functions containing at most one statement.
Definition: Format.h:92
tooling::Replacements reformat(const FormatStyle &Style, SourceManager &SourceMgr, FileID ID, ArrayRef< CharSourceRange > Ranges, bool *IncompleteFormat=nullptr)
Reformats the given Ranges in the file ID.
Definition: Format.cpp:1563
std::error_code parseConfiguration(StringRef Text, FormatStyle *Style)
Parse configuration from YAML-formatted text.
Definition: Format.cpp:563
Align pointer to the right.
Definition: Format.h:353
DefinitionReturnTypeBreakingStyle
Different ways to break after the function definition return type.
Definition: Format.h:116
Always break after the return type.
Definition: Format.h:121
unsigned MaxEmptyLinesToKeep
The maximum number of consecutive empty lines to keep.
Definition: Format.h:303
This class handles loading and caching of source files into memory.
bool BinPackParameters
If false, a function declaration's or function definition's parameters will either all be on the same...
Definition: Format.h:147