Home | History | Annotate | Download | only in Format
      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/Basic/LangOptions.h"
     19 #include "clang/Tooling/Core/Replacement.h"
     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:.
     44   int AccessModifierOffset;
     45 
     46   /// \brief Different styles for aligning after open brackets.
     47   enum BracketAlignmentStyle {
     48     /// \brief Align parameters on the open bracket, e.g.:
     49     /// \code
     50     ///   someLongFunction(argument1,
     51     ///                    argument2);
     52     /// \endcode
     53     BAS_Align,
     54     /// \brief Don't align, instead use \c ContinuationIndentWidth, e.g.:
     55     /// \code
     56     ///   someLongFunction(argument1,
     57     ///       argument2);
     58     /// \endcode
     59     BAS_DontAlign,
     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
     66     BAS_AlwaysBreak,
     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.
     73   BracketAlignmentStyle AlignAfterOpenBracket;
     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
     84   bool AlignConsecutiveAssignments;
     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
     95   bool AlignConsecutiveDeclarations;
     96 
     97   /// \brief If \c true, aligns escaped newlines as far left as possible.
     98   /// Otherwise puts them into the right-most column.
     99   bool AlignEscapedNewlinesLeft;
    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
    110   bool AlignOperands;
    111 
    112   /// \brief If \c true, aligns trailing comments.
    113   bool AlignTrailingComments;
    114 
    115   /// \brief Allow putting all parameters of a function declaration onto
    116   /// the next line even if \c BinPackParameters is \c false.
    117   bool AllowAllParametersOfDeclarationOnNextLine;
    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.
    122   bool AllowShortBlocksOnASingleLine;
    123 
    124   /// \brief If \c true, short case labels will be contracted to a single line.
    125   bool AllowShortCaseLabelsOnASingleLine;
    126 
    127   /// \brief Different styles for merging short functions containing at most one
    128   /// statement.
    129   enum ShortFunctionStyle {
    130     /// \brief Never merge functions into a single line.
    131     SFS_None,
    132     /// \brief Only merge empty functions.
    133     SFS_Empty,
    134     /// \brief Only merge functions defined inside a class. Implies "empty".
    135     SFS_Inline,
    136     /// \brief Merge all functions fitting on a single line.
    137     SFS_All,
    138   };
    139 
    140   /// \brief Dependent on the value, <tt>int f() { return 0; }</tt> can be put
    141   /// on a single line.
    142   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
    143 
    144   /// \brief If \c true, <tt>if (a) return;</tt> can be put on a single
    145   /// line.
    146   bool AllowShortIfStatementsOnASingleLine;
    147 
    148   /// \brief If \c true, <tt>while (true) continue;</tt> can be put on a
    149   /// single line.
    150   bool AllowShortLoopsOnASingleLine;
    151 
    152   /// \brief Different ways to break after the function definition return type.
    153   enum DefinitionReturnTypeBreakingStyle {
    154     /// Break after return type automatically.
    155     /// \c PenaltyReturnTypeOnItsOwnLine is taken into account.
    156     DRTBS_None,
    157     /// Always break after the return type.
    158     DRTBS_All,
    159     /// Always break after the return types of top-level functions.
    160     DRTBS_TopLevel,
    161   };
    162 
    163   /// \brief Different ways to break after the function definition or
    164   /// declaration return type.
    165   enum ReturnTypeBreakingStyle {
    166     /// Break after return type automatically.
    167     /// \c PenaltyReturnTypeOnItsOwnLine is taken into account.
    168     RTBS_None,
    169     /// Always break after the return type.
    170     RTBS_All,
    171     /// Always break after the return types of top-level functions.
    172     RTBS_TopLevel,
    173     /// Always break after the return type of function definitions.
    174     RTBS_AllDefinitions,
    175     /// Always break after the return type of top-level definitions.
    176     RTBS_TopLevelDefinitions,
    177   };
    178 
    179   /// \brief The function definition return type breaking style to use.  This
    180   /// option is deprecated and is retained for backwards compatibility.
    181   DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
    182 
    183   /// \brief The function declaration return type breaking style to use.
    184   ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
    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.
    192   bool AlwaysBreakBeforeMultilineStrings;
    193 
    194   /// \brief If \c true, always break after the <tt>template<...></tt> of a
    195   /// template declaration.
    196   bool AlwaysBreakTemplateDeclarations;
    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.
    200   bool BinPackArguments;
    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.
    204   bool BinPackParameters;
    205 
    206   /// \brief The style of breaking before or after binary operators.
    207   enum BinaryOperatorStyle {
    208     /// Break after operators.
    209     BOS_None,
    210     /// Break before operators that aren't assignments.
    211     BOS_NonAssignment,
    212     /// Break before operators.
    213     BOS_All,
    214   };
    215 
    216   /// \brief The way to wrap binary operators.
    217   BinaryOperatorStyle BreakBeforeBinaryOperators;
    218 
    219   /// \brief Different ways to attach braces to their surrounding context.
    220   enum BraceBreakingStyle {
    221     /// Always attach braces to surrounding context.
    222     BS_Attach,
    223     /// Like \c Attach, but break before braces on function, namespace and
    224     /// class definitions.
    225     BS_Linux,
    226     /// Like ``Attach``, but break before braces on enum, function, and record
    227     /// definitions.
    228     BS_Mozilla,
    229     /// Like \c Attach, but break before function definitions, 'catch', and 'else'.
    230     BS_Stroustrup,
    231     /// Always break before braces.
    232     BS_Allman,
    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.
    236     BS_GNU,
    237     /// Like ``Attach``, but break before functions.
    238     BS_WebKit,
    239     /// Configure each individual brace in \c BraceWrapping.
    240     BS_Custom
    241   };
    242 
    243   /// \brief The brace breaking style to use.
    244   BraceBreakingStyle BreakBeforeBraces;
    245 
    246   /// \brief Precise control over the wrapping of braces.
    247   struct BraceWrappingFlags {
    248     /// \brief Wrap class definitions.
    249     bool AfterClass;
    250     /// \brief Wrap control statements (if/for/while/switch/..).
    251     bool AfterControlStatement;
    252     /// \brief Wrap enum definitions.
    253     bool AfterEnum;
    254     /// \brief Wrap function definitions.
    255     bool AfterFunction;
    256     /// \brief Wrap namespace definitions.
    257     bool AfterNamespace;
    258     /// \brief Wrap ObjC definitions (@autoreleasepool, interfaces, ..).
    259     bool AfterObjCDeclaration;
    260     /// \brief Wrap struct definitions.
    261     bool AfterStruct;
    262     /// \brief Wrap union definitions.
    263     bool AfterUnion;
    264     /// \brief Wrap before \c catch.
    265     bool BeforeCatch;
    266     /// \brief Wrap before \c else.
    267     bool BeforeElse;
    268     /// \brief Indent the wrapped braces themselves.
    269     bool IndentBraces;
    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.
    276   BraceWrappingFlags BraceWrapping;
    277 
    278   /// \brief If \c true, ternary operators will be placed after line breaks.
    279   bool BreakBeforeTernaryOperators;
    280 
    281   /// \brief Always break constructor initializers before commas and align
    282   /// the commas with the colon.
    283   bool BreakConstructorInitializersBeforeComma;
    284 
    285   /// \brief Break after each annotation on a field in Java files.
    286   bool BreakAfterJavaFieldAnnotations;
    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.
    301   bool ConstructorInitializerAllOnOneLineOrOnePerLine;
    302 
    303   /// \brief The number of characters to use for indentation of constructor
    304   /// initializer lists.
    305   unsigned ConstructorInitializerIndentWidth;
    306 
    307   /// \brief Indent width for line continuations.
    308   unsigned ContinuationIndentWidth;
    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.
    323   bool Cpp11BracedListStyle;
    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.
    327   bool DerivePointerAlignment;
    328 
    329   /// \brief Disables formatting completely.
    330   bool DisableFormat;
    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.
    342   bool ExperimentalAutoDetectBinPacking;
    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.
    362   struct IncludeCategory {
    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.
    404   bool IndentCaseLabels;
    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.
    411   bool IndentWrappedFunctionNames;
    412 
    413   /// \brief If true, empty lines at the start of blocks are kept.
    414   bool KeepEmptyLinesAtTheStartOfBlocks;
    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.
    419   enum LanguageKind {
    420     /// Do not use.
    421     LK_None,
    422     /// Should be used for C, C++, ObjectiveC, ObjectiveC++.
    423     LK_Cpp,
    424     /// Should be used for Java.
    425     LK_Java,
    426     /// Should be used for JavaScript.
    427     LK_JavaScript,
    428     /// Should be used for Protocol Buffers
    429     /// (https://developers.google.com/protocol-buffers/).
    430     LK_Proto
    431   };
    432 
    433   /// \brief Language, this format style is targeted at.
    434   LanguageKind Language;
    435 
    436   /// \brief A regular expression matching macros that start a block.
    437   std::string MacroBlockBegin;
    438 
    439   /// \brief A regular expression matching macros that end a block.
    440   std::string MacroBlockEnd;
    441 
    442   /// \brief The maximum number of consecutive empty lines to keep.
    443   unsigned MaxEmptyLinesToKeep;
    444 
    445   /// \brief Different ways to indent namespace contents.
    446   enum NamespaceIndentationKind {
    447     /// Don't indent in namespaces.
    448     NI_None,
    449     /// Indent only in inner namespaces (nested in other namespaces).
    450     NI_Inner,
    451     /// Indent in all namespaces.
    452     NI_All
    453   };
    454 
    455   /// \brief The indentation used for namespaces.
    456   NamespaceIndentationKind NamespaceIndentation;
    457 
    458   /// \brief The number of characters to use for indentation of ObjC blocks.
    459   unsigned ObjCBlockIndentWidth;
    460 
    461   /// \brief Add a space after \c @property in Objective-C, i.e. use
    462   /// <tt>\@property (readonly)</tt> instead of <tt>\@property(readonly)</tt>.
    463   bool ObjCSpaceAfterProperty;
    464 
    465   /// \brief Add a space in front of an Objective-C protocol list, i.e. use
    466   /// <tt>Foo <Protocol></tt> instead of \c Foo<Protocol>.
    467   bool ObjCSpaceBeforeProtocolList;
    468 
    469   /// \brief The penalty for breaking a function call after "call(".
    470   unsigned PenaltyBreakBeforeFirstCallParameter;
    471 
    472   /// \brief The penalty for each line break introduced inside a comment.
    473   unsigned PenaltyBreakComment;
    474 
    475   /// \brief The penalty for breaking before the first \c <<.
    476   unsigned PenaltyBreakFirstLessLess;
    477 
    478   /// \brief The penalty for each line break introduced inside a string literal.
    479   unsigned PenaltyBreakString;
    480 
    481   /// \brief The penalty for each character outside of the column limit.
    482   unsigned PenaltyExcessCharacter;
    483 
    484   /// \brief Penalty for putting the return type of a function onto its own
    485   /// line.
    486   unsigned PenaltyReturnTypeOnItsOwnLine;
    487 
    488   /// \brief The & and * alignment style.
    489   enum PointerAlignmentStyle {
    490     /// Align pointer to the left.
    491     PAS_Left,
    492     /// Align pointer to the right.
    493     PAS_Right,
    494     /// Align pointer in the middle.
    495     PAS_Middle
    496   };
    497 
    498   /// \brief Pointer and reference alignment style.
    499   PointerAlignmentStyle PointerAlignment;
    500 
    501   /// \brief If true, clang-format will attempt to re-flow comments.
    502   bool ReflowComments;
    503 
    504   /// \brief If true, clang-format will sort #includes.
    505   bool SortIncludes;
    506 
    507   /// \brief If \c true, a space may be inserted after C style casts.
    508   bool SpaceAfterCStyleCast;
    509 
    510   /// \brief If \c false, spaces will be removed before assignment operators.
    511   bool SpaceBeforeAssignmentOperators;
    512 
    513   /// \brief Different ways to put a space before opening parentheses.
    514   enum SpaceBeforeParensOptions {
    515     /// Never put a space before opening parentheses.
    516     SBPO_Never,
    517     /// Put a space before opening parentheses only after control statement
    518     /// keywords (<tt>for/if/while...</tt>).
    519     SBPO_ControlStatements,
    520     /// Always put a space before opening parentheses, except when it's
    521     /// prohibited by the syntax rules (in function-like macro definitions) or
    522     /// when determined by other style rules (after unary operators, opening
    523     /// parentheses, etc.)
    524     SBPO_Always
    525   };
    526 
    527   /// \brief Defines in which cases to put a space before opening parentheses.
    528   SpaceBeforeParensOptions SpaceBeforeParens;
    529 
    530   /// \brief If \c true, spaces may be inserted into '()'.
    531   bool SpaceInEmptyParentheses;
    532 
    533   /// \brief The number of spaces before trailing line comments
    534   /// (\c // - comments).
    535   ///
    536   /// This does not affect trailing block comments (\c /**/ - comments) as those
    537   /// commonly have different usage patterns and a number of special cases.
    538   unsigned SpacesBeforeTrailingComments;
    539 
    540   /// \brief If \c true, spaces will be inserted after '<' and before '>' in
    541   /// template argument lists
    542   bool SpacesInAngles;
    543 
    544   /// \brief If \c true, spaces are inserted inside container literals (e.g.
    545   /// ObjC and Javascript array and dict literals).
    546   bool SpacesInContainerLiterals;
    547 
    548   /// \brief If \c true, spaces may be inserted into C style casts.
    549   bool SpacesInCStyleCastParentheses;
    550 
    551   /// \brief If \c true, spaces will be inserted after '(' and before ')'.
    552   bool SpacesInParentheses;
    553 
    554   /// \brief If \c true, spaces will be inserted after '[' and before ']'.
    555   bool SpacesInSquareBrackets;
    556 
    557   /// \brief Supported language standards.
    558   enum LanguageStandard {
    559     /// Use C++03-compatible syntax.
    560     LS_Cpp03,
    561     /// Use features of C++11 (e.g. \c A<A<int>> instead of
    562     /// <tt>A<A<int> ></tt>).
    563     LS_Cpp11,
    564     /// Automatic detection based on the input.
    565     LS_Auto
    566   };
    567 
    568   /// \brief Format compatible with this standard, e.g. use
    569   /// <tt>A<A<int> ></tt> instead of \c A<A<int>> for LS_Cpp03.
    570   LanguageStandard Standard;
    571 
    572   /// \brief The number of columns used for tab stops.
    573   unsigned TabWidth;
    574 
    575   /// \brief Different ways to use tab in formatting.
    576   enum UseTabStyle {
    577     /// Never use tab.
    578     UT_Never,
    579     /// Use tabs only for indentation.
    580     UT_ForIndentation,
    581     /// Use tabs whenever we need to fill whitespace that spans at least from
    582     /// one tab stop to the next one.
    583     UT_Always
    584   };
    585 
    586   /// \brief The way to use tab characters in the resulting file.
    587   UseTabStyle UseTab;
    588 
    589   bool operator==(const FormatStyle &R) const {
    590     return AccessModifierOffset == R.AccessModifierOffset &&
    591            AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
    592            AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
    593            AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
    594            AlignEscapedNewlinesLeft == R.AlignEscapedNewlinesLeft &&
    595            AlignOperands == R.AlignOperands &&
    596            AlignTrailingComments == R.AlignTrailingComments &&
    597            AllowAllParametersOfDeclarationOnNextLine ==
    598                R.AllowAllParametersOfDeclarationOnNextLine &&
    599            AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
    600            AllowShortCaseLabelsOnASingleLine ==
    601                R.AllowShortCaseLabelsOnASingleLine &&
    602            AllowShortFunctionsOnASingleLine ==
    603                R.AllowShortFunctionsOnASingleLine &&
    604            AllowShortIfStatementsOnASingleLine ==
    605                R.AllowShortIfStatementsOnASingleLine &&
    606            AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
    607            AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
    608            AlwaysBreakBeforeMultilineStrings ==
    609                R.AlwaysBreakBeforeMultilineStrings &&
    610            AlwaysBreakTemplateDeclarations ==
    611                R.AlwaysBreakTemplateDeclarations &&
    612            BinPackArguments == R.BinPackArguments &&
    613            BinPackParameters == R.BinPackParameters &&
    614            BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
    615            BreakBeforeBraces == R.BreakBeforeBraces &&
    616            BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
    617            BreakConstructorInitializersBeforeComma ==
    618                R.BreakConstructorInitializersBeforeComma &&
    619            BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
    620            ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
    621            ConstructorInitializerAllOnOneLineOrOnePerLine ==
    622                R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
    623            ConstructorInitializerIndentWidth ==
    624                R.ConstructorInitializerIndentWidth &&
    625            ContinuationIndentWidth == R.ContinuationIndentWidth &&
    626            Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
    627            DerivePointerAlignment == R.DerivePointerAlignment &&
    628            DisableFormat == R.DisableFormat &&
    629            ExperimentalAutoDetectBinPacking ==
    630                R.ExperimentalAutoDetectBinPacking &&
    631            ForEachMacros == R.ForEachMacros &&
    632            IncludeCategories == R.IncludeCategories &&
    633            IndentCaseLabels == R.IndentCaseLabels &&
    634            IndentWidth == R.IndentWidth && Language == R.Language &&
    635            IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
    636            KeepEmptyLinesAtTheStartOfBlocks ==
    637                R.KeepEmptyLinesAtTheStartOfBlocks &&
    638            MacroBlockBegin == R.MacroBlockBegin &&
    639            MacroBlockEnd == R.MacroBlockEnd &&
    640            MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
    641            NamespaceIndentation == R.NamespaceIndentation &&
    642            ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
    643            ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
    644            ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
    645            PenaltyBreakBeforeFirstCallParameter ==
    646                R.PenaltyBreakBeforeFirstCallParameter &&
    647            PenaltyBreakComment == R.PenaltyBreakComment &&
    648            PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
    649            PenaltyBreakString == R.PenaltyBreakString &&
    650            PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
    651            PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
    652            PointerAlignment == R.PointerAlignment &&
    653            SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
    654            SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
    655            SpaceBeforeParens == R.SpaceBeforeParens &&
    656            SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
    657            SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
    658            SpacesInAngles == R.SpacesInAngles &&
    659            SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
    660            SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
    661            SpacesInParentheses == R.SpacesInParentheses &&
    662            SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
    663            Standard == R.Standard && TabWidth == R.TabWidth &&
    664            UseTab == R.UseTab;
    665   }
    666 };
    667 
    668 /// \brief Returns a format style complying with the LLVM coding standards:
    669 /// http://llvm.org/docs/CodingStandards.html.
    670 FormatStyle getLLVMStyle();
    671 
    672 /// \brief Returns a format style complying with one of Google's style guides:
    673 /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
    674 /// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
    675 /// https://developers.google.com/protocol-buffers/docs/style.
    676 FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
    677 
    678 /// \brief Returns a format style complying with Chromium's style guide:
    679 /// http://www.chromium.org/developers/coding-style.
    680 FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
    681 
    682 /// \brief Returns a format style complying with Mozilla's style guide:
    683 /// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
    684 FormatStyle getMozillaStyle();
    685 
    686 /// \brief Returns a format style complying with Webkit's style guide:
    687 /// http://www.webkit.org/coding/coding-style.html
    688 FormatStyle getWebKitStyle();
    689 
    690 /// \brief Returns a format style complying with GNU Coding Standards:
    691 /// http://www.gnu.org/prep/standards/standards.html
    692 FormatStyle getGNUStyle();
    693 
    694 /// \brief Returns style indicating formatting should be not applied at all.
    695 FormatStyle getNoStyle();
    696 
    697 /// \brief Gets a predefined style for the specified language by name.
    698 ///
    699 /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
    700 /// compared case-insensitively.
    701 ///
    702 /// Returns \c true if the Style has been set.
    703 bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
    704                         FormatStyle *Style);
    705 
    706 /// \brief Parse configuration from YAML-formatted text.
    707 ///
    708 /// Style->Language is used to get the base style, if the \c BasedOnStyle
    709 /// option is present.
    710 ///
    711 /// When \c BasedOnStyle is not present, options not present in the YAML
    712 /// document, are retained in \p Style.
    713 std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
    714 
    715 /// \brief Gets configuration in a YAML string.
    716 std::string configurationAsText(const FormatStyle &Style);
    717 
    718 /// \brief Returns the replacements necessary to sort all #include blocks that
    719 /// are affected by 'Ranges'.
    720 tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
    721                                    ArrayRef<tooling::Range> Ranges,
    722                                    StringRef FileName,
    723                                    unsigned *Cursor = nullptr);
    724 
    725 /// \brief Reformats the given \p Ranges in the file \p ID.
    726 ///
    727 /// Each range is extended on either end to its next bigger logic unit, i.e.
    728 /// everything that might influence its formatting or might be influenced by its
    729 /// formatting.
    730 ///
    731 /// Returns the \c Replacements necessary to make all \p Ranges comply with
    732 /// \p Style.
    733 ///
    734 /// If \c IncompleteFormat is non-null, its value will be set to true if any
    735 /// of the affected ranges were not formatted due to a non-recoverable syntax
    736 /// error.
    737 tooling::Replacements reformat(const FormatStyle &Style,
    738                                SourceManager &SourceMgr, FileID ID,
    739                                ArrayRef<CharSourceRange> Ranges,
    740                                bool *IncompleteFormat = nullptr);
    741 
    742 /// \brief Reformats the given \p Ranges in \p Code.
    743 ///
    744 /// Otherwise identical to the reformat() function using a file ID.
    745 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
    746                                ArrayRef<tooling::Range> Ranges,
    747                                StringRef FileName = "<stdin>",
    748                                bool *IncompleteFormat = nullptr);
    749 
    750 /// \brief Returns the \c LangOpts that the formatter expects you to set.
    751 ///
    752 /// \param Style determines specific settings for lexing mode.
    753 LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle());
    754 
    755 /// \brief Description to be used for help text for a llvm::cl option for
    756 /// specifying format style. The description is closely related to the operation
    757 /// of getStyle().
    758 extern const char *StyleOptionHelpDescription;
    759 
    760 /// \brief Construct a FormatStyle based on \c StyleName.
    761 ///
    762 /// \c StyleName can take several forms:
    763 /// \li "{<key>: <value>, ...}" - Set specic style parameters.
    764 /// \li "<style name>" - One of the style names supported by
    765 /// getPredefinedStyle().
    766 /// \li "file" - Load style configuration from a file called '.clang-format'
    767 /// located in one of the parent directories of \c FileName or the current
    768 /// directory if \c FileName is empty.
    769 ///
    770 /// \param[in] StyleName Style name to interpret according to the description
    771 /// above.
    772 /// \param[in] FileName Path to start search for .clang-format if \c StyleName
    773 /// == "file".
    774 /// \param[in] FallbackStyle The name of a predefined style used to fallback to
    775 /// in case the style can't be determined from \p StyleName.
    776 ///
    777 /// \returns FormatStyle as specified by \c StyleName. If no style could be
    778 /// determined, the default is LLVM Style (see getLLVMStyle()).
    779 FormatStyle getStyle(StringRef StyleName, StringRef FileName,
    780                      StringRef FallbackStyle);
    781 
    782 } // end namespace format
    783 } // end namespace clang
    784 
    785 namespace std {
    786 template <>
    787 struct is_error_code_enum<clang::format::ParseError> : std::true_type {};
    788 }
    789 
    790 #endif // LLVM_CLANG_FORMAT_FORMAT_H
    791