clang  3.8.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 Different styles for aligning after open brackets.
48  /// \brief Align parameters on the open bracket, e.g.:
49  /// \code
50  /// someLongFunction(argument1,
51  /// argument2);
52  /// \endcode
54  /// \brief Don't align, instead use \c ContinuationIndentWidth, e.g.:
55  /// \code
56  /// someLongFunction(argument1,
57  /// argument2);
58  /// \endcode
60  /// \brief Always break after an open bracket, if the parameters don't fit
61  /// on a single line, e.g.:
62  /// \code
63  /// someLongFunction(
64  /// argument1, argument2);
65  /// \endcode
67  };
68 
69  /// \brief If \c true, horizontally aligns arguments after an open bracket.
70  ///
71  /// This applies to round brackets (parentheses), angle brackets and square
72  /// brackets.
74 
75  /// \brief If \c true, aligns consecutive assignments.
76  ///
77  /// This will align the assignment operators of consecutive lines. This
78  /// will result in formattings like
79  /// \code
80  /// int aaaa = 12;
81  /// int b = 23;
82  /// int ccc = 23;
83  /// \endcode
85 
86  /// \brief If \c true, aligns consecutive declarations.
87  ///
88  /// This will align the declaration names of consecutive lines. This
89  /// will result in formattings like
90  /// \code
91  /// int aaaa = 12;
92  /// float b = 23;
93  /// std::string ccc = 23;
94  /// \endcode
96 
97  /// \brief If \c true, aligns escaped newlines as far left as possible.
98  /// Otherwise puts them into the right-most column.
100 
101  /// \brief If \c true, horizontally align operands of binary and ternary
102  /// expressions.
103  ///
104  /// Specifically, this aligns operands of a single expression that needs to be
105  /// split over multiple lines, e.g.:
106  /// \code
107  /// int aaa = bbbbbbbbbbbbbbb +
108  /// ccccccccccccccc;
109  /// \endcode
111 
112  /// \brief If \c true, aligns trailing comments.
114 
115  /// \brief Allow putting all parameters of a function declaration onto
116  /// the next line even if \c BinPackParameters is \c false.
118 
119  /// \brief Allows contracting simple braced statements to a single line.
120  ///
121  /// E.g., this allows <tt>if (a) { return; }</tt> to be put on a single line.
123 
124  /// \brief If \c true, short case labels will be contracted to a single line.
126 
127  /// \brief Different styles for merging short functions containing at most one
128  /// statement.
130  /// \brief Never merge functions into a single line.
132  /// \brief Only merge empty functions.
134  /// \brief Only merge functions defined inside a class. Implies "empty".
136  /// \brief Merge all functions fitting on a single line.
138  };
139 
140  /// \brief Dependent on the value, <tt>int f() { return 0; }</tt> can be put
141  /// on a single line.
143 
144  /// \brief If \c true, <tt>if (a) return;</tt> can be put on a single
145  /// line.
147 
148  /// \brief If \c true, <tt>while (true) continue;</tt> can be put on a
149  /// single line.
151 
152  /// \brief Different ways to break after the function definition return type.
154  /// Break after return type automatically.
155  /// \c PenaltyReturnTypeOnItsOwnLine is taken into account.
157  /// Always break after the return type.
159  /// Always break after the return types of top-level functions.
161  };
162 
163  /// \brief Different ways to break after the function definition or
164  /// declaration return type.
166  /// Break after return type automatically.
167  /// \c PenaltyReturnTypeOnItsOwnLine is taken into account.
169  /// Always break after the return type.
171  /// Always break after the return types of top-level functions.
173  /// Always break after the return type of function definitions.
175  /// Always break after the return type of top-level definitions.
177  };
178 
179  /// \brief The function definition return type breaking style to use. This
180  /// option is deprecated and is retained for backwards compatibility.
182 
183  /// \brief The function declaration return type breaking style to use.
185 
186  /// \brief If \c true, always break before multiline string literals.
187  ///
188  /// This flag is mean to make cases where there are multiple multiline strings
189  /// in a file look more consistent. Thus, it will only take effect if wrapping
190  /// the string at that point leads to it being indented
191  /// \c ContinuationIndentWidth spaces from the start of the line.
193 
194  /// \brief If \c true, always break after the <tt>template<...></tt> of a
195  /// template declaration.
197 
198  /// \brief If \c false, a function call's arguments will either be all on the
199  /// same line or will have one line each.
201 
202  /// \brief If \c false, a function declaration's or function definition's
203  /// parameters will either all be on the same line or will have one line each.
205 
206  /// \brief The style of breaking before or after binary operators.
208  /// Break after operators.
210  /// Break before operators that aren't assignments.
212  /// Break before operators.
214  };
215 
216  /// \brief The way to wrap binary operators.
218 
219  /// \brief Different ways to attach braces to their surrounding context.
221  /// Always attach braces to surrounding context.
223  /// Like \c Attach, but break before braces on function, namespace and
224  /// class definitions.
226  /// Like ``Attach``, but break before braces on enum, function, and record
227  /// definitions.
229  /// Like \c Attach, but break before function definitions, 'catch', and 'else'.
231  /// Always break before braces.
233  /// Always break before braces and add an extra level of indentation to
234  /// braces of control statements, not to those of class, function
235  /// or other definitions.
237  /// Like ``Attach``, but break before functions.
239  /// Configure each individual brace in \c BraceWrapping.
241  };
242 
243  /// \brief The brace breaking style to use.
245 
246  /// \brief Precise control over the wrapping of braces.
248  /// \brief Wrap class definitions.
250  /// \brief Wrap control statements (if/for/while/switch/..).
252  /// \brief Wrap enum definitions.
253  bool AfterEnum;
254  /// \brief Wrap function definitions.
256  /// \brief Wrap namespace definitions.
258  /// \brief Wrap ObjC definitions (@autoreleasepool, interfaces, ..).
260  /// \brief Wrap struct definitions.
262  /// \brief Wrap union definitions.
264  /// \brief Wrap before \c catch.
266  /// \brief Wrap before \c else.
268  /// \brief Indent the wrapped braces themselves.
270  };
271 
272  /// \brief Control of individual brace wrapping cases.
273  ///
274  /// If \c BreakBeforeBraces is set to \c custom, use this to specify how each
275  /// individual brace case should be handled. Otherwise, this is ignored.
277 
278  /// \brief If \c true, ternary operators will be placed after line breaks.
280 
281  /// \brief Always break constructor initializers before commas and align
282  /// the commas with the colon.
284 
285  /// \brief Break after each annotation on a field in Java files.
287 
288  /// \brief The column limit.
289  ///
290  /// A column limit of \c 0 means that there is no column limit. In this case,
291  /// clang-format will respect the input's line breaking decisions within
292  /// statements unless they contradict other rules.
293  unsigned ColumnLimit;
294 
295  /// \brief A regular expression that describes comments with special meaning,
296  /// which should not be split into lines or otherwise changed.
297  std::string CommentPragmas;
298 
299  /// \brief If the constructor initializers don't fit on a line, put each
300  /// initializer on its own line.
302 
303  /// \brief The number of characters to use for indentation of constructor
304  /// initializer lists.
306 
307  /// \brief Indent width for line continuations.
309 
310  /// \brief If \c true, format braced lists as best suited for C++11 braced
311  /// lists.
312  ///
313  /// Important differences:
314  /// - No spaces inside the braced list.
315  /// - No line break before the closing brace.
316  /// - Indentation with the continuation indent, not with the block indent.
317  ///
318  /// Fundamentally, C++11 braced lists are formatted exactly like function
319  /// calls would be formatted in their place. If the braced list follows a name
320  /// (e.g. a type or variable name), clang-format formats as if the \c {} were
321  /// the parentheses of a function call with that name. If there is no name,
322  /// a zero-length name is assumed.
324 
325  /// \brief If \c true, analyze the formatted file for the most common
326  /// alignment of & and *. \c PointerAlignment is then used only as fallback.
328 
329  /// \brief Disables formatting completely.
331 
332  /// \brief If \c true, clang-format detects whether function calls and
333  /// definitions are formatted with one parameter per line.
334  ///
335  /// Each call can be bin-packed, one-per-line or inconclusive. If it is
336  /// inconclusive, e.g. completely on one line, but a decision needs to be
337  /// made, clang-format analyzes whether there are other bin-packed cases in
338  /// the input file and act accordingly.
339  ///
340  /// NOTE: This is an experimental flag, that might go away or be renamed. Do
341  /// not use this in config files, etc. Use at your own risk.
343 
344  /// \brief A vector of macros that should be interpreted as foreach loops
345  /// instead of as function calls.
346  ///
347  /// These are expected to be macros of the form:
348  /// \code
349  /// FOREACH(<variable-declaration>, ...)
350  /// <loop-body>
351  /// \endcode
352  ///
353  /// In the .clang-format configuration file, this can be configured like:
354  /// \code
355  /// ForEachMacros: ['RANGES_FOR', 'FOREACH']
356  /// \endcode
357  ///
358  /// For example: BOOST_FOREACH.
359  std::vector<std::string> ForEachMacros;
360 
361  /// \brief See documentation of \c IncludeCategories.
363  /// \brief The regular expression that this category matches.
364  std::string Regex;
365  /// \brief The priority to assign to this category.
366  int Priority;
367  bool operator==(const IncludeCategory &Other) const {
368  return Regex == Other.Regex && Priority == Other.Priority;
369  }
370  };
371 
372  /// \brief Regular expressions denoting the different #include categories used
373  /// for ordering #includes.
374  ///
375  /// These regular expressions are matched against the filename of an include
376  /// (including the <> or "") in order. The value belonging to the first
377  /// matching regular expression is assigned and #includes are sorted first
378  /// according to increasing category number and then alphabetically within
379  /// each category.
380  ///
381  /// If none of the regular expressions match, INT_MAX is assigned as
382  /// category. The main header for a source file automatically gets category 0.
383  /// so that it is generally kept at the beginning of the #includes
384  /// (http://llvm.org/docs/CodingStandards.html#include-style). However, you
385  /// can also assign negative priorities if you have certain headers that
386  /// always need to be first.
387  ///
388  /// To configure this in the .clang-format file, use:
389  /// \code
390  /// IncludeCategories:
391  /// - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
392  /// Priority: 2
393  /// - Regex: '^(<|"(gtest|isl|json)/)'
394  /// Priority: 3
395  /// - Regex: '.*'
396  /// Priority: 1
397  /// \endcode
398  std::vector<IncludeCategory> IncludeCategories;
399 
400  /// \brief Indent case labels one level from the switch statement.
401  ///
402  /// When \c false, use the same indentation level as for the switch statement.
403  /// Switch statement body is always indented one level more than case labels.
405 
406  /// \brief The number of columns to use for indentation.
407  unsigned IndentWidth;
408 
409  /// \brief Indent if a function definition or declaration is wrapped after the
410  /// type.
412 
413  /// \brief If true, empty lines at the start of blocks are kept.
415 
416  /// \brief Supported languages. When stored in a configuration file, specifies
417  /// the language, that the configuration targets. When passed to the
418  /// reformat() function, enables syntax features specific to the language.
420  /// Do not use.
422  /// Should be used for C, C++, ObjectiveC, ObjectiveC++.
424  /// Should be used for Java.
426  /// Should be used for JavaScript.
428  /// Should be used for Protocol Buffers
429  /// (https://developers.google.com/protocol-buffers/).
431  /// Should be used for TableGen code.
433  };
434 
435  /// \brief Language, this format style is targeted at.
437 
438  /// \brief A regular expression matching macros that start a block.
439  std::string MacroBlockBegin;
440 
441  /// \brief A regular expression matching macros that end a block.
442  std::string MacroBlockEnd;
443 
444  /// \brief The maximum number of consecutive empty lines to keep.
446 
447  /// \brief Different ways to indent namespace contents.
449  /// Don't indent in namespaces.
451  /// Indent only in inner namespaces (nested in other namespaces).
453  /// Indent in all namespaces.
455  };
456 
457  /// \brief The indentation used for namespaces.
459 
460  /// \brief The number of characters to use for indentation of ObjC blocks.
462 
463  /// \brief Add a space after \c @property in Objective-C, i.e. use
464  /// <tt>\@property (readonly)</tt> instead of <tt>\@property(readonly)</tt>.
466 
467  /// \brief Add a space in front of an Objective-C protocol list, i.e. use
468  /// <tt>Foo <Protocol></tt> instead of \c Foo<Protocol>.
470 
471  /// \brief The penalty for breaking a function call after "call(".
473 
474  /// \brief The penalty for each line break introduced inside a comment.
476 
477  /// \brief The penalty for breaking before the first \c <<.
479 
480  /// \brief The penalty for each line break introduced inside a string literal.
482 
483  /// \brief The penalty for each character outside of the column limit.
485 
486  /// \brief Penalty for putting the return type of a function onto its own
487  /// line.
489 
490  /// \brief The & and * alignment style.
492  /// Align pointer to the left.
494  /// Align pointer to the right.
496  /// Align pointer in the middle.
498  };
499 
500  /// \brief Pointer and reference alignment style.
502 
503  /// \brief If true, clang-format will attempt to re-flow comments.
505 
506  /// \brief If true, clang-format will sort #includes.
508 
509  /// \brief If \c true, a space may be inserted after C style casts.
511 
512  /// \brief If \c false, spaces will be removed before assignment operators.
514 
515  /// \brief Different ways to put a space before opening parentheses.
517  /// Never put a space before opening parentheses.
519  /// Put a space before opening parentheses only after control statement
520  /// keywords (<tt>for/if/while...</tt>).
522  /// Always put a space before opening parentheses, except when it's
523  /// prohibited by the syntax rules (in function-like macro definitions) or
524  /// when determined by other style rules (after unary operators, opening
525  /// parentheses, etc.)
527  };
528 
529  /// \brief Defines in which cases to put a space before opening parentheses.
531 
532  /// \brief If \c true, spaces may be inserted into '()'.
534 
535  /// \brief The number of spaces before trailing line comments
536  /// (\c // - comments).
537  ///
538  /// This does not affect trailing block comments (\c /**/ - comments) as those
539  /// commonly have different usage patterns and a number of special cases.
541 
542  /// \brief If \c true, spaces will be inserted after '<' and before '>' in
543  /// template argument lists
545 
546  /// \brief If \c true, spaces are inserted inside container literals (e.g.
547  /// ObjC and Javascript array and dict literals).
549 
550  /// \brief If \c true, spaces may be inserted into C style casts.
552 
553  /// \brief If \c true, spaces will be inserted after '(' and before ')'.
555 
556  /// \brief If \c true, spaces will be inserted after '[' and before ']'.
558 
559  /// \brief Supported language standards.
561  /// Use C++03-compatible syntax.
563  /// Use features of C++11 (e.g. \c A<A<int>> instead of
564  /// <tt>A<A<int> ></tt>).
566  /// Automatic detection based on the input.
568  };
569 
570  /// \brief Format compatible with this standard, e.g. use
571  /// <tt>A<A<int> ></tt> instead of \c A<A<int>> for LS_Cpp03.
573 
574  /// \brief The number of columns used for tab stops.
575  unsigned TabWidth;
576 
577  /// \brief Different ways to use tab in formatting.
578  enum UseTabStyle {
579  /// Never use tab.
581  /// Use tabs only for indentation.
583  /// Use tabs whenever we need to fill whitespace that spans at least from
584  /// one tab stop to the next one.
586  };
587 
588  /// \brief The way to use tab characters in the resulting file.
590 
591  bool operator==(const FormatStyle &R) const {
636  IndentWidth == R.IndentWidth && Language == R.Language &&
665  Standard == R.Standard && TabWidth == R.TabWidth &&
666  UseTab == R.UseTab;
667  }
668 };
669 
670 /// \brief Returns a format style complying with the LLVM coding standards:
671 /// http://llvm.org/docs/CodingStandards.html.
672 FormatStyle getLLVMStyle();
673 
674 /// \brief Returns a format style complying with one of Google's style guides:
675 /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
676 /// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
677 /// https://developers.google.com/protocol-buffers/docs/style.
678 FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
679 
680 /// \brief Returns a format style complying with Chromium's style guide:
681 /// http://www.chromium.org/developers/coding-style.
682 FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
683 
684 /// \brief Returns a format style complying with Mozilla's style guide:
685 /// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
686 FormatStyle getMozillaStyle();
687 
688 /// \brief Returns a format style complying with Webkit's style guide:
689 /// http://www.webkit.org/coding/coding-style.html
690 FormatStyle getWebKitStyle();
691 
692 /// \brief Returns a format style complying with GNU Coding Standards:
693 /// http://www.gnu.org/prep/standards/standards.html
694 FormatStyle getGNUStyle();
695 
696 /// \brief Returns style indicating formatting should be not applied at all.
697 FormatStyle getNoStyle();
698 
699 /// \brief Gets a predefined style for the specified language by name.
700 ///
701 /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
702 /// compared case-insensitively.
703 ///
704 /// Returns \c true if the Style has been set.
705 bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
706  FormatStyle *Style);
707 
708 /// \brief Parse configuration from YAML-formatted text.
709 ///
710 /// Style->Language is used to get the base style, if the \c BasedOnStyle
711 /// option is present.
712 ///
713 /// When \c BasedOnStyle is not present, options not present in the YAML
714 /// document, are retained in \p Style.
715 std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
716 
717 /// \brief Gets configuration in a YAML string.
718 std::string configurationAsText(const FormatStyle &Style);
719 
720 /// \brief Returns the replacements necessary to sort all #include blocks that
721 /// are affected by 'Ranges'.
722 tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
724  StringRef FileName,
725  unsigned *Cursor = nullptr);
726 
727 /// \brief Reformats the given \p Ranges in the file \p ID.
728 ///
729 /// Each range is extended on either end to its next bigger logic unit, i.e.
730 /// everything that might influence its formatting or might be influenced by its
731 /// formatting.
732 ///
733 /// Returns the \c Replacements necessary to make all \p Ranges comply with
734 /// \p Style.
735 ///
736 /// If \c IncompleteFormat is non-null, its value will be set to true if any
737 /// of the affected ranges were not formatted due to a non-recoverable syntax
738 /// error.
739 tooling::Replacements reformat(const FormatStyle &Style,
742  bool *IncompleteFormat = nullptr);
743 
744 /// \brief Reformats the given \p Ranges in \p Code.
745 ///
746 /// Otherwise identical to the reformat() function using a file ID.
747 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
749  StringRef FileName = "<stdin>",
750  bool *IncompleteFormat = nullptr);
751 
752 /// \brief Returns the \c LangOpts that the formatter expects you to set.
753 ///
754 /// \param Style determines specific settings for lexing mode.
755 LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle());
756 
757 /// \brief Description to be used for help text for a llvm::cl option for
758 /// specifying format style. The description is closely related to the operation
759 /// of getStyle().
760 extern const char *StyleOptionHelpDescription;
761 
762 /// \brief Construct a FormatStyle based on \c StyleName.
763 ///
764 /// \c StyleName can take several forms:
765 /// \li "{<key>: <value>, ...}" - Set specic style parameters.
766 /// \li "<style name>" - One of the style names supported by
767 /// getPredefinedStyle().
768 /// \li "file" - Load style configuration from a file called '.clang-format'
769 /// located in one of the parent directories of \c FileName or the current
770 /// directory if \c FileName is empty.
771 ///
772 /// \param[in] StyleName Style name to interpret according to the description
773 /// above.
774 /// \param[in] FileName Path to start search for .clang-format if \c StyleName
775 /// == "file".
776 /// \param[in] FallbackStyle The name of a predefined style used to fallback to
777 /// in case the style can't be determined from \p StyleName.
778 ///
779 /// \returns FormatStyle as specified by \c StyleName. If no style could be
780 /// determined, the default is LLVM Style (see getLLVMStyle()).
781 FormatStyle getStyle(StringRef StyleName, StringRef FileName,
782  StringRef FallbackStyle);
783 
784 } // end namespace format
785 } // end namespace clang
786 
787 namespace std {
788 template <>
789 struct is_error_code_enum<clang::format::ParseError> : std::true_type {};
790 }
791 
792 #endif // LLVM_CLANG_FORMAT_FORMAT_H
Always break after the return type of top-level definitions.
Definition: Format.h:176
Use tabs only for indentation.
Definition: Format.h:582
See documentation of IncludeCategories.
Definition: Format.h:362
PointerAlignmentStyle
The & and * alignment style.
Definition: Format.h:491
bool AfterUnion
Wrap union definitions.
Definition: Format.h:263
Indent in all namespaces.
Definition: Format.h:454
bool AlwaysBreakBeforeMultilineStrings
If true, always break before multiline string literals.
Definition: Format.h:192
unsigned PenaltyBreakBeforeFirstCallParameter
The penalty for breaking a function call after "call(".
Definition: Format.h:472
bool AlignEscapedNewlinesLeft
If true, aligns escaped newlines as far left as possible.
Definition: Format.h:99
tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, unsigned *Cursor=nullptr)
Returns the replacements necessary to sort all #include blocks that are affected by 'Ranges'...
Definition: Format.cpp:1799
Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).
Definition: Format.h:430
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:540
std::set< Replacement > Replacements
A set of Replacements.
Definition: Replacement.h:141
bool IndentCaseLabels
Indent case labels one level from the switch statement.
Definition: Format.h:404
unsigned IndentWidth
The number of columns to use for indentation.
Definition: Format.h:407
bool DisableFormat
Disables formatting completely.
Definition: Format.h:330
bool AlignConsecutiveDeclarations
If true, aligns consecutive declarations.
Definition: Format.h:95
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:616
DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType
The function definition return type breaking style to use.
Definition: Format.h:181
PointerAlignmentStyle PointerAlignment
Pointer and reference alignment style.
Definition: Format.h:501
std::error_code make_error_code(ParseError e)
Definition: Format.cpp:396
Align pointer to the left.
Definition: Format.h:493
Should be used for C, C++, ObjectiveC, ObjectiveC++.
Definition: Format.h:423
unsigned PenaltyBreakFirstLessLess
The penalty for breaking before the first <<.
Definition: Format.h:478
LanguageKind
Supported languages.
Definition: Format.h:419
bool AfterEnum
Wrap enum definitions.
Definition: Format.h:253
Break after operators.
Definition: Format.h:209
FormatStyle getWebKitStyle()
Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style...
Definition: Format.cpp:638
Use tabs whenever we need to fill whitespace that spans at least from one tab stop to the next one...
Definition: Format.h:585
bool operator==(const IncludeCategory &Other) const
Definition: Format.h:367
const char * name() const LLVM_NOEXCEPT override
Definition: Format.cpp:400
Like Attach, but break before braces on enum, function, and record definitions.
Definition: Format.h:228
Always break after the return type.
Definition: Format.h:170
bool AfterObjCDeclaration
Wrap ObjC definitions (, interfaces, ..).
Definition: Format.h:259
bool DerivePointerAlignment
If true, analyze the formatted file for the most common alignment of & and *.
Definition: Format.h:327
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4381
bool ExperimentalAutoDetectBinPacking
If true, clang-format detects whether function calls and definitions are formatted with one parameter...
Definition: Format.h:342
bool SpaceInEmptyParentheses
If true, spaces may be inserted into '()'.
Definition: Format.h:533
bool IndentBraces
Indent the wrapped braces themselves.
Definition: Format.h:269
std::string message(int EV) const override
Definition: Format.cpp:404
Should be used for Java.
Definition: Format.h:425
Always break after the return type of function definitions.
Definition: Format.h:174
std::vector< IncludeCategory > IncludeCategories
Regular expressions denoting the different #include categories used for ordering #includes.
Definition: Format.h:398
NamespaceIndentationKind
Different ways to indent namespace contents.
Definition: Format.h:448
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:160
bool BreakAfterJavaFieldAnnotations
Break after each annotation on a field in Java files.
Definition: Format.h:286
bool ConstructorInitializerAllOnOneLineOrOnePerLine
If the constructor initializers don't fit on a line, put each initializer on its own line...
Definition: Format.h:301
unsigned PenaltyBreakComment
The penalty for each line break introduced inside a comment.
Definition: Format.h:475
bool IndentWrappedFunctionNames
Indent if a function definition or declaration is wrapped after the type.
Definition: Format.h:411
std::string Regex
The regular expression that this category matches.
Definition: Format.h:364
bool SpacesInParentheses
If true, spaces will be inserted after '(' and before ')'.
Definition: Format.h:554
Always break after an open bracket, if the parameters don't fit on a single line, e...
Definition: Format.h:66
SmallVector< CharSourceRange, 8 > Ranges
Definition: Format.cpp:1715
NamespaceIndentationKind NamespaceIndentation
The indentation used for namespaces.
Definition: Format.h:458
ReturnTypeBreakingStyle AlwaysBreakAfterReturnType
The function declaration return type breaking style to use.
Definition: Format.h:184
bool BreakConstructorInitializersBeforeComma
Always break constructor initializers before commas and align the commas with the colon...
Definition: Format.h:283
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:200
unsigned ObjCBlockIndentWidth
The number of characters to use for indentation of ObjC blocks.
Definition: Format.h:461
bool SpaceBeforeAssignmentOperators
If false, spaces will be removed before assignment operators.
Definition: Format.h:513
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:597
SpaceBeforeParensOptions SpaceBeforeParens
Defines in which cases to put a space before opening parentheses.
Definition: Format.h:530
FormatStyle getGNUStyle()
Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standar...
Definition: Format.cpp:658
Always put a space before opening parentheses, except when it's prohibited by the syntax rules (in fu...
Definition: Format.h:526
bool AlignConsecutiveAssignments
If true, aligns consecutive assignments.
Definition: Format.h:84
unsigned ColumnLimit
The column limit.
Definition: Format.h:293
Never merge functions into a single line.
Definition: Format.h:131
bool AllowShortCaseLabelsOnASingleLine
If true, short case labels will be contracted to a single line.
Definition: Format.h:125
int Priority
The priority to assign to this category.
Definition: Format.h:366
BracketAlignmentStyle AlignAfterOpenBracket
If true, horizontally aligns arguments after an open bracket.
Definition: Format.h:73
bool KeepEmptyLinesAtTheStartOfBlocks
If true, empty lines at the start of blocks are kept.
Definition: Format.h:414
std::vector< std::string > ForEachMacros
A vector of macros that should be interpreted as foreach loops instead of as function calls...
Definition: Format.h:359
SpaceBeforeParensOptions
Different ways to put a space before opening parentheses.
Definition: Format.h:516
Break before operators that aren't assignments.
Definition: Format.h:211
UseTabStyle UseTab
The way to use tab characters in the resulting file.
Definition: Format.h:589
std::string MacroBlockEnd
A regular expression matching macros that end a block.
Definition: Format.h:442
FormatStyle getLLVMStyle()
Returns a format style complying with the LLVM coding standards: http://llvm.org/docs/CodingStandards...
Definition: Format.cpp:464
Break after return type automatically.
Definition: Format.h:168
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:297
Only merge empty functions.
Definition: Format.h:133
Defines the clang::LangOptions interface.
std::string MacroBlockBegin
A regular expression matching macros that start a block.
Definition: Format.h:439
Should be used for JavaScript.
Definition: Format.h:427
Precise control over the wrapping of braces.
Definition: Format.h:247
SourceManager & SourceMgr
Definition: Format.cpp:1352
LangOptions getFormattingLangOpts(const FormatStyle &Style=getLLVMStyle())
Returns the LangOpts that the formatter expects you to set.
Definition: Format.cpp:1922
bool SpacesInContainerLiterals
If true, spaces are inserted inside container literals (e.g.
Definition: Format.h:548
BraceWrappingFlags BraceWrapping
Control of individual brace wrapping cases.
Definition: Format.h:276
bool SpacesInAngles
If true, spaces will be inserted after '<' and before '>' in template argument lists...
Definition: Format.h:544
bool AlignOperands
If true, horizontally align operands of binary and ternary expressions.
Definition: Format.h:110
bool AfterFunction
Wrap function definitions.
Definition: Format.h:255
Break after return type automatically.
Definition: Format.h:156
FormatStyle getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle)
Construct a FormatStyle based on StyleName.
Definition: Format.cpp:1962
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.
Definition: Format.cpp:545
Don't indent in namespaces.
Definition: Format.h:450
BinaryOperatorStyle
The style of breaking before or after binary operators.
Definition: Format.h:207
BraceBreakingStyle BreakBeforeBraces
The brace breaking style to use.
Definition: Format.h:244
Don't align, instead use ContinuationIndentWidth, e.g.
Definition: Format.h:59
unsigned PenaltyBreakString
The penalty for each line break introduced inside a string literal.
Definition: Format.h:481
LanguageStandard
Supported language standards.
Definition: Format.h:560
Always attach braces to surrounding context.
Definition: Format.h:222
Align pointer in the middle.
Definition: Format.h:497
unsigned PenaltyExcessCharacter
The penalty for each character outside of the column limit.
Definition: Format.h:484
bool ReflowComments
If true, clang-format will attempt to re-flow comments.
Definition: Format.h:504
Put a space before opening parentheses only after control statement keywords (for/if/while...).
Definition: Format.h:521
Automatic detection based on the input.
Definition: Format.h:567
bool BreakBeforeTernaryOperators
If true, ternary operators will be placed after line breaks.
Definition: Format.h:279
unsigned ContinuationIndentWidth
Indent width for line continuations.
Definition: Format.h:308
bool AlwaysBreakTemplateDeclarations
If true, always break after the template<...> of a template declaration.
Definition: Format.h:196
bool AllowShortLoopsOnASingleLine
If true, while (true) continue; can be put on a single line.
Definition: Format.h:150
bool SpacesInCStyleCastParentheses
If true, spaces may be inserted into C style casts.
Definition: Format.h:551
bool SpacesInSquareBrackets
If true, spaces will be inserted after '[' and before ']'.
Definition: Format.h:557
ReturnTypeBreakingStyle
Different ways to break after the function definition or declaration return type. ...
Definition: Format.h:165
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:518
unsigned PenaltyReturnTypeOnItsOwnLine
Penalty for putting the return type of a function onto its own line.
Definition: Format.h:488
Indent only in inner namespaces (nested in other namespaces).
Definition: Format.h:452
std::string configurationAsText(const FormatStyle &Style)
Gets configuration in a YAML string.
Definition: Format.cpp:749
LanguageKind Language
Language, this format style is targeted at.
Definition: Format.h:436
Always break before braces.
Definition: Format.h:232
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.
Definition: Format.cpp:1938
ShortFunctionStyle AllowShortFunctionsOnASingleLine
Dependent on the value, int f() { return 0; } can be put on a single line.
Definition: Format.h:142
bool SortIncludes
If true, clang-format will sort #includes.
Definition: Format.h:507
Use C++03-compatible syntax.
Definition: Format.h:562
Always break after the return types of top-level functions.
Definition: Format.h:172
Should be used for TableGen code.
Definition: Format.h:432
Use features of C++11 (e.g.
Definition: Format.h:565
bool Cpp11BracedListStyle
If true, format braced lists as best suited for C++11 braced lists.
Definition: Format.h:323
BraceBreakingStyle
Different ways to attach braces to their surrounding context.
Definition: Format.h:220
BracketAlignmentStyle
Different styles for aligning after open brackets.
Definition: Format.h:47
Configure each individual brace in BraceWrapping.
Definition: Format.h:240
FormatStyle & Style
Definition: Format.cpp:1354
Merge all functions fitting on a single line.
Definition: Format.h:137
bool operator==(const FormatStyle &R) const
Definition: Format.h:591
Like Attach, but break before functions.
Definition: Format.h:238
bool AfterStruct
Wrap struct definitions.
Definition: Format.h:261
bool AllowAllParametersOfDeclarationOnNextLine
Allow putting all parameters of a function declaration onto the next line even if BinPackParameters i...
Definition: Format.h:117
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
Gets a predefined style for the specified language by name.
Definition: Format.cpp:679
unsigned TabWidth
The number of columns used for tab stops.
Definition: Format.h:575
UseTabStyle
Different ways to use tab in formatting.
Definition: Format.h:578
bool SpaceAfterCStyleCast
If true, a space may be inserted after C style casts.
Definition: Format.h:510
bool AllowShortIfStatementsOnASingleLine
If true, if (a) return; can be put on a single line.
Definition: Format.h:146
Like Attach, but break before function definitions, 'catch', and 'else'.
Definition: Format.h:230
FormatStyle getNoStyle()
Returns style indicating formatting should be not applied at all.
Definition: Format.cpp:672
Align parameters on the open bracket, e.g.
Definition: Format.h:53
Only merge functions defined inside a class. Implies "empty".
Definition: Format.h:135
LanguageStandard Standard
Format compatible with this standard, e.g.
Definition: Format.h:572
unsigned ConstructorInitializerIndentWidth
The number of characters to use for indentation of constructor initializer lists. ...
Definition: Format.h:305
const std::error_category & getParseCategory()
Definition: Format.cpp:392
BinaryOperatorStyle BreakBeforeBinaryOperators
The way to wrap binary operators.
Definition: Format.h:217
Break before operators.
Definition: Format.h:213
bool ObjCSpaceBeforeProtocolList
Add a space in front of an Objective-C protocol list, i.e.
Definition: Format.h:469
bool AfterControlStatement
Wrap control statements (if/for/while/switch/..).
Definition: Format.h:251
bool AllowShortBlocksOnASingleLine
Allows contracting simple braced statements to a single line.
Definition: Format.h:122
bool AlignTrailingComments
If true, aligns trailing comments.
Definition: Format.h:113
ShortFunctionStyle
Different styles for merging short functions containing at most one statement.
Definition: Format.h:129
bool AfterClass
Wrap class definitions.
Definition: Format.h:249
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:1883
StringRef Text
Definition: Format.cpp:1724
Always break before braces and add an extra level of indentation to braces of control statements...
Definition: Format.h:236
std::error_code parseConfiguration(StringRef Text, FormatStyle *Style)
Parse configuration from YAML-formatted text.
Definition: Format.cpp:703
Align pointer to the right.
Definition: Format.h:495
DefinitionReturnTypeBreakingStyle
Different ways to break after the function definition return type.
Definition: Format.h:153
Always break after the return type.
Definition: Format.h:158
unsigned MaxEmptyLinesToKeep
The maximum number of consecutive empty lines to keep.
Definition: Format.h:445
bool AfterNamespace
Wrap namespace definitions.
Definition: Format.h:257
This class handles loading and caching of source files into memory.
Like Attach, but break before braces on function, namespace and class definitions.
Definition: Format.h:225
bool BinPackParameters
If false, a function declaration's or function definition's parameters will either all be on the same...
Definition: Format.h:204