Home | History | Annotate | Line # | Download | only in Format
      1 //===--- Format.h - Format C++ code -----------------------------*- C++ -*-===//
      2 //
      3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4 // See https://llvm.org/LICENSE.txt for license information.
      5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6 //
      7 //===----------------------------------------------------------------------===//
      8 ///
      9 /// \file
     10 /// Various functions to configurably format source code.
     11 ///
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_CLANG_FORMAT_FORMAT_H
     15 #define LLVM_CLANG_FORMAT_FORMAT_H
     16 
     17 #include "clang/Basic/LangOptions.h"
     18 #include "clang/Tooling/Core/Replacement.h"
     19 #include "clang/Tooling/Inclusions/IncludeStyle.h"
     20 #include "llvm/ADT/ArrayRef.h"
     21 #include "llvm/Support/Regex.h"
     22 #include "llvm/Support/SourceMgr.h"
     23 #include <system_error>
     24 
     25 namespace llvm {
     26 namespace vfs {
     27 class FileSystem;
     28 }
     29 } // namespace llvm
     30 
     31 namespace clang {
     32 
     33 class Lexer;
     34 class SourceManager;
     35 class DiagnosticConsumer;
     36 
     37 namespace format {
     38 
     39 enum class ParseError {
     40   Success = 0,
     41   Error,
     42   Unsuitable,
     43   BinPackTrailingCommaConflict
     44 };
     45 class ParseErrorCategory final : public std::error_category {
     46 public:
     47   const char *name() const noexcept override;
     48   std::string message(int EV) const override;
     49 };
     50 const std::error_category &getParseCategory();
     51 std::error_code make_error_code(ParseError e);
     52 
     53 /// The ``FormatStyle`` is used to configure the formatting to follow
     54 /// specific guidelines.
     55 struct FormatStyle {
     56   // If the BasedOn: was InheritParentConfig and this style needs the file from
     57   // the parent directories. It is not part of the actual style for formatting.
     58   // Thus the // instead of ///.
     59   bool InheritsParentConfig;
     60 
     61   /// The extra indent or outdent of access modifiers, e.g. ``public:``.
     62   int AccessModifierOffset;
     63 
     64   /// Different styles for aligning after open brackets.
     65   enum BracketAlignmentStyle : unsigned char {
     66     /// Align parameters on the open bracket, e.g.:
     67     /// \code
     68     ///   someLongFunction(argument1,
     69     ///                    argument2);
     70     /// \endcode
     71     BAS_Align,
     72     /// Don't align, instead use ``ContinuationIndentWidth``, e.g.:
     73     /// \code
     74     ///   someLongFunction(argument1,
     75     ///       argument2);
     76     /// \endcode
     77     BAS_DontAlign,
     78     /// Always break after an open bracket, if the parameters don't fit
     79     /// on a single line, e.g.:
     80     /// \code
     81     ///   someLongFunction(
     82     ///       argument1, argument2);
     83     /// \endcode
     84     BAS_AlwaysBreak,
     85   };
     86 
     87   /// If ``true``, horizontally aligns arguments after an open bracket.
     88   ///
     89   /// This applies to round brackets (parentheses), angle brackets and square
     90   /// brackets.
     91   BracketAlignmentStyle AlignAfterOpenBracket;
     92 
     93   /// Styles for alignment of consecutive tokens. Tokens can be assignment signs
     94   /// (see
     95   /// ``AlignConsecutiveAssignments``), bitfield member separators (see
     96   /// ``AlignConsecutiveBitFields``), names in declarations (see
     97   /// ``AlignConsecutiveDeclarations``) or macro definitions (see
     98   /// ``AlignConsecutiveMacros``).
     99   enum AlignConsecutiveStyle {
    100     ACS_None,
    101     ACS_Consecutive,
    102     ACS_AcrossEmptyLines,
    103     ACS_AcrossComments,
    104     ACS_AcrossEmptyLinesAndComments
    105   };
    106 
    107   /// Style of aligning consecutive macro definitions.
    108   ///
    109   /// ``Consecutive`` will result in formattings like:
    110   /// \code
    111   ///   #define SHORT_NAME       42
    112   ///   #define LONGER_NAME      0x007f
    113   ///   #define EVEN_LONGER_NAME (2)
    114   ///   #define foo(x)           (x * x)
    115   ///   #define bar(y, z)        (y + z)
    116   /// \endcode
    117   ///
    118   /// Possible values:
    119   ///
    120   /// * ``ACS_None`` (in configuration: ``None``)
    121   ///    Do not align macro definitions on consecutive lines.
    122   ///
    123   /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``)
    124   ///    Align macro definitions on consecutive lines. This will result in
    125   ///    formattings like:
    126   ///    \code
    127   ///      #define SHORT_NAME       42
    128   ///      #define LONGER_NAME      0x007f
    129   ///      #define EVEN_LONGER_NAME (2)
    130   ///
    131   ///      #define foo(x) (x * x)
    132   ///      /* some comment */
    133   ///      #define bar(y, z) (y + z)
    134   ///    \endcode
    135   ///
    136   /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
    137   ///    Same as ACS_Consecutive, but also spans over empty lines, e.g.
    138   ///    \code
    139   ///      #define SHORT_NAME       42
    140   ///      #define LONGER_NAME      0x007f
    141   ///      #define EVEN_LONGER_NAME (2)
    142   ///
    143   ///      #define foo(x)           (x * x)
    144   ///      /* some comment */
    145   ///      #define bar(y, z) (y + z)
    146   ///    \endcode
    147   ///
    148   /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
    149   ///    Same as ACS_Consecutive, but also spans over lines only containing
    150   ///    comments, e.g.
    151   ///    \code
    152   ///      #define SHORT_NAME       42
    153   ///      #define LONGER_NAME      0x007f
    154   ///      #define EVEN_LONGER_NAME (2)
    155   ///
    156   ///      #define foo(x)    (x * x)
    157   ///      /* some comment */
    158   ///      #define bar(y, z) (y + z)
    159   ///    \endcode
    160   ///
    161   /// * ``ACS_AcrossEmptyLinesAndComments``
    162   ///   (in configuration: ``AcrossEmptyLinesAndComments``)
    163   ///
    164   ///    Same as ACS_Consecutive, but also spans over lines only containing
    165   ///    comments and empty lines, e.g.
    166   ///    \code
    167   ///      #define SHORT_NAME       42
    168   ///      #define LONGER_NAME      0x007f
    169   ///      #define EVEN_LONGER_NAME (2)
    170   ///
    171   ///      #define foo(x)           (x * x)
    172   ///      /* some comment */
    173   ///      #define bar(y, z)        (y + z)
    174   ///    \endcode
    175   AlignConsecutiveStyle AlignConsecutiveMacros;
    176 
    177   /// Style of aligning consecutive assignments.
    178   ///
    179   /// ``Consecutive`` will result in formattings like:
    180   /// \code
    181   ///   int a            = 1;
    182   ///   int somelongname = 2;
    183   ///   double c         = 3;
    184   /// \endcode
    185   ///
    186   /// Possible values:
    187   ///
    188   /// * ``ACS_None`` (in configuration: ``None``)
    189   ///    Do not align assignments on consecutive lines.
    190   ///
    191   /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``)
    192   ///    Align assignments on consecutive lines. This will result in
    193   ///    formattings like:
    194   ///    \code
    195   ///      int a            = 1;
    196   ///      int somelongname = 2;
    197   ///      double c         = 3;
    198   ///
    199   ///      int d = 3;
    200   ///      /* A comment. */
    201   ///      double e = 4;
    202   ///    \endcode
    203   ///
    204   /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
    205   ///    Same as ACS_Consecutive, but also spans over empty lines, e.g.
    206   ///    \code
    207   ///      int a            = 1;
    208   ///      int somelongname = 2;
    209   ///      double c         = 3;
    210   ///
    211   ///      int d            = 3;
    212   ///      /* A comment. */
    213   ///      double e = 4;
    214   ///    \endcode
    215   ///
    216   /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
    217   ///    Same as ACS_Consecutive, but also spans over lines only containing
    218   ///    comments, e.g.
    219   ///    \code
    220   ///      int a            = 1;
    221   ///      int somelongname = 2;
    222   ///      double c         = 3;
    223   ///
    224   ///      int d    = 3;
    225   ///      /* A comment. */
    226   ///      double e = 4;
    227   ///    \endcode
    228   ///
    229   /// * ``ACS_AcrossEmptyLinesAndComments``
    230   ///   (in configuration: ``AcrossEmptyLinesAndComments``)
    231   ///
    232   ///    Same as ACS_Consecutive, but also spans over lines only containing
    233   ///    comments and empty lines, e.g.
    234   ///    \code
    235   ///      int a            = 1;
    236   ///      int somelongname = 2;
    237   ///      double c         = 3;
    238   ///
    239   ///      int d            = 3;
    240   ///      /* A comment. */
    241   ///      double e         = 4;
    242   ///    \endcode
    243   AlignConsecutiveStyle AlignConsecutiveAssignments;
    244 
    245   /// Style of aligning consecutive bit field.
    246   ///
    247   /// ``Consecutive`` will align the bitfield separators of consecutive lines.
    248   /// This will result in formattings like:
    249   /// \code
    250   ///   int aaaa : 1;
    251   ///   int b    : 12;
    252   ///   int ccc  : 8;
    253   /// \endcode
    254   ///
    255   /// Possible values:
    256   ///
    257   /// * ``ACS_None`` (in configuration: ``None``)
    258   ///    Do not align bit fields on consecutive lines.
    259   ///
    260   /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``)
    261   ///    Align bit fields on consecutive lines. This will result in
    262   ///    formattings like:
    263   ///    \code
    264   ///      int aaaa : 1;
    265   ///      int b    : 12;
    266   ///      int ccc  : 8;
    267   ///
    268   ///      int d : 2;
    269   ///      /* A comment. */
    270   ///      int ee : 3;
    271   ///    \endcode
    272   ///
    273   /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
    274   ///    Same as ACS_Consecutive, but also spans over empty lines, e.g.
    275   ///    \code
    276   ///      int aaaa : 1;
    277   ///      int b    : 12;
    278   ///      int ccc  : 8;
    279   ///
    280   ///      int d    : 2;
    281   ///      /* A comment. */
    282   ///      int ee : 3;
    283   ///    \endcode
    284   ///
    285   /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
    286   ///    Same as ACS_Consecutive, but also spans over lines only containing
    287   ///    comments, e.g.
    288   ///    \code
    289   ///      int aaaa : 1;
    290   ///      int b    : 12;
    291   ///      int ccc  : 8;
    292   ///
    293   ///      int d  : 2;
    294   ///      /* A comment. */
    295   ///      int ee : 3;
    296   ///    \endcode
    297   ///
    298   /// * ``ACS_AcrossEmptyLinesAndComments``
    299   ///   (in configuration: ``AcrossEmptyLinesAndComments``)
    300   ///
    301   ///    Same as ACS_Consecutive, but also spans over lines only containing
    302   ///    comments and empty lines, e.g.
    303   ///    \code
    304   ///      int aaaa : 1;
    305   ///      int b    : 12;
    306   ///      int ccc  : 8;
    307   ///
    308   ///      int d    : 2;
    309   ///      /* A comment. */
    310   ///      int ee   : 3;
    311   ///    \endcode
    312   AlignConsecutiveStyle AlignConsecutiveBitFields;
    313 
    314   /// Style of aligning consecutive declarations.
    315   ///
    316   /// ``Consecutive`` will align the declaration names of consecutive lines.
    317   /// This will result in formattings like:
    318   /// \code
    319   ///   int         aaaa = 12;
    320   ///   float       b = 23;
    321   ///   std::string ccc;
    322   /// \endcode
    323   ///
    324   /// Possible values:
    325   ///
    326   /// * ``ACS_None`` (in configuration: ``None``)
    327   ///    Do not align bit declarations on consecutive lines.
    328   ///
    329   /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``)
    330   ///    Align declarations on consecutive lines. This will result in
    331   ///    formattings like:
    332   ///    \code
    333   ///      int         aaaa = 12;
    334   ///      float       b = 23;
    335   ///      std::string ccc;
    336   ///
    337   ///      int a = 42;
    338   ///      /* A comment. */
    339   ///      bool c = false;
    340   ///    \endcode
    341   ///
    342   /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
    343   ///    Same as ACS_Consecutive, but also spans over empty lines, e.g.
    344   ///    \code
    345   ///      int         aaaa = 12;
    346   ///      float       b = 23;
    347   ///      std::string ccc;
    348   ///
    349   ///      int         a = 42;
    350   ///      /* A comment. */
    351   ///      bool c = false;
    352   ///    \endcode
    353   ///
    354   /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
    355   ///    Same as ACS_Consecutive, but also spans over lines only containing
    356   ///    comments, e.g.
    357   ///    \code
    358   ///      int         aaaa = 12;
    359   ///      float       b = 23;
    360   ///      std::string ccc;
    361   ///
    362   ///      int  a = 42;
    363   ///      /* A comment. */
    364   ///      bool c = false;
    365   ///    \endcode
    366   ///
    367   /// * ``ACS_AcrossEmptyLinesAndComments``
    368   ///   (in configuration: ``AcrossEmptyLinesAndComments``)
    369   ///
    370   ///    Same as ACS_Consecutive, but also spans over lines only containing
    371   ///    comments and empty lines, e.g.
    372   ///    \code
    373   ///      int         aaaa = 12;
    374   ///      float       b = 23;
    375   ///      std::string ccc;
    376   ///
    377   ///      int         a = 42;
    378   ///      /* A comment. */
    379   ///      bool        c = false;
    380   ///    \endcode
    381   AlignConsecutiveStyle AlignConsecutiveDeclarations;
    382 
    383   /// Different styles for aligning escaped newlines.
    384   enum EscapedNewlineAlignmentStyle : unsigned char {
    385     /// Don't align escaped newlines.
    386     /// \code
    387     ///   #define A \
    388     ///     int aaaa; \
    389     ///     int b; \
    390     ///     int dddddddddd;
    391     /// \endcode
    392     ENAS_DontAlign,
    393     /// Align escaped newlines as far left as possible.
    394     /// \code
    395     ///   true:
    396     ///   #define A   \
    397     ///     int aaaa; \
    398     ///     int b;    \
    399     ///     int dddddddddd;
    400     ///
    401     ///   false:
    402     /// \endcode
    403     ENAS_Left,
    404     /// Align escaped newlines in the right-most column.
    405     /// \code
    406     ///   #define A                                                                      \
    407     ///     int aaaa;                                                                    \
    408     ///     int b;                                                                       \
    409     ///     int dddddddddd;
    410     /// \endcode
    411     ENAS_Right,
    412   };
    413 
    414   /// Options for aligning backslashes in escaped newlines.
    415   EscapedNewlineAlignmentStyle AlignEscapedNewlines;
    416 
    417   /// Different styles for aligning operands.
    418   enum OperandAlignmentStyle : unsigned char {
    419     /// Do not align operands of binary and ternary expressions.
    420     /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
    421     /// the start of the line.
    422     OAS_DontAlign,
    423     /// Horizontally align operands of binary and ternary expressions.
    424     ///
    425     /// Specifically, this aligns operands of a single expression that needs
    426     /// to be split over multiple lines, e.g.:
    427     /// \code
    428     ///   int aaa = bbbbbbbbbbbbbbb +
    429     ///             ccccccccccccccc;
    430     /// \endcode
    431     ///
    432     /// When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is
    433     /// aligned with the operand on the first line.
    434     /// \code
    435     ///   int aaa = bbbbbbbbbbbbbbb
    436     ///             + ccccccccccccccc;
    437     /// \endcode
    438     OAS_Align,
    439     /// Horizontally align operands of binary and ternary expressions.
    440     ///
    441     /// This is similar to ``AO_Align``, except when
    442     /// ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so
    443     /// that the wrapped operand is aligned with the operand on the first line.
    444     /// \code
    445     ///   int aaa = bbbbbbbbbbbbbbb
    446     ///           + ccccccccccccccc;
    447     /// \endcode
    448     OAS_AlignAfterOperator,
    449   };
    450 
    451   /// If ``true``, horizontally align operands of binary and ternary
    452   /// expressions.
    453   OperandAlignmentStyle AlignOperands;
    454 
    455   /// If ``true``, aligns trailing comments.
    456   /// \code
    457   ///   true:                                   false:
    458   ///   int a;     // My comment a      vs.     int a; // My comment a
    459   ///   int b = 2; // comment  b                int b = 2; // comment about b
    460   /// \endcode
    461   bool AlignTrailingComments;
    462 
    463   /// \brief If a function call or braced initializer list doesn't fit on a
    464   /// line, allow putting all arguments onto the next line, even if
    465   /// ``BinPackArguments`` is ``false``.
    466   /// \code
    467   ///   true:
    468   ///   callFunction(
    469   ///       a, b, c, d);
    470   ///
    471   ///   false:
    472   ///   callFunction(a,
    473   ///                b,
    474   ///                c,
    475   ///                d);
    476   /// \endcode
    477   bool AllowAllArgumentsOnNextLine;
    478 
    479   /// \brief If a constructor definition with a member initializer list doesn't
    480   /// fit on a single line, allow putting all member initializers onto the next
    481   /// line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true.
    482   /// Note that this parameter has no effect if
    483   /// ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is false.
    484   /// \code
    485   ///   true:
    486   ///   MyClass::MyClass() :
    487   ///       member0(0), member1(2) {}
    488   ///
    489   ///   false:
    490   ///   MyClass::MyClass() :
    491   ///       member0(0),
    492   ///       member1(2) {}
    493   bool AllowAllConstructorInitializersOnNextLine;
    494 
    495   /// If the function declaration doesn't fit on a line,
    496   /// allow putting all parameters of a function declaration onto
    497   /// the next line even if ``BinPackParameters`` is ``false``.
    498   /// \code
    499   ///   true:
    500   ///   void myFunction(
    501   ///       int a, int b, int c, int d, int e);
    502   ///
    503   ///   false:
    504   ///   void myFunction(int a,
    505   ///                   int b,
    506   ///                   int c,
    507   ///                   int d,
    508   ///                   int e);
    509   /// \endcode
    510   bool AllowAllParametersOfDeclarationOnNextLine;
    511 
    512   /// Allow short enums on a single line.
    513   /// \code
    514   ///   true:
    515   ///   enum { A, B } myEnum;
    516   ///
    517   ///   false:
    518   ///   enum
    519   ///   {
    520   ///     A,
    521   ///     B
    522   ///   } myEnum;
    523   /// \endcode
    524   bool AllowShortEnumsOnASingleLine;
    525 
    526   /// Different styles for merging short blocks containing at most one
    527   /// statement.
    528   enum ShortBlockStyle : unsigned char {
    529     /// Never merge blocks into a single line.
    530     /// \code
    531     ///   while (true) {
    532     ///   }
    533     ///   while (true) {
    534     ///     continue;
    535     ///   }
    536     /// \endcode
    537     SBS_Never,
    538     /// Only merge empty blocks.
    539     /// \code
    540     ///   while (true) {}
    541     ///   while (true) {
    542     ///     continue;
    543     ///   }
    544     /// \endcode
    545     SBS_Empty,
    546     /// Always merge short blocks into a single line.
    547     /// \code
    548     ///   while (true) {}
    549     ///   while (true) { continue; }
    550     /// \endcode
    551     SBS_Always,
    552   };
    553 
    554   /// Dependent on the value, ``while (true) { continue; }`` can be put on a
    555   /// single line.
    556   ShortBlockStyle AllowShortBlocksOnASingleLine;
    557 
    558   /// If ``true``, short case labels will be contracted to a single line.
    559   /// \code
    560   ///   true:                                   false:
    561   ///   switch (a) {                    vs.     switch (a) {
    562   ///   case 1: x = 1; break;                   case 1:
    563   ///   case 2: return;                           x = 1;
    564   ///   }                                         break;
    565   ///                                           case 2:
    566   ///                                             return;
    567   ///                                           }
    568   /// \endcode
    569   bool AllowShortCaseLabelsOnASingleLine;
    570 
    571   /// Different styles for merging short functions containing at most one
    572   /// statement.
    573   enum ShortFunctionStyle : unsigned char {
    574     /// Never merge functions into a single line.
    575     SFS_None,
    576     /// Only merge functions defined inside a class. Same as "inline",
    577     /// except it does not implies "empty": i.e. top level empty functions
    578     /// are not merged either.
    579     /// \code
    580     ///   class Foo {
    581     ///     void f() { foo(); }
    582     ///   };
    583     ///   void f() {
    584     ///     foo();
    585     ///   }
    586     ///   void f() {
    587     ///   }
    588     /// \endcode
    589     SFS_InlineOnly,
    590     /// Only merge empty functions.
    591     /// \code
    592     ///   void f() {}
    593     ///   void f2() {
    594     ///     bar2();
    595     ///   }
    596     /// \endcode
    597     SFS_Empty,
    598     /// Only merge functions defined inside a class. Implies "empty".
    599     /// \code
    600     ///   class Foo {
    601     ///     void f() { foo(); }
    602     ///   };
    603     ///   void f() {
    604     ///     foo();
    605     ///   }
    606     ///   void f() {}
    607     /// \endcode
    608     SFS_Inline,
    609     /// Merge all functions fitting on a single line.
    610     /// \code
    611     ///   class Foo {
    612     ///     void f() { foo(); }
    613     ///   };
    614     ///   void f() { bar(); }
    615     /// \endcode
    616     SFS_All,
    617   };
    618 
    619   /// Dependent on the value, ``int f() { return 0; }`` can be put on a
    620   /// single line.
    621   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
    622 
    623   /// Different styles for handling short if statements.
    624   enum ShortIfStyle : unsigned char {
    625     /// Never put short ifs on the same line.
    626     /// \code
    627     ///   if (a)
    628     ///     return;
    629     ///
    630     ///   if (b)
    631     ///     return;
    632     ///   else
    633     ///     return;
    634     ///
    635     ///   if (c)
    636     ///     return;
    637     ///   else {
    638     ///     return;
    639     ///   }
    640     /// \endcode
    641     SIS_Never,
    642     /// Put short ifs on the same line only if there is no else statement.
    643     /// \code
    644     ///   if (a) return;
    645     ///
    646     ///   if (b)
    647     ///     return;
    648     ///   else
    649     ///     return;
    650     ///
    651     ///   if (c)
    652     ///     return;
    653     ///   else {
    654     ///     return;
    655     ///   }
    656     /// \endcode
    657     SIS_WithoutElse,
    658     /// Put short ifs, but not else ifs nor else statements, on the same line.
    659     /// \code
    660     ///   if (a) return;
    661     ///
    662     ///   if (b) return;
    663     ///   else if (b)
    664     ///     return;
    665     ///   else
    666     ///     return;
    667     ///
    668     ///   if (c) return;
    669     ///   else {
    670     ///     return;
    671     ///   }
    672     /// \endcode
    673     SIS_OnlyFirstIf,
    674     /// Always put short ifs, else ifs and else statements on the same
    675     /// line.
    676     /// \code
    677     ///   if (a) return;
    678     ///
    679     ///   if (b) return;
    680     ///   else return;
    681     ///
    682     ///   if (c) return;
    683     ///   else {
    684     ///     return;
    685     ///   }
    686     /// \endcode
    687     SIS_AllIfsAndElse,
    688   };
    689 
    690   /// Dependent on the value, ``if (a) return;`` can be put on a single line.
    691   ShortIfStyle AllowShortIfStatementsOnASingleLine;
    692 
    693   /// Different styles for merging short lambdas containing at most one
    694   /// statement.
    695   enum ShortLambdaStyle : unsigned char {
    696     /// Never merge lambdas into a single line.
    697     SLS_None,
    698     /// Only merge empty lambdas.
    699     /// \code
    700     ///   auto lambda = [](int a) {}
    701     ///   auto lambda2 = [](int a) {
    702     ///       return a;
    703     ///   };
    704     /// \endcode
    705     SLS_Empty,
    706     /// Merge lambda into a single line if argument of a function.
    707     /// \code
    708     ///   auto lambda = [](int a) {
    709     ///       return a;
    710     ///   };
    711     ///   sort(a.begin(), a.end(), ()[] { return x < y; })
    712     /// \endcode
    713     SLS_Inline,
    714     /// Merge all lambdas fitting on a single line.
    715     /// \code
    716     ///   auto lambda = [](int a) {}
    717     ///   auto lambda2 = [](int a) { return a; };
    718     /// \endcode
    719     SLS_All,
    720   };
    721 
    722   /// Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
    723   /// single line.
    724   ShortLambdaStyle AllowShortLambdasOnASingleLine;
    725 
    726   /// If ``true``, ``while (true) continue;`` can be put on a single
    727   /// line.
    728   bool AllowShortLoopsOnASingleLine;
    729 
    730   /// Different ways to break after the function definition return type.
    731   /// This option is **deprecated** and is retained for backwards compatibility.
    732   enum DefinitionReturnTypeBreakingStyle : unsigned char {
    733     /// Break after return type automatically.
    734     /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
    735     DRTBS_None,
    736     /// Always break after the return type.
    737     DRTBS_All,
    738     /// Always break after the return types of top-level functions.
    739     DRTBS_TopLevel,
    740   };
    741 
    742   /// Different ways to break after the function definition or
    743   /// declaration return type.
    744   enum ReturnTypeBreakingStyle : unsigned char {
    745     /// Break after return type automatically.
    746     /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
    747     /// \code
    748     ///   class A {
    749     ///     int f() { return 0; };
    750     ///   };
    751     ///   int f();
    752     ///   int f() { return 1; }
    753     /// \endcode
    754     RTBS_None,
    755     /// Always break after the return type.
    756     /// \code
    757     ///   class A {
    758     ///     int
    759     ///     f() {
    760     ///       return 0;
    761     ///     };
    762     ///   };
    763     ///   int
    764     ///   f();
    765     ///   int
    766     ///   f() {
    767     ///     return 1;
    768     ///   }
    769     /// \endcode
    770     RTBS_All,
    771     /// Always break after the return types of top-level functions.
    772     /// \code
    773     ///   class A {
    774     ///     int f() { return 0; };
    775     ///   };
    776     ///   int
    777     ///   f();
    778     ///   int
    779     ///   f() {
    780     ///     return 1;
    781     ///   }
    782     /// \endcode
    783     RTBS_TopLevel,
    784     /// Always break after the return type of function definitions.
    785     /// \code
    786     ///   class A {
    787     ///     int
    788     ///     f() {
    789     ///       return 0;
    790     ///     };
    791     ///   };
    792     ///   int f();
    793     ///   int
    794     ///   f() {
    795     ///     return 1;
    796     ///   }
    797     /// \endcode
    798     RTBS_AllDefinitions,
    799     /// Always break after the return type of top-level definitions.
    800     /// \code
    801     ///   class A {
    802     ///     int f() { return 0; };
    803     ///   };
    804     ///   int f();
    805     ///   int
    806     ///   f() {
    807     ///     return 1;
    808     ///   }
    809     /// \endcode
    810     RTBS_TopLevelDefinitions,
    811   };
    812 
    813   /// The function definition return type breaking style to use.  This
    814   /// option is **deprecated** and is retained for backwards compatibility.
    815   DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
    816 
    817   /// The function declaration return type breaking style to use.
    818   ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
    819 
    820   /// If ``true``, always break before multiline string literals.
    821   ///
    822   /// This flag is mean to make cases where there are multiple multiline strings
    823   /// in a file look more consistent. Thus, it will only take effect if wrapping
    824   /// the string at that point leads to it being indented
    825   /// ``ContinuationIndentWidth`` spaces from the start of the line.
    826   /// \code
    827   ///    true:                                  false:
    828   ///    aaaa =                         vs.     aaaa = "bbbb"
    829   ///        "bbbb"                                    "cccc";
    830   ///        "cccc";
    831   /// \endcode
    832   bool AlwaysBreakBeforeMultilineStrings;
    833 
    834   /// Different ways to break after the template declaration.
    835   enum BreakTemplateDeclarationsStyle : unsigned char {
    836     /// Do not force break before declaration.
    837     /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
    838     /// \code
    839     ///    template <typename T> T foo() {
    840     ///    }
    841     ///    template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
    842     ///                                int bbbbbbbbbbbbbbbbbbbbb) {
    843     ///    }
    844     /// \endcode
    845     BTDS_No,
    846     /// Force break after template declaration only when the following
    847     /// declaration spans multiple lines.
    848     /// \code
    849     ///    template <typename T> T foo() {
    850     ///    }
    851     ///    template <typename T>
    852     ///    T foo(int aaaaaaaaaaaaaaaaaaaaa,
    853     ///          int bbbbbbbbbbbbbbbbbbbbb) {
    854     ///    }
    855     /// \endcode
    856     BTDS_MultiLine,
    857     /// Always break after template declaration.
    858     /// \code
    859     ///    template <typename T>
    860     ///    T foo() {
    861     ///    }
    862     ///    template <typename T>
    863     ///    T foo(int aaaaaaaaaaaaaaaaaaaaa,
    864     ///          int bbbbbbbbbbbbbbbbbbbbb) {
    865     ///    }
    866     /// \endcode
    867     BTDS_Yes
    868   };
    869 
    870   /// The template declaration breaking style to use.
    871   BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
    872 
    873   /// A vector of strings that should be interpreted as attributes/qualifiers
    874   /// instead of identifiers. This can be useful for language extensions or
    875   /// static analyzer annotations.
    876   ///
    877   /// For example:
    878   /// \code
    879   ///   x = (char *__capability)&y;
    880   ///   int function(void) __ununsed;
    881   ///   void only_writes_to_buffer(char *__output buffer);
    882   /// \endcode
    883   ///
    884   /// In the .clang-format configuration file, this can be configured like:
    885   /// \code{.yaml}
    886   ///   AttributeMacros: ['__capability', '__output', '__ununsed']
    887   /// \endcode
    888   ///
    889   std::vector<std::string> AttributeMacros;
    890 
    891   /// If ``false``, a function call's arguments will either be all on the
    892   /// same line or will have one line each.
    893   /// \code
    894   ///   true:
    895   ///   void f() {
    896   ///     f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
    897   ///       aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
    898   ///   }
    899   ///
    900   ///   false:
    901   ///   void f() {
    902   ///     f(aaaaaaaaaaaaaaaaaaaa,
    903   ///       aaaaaaaaaaaaaaaaaaaa,
    904   ///       aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
    905   ///   }
    906   /// \endcode
    907   bool BinPackArguments;
    908 
    909   /// The style of inserting trailing commas into container literals.
    910   enum TrailingCommaStyle : unsigned char {
    911     /// Do not insert trailing commas.
    912     TCS_None,
    913     /// Insert trailing commas in container literals that were wrapped over
    914     /// multiple lines. Note that this is conceptually incompatible with
    915     /// bin-packing, because the trailing comma is used as an indicator
    916     /// that a container should be formatted one-per-line (i.e. not bin-packed).
    917     /// So inserting a trailing comma counteracts bin-packing.
    918     TCS_Wrapped,
    919   };
    920 
    921   /// If set to ``TCS_Wrapped`` will insert trailing commas in container
    922   /// literals (arrays and objects) that wrap across multiple lines.
    923   /// It is currently only available for JavaScript
    924   /// and disabled by default ``TCS_None``.
    925   /// ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
    926   /// as inserting the comma disables bin-packing.
    927   /// \code
    928   ///   TSC_Wrapped:
    929   ///   const someArray = [
    930   ///   aaaaaaaaaaaaaaaaaaaaaaaaaa,
    931   ///   aaaaaaaaaaaaaaaaaaaaaaaaaa,
    932   ///   aaaaaaaaaaaaaaaaaaaaaaaaaa,
    933   ///   //                        ^ inserted
    934   ///   ]
    935   /// \endcode
    936   TrailingCommaStyle InsertTrailingCommas;
    937 
    938   /// If ``false``, a function declaration's or function definition's
    939   /// parameters will either all be on the same line or will have one line each.
    940   /// \code
    941   ///   true:
    942   ///   void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
    943   ///          int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
    944   ///
    945   ///   false:
    946   ///   void f(int aaaaaaaaaaaaaaaaaaaa,
    947   ///          int aaaaaaaaaaaaaaaaaaaa,
    948   ///          int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
    949   /// \endcode
    950   bool BinPackParameters;
    951 
    952   /// The style of wrapping parameters on the same line (bin-packed) or
    953   /// on one line each.
    954   enum BinPackStyle : unsigned char {
    955     /// Automatically determine parameter bin-packing behavior.
    956     BPS_Auto,
    957     /// Always bin-pack parameters.
    958     BPS_Always,
    959     /// Never bin-pack parameters.
    960     BPS_Never,
    961   };
    962 
    963   /// The style of breaking before or after binary operators.
    964   enum BinaryOperatorStyle : unsigned char {
    965     /// Break after operators.
    966     /// \code
    967     ///    LooooooooooongType loooooooooooooooooooooongVariable =
    968     ///        someLooooooooooooooooongFunction();
    969     ///
    970     ///    bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
    971     ///                         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
    972     ///                     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
    973     ///                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
    974     ///                     ccccccccccccccccccccccccccccccccccccccccc;
    975     /// \endcode
    976     BOS_None,
    977     /// Break before operators that aren't assignments.
    978     /// \code
    979     ///    LooooooooooongType loooooooooooooooooooooongVariable =
    980     ///        someLooooooooooooooooongFunction();
    981     ///
    982     ///    bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    983     ///                         + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    984     ///                     == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    985     ///                 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    986     ///                        > ccccccccccccccccccccccccccccccccccccccccc;
    987     /// \endcode
    988     BOS_NonAssignment,
    989     /// Break before operators.
    990     /// \code
    991     ///    LooooooooooongType loooooooooooooooooooooongVariable
    992     ///        = someLooooooooooooooooongFunction();
    993     ///
    994     ///    bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    995     ///                         + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    996     ///                     == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    997     ///                 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    998     ///                        > ccccccccccccccccccccccccccccccccccccccccc;
    999     /// \endcode
   1000     BOS_All,
   1001   };
   1002 
   1003   /// The way to wrap binary operators.
   1004   BinaryOperatorStyle BreakBeforeBinaryOperators;
   1005 
   1006   /// Different ways to attach braces to their surrounding context.
   1007   enum BraceBreakingStyle : unsigned char {
   1008     /// Always attach braces to surrounding context.
   1009     /// \code
   1010     ///   namespace N {
   1011     ///   enum E {
   1012     ///     E1,
   1013     ///     E2,
   1014     ///   };
   1015     ///
   1016     ///   class C {
   1017     ///   public:
   1018     ///     C();
   1019     ///   };
   1020     ///
   1021     ///   bool baz(int i) {
   1022     ///     try {
   1023     ///       do {
   1024     ///         switch (i) {
   1025     ///         case 1: {
   1026     ///           foobar();
   1027     ///           break;
   1028     ///         }
   1029     ///         default: {
   1030     ///           break;
   1031     ///         }
   1032     ///         }
   1033     ///       } while (--i);
   1034     ///       return true;
   1035     ///     } catch (...) {
   1036     ///       handleError();
   1037     ///       return false;
   1038     ///     }
   1039     ///   }
   1040     ///
   1041     ///   void foo(bool b) {
   1042     ///     if (b) {
   1043     ///       baz(2);
   1044     ///     } else {
   1045     ///       baz(5);
   1046     ///     }
   1047     ///   }
   1048     ///
   1049     ///   void bar() { foo(true); }
   1050     ///   } // namespace N
   1051     /// \endcode
   1052     BS_Attach,
   1053     /// Like ``Attach``, but break before braces on function, namespace and
   1054     /// class definitions.
   1055     /// \code
   1056     ///   namespace N
   1057     ///   {
   1058     ///   enum E {
   1059     ///     E1,
   1060     ///     E2,
   1061     ///   };
   1062     ///
   1063     ///   class C
   1064     ///   {
   1065     ///   public:
   1066     ///     C();
   1067     ///   };
   1068     ///
   1069     ///   bool baz(int i)
   1070     ///   {
   1071     ///     try {
   1072     ///       do {
   1073     ///         switch (i) {
   1074     ///         case 1: {
   1075     ///           foobar();
   1076     ///           break;
   1077     ///         }
   1078     ///         default: {
   1079     ///           break;
   1080     ///         }
   1081     ///         }
   1082     ///       } while (--i);
   1083     ///       return true;
   1084     ///     } catch (...) {
   1085     ///       handleError();
   1086     ///       return false;
   1087     ///     }
   1088     ///   }
   1089     ///
   1090     ///   void foo(bool b)
   1091     ///   {
   1092     ///     if (b) {
   1093     ///       baz(2);
   1094     ///     } else {
   1095     ///       baz(5);
   1096     ///     }
   1097     ///   }
   1098     ///
   1099     ///   void bar() { foo(true); }
   1100     ///   } // namespace N
   1101     /// \endcode
   1102     BS_Linux,
   1103     /// Like ``Attach``, but break before braces on enum, function, and record
   1104     /// definitions.
   1105     /// \code
   1106     ///   namespace N {
   1107     ///   enum E
   1108     ///   {
   1109     ///     E1,
   1110     ///     E2,
   1111     ///   };
   1112     ///
   1113     ///   class C
   1114     ///   {
   1115     ///   public:
   1116     ///     C();
   1117     ///   };
   1118     ///
   1119     ///   bool baz(int i)
   1120     ///   {
   1121     ///     try {
   1122     ///       do {
   1123     ///         switch (i) {
   1124     ///         case 1: {
   1125     ///           foobar();
   1126     ///           break;
   1127     ///         }
   1128     ///         default: {
   1129     ///           break;
   1130     ///         }
   1131     ///         }
   1132     ///       } while (--i);
   1133     ///       return true;
   1134     ///     } catch (...) {
   1135     ///       handleError();
   1136     ///       return false;
   1137     ///     }
   1138     ///   }
   1139     ///
   1140     ///   void foo(bool b)
   1141     ///   {
   1142     ///     if (b) {
   1143     ///       baz(2);
   1144     ///     } else {
   1145     ///       baz(5);
   1146     ///     }
   1147     ///   }
   1148     ///
   1149     ///   void bar() { foo(true); }
   1150     ///   } // namespace N
   1151     /// \endcode
   1152     BS_Mozilla,
   1153     /// Like ``Attach``, but break before function definitions, ``catch``, and
   1154     /// ``else``.
   1155     /// \code
   1156     ///   namespace N {
   1157     ///   enum E {
   1158     ///     E1,
   1159     ///     E2,
   1160     ///   };
   1161     ///
   1162     ///   class C {
   1163     ///   public:
   1164     ///     C();
   1165     ///   };
   1166     ///
   1167     ///   bool baz(int i)
   1168     ///   {
   1169     ///     try {
   1170     ///       do {
   1171     ///         switch (i) {
   1172     ///         case 1: {
   1173     ///           foobar();
   1174     ///           break;
   1175     ///         }
   1176     ///         default: {
   1177     ///           break;
   1178     ///         }
   1179     ///         }
   1180     ///       } while (--i);
   1181     ///       return true;
   1182     ///     }
   1183     ///     catch (...) {
   1184     ///       handleError();
   1185     ///       return false;
   1186     ///     }
   1187     ///   }
   1188     ///
   1189     ///   void foo(bool b)
   1190     ///   {
   1191     ///     if (b) {
   1192     ///       baz(2);
   1193     ///     }
   1194     ///     else {
   1195     ///       baz(5);
   1196     ///     }
   1197     ///   }
   1198     ///
   1199     ///   void bar() { foo(true); }
   1200     ///   } // namespace N
   1201     /// \endcode
   1202     BS_Stroustrup,
   1203     /// Always break before braces.
   1204     /// \code
   1205     ///   namespace N
   1206     ///   {
   1207     ///   enum E
   1208     ///   {
   1209     ///     E1,
   1210     ///     E2,
   1211     ///   };
   1212     ///
   1213     ///   class C
   1214     ///   {
   1215     ///   public:
   1216     ///     C();
   1217     ///   };
   1218     ///
   1219     ///   bool baz(int i)
   1220     ///   {
   1221     ///     try
   1222     ///     {
   1223     ///       do
   1224     ///       {
   1225     ///         switch (i)
   1226     ///         {
   1227     ///         case 1:
   1228     ///         {
   1229     ///           foobar();
   1230     ///           break;
   1231     ///         }
   1232     ///         default:
   1233     ///         {
   1234     ///           break;
   1235     ///         }
   1236     ///         }
   1237     ///       } while (--i);
   1238     ///       return true;
   1239     ///     }
   1240     ///     catch (...)
   1241     ///     {
   1242     ///       handleError();
   1243     ///       return false;
   1244     ///     }
   1245     ///   }
   1246     ///
   1247     ///   void foo(bool b)
   1248     ///   {
   1249     ///     if (b)
   1250     ///     {
   1251     ///       baz(2);
   1252     ///     }
   1253     ///     else
   1254     ///     {
   1255     ///       baz(5);
   1256     ///     }
   1257     ///   }
   1258     ///
   1259     ///   void bar() { foo(true); }
   1260     ///   } // namespace N
   1261     /// \endcode
   1262     BS_Allman,
   1263     /// Like ``Allman`` but always indent braces and line up code with braces.
   1264     /// \code
   1265     ///   namespace N
   1266     ///     {
   1267     ///   enum E
   1268     ///     {
   1269     ///     E1,
   1270     ///     E2,
   1271     ///     };
   1272     ///
   1273     ///   class C
   1274     ///     {
   1275     ///   public:
   1276     ///     C();
   1277     ///     };
   1278     ///
   1279     ///   bool baz(int i)
   1280     ///     {
   1281     ///     try
   1282     ///       {
   1283     ///       do
   1284     ///         {
   1285     ///         switch (i)
   1286     ///           {
   1287     ///           case 1:
   1288     ///           {
   1289     ///           foobar();
   1290     ///           break;
   1291     ///           }
   1292     ///           default:
   1293     ///           {
   1294     ///           break;
   1295     ///           }
   1296     ///           }
   1297     ///         } while (--i);
   1298     ///       return true;
   1299     ///       }
   1300     ///     catch (...)
   1301     ///       {
   1302     ///       handleError();
   1303     ///       return false;
   1304     ///       }
   1305     ///     }
   1306     ///
   1307     ///   void foo(bool b)
   1308     ///     {
   1309     ///     if (b)
   1310     ///       {
   1311     ///       baz(2);
   1312     ///       }
   1313     ///     else
   1314     ///       {
   1315     ///       baz(5);
   1316     ///       }
   1317     ///     }
   1318     ///
   1319     ///   void bar() { foo(true); }
   1320     ///     } // namespace N
   1321     /// \endcode
   1322     BS_Whitesmiths,
   1323     /// Always break before braces and add an extra level of indentation to
   1324     /// braces of control statements, not to those of class, function
   1325     /// or other definitions.
   1326     /// \code
   1327     ///   namespace N
   1328     ///   {
   1329     ///   enum E
   1330     ///   {
   1331     ///     E1,
   1332     ///     E2,
   1333     ///   };
   1334     ///
   1335     ///   class C
   1336     ///   {
   1337     ///   public:
   1338     ///     C();
   1339     ///   };
   1340     ///
   1341     ///   bool baz(int i)
   1342     ///   {
   1343     ///     try
   1344     ///       {
   1345     ///         do
   1346     ///           {
   1347     ///             switch (i)
   1348     ///               {
   1349     ///               case 1:
   1350     ///                 {
   1351     ///                   foobar();
   1352     ///                   break;
   1353     ///                 }
   1354     ///               default:
   1355     ///                 {
   1356     ///                   break;
   1357     ///                 }
   1358     ///               }
   1359     ///           }
   1360     ///         while (--i);
   1361     ///         return true;
   1362     ///       }
   1363     ///     catch (...)
   1364     ///       {
   1365     ///         handleError();
   1366     ///         return false;
   1367     ///       }
   1368     ///   }
   1369     ///
   1370     ///   void foo(bool b)
   1371     ///   {
   1372     ///     if (b)
   1373     ///       {
   1374     ///         baz(2);
   1375     ///       }
   1376     ///     else
   1377     ///       {
   1378     ///         baz(5);
   1379     ///       }
   1380     ///   }
   1381     ///
   1382     ///   void bar() { foo(true); }
   1383     ///   } // namespace N
   1384     /// \endcode
   1385     BS_GNU,
   1386     /// Like ``Attach``, but break before functions.
   1387     /// \code
   1388     ///   namespace N {
   1389     ///   enum E {
   1390     ///     E1,
   1391     ///     E2,
   1392     ///   };
   1393     ///
   1394     ///   class C {
   1395     ///   public:
   1396     ///     C();
   1397     ///   };
   1398     ///
   1399     ///   bool baz(int i)
   1400     ///   {
   1401     ///     try {
   1402     ///       do {
   1403     ///         switch (i) {
   1404     ///         case 1: {
   1405     ///           foobar();
   1406     ///           break;
   1407     ///         }
   1408     ///         default: {
   1409     ///           break;
   1410     ///         }
   1411     ///         }
   1412     ///       } while (--i);
   1413     ///       return true;
   1414     ///     } catch (...) {
   1415     ///       handleError();
   1416     ///       return false;
   1417     ///     }
   1418     ///   }
   1419     ///
   1420     ///   void foo(bool b)
   1421     ///   {
   1422     ///     if (b) {
   1423     ///       baz(2);
   1424     ///     } else {
   1425     ///       baz(5);
   1426     ///     }
   1427     ///   }
   1428     ///
   1429     ///   void bar() { foo(true); }
   1430     ///   } // namespace N
   1431     /// \endcode
   1432     BS_WebKit,
   1433     /// Configure each individual brace in `BraceWrapping`.
   1434     BS_Custom
   1435   };
   1436 
   1437   /// The brace breaking style to use.
   1438   BraceBreakingStyle BreakBeforeBraces;
   1439 
   1440   /// Different ways to wrap braces after control statements.
   1441   enum BraceWrappingAfterControlStatementStyle : unsigned char {
   1442     /// Never wrap braces after a control statement.
   1443     /// \code
   1444     ///   if (foo()) {
   1445     ///   } else {
   1446     ///   }
   1447     ///   for (int i = 0; i < 10; ++i) {
   1448     ///   }
   1449     /// \endcode
   1450     BWACS_Never,
   1451     /// Only wrap braces after a multi-line control statement.
   1452     /// \code
   1453     ///   if (foo && bar &&
   1454     ///       baz)
   1455     ///   {
   1456     ///     quux();
   1457     ///   }
   1458     ///   while (foo || bar) {
   1459     ///   }
   1460     /// \endcode
   1461     BWACS_MultiLine,
   1462     /// Always wrap braces after a control statement.
   1463     /// \code
   1464     ///   if (foo())
   1465     ///   {
   1466     ///   } else
   1467     ///   {}
   1468     ///   for (int i = 0; i < 10; ++i)
   1469     ///   {}
   1470     /// \endcode
   1471     BWACS_Always
   1472   };
   1473 
   1474   /// Precise control over the wrapping of braces.
   1475   /// \code
   1476   ///   # Should be declared this way:
   1477   ///   BreakBeforeBraces: Custom
   1478   ///   BraceWrapping:
   1479   ///       AfterClass: true
   1480   /// \endcode
   1481   struct BraceWrappingFlags {
   1482     /// Wrap case labels.
   1483     /// \code
   1484     ///   false:                                true:
   1485     ///   switch (foo) {                vs.     switch (foo) {
   1486     ///     case 1: {                             case 1:
   1487     ///       bar();                              {
   1488     ///       break;                                bar();
   1489     ///     }                                       break;
   1490     ///     default: {                            }
   1491     ///       plop();                             default:
   1492     ///     }                                     {
   1493     ///   }                                         plop();
   1494     ///                                           }
   1495     ///                                         }
   1496     /// \endcode
   1497     bool AfterCaseLabel;
   1498     /// Wrap class definitions.
   1499     /// \code
   1500     ///   true:
   1501     ///   class foo {};
   1502     ///
   1503     ///   false:
   1504     ///   class foo
   1505     ///   {};
   1506     /// \endcode
   1507     bool AfterClass;
   1508 
   1509     /// Wrap control statements (``if``/``for``/``while``/``switch``/..).
   1510     BraceWrappingAfterControlStatementStyle AfterControlStatement;
   1511     /// Wrap enum definitions.
   1512     /// \code
   1513     ///   true:
   1514     ///   enum X : int
   1515     ///   {
   1516     ///     B
   1517     ///   };
   1518     ///
   1519     ///   false:
   1520     ///   enum X : int { B };
   1521     /// \endcode
   1522     bool AfterEnum;
   1523     /// Wrap function definitions.
   1524     /// \code
   1525     ///   true:
   1526     ///   void foo()
   1527     ///   {
   1528     ///     bar();
   1529     ///     bar2();
   1530     ///   }
   1531     ///
   1532     ///   false:
   1533     ///   void foo() {
   1534     ///     bar();
   1535     ///     bar2();
   1536     ///   }
   1537     /// \endcode
   1538     bool AfterFunction;
   1539     /// Wrap namespace definitions.
   1540     /// \code
   1541     ///   true:
   1542     ///   namespace
   1543     ///   {
   1544     ///   int foo();
   1545     ///   int bar();
   1546     ///   }
   1547     ///
   1548     ///   false:
   1549     ///   namespace {
   1550     ///   int foo();
   1551     ///   int bar();
   1552     ///   }
   1553     /// \endcode
   1554     bool AfterNamespace;
   1555     /// Wrap ObjC definitions (interfaces, implementations...).
   1556     /// \note @autoreleasepool and @synchronized blocks are wrapped
   1557     /// according to `AfterControlStatement` flag.
   1558     bool AfterObjCDeclaration;
   1559     /// Wrap struct definitions.
   1560     /// \code
   1561     ///   true:
   1562     ///   struct foo
   1563     ///   {
   1564     ///     int x;
   1565     ///   };
   1566     ///
   1567     ///   false:
   1568     ///   struct foo {
   1569     ///     int x;
   1570     ///   };
   1571     /// \endcode
   1572     bool AfterStruct;
   1573     /// Wrap union definitions.
   1574     /// \code
   1575     ///   true:
   1576     ///   union foo
   1577     ///   {
   1578     ///     int x;
   1579     ///   }
   1580     ///
   1581     ///   false:
   1582     ///   union foo {
   1583     ///     int x;
   1584     ///   }
   1585     /// \endcode
   1586     bool AfterUnion;
   1587     /// Wrap extern blocks.
   1588     /// \code
   1589     ///   true:
   1590     ///   extern "C"
   1591     ///   {
   1592     ///     int foo();
   1593     ///   }
   1594     ///
   1595     ///   false:
   1596     ///   extern "C" {
   1597     ///   int foo();
   1598     ///   }
   1599     /// \endcode
   1600     bool AfterExternBlock; // Partially superseded by IndentExternBlock
   1601     /// Wrap before ``catch``.
   1602     /// \code
   1603     ///   true:
   1604     ///   try {
   1605     ///     foo();
   1606     ///   }
   1607     ///   catch () {
   1608     ///   }
   1609     ///
   1610     ///   false:
   1611     ///   try {
   1612     ///     foo();
   1613     ///   } catch () {
   1614     ///   }
   1615     /// \endcode
   1616     bool BeforeCatch;
   1617     /// Wrap before ``else``.
   1618     /// \code
   1619     ///   true:
   1620     ///   if (foo()) {
   1621     ///   }
   1622     ///   else {
   1623     ///   }
   1624     ///
   1625     ///   false:
   1626     ///   if (foo()) {
   1627     ///   } else {
   1628     ///   }
   1629     /// \endcode
   1630     bool BeforeElse;
   1631     /// Wrap lambda block.
   1632     /// \code
   1633     ///   true:
   1634     ///   connect(
   1635     ///     []()
   1636     ///     {
   1637     ///       foo();
   1638     ///       bar();
   1639     ///     });
   1640     ///
   1641     ///   false:
   1642     ///   connect([]() {
   1643     ///     foo();
   1644     ///     bar();
   1645     ///   });
   1646     /// \endcode
   1647     bool BeforeLambdaBody;
   1648     /// Wrap before ``while``.
   1649     /// \code
   1650     ///   true:
   1651     ///   do {
   1652     ///     foo();
   1653     ///   }
   1654     ///   while (1);
   1655     ///
   1656     ///   false:
   1657     ///   do {
   1658     ///     foo();
   1659     ///   } while (1);
   1660     /// \endcode
   1661     bool BeforeWhile;
   1662     /// Indent the wrapped braces themselves.
   1663     bool IndentBraces;
   1664     /// If ``false``, empty function body can be put on a single line.
   1665     /// This option is used only if the opening brace of the function has
   1666     /// already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
   1667     /// set, and the function could/should not be put on a single line (as per
   1668     /// `AllowShortFunctionsOnASingleLine` and constructor formatting options).
   1669     /// \code
   1670     ///   int f()   vs.   int f()
   1671     ///   {}              {
   1672     ///                   }
   1673     /// \endcode
   1674     ///
   1675     bool SplitEmptyFunction;
   1676     /// If ``false``, empty record (e.g. class, struct or union) body
   1677     /// can be put on a single line. This option is used only if the opening
   1678     /// brace of the record has already been wrapped, i.e. the `AfterClass`
   1679     /// (for classes) brace wrapping mode is set.
   1680     /// \code
   1681     ///   class Foo   vs.  class Foo
   1682     ///   {}               {
   1683     ///                    }
   1684     /// \endcode
   1685     ///
   1686     bool SplitEmptyRecord;
   1687     /// If ``false``, empty namespace body can be put on a single line.
   1688     /// This option is used only if the opening brace of the namespace has
   1689     /// already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
   1690     /// set.
   1691     /// \code
   1692     ///   namespace Foo   vs.  namespace Foo
   1693     ///   {}                   {
   1694     ///                        }
   1695     /// \endcode
   1696     ///
   1697     bool SplitEmptyNamespace;
   1698   };
   1699 
   1700   /// Control of individual brace wrapping cases.
   1701   ///
   1702   /// If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
   1703   /// each individual brace case should be handled. Otherwise, this is ignored.
   1704   /// \code{.yaml}
   1705   ///   # Example of usage:
   1706   ///   BreakBeforeBraces: Custom
   1707   ///   BraceWrapping:
   1708   ///     AfterEnum: true
   1709   ///     AfterStruct: false
   1710   ///     SplitEmptyFunction: false
   1711   /// \endcode
   1712   BraceWrappingFlags BraceWrapping;
   1713 
   1714   /// If ``true``, concept will be placed on a new line.
   1715   /// \code
   1716   ///   true:
   1717   ///    template<typename T>
   1718   ///    concept ...
   1719   ///
   1720   ///   false:
   1721   ///    template<typename T> concept ...
   1722   /// \endcode
   1723   bool BreakBeforeConceptDeclarations;
   1724 
   1725   /// If ``true``, ternary operators will be placed after line breaks.
   1726   /// \code
   1727   ///    true:
   1728   ///    veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
   1729   ///        ? firstValue
   1730   ///        : SecondValueVeryVeryVeryVeryLong;
   1731   ///
   1732   ///    false:
   1733   ///    veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
   1734   ///        firstValue :
   1735   ///        SecondValueVeryVeryVeryVeryLong;
   1736   /// \endcode
   1737   bool BreakBeforeTernaryOperators;
   1738 
   1739   /// Different ways to break initializers.
   1740   enum BreakConstructorInitializersStyle : unsigned char {
   1741     /// Break constructor initializers before the colon and after the commas.
   1742     /// \code
   1743     ///    Constructor()
   1744     ///        : initializer1(),
   1745     ///          initializer2()
   1746     /// \endcode
   1747     BCIS_BeforeColon,
   1748     /// Break constructor initializers before the colon and commas, and align
   1749     /// the commas with the colon.
   1750     /// \code
   1751     ///    Constructor()
   1752     ///        : initializer1()
   1753     ///        , initializer2()
   1754     /// \endcode
   1755     BCIS_BeforeComma,
   1756     /// Break constructor initializers after the colon and commas.
   1757     /// \code
   1758     ///    Constructor() :
   1759     ///        initializer1(),
   1760     ///        initializer2()
   1761     /// \endcode
   1762     BCIS_AfterColon
   1763   };
   1764 
   1765   /// The constructor initializers style to use.
   1766   BreakConstructorInitializersStyle BreakConstructorInitializers;
   1767 
   1768   /// Break after each annotation on a field in Java files.
   1769   /// \code{.java}
   1770   ///    true:                                  false:
   1771   ///    @Partial                       vs.     @Partial @Mock DataLoad loader;
   1772   ///    @Mock
   1773   ///    DataLoad loader;
   1774   /// \endcode
   1775   bool BreakAfterJavaFieldAnnotations;
   1776 
   1777   /// Allow breaking string literals when formatting.
   1778   /// \code
   1779   ///    true:
   1780   ///    const char* x = "veryVeryVeryVeryVeryVe"
   1781   ///                    "ryVeryVeryVeryVeryVery"
   1782   ///                    "VeryLongString";
   1783   ///
   1784   ///    false:
   1785   ///    const char* x =
   1786   ///      "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
   1787   /// \endcode
   1788   bool BreakStringLiterals;
   1789 
   1790   /// The column limit.
   1791   ///
   1792   /// A column limit of ``0`` means that there is no column limit. In this case,
   1793   /// clang-format will respect the input's line breaking decisions within
   1794   /// statements unless they contradict other rules.
   1795   unsigned ColumnLimit;
   1796 
   1797   /// A regular expression that describes comments with special meaning,
   1798   /// which should not be split into lines or otherwise changed.
   1799   /// \code
   1800   ///    // CommentPragmas: '^ FOOBAR pragma:'
   1801   ///    // Will leave the following line unaffected
   1802   ///    #include <vector> // FOOBAR pragma: keep
   1803   /// \endcode
   1804   std::string CommentPragmas;
   1805 
   1806   /// Different ways to break inheritance list.
   1807   enum BreakInheritanceListStyle : unsigned char {
   1808     /// Break inheritance list before the colon and after the commas.
   1809     /// \code
   1810     ///    class Foo
   1811     ///        : Base1,
   1812     ///          Base2
   1813     ///    {};
   1814     /// \endcode
   1815     BILS_BeforeColon,
   1816     /// Break inheritance list before the colon and commas, and align
   1817     /// the commas with the colon.
   1818     /// \code
   1819     ///    class Foo
   1820     ///        : Base1
   1821     ///        , Base2
   1822     ///    {};
   1823     /// \endcode
   1824     BILS_BeforeComma,
   1825     /// Break inheritance list after the colon and commas.
   1826     /// \code
   1827     ///    class Foo :
   1828     ///        Base1,
   1829     ///        Base2
   1830     ///    {};
   1831     /// \endcode
   1832     BILS_AfterColon
   1833   };
   1834 
   1835   /// The inheritance list style to use.
   1836   BreakInheritanceListStyle BreakInheritanceList;
   1837 
   1838   /// If ``true``, consecutive namespace declarations will be on the same
   1839   /// line. If ``false``, each namespace is declared on a new line.
   1840   /// \code
   1841   ///   true:
   1842   ///   namespace Foo { namespace Bar {
   1843   ///   }}
   1844   ///
   1845   ///   false:
   1846   ///   namespace Foo {
   1847   ///   namespace Bar {
   1848   ///   }
   1849   ///   }
   1850   /// \endcode
   1851   ///
   1852   /// If it does not fit on a single line, the overflowing namespaces get
   1853   /// wrapped:
   1854   /// \code
   1855   ///   namespace Foo { namespace Bar {
   1856   ///   namespace Extra {
   1857   ///   }}}
   1858   /// \endcode
   1859   bool CompactNamespaces;
   1860 
   1861   // clang-format off
   1862   /// If the constructor initializers don't fit on a line, put each
   1863   /// initializer on its own line.
   1864   /// \code
   1865   ///   true:
   1866   ///   SomeClass::Constructor()
   1867   ///       : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
   1868   ///     return 0;
   1869   ///   }
   1870   ///
   1871   ///   false:
   1872   ///   SomeClass::Constructor()
   1873   ///       : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
   1874   ///         aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
   1875   ///     return 0;
   1876   ///   }
   1877   /// \endcode
   1878   bool ConstructorInitializerAllOnOneLineOrOnePerLine;
   1879   // clang-format on
   1880 
   1881   /// The number of characters to use for indentation of constructor
   1882   /// initializer lists as well as inheritance lists.
   1883   unsigned ConstructorInitializerIndentWidth;
   1884 
   1885   /// Indent width for line continuations.
   1886   /// \code
   1887   ///    ContinuationIndentWidth: 2
   1888   ///
   1889   ///    int i =         //  VeryVeryVeryVeryVeryLongComment
   1890   ///      longFunction( // Again a long comment
   1891   ///        arg);
   1892   /// \endcode
   1893   unsigned ContinuationIndentWidth;
   1894 
   1895   /// If ``true``, format braced lists as best suited for C++11 braced
   1896   /// lists.
   1897   ///
   1898   /// Important differences:
   1899   /// - No spaces inside the braced list.
   1900   /// - No line break before the closing brace.
   1901   /// - Indentation with the continuation indent, not with the block indent.
   1902   ///
   1903   /// Fundamentally, C++11 braced lists are formatted exactly like function
   1904   /// calls would be formatted in their place. If the braced list follows a name
   1905   /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were
   1906   /// the parentheses of a function call with that name. If there is no name,
   1907   /// a zero-length name is assumed.
   1908   /// \code
   1909   ///    true:                                  false:
   1910   ///    vector<int> x{1, 2, 3, 4};     vs.     vector<int> x{ 1, 2, 3, 4 };
   1911   ///    vector<T> x{{}, {}, {}, {}};           vector<T> x{ {}, {}, {}, {} };
   1912   ///    f(MyMap[{composite, key}]);            f(MyMap[{ composite, key }]);
   1913   ///    new int[3]{1, 2, 3};                   new int[3]{ 1, 2, 3 };
   1914   /// \endcode
   1915   bool Cpp11BracedListStyle;
   1916 
   1917   /// \brief Analyze the formatted file for the most used line ending (``\r\n``
   1918   /// or ``\n``). ``UseCRLF`` is only used as a fallback if none can be derived.
   1919   bool DeriveLineEnding;
   1920 
   1921   /// If ``true``, analyze the formatted file for the most common
   1922   /// alignment of ``&`` and ``*``.
   1923   /// Pointer and reference alignment styles are going to be updated according
   1924   /// to the preferences found in the file.
   1925   /// ``PointerAlignment`` is then used only as fallback.
   1926   bool DerivePointerAlignment;
   1927 
   1928   /// Disables formatting completely.
   1929   bool DisableFormat;
   1930 
   1931   /// Different styles for empty line after access modifiers.
   1932   /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
   1933   /// empty lines between two access modifiers.
   1934   enum EmptyLineAfterAccessModifierStyle : unsigned char {
   1935     /// Remove all empty lines after access modifiers.
   1936     /// \code
   1937     ///   struct foo {
   1938     ///   private:
   1939     ///     int i;
   1940     ///   protected:
   1941     ///     int j;
   1942     ///     /* comment */
   1943     ///   public:
   1944     ///     foo() {}
   1945     ///   private:
   1946     ///   protected:
   1947     ///   };
   1948     /// \endcode
   1949     ELAAMS_Never,
   1950     /// Keep existing empty lines after access modifiers.
   1951     /// MaxEmptyLinesToKeep is applied instead.
   1952     ELAAMS_Leave,
   1953     /// Always add empty line after access modifiers if there are none.
   1954     /// MaxEmptyLinesToKeep is applied also.
   1955     /// \code
   1956     ///   struct foo {
   1957     ///   private:
   1958     ///
   1959     ///     int i;
   1960     ///   protected:
   1961     ///
   1962     ///     int j;
   1963     ///     /* comment */
   1964     ///   public:
   1965     ///
   1966     ///     foo() {}
   1967     ///   private:
   1968     ///
   1969     ///   protected:
   1970     ///
   1971     ///   };
   1972     /// \endcode
   1973     ELAAMS_Always,
   1974   };
   1975 
   1976   /// Defines in which cases to put empty line after access modifiers.
   1977   EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier;
   1978 
   1979   /// Different styles for empty line before access modifiers.
   1980   enum EmptyLineBeforeAccessModifierStyle : unsigned char {
   1981     /// Remove all empty lines before access modifiers.
   1982     /// \code
   1983     ///   struct foo {
   1984     ///   private:
   1985     ///     int i;
   1986     ///   protected:
   1987     ///     int j;
   1988     ///     /* comment */
   1989     ///   public:
   1990     ///     foo() {}
   1991     ///   private:
   1992     ///   protected:
   1993     ///   };
   1994     /// \endcode
   1995     ELBAMS_Never,
   1996     /// Keep existing empty lines before access modifiers.
   1997     ELBAMS_Leave,
   1998     /// Add empty line only when access modifier starts a new logical block.
   1999     /// Logical block is a group of one or more member fields or functions.
   2000     /// \code
   2001     ///   struct foo {
   2002     ///   private:
   2003     ///     int i;
   2004     ///
   2005     ///   protected:
   2006     ///     int j;
   2007     ///     /* comment */
   2008     ///   public:
   2009     ///     foo() {}
   2010     ///
   2011     ///   private:
   2012     ///   protected:
   2013     ///   };
   2014     /// \endcode
   2015     ELBAMS_LogicalBlock,
   2016     /// Always add empty line before access modifiers unless access modifier
   2017     /// is at the start of struct or class definition.
   2018     /// \code
   2019     ///   struct foo {
   2020     ///   private:
   2021     ///     int i;
   2022     ///
   2023     ///   protected:
   2024     ///     int j;
   2025     ///     /* comment */
   2026     ///
   2027     ///   public:
   2028     ///     foo() {}
   2029     ///
   2030     ///   private:
   2031     ///
   2032     ///   protected:
   2033     ///   };
   2034     /// \endcode
   2035     ELBAMS_Always,
   2036   };
   2037 
   2038   /// Defines in which cases to put empty line before access modifiers.
   2039   EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
   2040 
   2041   /// If ``true``, clang-format detects whether function calls and
   2042   /// definitions are formatted with one parameter per line.
   2043   ///
   2044   /// Each call can be bin-packed, one-per-line or inconclusive. If it is
   2045   /// inconclusive, e.g. completely on one line, but a decision needs to be
   2046   /// made, clang-format analyzes whether there are other bin-packed cases in
   2047   /// the input file and act accordingly.
   2048   ///
   2049   /// NOTE: This is an experimental flag, that might go away or be renamed. Do
   2050   /// not use this in config files, etc. Use at your own risk.
   2051   bool ExperimentalAutoDetectBinPacking;
   2052 
   2053   /// If ``true``, clang-format adds missing namespace end comments for
   2054   /// short namespaces and fixes invalid existing ones. Short ones are
   2055   /// controlled by "ShortNamespaceLines".
   2056   /// \code
   2057   ///    true:                                  false:
   2058   ///    namespace a {                  vs.     namespace a {
   2059   ///    foo();                                 foo();
   2060   ///    bar();                                 bar();
   2061   ///    } // namespace a                       }
   2062   /// \endcode
   2063   bool FixNamespaceComments;
   2064 
   2065   /// A vector of macros that should be interpreted as foreach loops
   2066   /// instead of as function calls.
   2067   ///
   2068   /// These are expected to be macros of the form:
   2069   /// \code
   2070   ///   FOREACH(<variable-declaration>, ...)
   2071   ///     <loop-body>
   2072   /// \endcode
   2073   ///
   2074   /// In the .clang-format configuration file, this can be configured like:
   2075   /// \code{.yaml}
   2076   ///   ForEachMacros: ['RANGES_FOR', 'FOREACH']
   2077   /// \endcode
   2078   ///
   2079   /// For example: BOOST_FOREACH.
   2080   std::vector<std::string> ForEachMacros;
   2081 
   2082   /// \brief A vector of macros that should be interpreted as type declarations
   2083   /// instead of as function calls.
   2084   ///
   2085   /// These are expected to be macros of the form:
   2086   /// \code
   2087   ///   STACK_OF(...)
   2088   /// \endcode
   2089   ///
   2090   /// In the .clang-format configuration file, this can be configured like:
   2091   /// \code{.yaml}
   2092   ///   TypenameMacros: ['STACK_OF', 'LIST']
   2093   /// \endcode
   2094   ///
   2095   /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
   2096   std::vector<std::string> TypenameMacros;
   2097 
   2098   /// A vector of macros that should be interpreted as complete
   2099   /// statements.
   2100   ///
   2101   /// Typical macros are expressions, and require a semi-colon to be
   2102   /// added; sometimes this is not the case, and this allows to make
   2103   /// clang-format aware of such cases.
   2104   ///
   2105   /// For example: Q_UNUSED
   2106   std::vector<std::string> StatementMacros;
   2107 
   2108   /// A vector of macros which are used to open namespace blocks.
   2109   ///
   2110   /// These are expected to be macros of the form:
   2111   /// \code
   2112   ///   NAMESPACE(<namespace-name>, ...) {
   2113   ///     <namespace-content>
   2114   ///   }
   2115   /// \endcode
   2116   ///
   2117   /// For example: TESTSUITE
   2118   std::vector<std::string> NamespaceMacros;
   2119 
   2120   /// A vector of macros which are whitespace-sensitive and should not
   2121   /// be touched.
   2122   ///
   2123   /// These are expected to be macros of the form:
   2124   /// \code
   2125   ///   STRINGIZE(...)
   2126   /// \endcode
   2127   ///
   2128   /// In the .clang-format configuration file, this can be configured like:
   2129   /// \code{.yaml}
   2130   ///   WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']
   2131   /// \endcode
   2132   ///
   2133   /// For example: BOOST_PP_STRINGIZE
   2134   std::vector<std::string> WhitespaceSensitiveMacros;
   2135 
   2136   tooling::IncludeStyle IncludeStyle;
   2137 
   2138   /// Specify whether access modifiers should have their own indentation level.
   2139   ///
   2140   /// When ``false``, access modifiers are indented (or outdented) relative to
   2141   /// the record members, respecting the ``AccessModifierOffset``. Record
   2142   /// members are indented one level below the record.
   2143   /// When ``true``, access modifiers get their own indentation level. As a
   2144   /// consequence, record members are always indented 2 levels below the record,
   2145   /// regardless of the access modifier presence. Value of the
   2146   /// ``AccessModifierOffset`` is ignored.
   2147   /// \code
   2148   ///    false:                                 true:
   2149   ///    class C {                      vs.     class C {
   2150   ///      class D {                                class D {
   2151   ///        void bar();                                void bar();
   2152   ///      protected:                                 protected:
   2153   ///        D();                                       D();
   2154   ///      };                                       };
   2155   ///    public:                                  public:
   2156   ///      C();                                     C();
   2157   ///    };                                     };
   2158   ///    void foo() {                           void foo() {
   2159   ///      return 1;                              return 1;
   2160   ///    }                                      }
   2161   /// \endcode
   2162   bool IndentAccessModifiers;
   2163 
   2164   /// Indent case labels one level from the switch statement.
   2165   ///
   2166   /// When ``false``, use the same indentation level as for the switch
   2167   /// statement. Switch statement body is always indented one level more than
   2168   /// case labels (except the first block following the case label, which
   2169   /// itself indents the code - unless IndentCaseBlocks is enabled).
   2170   /// \code
   2171   ///    false:                                 true:
   2172   ///    switch (fool) {                vs.     switch (fool) {
   2173   ///    case 1:                                  case 1:
   2174   ///      bar();                                   bar();
   2175   ///      break;                                   break;
   2176   ///    default:                                 default:
   2177   ///      plop();                                  plop();
   2178   ///    }                                      }
   2179   /// \endcode
   2180   bool IndentCaseLabels;
   2181 
   2182   /// Indent case label blocks one level from the case label.
   2183   ///
   2184   /// When ``false``, the block following the case label uses the same
   2185   /// indentation level as for the case label, treating the case label the same
   2186   /// as an if-statement.
   2187   /// When ``true``, the block gets indented as a scope block.
   2188   /// \code
   2189   ///    false:                                 true:
   2190   ///    switch (fool) {                vs.     switch (fool) {
   2191   ///    case 1: {                              case 1:
   2192   ///      bar();                                 {
   2193   ///    } break;                                   bar();
   2194   ///    default: {                               }
   2195   ///      plop();                                break;
   2196   ///    }                                      default:
   2197   ///    }                                        {
   2198   ///                                               plop();
   2199   ///                                             }
   2200   ///                                           }
   2201   /// \endcode
   2202   bool IndentCaseBlocks;
   2203 
   2204   /// Indent goto labels.
   2205   ///
   2206   /// When ``false``, goto labels are flushed left.
   2207   /// \code
   2208   ///    true:                                  false:
   2209   ///    int f() {                      vs.     int f() {
   2210   ///      if (foo()) {                           if (foo()) {
   2211   ///      label1:                              label1:
   2212   ///        bar();                                 bar();
   2213   ///      }                                      }
   2214   ///    label2:                                label2:
   2215   ///      return 1;                              return 1;
   2216   ///    }                                      }
   2217   /// \endcode
   2218   bool IndentGotoLabels;
   2219 
   2220   /// Options for indenting preprocessor directives.
   2221   enum PPDirectiveIndentStyle : unsigned char {
   2222     /// Does not indent any directives.
   2223     /// \code
   2224     ///    #if FOO
   2225     ///    #if BAR
   2226     ///    #include <foo>
   2227     ///    #endif
   2228     ///    #endif
   2229     /// \endcode
   2230     PPDIS_None,
   2231     /// Indents directives after the hash.
   2232     /// \code
   2233     ///    #if FOO
   2234     ///    #  if BAR
   2235     ///    #    include <foo>
   2236     ///    #  endif
   2237     ///    #endif
   2238     /// \endcode
   2239     PPDIS_AfterHash,
   2240     /// Indents directives before the hash.
   2241     /// \code
   2242     ///    #if FOO
   2243     ///      #if BAR
   2244     ///        #include <foo>
   2245     ///      #endif
   2246     ///    #endif
   2247     /// \endcode
   2248     PPDIS_BeforeHash
   2249   };
   2250 
   2251   /// The preprocessor directive indenting style to use.
   2252   PPDirectiveIndentStyle IndentPPDirectives;
   2253 
   2254   /// Indents extern blocks
   2255   enum IndentExternBlockStyle : unsigned char {
   2256     /// Backwards compatible with AfterExternBlock's indenting.
   2257     /// \code
   2258     ///    IndentExternBlock: AfterExternBlock
   2259     ///    BraceWrapping.AfterExternBlock: true
   2260     ///    extern "C"
   2261     ///    {
   2262     ///        void foo();
   2263     ///    }
   2264     /// \endcode
   2265     ///
   2266     /// \code
   2267     ///    IndentExternBlock: AfterExternBlock
   2268     ///    BraceWrapping.AfterExternBlock: false
   2269     ///    extern "C" {
   2270     ///    void foo();
   2271     ///    }
   2272     /// \endcode
   2273     IEBS_AfterExternBlock,
   2274     /// Does not indent extern blocks.
   2275     /// \code
   2276     ///     extern "C" {
   2277     ///     void foo();
   2278     ///     }
   2279     /// \endcode
   2280     IEBS_NoIndent,
   2281     /// Indents extern blocks.
   2282     /// \code
   2283     ///     extern "C" {
   2284     ///       void foo();
   2285     ///     }
   2286     /// \endcode
   2287     IEBS_Indent,
   2288   };
   2289 
   2290   /// IndentExternBlockStyle is the type of indenting of extern blocks.
   2291   IndentExternBlockStyle IndentExternBlock;
   2292 
   2293   /// Indent the requires clause in a template
   2294   /// \code
   2295   ///    true:
   2296   ///    template <typename It>
   2297   ///      requires Iterator<It>
   2298   ///    void sort(It begin, It end) {
   2299   ///      //....
   2300   ///    }
   2301   ///
   2302   ///    false:
   2303   ///    template <typename It>
   2304   ///    requires Iterator<It>
   2305   ///    void sort(It begin, It end) {
   2306   ///      //....
   2307   ///    }
   2308   /// \endcode
   2309   bool IndentRequires;
   2310 
   2311   /// The number of columns to use for indentation.
   2312   /// \code
   2313   ///    IndentWidth: 3
   2314   ///
   2315   ///    void f() {
   2316   ///       someFunction();
   2317   ///       if (true, false) {
   2318   ///          f();
   2319   ///       }
   2320   ///    }
   2321   /// \endcode
   2322   unsigned IndentWidth;
   2323 
   2324   /// Indent if a function definition or declaration is wrapped after the
   2325   /// type.
   2326   /// \code
   2327   ///    true:
   2328   ///    LoooooooooooooooooooooooooooooooooooooooongReturnType
   2329   ///        LoooooooooooooooooooooooooooooooongFunctionDeclaration();
   2330   ///
   2331   ///    false:
   2332   ///    LoooooooooooooooooooooooooooooooooooooooongReturnType
   2333   ///    LoooooooooooooooooooooooooooooooongFunctionDeclaration();
   2334   /// \endcode
   2335   bool IndentWrappedFunctionNames;
   2336 
   2337   /// A vector of prefixes ordered by the desired groups for Java imports.
   2338   ///
   2339   /// One group's prefix can be a subset of another - the longest prefix is
   2340   /// always matched. Within a group, the imports are ordered lexicographically.
   2341   /// Static imports are grouped separately and follow the same group rules.
   2342   /// By default, static imports are placed before non-static imports,
   2343   /// but this behavior is changed by another option,
   2344   /// ``SortJavaStaticImport``.
   2345   ///
   2346   /// In the .clang-format configuration file, this can be configured like
   2347   /// in the following yaml example. This will result in imports being
   2348   /// formatted as in the Java example below.
   2349   /// \code{.yaml}
   2350   ///   JavaImportGroups: ['com.example', 'com', 'org']
   2351   /// \endcode
   2352   ///
   2353   /// \code{.java}
   2354   ///    import static com.example.function1;
   2355   ///
   2356   ///    import static com.test.function2;
   2357   ///
   2358   ///    import static org.example.function3;
   2359   ///
   2360   ///    import com.example.ClassA;
   2361   ///    import com.example.Test;
   2362   ///    import com.example.a.ClassB;
   2363   ///
   2364   ///    import com.test.ClassC;
   2365   ///
   2366   ///    import org.example.ClassD;
   2367   /// \endcode
   2368   std::vector<std::string> JavaImportGroups;
   2369 
   2370   /// Quotation styles for JavaScript strings. Does not affect template
   2371   /// strings.
   2372   enum JavaScriptQuoteStyle : unsigned char {
   2373     /// Leave string quotes as they are.
   2374     /// \code{.js}
   2375     ///    string1 = "foo";
   2376     ///    string2 = 'bar';
   2377     /// \endcode
   2378     JSQS_Leave,
   2379     /// Always use single quotes.
   2380     /// \code{.js}
   2381     ///    string1 = 'foo';
   2382     ///    string2 = 'bar';
   2383     /// \endcode
   2384     JSQS_Single,
   2385     /// Always use double quotes.
   2386     /// \code{.js}
   2387     ///    string1 = "foo";
   2388     ///    string2 = "bar";
   2389     /// \endcode
   2390     JSQS_Double
   2391   };
   2392 
   2393   /// The JavaScriptQuoteStyle to use for JavaScript strings.
   2394   JavaScriptQuoteStyle JavaScriptQuotes;
   2395 
   2396   // clang-format off
   2397   /// Whether to wrap JavaScript import/export statements.
   2398   /// \code{.js}
   2399   ///    true:
   2400   ///    import {
   2401   ///        VeryLongImportsAreAnnoying,
   2402   ///        VeryLongImportsAreAnnoying,
   2403   ///        VeryLongImportsAreAnnoying,
   2404   ///    } from 'some/module.js'
   2405   ///
   2406   ///    false:
   2407   ///    import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
   2408   /// \endcode
   2409   bool JavaScriptWrapImports;
   2410   // clang-format on
   2411 
   2412   /// If true, the empty line at the start of blocks is kept.
   2413   /// \code
   2414   ///    true:                                  false:
   2415   ///    if (foo) {                     vs.     if (foo) {
   2416   ///                                             bar();
   2417   ///      bar();                               }
   2418   ///    }
   2419   /// \endcode
   2420   bool KeepEmptyLinesAtTheStartOfBlocks;
   2421 
   2422   /// Supported languages.
   2423   ///
   2424   /// When stored in a configuration file, specifies the language, that the
   2425   /// configuration targets. When passed to the ``reformat()`` function, enables
   2426   /// syntax features specific to the language.
   2427   enum LanguageKind : unsigned char {
   2428     /// Do not use.
   2429     LK_None,
   2430     /// Should be used for C, C++.
   2431     LK_Cpp,
   2432     /// Should be used for C#.
   2433     LK_CSharp,
   2434     /// Should be used for Java.
   2435     LK_Java,
   2436     /// Should be used for JavaScript.
   2437     LK_JavaScript,
   2438     /// Should be used for Objective-C, Objective-C++.
   2439     LK_ObjC,
   2440     /// Should be used for Protocol Buffers
   2441     /// (https://developers.google.com/protocol-buffers/).
   2442     LK_Proto,
   2443     /// Should be used for TableGen code.
   2444     LK_TableGen,
   2445     /// Should be used for Protocol Buffer messages in text format
   2446     /// (https://developers.google.com/protocol-buffers/).
   2447     LK_TextProto
   2448   };
   2449   bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
   2450   bool isCSharp() const { return Language == LK_CSharp; }
   2451 
   2452   /// Language, this format style is targeted at.
   2453   LanguageKind Language;
   2454 
   2455   /// A regular expression matching macros that start a block.
   2456   /// \code
   2457   ///    # With:
   2458   ///    MacroBlockBegin: "^NS_MAP_BEGIN|\
   2459   ///    NS_TABLE_HEAD$"
   2460   ///    MacroBlockEnd: "^\
   2461   ///    NS_MAP_END|\
   2462   ///    NS_TABLE_.*_END$"
   2463   ///
   2464   ///    NS_MAP_BEGIN
   2465   ///      foo();
   2466   ///    NS_MAP_END
   2467   ///
   2468   ///    NS_TABLE_HEAD
   2469   ///      bar();
   2470   ///    NS_TABLE_FOO_END
   2471   ///
   2472   ///    # Without:
   2473   ///    NS_MAP_BEGIN
   2474   ///    foo();
   2475   ///    NS_MAP_END
   2476   ///
   2477   ///    NS_TABLE_HEAD
   2478   ///    bar();
   2479   ///    NS_TABLE_FOO_END
   2480   /// \endcode
   2481   std::string MacroBlockBegin;
   2482 
   2483   /// A regular expression matching macros that end a block.
   2484   std::string MacroBlockEnd;
   2485 
   2486   /// The maximum number of consecutive empty lines to keep.
   2487   /// \code
   2488   ///    MaxEmptyLinesToKeep: 1         vs.     MaxEmptyLinesToKeep: 0
   2489   ///    int f() {                              int f() {
   2490   ///      int = 1;                                 int i = 1;
   2491   ///                                               i = foo();
   2492   ///      i = foo();                               return i;
   2493   ///                                           }
   2494   ///      return i;
   2495   ///    }
   2496   /// \endcode
   2497   unsigned MaxEmptyLinesToKeep;
   2498 
   2499   /// Different ways to indent namespace contents.
   2500   enum NamespaceIndentationKind : unsigned char {
   2501     /// Don't indent in namespaces.
   2502     /// \code
   2503     ///    namespace out {
   2504     ///    int i;
   2505     ///    namespace in {
   2506     ///    int i;
   2507     ///    }
   2508     ///    }
   2509     /// \endcode
   2510     NI_None,
   2511     /// Indent only in inner namespaces (nested in other namespaces).
   2512     /// \code
   2513     ///    namespace out {
   2514     ///    int i;
   2515     ///    namespace in {
   2516     ///      int i;
   2517     ///    }
   2518     ///    }
   2519     /// \endcode
   2520     NI_Inner,
   2521     /// Indent in all namespaces.
   2522     /// \code
   2523     ///    namespace out {
   2524     ///      int i;
   2525     ///      namespace in {
   2526     ///        int i;
   2527     ///      }
   2528     ///    }
   2529     /// \endcode
   2530     NI_All
   2531   };
   2532 
   2533   /// The indentation used for namespaces.
   2534   NamespaceIndentationKind NamespaceIndentation;
   2535 
   2536   /// Controls bin-packing Objective-C protocol conformance list
   2537   /// items into as few lines as possible when they go over ``ColumnLimit``.
   2538   ///
   2539   /// If ``Auto`` (the default), delegates to the value in
   2540   /// ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
   2541   /// protocol conformance list items into as few lines as possible
   2542   /// whenever they go over ``ColumnLimit``.
   2543   ///
   2544   /// If ``Always``, always bin-packs Objective-C protocol conformance
   2545   /// list items into as few lines as possible whenever they go over
   2546   /// ``ColumnLimit``.
   2547   ///
   2548   /// If ``Never``, lays out Objective-C protocol conformance list items
   2549   /// onto individual lines whenever they go over ``ColumnLimit``.
   2550   ///
   2551   /// \code{.objc}
   2552   ///    Always (or Auto, if BinPackParameters=true):
   2553   ///    @interface ccccccccccccc () <
   2554   ///        ccccccccccccc, ccccccccccccc,
   2555   ///        ccccccccccccc, ccccccccccccc> {
   2556   ///    }
   2557   ///
   2558   ///    Never (or Auto, if BinPackParameters=false):
   2559   ///    @interface ddddddddddddd () <
   2560   ///        ddddddddddddd,
   2561   ///        ddddddddddddd,
   2562   ///        ddddddddddddd,
   2563   ///        ddddddddddddd> {
   2564   ///    }
   2565   /// \endcode
   2566   BinPackStyle ObjCBinPackProtocolList;
   2567 
   2568   /// The number of characters to use for indentation of ObjC blocks.
   2569   /// \code{.objc}
   2570   ///    ObjCBlockIndentWidth: 4
   2571   ///
   2572   ///    [operation setCompletionBlock:^{
   2573   ///        [self onOperationDone];
   2574   ///    }];
   2575   /// \endcode
   2576   unsigned ObjCBlockIndentWidth;
   2577 
   2578   /// Add a space after ``@property`` in Objective-C, i.e. use
   2579   /// ``@property (readonly)`` instead of ``@property(readonly)``.
   2580   bool ObjCSpaceAfterProperty;
   2581 
   2582   /// Break parameters list into lines when there is nested block
   2583   /// parameters in a function call.
   2584   /// \code
   2585   ///   false:
   2586   ///    - (void)_aMethod
   2587   ///    {
   2588   ///        [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
   2589   ///        *u, NSNumber *v) {
   2590   ///            u = c;
   2591   ///        }]
   2592   ///    }
   2593   ///    true:
   2594   ///    - (void)_aMethod
   2595   ///    {
   2596   ///       [self.test1 t:self
   2597   ///                    w:self
   2598   ///           callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
   2599   ///                u = c;
   2600   ///            }]
   2601   ///    }
   2602   /// \endcode
   2603   bool ObjCBreakBeforeNestedBlockParam;
   2604 
   2605   /// Add a space in front of an Objective-C protocol list, i.e. use
   2606   /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
   2607   bool ObjCSpaceBeforeProtocolList;
   2608 
   2609   /// The penalty for breaking around an assignment operator.
   2610   unsigned PenaltyBreakAssignment;
   2611 
   2612   /// The penalty for breaking a function call after ``call(``.
   2613   unsigned PenaltyBreakBeforeFirstCallParameter;
   2614 
   2615   /// The penalty for each line break introduced inside a comment.
   2616   unsigned PenaltyBreakComment;
   2617 
   2618   /// The penalty for breaking before the first ``<<``.
   2619   unsigned PenaltyBreakFirstLessLess;
   2620 
   2621   /// The penalty for each line break introduced inside a string literal.
   2622   unsigned PenaltyBreakString;
   2623 
   2624   /// The penalty for breaking after template declaration.
   2625   unsigned PenaltyBreakTemplateDeclaration;
   2626 
   2627   /// The penalty for each character outside of the column limit.
   2628   unsigned PenaltyExcessCharacter;
   2629 
   2630   /// Penalty for putting the return type of a function onto its own
   2631   /// line.
   2632   unsigned PenaltyReturnTypeOnItsOwnLine;
   2633 
   2634   /// Penalty for each character of whitespace indentation
   2635   /// (counted relative to leading non-whitespace column).
   2636   unsigned PenaltyIndentedWhitespace;
   2637 
   2638   /// The ``&`` and ``*`` alignment style.
   2639   enum PointerAlignmentStyle : unsigned char {
   2640     /// Align pointer to the left.
   2641     /// \code
   2642     ///   int* a;
   2643     /// \endcode
   2644     PAS_Left,
   2645     /// Align pointer to the right.
   2646     /// \code
   2647     ///   int *a;
   2648     /// \endcode
   2649     PAS_Right,
   2650     /// Align pointer in the middle.
   2651     /// \code
   2652     ///   int * a;
   2653     /// \endcode
   2654     PAS_Middle
   2655   };
   2656 
   2657   /// Pointer and reference alignment style.
   2658   PointerAlignmentStyle PointerAlignment;
   2659 
   2660   /// See documentation of ``RawStringFormats``.
   2661   struct RawStringFormat {
   2662     /// The language of this raw string.
   2663     LanguageKind Language;
   2664     /// A list of raw string delimiters that match this language.
   2665     std::vector<std::string> Delimiters;
   2666     /// A list of enclosing function names that match this language.
   2667     std::vector<std::string> EnclosingFunctions;
   2668     /// The canonical delimiter for this language.
   2669     std::string CanonicalDelimiter;
   2670     /// The style name on which this raw string format is based on.
   2671     /// If not specified, the raw string format is based on the style that this
   2672     /// format is based on.
   2673     std::string BasedOnStyle;
   2674     bool operator==(const RawStringFormat &Other) const {
   2675       return Language == Other.Language && Delimiters == Other.Delimiters &&
   2676              EnclosingFunctions == Other.EnclosingFunctions &&
   2677              CanonicalDelimiter == Other.CanonicalDelimiter &&
   2678              BasedOnStyle == Other.BasedOnStyle;
   2679     }
   2680   };
   2681 
   2682   /// Defines hints for detecting supported languages code blocks in raw
   2683   /// strings.
   2684   ///
   2685   /// A raw string with a matching delimiter or a matching enclosing function
   2686   /// name will be reformatted assuming the specified language based on the
   2687   /// style for that language defined in the .clang-format file. If no style has
   2688   /// been defined in the .clang-format file for the specific language, a
   2689   /// predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
   2690   /// found, the formatting is based on llvm style. A matching delimiter takes
   2691   /// precedence over a matching enclosing function name for determining the
   2692   /// language of the raw string contents.
   2693   ///
   2694   /// If a canonical delimiter is specified, occurrences of other delimiters for
   2695   /// the same language will be updated to the canonical if possible.
   2696   ///
   2697   /// There should be at most one specification per language and each delimiter
   2698   /// and enclosing function should not occur in multiple specifications.
   2699   ///
   2700   /// To configure this in the .clang-format file, use:
   2701   /// \code{.yaml}
   2702   ///   RawStringFormats:
   2703   ///     - Language: TextProto
   2704   ///         Delimiters:
   2705   ///           - 'pb'
   2706   ///           - 'proto'
   2707   ///         EnclosingFunctions:
   2708   ///           - 'PARSE_TEXT_PROTO'
   2709   ///         BasedOnStyle: google
   2710   ///     - Language: Cpp
   2711   ///         Delimiters:
   2712   ///           - 'cc'
   2713   ///           - 'cpp'
   2714   ///         BasedOnStyle: llvm
   2715   ///         CanonicalDelimiter: 'cc'
   2716   /// \endcode
   2717   std::vector<RawStringFormat> RawStringFormats;
   2718 
   2719   // clang-format off
   2720   /// If ``true``, clang-format will attempt to re-flow comments.
   2721   /// \code
   2722   ///    false:
   2723   ///    // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
   2724   ///    /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
   2725   ///
   2726   ///    true:
   2727   ///    // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
   2728   ///    // information
   2729   ///    /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
   2730   ///     * information */
   2731   /// \endcode
   2732   bool ReflowComments;
   2733   // clang-format on
   2734 
   2735   /// The maximal number of unwrapped lines that a short namespace spans.
   2736   /// Defaults to 1.
   2737   ///
   2738   /// This determines the maximum length of short namespaces by counting
   2739   /// unwrapped lines (i.e. containing neither opening nor closing
   2740   /// namespace brace) and makes "FixNamespaceComments" omit adding
   2741   /// end comments for those.
   2742   /// \code
   2743   ///    ShortNamespaceLines: 1     vs.     ShortNamespaceLines: 0
   2744   ///    namespace a {                      namespace a {
   2745   ///      int foo;                           int foo;
   2746   ///    }                                  } // namespace a
   2747   ///
   2748   ///    ShortNamespaceLines: 1     vs.     ShortNamespaceLines: 0
   2749   ///    namespace b {                      namespace b {
   2750   ///      int foo;                           int foo;
   2751   ///      int bar;                           int bar;
   2752   ///    } // namespace b                   } // namespace b
   2753   /// \endcode
   2754   unsigned ShortNamespaceLines;
   2755 
   2756   /// Include sorting options.
   2757   enum SortIncludesOptions : unsigned char {
   2758     /// Includes are never sorted.
   2759     /// \code
   2760     ///    #include "B/A.h"
   2761     ///    #include "A/B.h"
   2762     ///    #include "a/b.h"
   2763     ///    #include "A/b.h"
   2764     ///    #include "B/a.h"
   2765     /// \endcode
   2766     SI_Never,
   2767     /// Includes are sorted in an ASCIIbetical or case sensitive fashion.
   2768     /// \code
   2769     ///    #include "A/B.h"
   2770     ///    #include "A/b.h"
   2771     ///    #include "B/A.h"
   2772     ///    #include "B/a.h"
   2773     ///    #include "a/b.h"
   2774     /// \endcode
   2775     SI_CaseSensitive,
   2776     /// Includes are sorted in an alphabetical or case insensitive fashion.
   2777     /// \code
   2778     ///    #include "A/B.h"
   2779     ///    #include "A/b.h"
   2780     ///    #include "a/b.h"
   2781     ///    #include "B/A.h"
   2782     ///    #include "B/a.h"
   2783     /// \endcode
   2784     SI_CaseInsensitive,
   2785   };
   2786 
   2787   /// Controls if and how clang-format will sort ``#includes``.
   2788   /// If ``Never``, includes are never sorted.
   2789   /// If ``CaseInsensitive``, includes are sorted in an ASCIIbetical or case
   2790   /// insensitive fashion.
   2791   /// If ``CaseSensitive``, includes are sorted in an alphabetical or case
   2792   /// sensitive fashion.
   2793   SortIncludesOptions SortIncludes;
   2794 
   2795   /// Position for Java Static imports.
   2796   enum SortJavaStaticImportOptions : unsigned char {
   2797     /// Static imports are placed before non-static imports.
   2798     /// \code{.java}
   2799     ///   import static org.example.function1;
   2800     ///
   2801     ///   import org.example.ClassA;
   2802     /// \endcode
   2803     SJSIO_Before,
   2804     /// Static imports are placed after non-static imports.
   2805     /// \code{.java}
   2806     ///   import org.example.ClassA;
   2807     ///
   2808     ///   import static org.example.function1;
   2809     /// \endcode
   2810     SJSIO_After,
   2811   };
   2812 
   2813   /// When sorting Java imports, by default static imports are placed before
   2814   /// non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
   2815   /// static imports are placed after non-static imports.
   2816   SortJavaStaticImportOptions SortJavaStaticImport;
   2817 
   2818   /// If ``true``, clang-format will sort using declarations.
   2819   ///
   2820   /// The order of using declarations is defined as follows:
   2821   /// Split the strings by "::" and discard any initial empty strings. The last
   2822   /// element of each list is a non-namespace name; all others are namespace
   2823   /// names. Sort the lists of names lexicographically, where the sort order of
   2824   /// individual names is that all non-namespace names come before all namespace
   2825   /// names, and within those groups, names are in case-insensitive
   2826   /// lexicographic order.
   2827   /// \code
   2828   ///    false:                                 true:
   2829   ///    using std::cout;               vs.     using std::cin;
   2830   ///    using std::cin;                        using std::cout;
   2831   /// \endcode
   2832   bool SortUsingDeclarations;
   2833 
   2834   /// If ``true``, a space is inserted after C style casts.
   2835   /// \code
   2836   ///    true:                                  false:
   2837   ///    (int) i;                       vs.     (int)i;
   2838   /// \endcode
   2839   bool SpaceAfterCStyleCast;
   2840 
   2841   /// If ``true``, a space is inserted after the logical not operator (``!``).
   2842   /// \code
   2843   ///    true:                                  false:
   2844   ///    ! someExpression();            vs.     !someExpression();
   2845   /// \endcode
   2846   bool SpaceAfterLogicalNot;
   2847 
   2848   /// If \c true, a space will be inserted after the 'template' keyword.
   2849   /// \code
   2850   ///    true:                                  false:
   2851   ///    template <int> void foo();     vs.     template<int> void foo();
   2852   /// \endcode
   2853   bool SpaceAfterTemplateKeyword;
   2854 
   2855   /// Different ways to put a space before opening parentheses.
   2856   enum SpaceAroundPointerQualifiersStyle : unsigned char {
   2857     /// Don't ensure spaces around pointer qualifiers and use PointerAlignment
   2858     /// instead.
   2859     /// \code
   2860     ///    PointerAlignment: Left                 PointerAlignment: Right
   2861     ///    void* const* x = NULL;         vs.     void *const *x = NULL;
   2862     /// \endcode
   2863     SAPQ_Default,
   2864     /// Ensure that there is a space before pointer qualifiers.
   2865     /// \code
   2866     ///    PointerAlignment: Left                 PointerAlignment: Right
   2867     ///    void* const* x = NULL;         vs.     void * const *x = NULL;
   2868     /// \endcode
   2869     SAPQ_Before,
   2870     /// Ensure that there is a space after pointer qualifiers.
   2871     /// \code
   2872     ///    PointerAlignment: Left                 PointerAlignment: Right
   2873     ///    void* const * x = NULL;         vs.     void *const *x = NULL;
   2874     /// \endcode
   2875     SAPQ_After,
   2876     /// Ensure that there is a space both before and after pointer qualifiers.
   2877     /// \code
   2878     ///    PointerAlignment: Left                 PointerAlignment: Right
   2879     ///    void* const * x = NULL;         vs.     void * const *x = NULL;
   2880     /// \endcode
   2881     SAPQ_Both,
   2882   };
   2883 
   2884   ///  Defines in which cases to put a space before or after pointer qualifiers
   2885   SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers;
   2886 
   2887   /// If ``false``, spaces will be removed before assignment operators.
   2888   /// \code
   2889   ///    true:                                  false:
   2890   ///    int a = 5;                     vs.     int a= 5;
   2891   ///    a += 42;                               a+= 42;
   2892   /// \endcode
   2893   bool SpaceBeforeAssignmentOperators;
   2894 
   2895   /// If ``false``, spaces will be removed before case colon.
   2896   /// \code
   2897   ///   true:                                   false
   2898   ///   switch (x) {                    vs.     switch (x) {
   2899   ///     case 1 : break;                         case 1: break;
   2900   ///   }                                       }
   2901   /// \endcode
   2902   bool SpaceBeforeCaseColon;
   2903 
   2904   /// If ``true``, a space will be inserted before a C++11 braced list
   2905   /// used to initialize an object (after the preceding identifier or type).
   2906   /// \code
   2907   ///    true:                                  false:
   2908   ///    Foo foo { bar };               vs.     Foo foo{ bar };
   2909   ///    Foo {};                                Foo{};
   2910   ///    vector<int> { 1, 2, 3 };               vector<int>{ 1, 2, 3 };
   2911   ///    new int[3] { 1, 2, 3 };                new int[3]{ 1, 2, 3 };
   2912   /// \endcode
   2913   bool SpaceBeforeCpp11BracedList;
   2914 
   2915   /// If ``false``, spaces will be removed before constructor initializer
   2916   /// colon.
   2917   /// \code
   2918   ///    true:                                  false:
   2919   ///    Foo::Foo() : a(a) {}                   Foo::Foo(): a(a) {}
   2920   /// \endcode
   2921   bool SpaceBeforeCtorInitializerColon;
   2922 
   2923   /// If ``false``, spaces will be removed before inheritance colon.
   2924   /// \code
   2925   ///    true:                                  false:
   2926   ///    class Foo : Bar {}             vs.     class Foo: Bar {}
   2927   /// \endcode
   2928   bool SpaceBeforeInheritanceColon;
   2929 
   2930   /// Different ways to put a space before opening parentheses.
   2931   enum SpaceBeforeParensOptions : unsigned char {
   2932     /// Never put a space before opening parentheses.
   2933     /// \code
   2934     ///    void f() {
   2935     ///      if(true) {
   2936     ///        f();
   2937     ///      }
   2938     ///    }
   2939     /// \endcode
   2940     SBPO_Never,
   2941     /// Put a space before opening parentheses only after control statement
   2942     /// keywords (``for/if/while...``).
   2943     /// \code
   2944     ///    void f() {
   2945     ///      if (true) {
   2946     ///        f();
   2947     ///      }
   2948     ///    }
   2949     /// \endcode
   2950     SBPO_ControlStatements,
   2951     /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
   2952     /// ForEach macros. This is useful in projects where ForEach macros are
   2953     /// treated as function calls instead of control statements.
   2954     /// \code
   2955     ///    void f() {
   2956     ///      Q_FOREACH(...) {
   2957     ///        f();
   2958     ///      }
   2959     ///    }
   2960     /// \endcode
   2961     SBPO_ControlStatementsExceptForEachMacros,
   2962     /// Put a space before opening parentheses only if the parentheses are not
   2963     /// empty i.e. '()'
   2964     /// \code
   2965     ///   void() {
   2966     ///     if (true) {
   2967     ///       f();
   2968     ///       g (x, y, z);
   2969     ///     }
   2970     ///   }
   2971     /// \endcode
   2972     SBPO_NonEmptyParentheses,
   2973     /// Always put a space before opening parentheses, except when it's
   2974     /// prohibited by the syntax rules (in function-like macro definitions) or
   2975     /// when determined by other style rules (after unary operators, opening
   2976     /// parentheses, etc.)
   2977     /// \code
   2978     ///    void f () {
   2979     ///      if (true) {
   2980     ///        f ();
   2981     ///      }
   2982     ///    }
   2983     /// \endcode
   2984     SBPO_Always
   2985   };
   2986 
   2987   /// Defines in which cases to put a space before opening parentheses.
   2988   SpaceBeforeParensOptions SpaceBeforeParens;
   2989 
   2990   /// If ``false``, spaces will be removed before range-based for loop
   2991   /// colon.
   2992   /// \code
   2993   ///    true:                                  false:
   2994   ///    for (auto v : values) {}       vs.     for(auto v: values) {}
   2995   /// \endcode
   2996   bool SpaceBeforeRangeBasedForLoopColon;
   2997 
   2998   /// If ``true``, spaces will be inserted into ``{}``.
   2999   /// \code
   3000   ///    true:                                false:
   3001   ///    void f() { }                   vs.   void f() {}
   3002   ///    while (true) { }                     while (true) {}
   3003   /// \endcode
   3004   bool SpaceInEmptyBlock;
   3005 
   3006   /// If ``true``, spaces may be inserted into ``()``.
   3007   /// \code
   3008   ///    true:                                false:
   3009   ///    void f( ) {                    vs.   void f() {
   3010   ///      int x[] = {foo( ), bar( )};          int x[] = {foo(), bar()};
   3011   ///      if (true) {                          if (true) {
   3012   ///        f( );                                f();
   3013   ///      }                                    }
   3014   ///    }                                    }
   3015   /// \endcode
   3016   bool SpaceInEmptyParentheses;
   3017 
   3018   /// The number of spaces before trailing line comments
   3019   /// (``//`` - comments).
   3020   ///
   3021   /// This does not affect trailing block comments (``/*`` - comments) as
   3022   /// those commonly have different usage patterns and a number of special
   3023   /// cases.
   3024   /// \code
   3025   ///    SpacesBeforeTrailingComments: 3
   3026   ///    void f() {
   3027   ///      if (true) {   // foo1
   3028   ///        f();        // bar
   3029   ///      }             // foo
   3030   ///    }
   3031   /// \endcode
   3032   unsigned SpacesBeforeTrailingComments;
   3033 
   3034   /// Styles for adding spacing after ``<`` and before ``>`
   3035   ///  in template argument lists.
   3036   enum SpacesInAnglesStyle : unsigned char {
   3037     /// Remove spaces after ``<`` and before ``>``.
   3038     /// \code
   3039     ///    static_cast<int>(arg);
   3040     ///    std::function<void(int)> fct;
   3041     /// \endcode
   3042     SIAS_Never,
   3043     /// Add spaces after ``<`` and before ``>``.
   3044     /// \code
   3045     ///    static_cast< int >(arg);
   3046     ///    std::function< void(int) > fct;
   3047     /// \endcode
   3048     SIAS_Always,
   3049     /// Keep a single space after ``<`` and before ``>`` if any spaces were
   3050     /// present. Option ``Standard: Cpp03`` takes precedence.
   3051     SIAS_Leave
   3052   };
   3053   /// The SpacesInAnglesStyle to use for template argument lists.
   3054   SpacesInAnglesStyle SpacesInAngles;
   3055 
   3056   /// If ``true``, spaces will be inserted around if/for/switch/while
   3057   /// conditions.
   3058   /// \code
   3059   ///    true:                                  false:
   3060   ///    if ( a )  { ... }              vs.     if (a) { ... }
   3061   ///    while ( i < 5 )  { ... }               while (i < 5) { ... }
   3062   /// \endcode
   3063   bool SpacesInConditionalStatement;
   3064 
   3065   /// If ``true``, spaces are inserted inside container literals (e.g.
   3066   /// ObjC and Javascript array and dict literals).
   3067   /// \code{.js}
   3068   ///    true:                                  false:
   3069   ///    var arr = [ 1, 2, 3 ];         vs.     var arr = [1, 2, 3];
   3070   ///    f({a : 1, b : 2, c : 3});              f({a: 1, b: 2, c: 3});
   3071   /// \endcode
   3072   bool SpacesInContainerLiterals;
   3073 
   3074   /// If ``true``, spaces may be inserted into C style casts.
   3075   /// \code
   3076   ///    true:                                  false:
   3077   ///    x = ( int32 )y                 vs.     x = (int32)y
   3078   /// \endcode
   3079   bool SpacesInCStyleCastParentheses;
   3080 
   3081   /// Control of spaces within a single line comment
   3082   struct SpacesInLineComment {
   3083     /// The minimum number of spaces at the start of the comment.
   3084     unsigned Minimum;
   3085     /// The maximum number of spaces at the start of the comment.
   3086     unsigned Maximum;
   3087   };
   3088 
   3089   /// How many spaces are allowed at the start of a line comment. To disable the
   3090   /// maximum set it to ``-1``, apart from that the maximum takes precedence
   3091   /// over the minimum.
   3092   /// \code Minimum = 1 Maximum = -1
   3093   /// // One space is forced
   3094   ///
   3095   /// //  but more spaces are possible
   3096   ///
   3097   /// Minimum = 0
   3098   /// Maximum = 0
   3099   /// //Forces to start every comment directly after the slashes
   3100   /// \endcode
   3101   ///
   3102   /// Note that in line comment sections the relative indent of the subsequent
   3103   /// lines is kept, that means the following:
   3104   /// \code
   3105   /// before:                                   after:
   3106   /// Minimum: 1
   3107   /// //if (b) {                                // if (b) {
   3108   /// //  return true;                          //   return true;
   3109   /// //}                                       // }
   3110   ///
   3111   /// Maximum: 0
   3112   /// /// List:                                 ///List:
   3113   /// ///  - Foo                                /// - Foo
   3114   /// ///    - Bar                              ///   - Bar
   3115   /// \endcode
   3116   SpacesInLineComment SpacesInLineCommentPrefix;
   3117 
   3118   /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
   3119   /// \code
   3120   ///    true:                                  false:
   3121   ///    t f( Deleted & ) & = delete;   vs.     t f(Deleted &) & = delete;
   3122   /// \endcode
   3123   bool SpacesInParentheses;
   3124 
   3125   /// If ``true``, spaces will be inserted after ``[`` and before ``]``.
   3126   /// Lambdas without arguments or unspecified size array declarations will not
   3127   /// be affected.
   3128   /// \code
   3129   ///    true:                                  false:
   3130   ///    int a[ 5 ];                    vs.     int a[5];
   3131   ///    std::unique_ptr<int[]> foo() {} // Won't be affected
   3132   /// \endcode
   3133   bool SpacesInSquareBrackets;
   3134 
   3135   /// If ``true``, spaces will be before  ``[``.
   3136   /// Lambdas will not be affected. Only the first ``[`` will get a space added.
   3137   /// \code
   3138   ///    true:                                  false:
   3139   ///    int a [5];                    vs.      int a[5];
   3140   ///    int a [5][5];                 vs.      int a[5][5];
   3141   /// \endcode
   3142   bool SpaceBeforeSquareBrackets;
   3143 
   3144   /// Styles for adding spacing around ``:`` in bitfield definitions.
   3145   enum BitFieldColonSpacingStyle : unsigned char {
   3146     /// Add one space on each side of the ``:``
   3147     /// \code
   3148     ///   unsigned bf : 2;
   3149     /// \endcode
   3150     BFCS_Both,
   3151     /// Add no space around the ``:`` (except when needed for
   3152     /// ``AlignConsecutiveBitFields``).
   3153     /// \code
   3154     ///   unsigned bf:2;
   3155     /// \endcode
   3156     BFCS_None,
   3157     /// Add space before the ``:`` only
   3158     /// \code
   3159     ///   unsigned bf :2;
   3160     /// \endcode
   3161     BFCS_Before,
   3162     /// Add space after the ``:`` only (space may be added before if
   3163     /// needed for ``AlignConsecutiveBitFields``).
   3164     /// \code
   3165     ///   unsigned bf: 2;
   3166     /// \endcode
   3167     BFCS_After
   3168   };
   3169   /// The BitFieldColonSpacingStyle to use for bitfields.
   3170   BitFieldColonSpacingStyle BitFieldColonSpacing;
   3171 
   3172   /// Supported language standards for parsing and formatting C++ constructs.
   3173   /// \code
   3174   ///    Latest:                                vector<set<int>>
   3175   ///    c++03                          vs.     vector<set<int> >
   3176   /// \endcode
   3177   ///
   3178   /// The correct way to spell a specific language version is e.g. ``c++11``.
   3179   /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
   3180   enum LanguageStandard : unsigned char {
   3181     /// Parse and format as C++03.
   3182     /// ``Cpp03`` is a deprecated alias for ``c++03``
   3183     LS_Cpp03, // c++03
   3184     /// Parse and format as C++11.
   3185     LS_Cpp11, // c++11
   3186     /// Parse and format as C++14.
   3187     LS_Cpp14, // c++14
   3188     /// Parse and format as C++17.
   3189     LS_Cpp17, // c++17
   3190     /// Parse and format as C++20.
   3191     LS_Cpp20, // c++20
   3192     /// Parse and format using the latest supported language version.
   3193     /// ``Cpp11`` is a deprecated alias for ``Latest``
   3194     LS_Latest,
   3195     /// Automatic detection based on the input.
   3196     LS_Auto,
   3197   };
   3198 
   3199   /// Parse and format C++ constructs compatible with this standard.
   3200   /// \code
   3201   ///    c++03:                                 latest:
   3202   ///    vector<set<int> > x;           vs.     vector<set<int>> x;
   3203   /// \endcode
   3204   LanguageStandard Standard;
   3205 
   3206   /// Macros which are ignored in front of a statement, as if they were an
   3207   /// attribute. So that they are not parsed as identifier, for example for Qts
   3208   /// emit.
   3209   /// \code
   3210   ///   AlignConsecutiveDeclarations: true
   3211   ///   StatementAttributeLikeMacros: []
   3212   ///   unsigned char data = 'x';
   3213   ///   emit          signal(data); // This is parsed as variable declaration.
   3214   ///
   3215   ///   AlignConsecutiveDeclarations: true
   3216   ///   StatementAttributeLikeMacros: [emit]
   3217   ///   unsigned char data = 'x';
   3218   ///   emit signal(data); // Now it's fine again.
   3219   /// \endcode
   3220   std::vector<std::string> StatementAttributeLikeMacros;
   3221 
   3222   /// The number of columns used for tab stops.
   3223   unsigned TabWidth;
   3224 
   3225   /// Different ways to use tab in formatting.
   3226   enum UseTabStyle : unsigned char {
   3227     /// Never use tab.
   3228     UT_Never,
   3229     /// Use tabs only for indentation.
   3230     UT_ForIndentation,
   3231     /// Fill all leading whitespace with tabs, and use spaces for alignment that
   3232     /// appears within a line (e.g. consecutive assignments and declarations).
   3233     UT_ForContinuationAndIndentation,
   3234     /// Use tabs for line continuation and indentation, and spaces for
   3235     /// alignment.
   3236     UT_AlignWithSpaces,
   3237     /// Use tabs whenever we need to fill whitespace that spans at least from
   3238     /// one tab stop to the next one.
   3239     UT_Always
   3240   };
   3241 
   3242   /// \brief Use ``\r\n`` instead of ``\n`` for line breaks.
   3243   /// Also used as fallback if ``DeriveLineEnding`` is true.
   3244   bool UseCRLF;
   3245 
   3246   /// The way to use tab characters in the resulting file.
   3247   UseTabStyle UseTab;
   3248 
   3249   bool operator==(const FormatStyle &R) const {
   3250     return AccessModifierOffset == R.AccessModifierOffset &&
   3251            AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
   3252            AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
   3253            AlignConsecutiveBitFields == R.AlignConsecutiveBitFields &&
   3254            AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
   3255            AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
   3256            AlignEscapedNewlines == R.AlignEscapedNewlines &&
   3257            AlignOperands == R.AlignOperands &&
   3258            AlignTrailingComments == R.AlignTrailingComments &&
   3259            AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
   3260            AllowAllConstructorInitializersOnNextLine ==
   3261                R.AllowAllConstructorInitializersOnNextLine &&
   3262            AllowAllParametersOfDeclarationOnNextLine ==
   3263                R.AllowAllParametersOfDeclarationOnNextLine &&
   3264            AllowShortEnumsOnASingleLine == R.AllowShortEnumsOnASingleLine &&
   3265            AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
   3266            AllowShortCaseLabelsOnASingleLine ==
   3267                R.AllowShortCaseLabelsOnASingleLine &&
   3268            AllowShortFunctionsOnASingleLine ==
   3269                R.AllowShortFunctionsOnASingleLine &&
   3270            AllowShortIfStatementsOnASingleLine ==
   3271                R.AllowShortIfStatementsOnASingleLine &&
   3272            AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
   3273            AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
   3274            AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
   3275            AlwaysBreakBeforeMultilineStrings ==
   3276                R.AlwaysBreakBeforeMultilineStrings &&
   3277            AlwaysBreakTemplateDeclarations ==
   3278                R.AlwaysBreakTemplateDeclarations &&
   3279            AttributeMacros == R.AttributeMacros &&
   3280            BinPackArguments == R.BinPackArguments &&
   3281            BinPackParameters == R.BinPackParameters &&
   3282            BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
   3283            BreakBeforeBraces == R.BreakBeforeBraces &&
   3284            BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations &&
   3285            BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
   3286            BreakConstructorInitializers == R.BreakConstructorInitializers &&
   3287            CompactNamespaces == R.CompactNamespaces &&
   3288            BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
   3289            BreakStringLiterals == R.BreakStringLiterals &&
   3290            ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
   3291            BreakInheritanceList == R.BreakInheritanceList &&
   3292            ConstructorInitializerAllOnOneLineOrOnePerLine ==
   3293                R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
   3294            ConstructorInitializerIndentWidth ==
   3295                R.ConstructorInitializerIndentWidth &&
   3296            ContinuationIndentWidth == R.ContinuationIndentWidth &&
   3297            Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
   3298            DeriveLineEnding == R.DeriveLineEnding &&
   3299            DerivePointerAlignment == R.DerivePointerAlignment &&
   3300            DisableFormat == R.DisableFormat &&
   3301            EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
   3302            EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
   3303            ExperimentalAutoDetectBinPacking ==
   3304                R.ExperimentalAutoDetectBinPacking &&
   3305            FixNamespaceComments == R.FixNamespaceComments &&
   3306            ForEachMacros == R.ForEachMacros &&
   3307            IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
   3308            IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories &&
   3309            IncludeStyle.IncludeIsMainRegex ==
   3310                R.IncludeStyle.IncludeIsMainRegex &&
   3311            IncludeStyle.IncludeIsMainSourceRegex ==
   3312                R.IncludeStyle.IncludeIsMainSourceRegex &&
   3313            IndentAccessModifiers == R.IndentAccessModifiers &&
   3314            IndentCaseLabels == R.IndentCaseLabels &&
   3315            IndentCaseBlocks == R.IndentCaseBlocks &&
   3316            IndentGotoLabels == R.IndentGotoLabels &&
   3317            IndentPPDirectives == R.IndentPPDirectives &&
   3318            IndentExternBlock == R.IndentExternBlock &&
   3319            IndentRequires == R.IndentRequires && IndentWidth == R.IndentWidth &&
   3320            Language == R.Language &&
   3321            IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
   3322            JavaImportGroups == R.JavaImportGroups &&
   3323            JavaScriptQuotes == R.JavaScriptQuotes &&
   3324            JavaScriptWrapImports == R.JavaScriptWrapImports &&
   3325            KeepEmptyLinesAtTheStartOfBlocks ==
   3326                R.KeepEmptyLinesAtTheStartOfBlocks &&
   3327            MacroBlockBegin == R.MacroBlockBegin &&
   3328            MacroBlockEnd == R.MacroBlockEnd &&
   3329            MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
   3330            NamespaceIndentation == R.NamespaceIndentation &&
   3331            NamespaceMacros == R.NamespaceMacros &&
   3332            ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
   3333            ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
   3334            ObjCBreakBeforeNestedBlockParam ==
   3335                R.ObjCBreakBeforeNestedBlockParam &&
   3336            ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
   3337            ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
   3338            PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
   3339            PenaltyBreakBeforeFirstCallParameter ==
   3340                R.PenaltyBreakBeforeFirstCallParameter &&
   3341            PenaltyBreakComment == R.PenaltyBreakComment &&
   3342            PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
   3343            PenaltyBreakString == R.PenaltyBreakString &&
   3344            PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
   3345            PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
   3346            PenaltyBreakTemplateDeclaration ==
   3347                R.PenaltyBreakTemplateDeclaration &&
   3348            PointerAlignment == R.PointerAlignment &&
   3349            RawStringFormats == R.RawStringFormats &&
   3350            ShortNamespaceLines == R.ShortNamespaceLines &&
   3351            SortIncludes == R.SortIncludes &&
   3352            SortJavaStaticImport == R.SortJavaStaticImport &&
   3353            SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
   3354            SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
   3355            SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
   3356            SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
   3357            SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&
   3358            SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
   3359            SpaceBeforeCtorInitializerColon ==
   3360                R.SpaceBeforeCtorInitializerColon &&
   3361            SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
   3362            SpaceBeforeParens == R.SpaceBeforeParens &&
   3363            SpaceAroundPointerQualifiers == R.SpaceAroundPointerQualifiers &&
   3364            SpaceBeforeRangeBasedForLoopColon ==
   3365                R.SpaceBeforeRangeBasedForLoopColon &&
   3366            SpaceInEmptyBlock == R.SpaceInEmptyBlock &&
   3367            SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
   3368            SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
   3369            SpacesInAngles == R.SpacesInAngles &&
   3370            SpacesInConditionalStatement == R.SpacesInConditionalStatement &&
   3371            SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
   3372            SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
   3373            SpacesInLineCommentPrefix.Minimum ==
   3374                R.SpacesInLineCommentPrefix.Minimum &&
   3375            SpacesInLineCommentPrefix.Maximum ==
   3376                R.SpacesInLineCommentPrefix.Maximum &&
   3377            SpacesInParentheses == R.SpacesInParentheses &&
   3378            SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
   3379            SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
   3380            BitFieldColonSpacing == R.BitFieldColonSpacing &&
   3381            Standard == R.Standard &&
   3382            StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
   3383            StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
   3384            UseTab == R.UseTab && UseCRLF == R.UseCRLF &&
   3385            TypenameMacros == R.TypenameMacros;
   3386   }
   3387 
   3388   llvm::Optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
   3389 
   3390   // Stores per-language styles. A FormatStyle instance inside has an empty
   3391   // StyleSet. A FormatStyle instance returned by the Get method has its
   3392   // StyleSet set to a copy of the originating StyleSet, effectively keeping the
   3393   // internal representation of that StyleSet alive.
   3394   //
   3395   // The memory management and ownership reminds of a birds nest: chicks
   3396   // leaving the nest take photos of the nest with them.
   3397   struct FormatStyleSet {
   3398     typedef std::map<FormatStyle::LanguageKind, FormatStyle> MapType;
   3399 
   3400     llvm::Optional<FormatStyle> Get(FormatStyle::LanguageKind Language) const;
   3401 
   3402     // Adds \p Style to this FormatStyleSet. Style must not have an associated
   3403     // FormatStyleSet.
   3404     // Style.Language should be different than LK_None. If this FormatStyleSet
   3405     // already contains an entry for Style.Language, that gets replaced with the
   3406     // passed Style.
   3407     void Add(FormatStyle Style);
   3408 
   3409     // Clears this FormatStyleSet.
   3410     void Clear();
   3411 
   3412   private:
   3413     std::shared_ptr<MapType> Styles;
   3414   };
   3415 
   3416   static FormatStyleSet BuildStyleSetFromConfiguration(
   3417       const FormatStyle &MainStyle,
   3418       const std::vector<FormatStyle> &ConfigurationStyles);
   3419 
   3420 private:
   3421   FormatStyleSet StyleSet;
   3422 
   3423   friend std::error_code
   3424   parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
   3425                      bool AllowUnknownOptions,
   3426                      llvm::SourceMgr::DiagHandlerTy DiagHandler,
   3427                      void *DiagHandlerCtxt);
   3428 };
   3429 
   3430 /// Returns a format style complying with the LLVM coding standards:
   3431 /// http://llvm.org/docs/CodingStandards.html.
   3432 FormatStyle getLLVMStyle(
   3433     FormatStyle::LanguageKind Language = FormatStyle::LanguageKind::LK_Cpp);
   3434 
   3435 /// Returns a format style complying with one of Google's style guides:
   3436 /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
   3437 /// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
   3438 /// https://developers.google.com/protocol-buffers/docs/style.
   3439 FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
   3440 
   3441 /// Returns a format style complying with Chromium's style guide:
   3442 /// http://www.chromium.org/developers/coding-style.
   3443 FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
   3444 
   3445 /// Returns a format style complying with Mozilla's style guide:
   3446 /// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
   3447 FormatStyle getMozillaStyle();
   3448 
   3449 /// Returns a format style complying with Webkit's style guide:
   3450 /// http://www.webkit.org/coding/coding-style.html
   3451 FormatStyle getWebKitStyle();
   3452 
   3453 /// Returns a format style complying with GNU Coding Standards:
   3454 /// http://www.gnu.org/prep/standards/standards.html
   3455 FormatStyle getGNUStyle();
   3456 
   3457 /// Returns a format style complying with Microsoft style guide:
   3458 /// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
   3459 FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language);
   3460 
   3461 /// Returns style indicating formatting should be not applied at all.
   3462 FormatStyle getNoStyle();
   3463 
   3464 /// Gets a predefined style for the specified language by name.
   3465 ///
   3466 /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
   3467 /// compared case-insensitively.
   3468 ///
   3469 /// Returns ``true`` if the Style has been set.
   3470 bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
   3471                         FormatStyle *Style);
   3472 
   3473 /// Parse configuration from YAML-formatted text.
   3474 ///
   3475 /// Style->Language is used to get the base style, if the ``BasedOnStyle``
   3476 /// option is present.
   3477 ///
   3478 /// The FormatStyleSet of Style is reset.
   3479 ///
   3480 /// When ``BasedOnStyle`` is not present, options not present in the YAML
   3481 /// document, are retained in \p Style.
   3482 ///
   3483 /// If AllowUnknownOptions is true, no errors are emitted if unknown
   3484 /// format options are occured.
   3485 ///
   3486 /// If set all diagnostics are emitted through the DiagHandler.
   3487 std::error_code
   3488 parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
   3489                    bool AllowUnknownOptions = false,
   3490                    llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
   3491                    void *DiagHandlerCtx = nullptr);
   3492 
   3493 /// Like above but accepts an unnamed buffer.
   3494 inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
   3495                                           bool AllowUnknownOptions = false) {
   3496   return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
   3497                             AllowUnknownOptions);
   3498 }
   3499 
   3500 /// Gets configuration in a YAML string.
   3501 std::string configurationAsText(const FormatStyle &Style);
   3502 
   3503 /// Returns the replacements necessary to sort all ``#include`` blocks
   3504 /// that are affected by ``Ranges``.
   3505 tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
   3506                                    ArrayRef<tooling::Range> Ranges,
   3507                                    StringRef FileName,
   3508                                    unsigned *Cursor = nullptr);
   3509 
   3510 /// Returns the replacements corresponding to applying and formatting
   3511 /// \p Replaces on success; otheriwse, return an llvm::Error carrying
   3512 /// llvm::StringError.
   3513 llvm::Expected<tooling::Replacements>
   3514 formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
   3515                    const FormatStyle &Style);
   3516 
   3517 /// Returns the replacements corresponding to applying \p Replaces and
   3518 /// cleaning up the code after that on success; otherwise, return an llvm::Error
   3519 /// carrying llvm::StringError.
   3520 /// This also supports inserting/deleting C++ #include directives:
   3521 /// - If a replacement has offset UINT_MAX, length 0, and a replacement text
   3522 ///   that is an #include directive, this will insert the #include into the
   3523 ///   correct block in the \p Code.
   3524 /// - If a replacement has offset UINT_MAX, length 1, and a replacement text
   3525 ///   that is the name of the header to be removed, the header will be removed
   3526 ///   from \p Code if it exists.
   3527 /// The include manipulation is done via `tooling::HeaderInclude`, see its
   3528 /// documentation for more details on how include insertion points are found and
   3529 /// what edits are produced.
   3530 llvm::Expected<tooling::Replacements>
   3531 cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
   3532                           const FormatStyle &Style);
   3533 
   3534 /// Represents the status of a formatting attempt.
   3535 struct FormattingAttemptStatus {
   3536   /// A value of ``false`` means that any of the affected ranges were not
   3537   /// formatted due to a non-recoverable syntax error.
   3538   bool FormatComplete = true;
   3539 
   3540   /// If ``FormatComplete`` is false, ``Line`` records a one-based
   3541   /// original line number at which a syntax error might have occurred. This is
   3542   /// based on a best-effort analysis and could be imprecise.
   3543   unsigned Line = 0;
   3544 };
   3545 
   3546 /// Reformats the given \p Ranges in \p Code.
   3547 ///
   3548 /// Each range is extended on either end to its next bigger logic unit, i.e.
   3549 /// everything that might influence its formatting or might be influenced by its
   3550 /// formatting.
   3551 ///
   3552 /// Returns the ``Replacements`` necessary to make all \p Ranges comply with
   3553 /// \p Style.
   3554 ///
   3555 /// If ``Status`` is non-null, its value will be populated with the status of
   3556 /// this formatting attempt. See \c FormattingAttemptStatus.
   3557 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
   3558                                ArrayRef<tooling::Range> Ranges,
   3559                                StringRef FileName = "<stdin>",
   3560                                FormattingAttemptStatus *Status = nullptr);
   3561 
   3562 /// Same as above, except if ``IncompleteFormat`` is non-null, its value
   3563 /// will be set to true if any of the affected ranges were not formatted due to
   3564 /// a non-recoverable syntax error.
   3565 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
   3566                                ArrayRef<tooling::Range> Ranges,
   3567                                StringRef FileName, bool *IncompleteFormat);
   3568 
   3569 /// Clean up any erroneous/redundant code in the given \p Ranges in \p
   3570 /// Code.
   3571 ///
   3572 /// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
   3573 tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
   3574                               ArrayRef<tooling::Range> Ranges,
   3575                               StringRef FileName = "<stdin>");
   3576 
   3577 /// Fix namespace end comments in the given \p Ranges in \p Code.
   3578 ///
   3579 /// Returns the ``Replacements`` that fix the namespace comments in all
   3580 /// \p Ranges in \p Code.
   3581 tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style,
   3582                                               StringRef Code,
   3583                                               ArrayRef<tooling::Range> Ranges,
   3584                                               StringRef FileName = "<stdin>");
   3585 
   3586 /// Sort consecutive using declarations in the given \p Ranges in
   3587 /// \p Code.
   3588 ///
   3589 /// Returns the ``Replacements`` that sort the using declarations in all
   3590 /// \p Ranges in \p Code.
   3591 tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
   3592                                             StringRef Code,
   3593                                             ArrayRef<tooling::Range> Ranges,
   3594                                             StringRef FileName = "<stdin>");
   3595 
   3596 /// Returns the ``LangOpts`` that the formatter expects you to set.
   3597 ///
   3598 /// \param Style determines specific settings for lexing mode.
   3599 LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle());
   3600 
   3601 /// Description to be used for help text for a ``llvm::cl`` option for
   3602 /// specifying format style. The description is closely related to the operation
   3603 /// of ``getStyle()``.
   3604 extern const char *StyleOptionHelpDescription;
   3605 
   3606 /// The suggested format style to use by default. This allows tools using
   3607 /// `getStyle` to have a consistent default style.
   3608 /// Different builds can modify the value to the preferred styles.
   3609 extern const char *DefaultFormatStyle;
   3610 
   3611 /// The suggested predefined style to use as the fallback style in `getStyle`.
   3612 /// Different builds can modify the value to the preferred styles.
   3613 extern const char *DefaultFallbackStyle;
   3614 
   3615 /// Construct a FormatStyle based on ``StyleName``.
   3616 ///
   3617 /// ``StyleName`` can take several forms:
   3618 /// * "{<key>: <value>, ...}" - Set specic style parameters.
   3619 /// * "<style name>" - One of the style names supported by
   3620 /// getPredefinedStyle().
   3621 /// * "file" - Load style configuration from a file called ``.clang-format``
   3622 /// located in one of the parent directories of ``FileName`` or the current
   3623 /// directory if ``FileName`` is empty.
   3624 ///
   3625 /// \param[in] StyleName Style name to interpret according to the description
   3626 /// above.
   3627 /// \param[in] FileName Path to start search for .clang-format if ``StyleName``
   3628 /// == "file".
   3629 /// \param[in] FallbackStyle The name of a predefined style used to fallback to
   3630 /// in case \p StyleName is "file" and no file can be found.
   3631 /// \param[in] Code The actual code to be formatted. Used to determine the
   3632 /// language if the filename isn't sufficient.
   3633 /// \param[in] FS The underlying file system, in which the file resides. By
   3634 /// default, the file system is the real file system.
   3635 /// \param[in] AllowUnknownOptions If true, unknown format options only
   3636 ///             emit a warning. If false, errors are emitted on unknown format
   3637 ///             options.
   3638 ///
   3639 /// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
   3640 /// "file" and no file is found, returns ``FallbackStyle``. If no style could be
   3641 /// determined, returns an Error.
   3642 llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
   3643                                      StringRef FallbackStyle,
   3644                                      StringRef Code = "",
   3645                                      llvm::vfs::FileSystem *FS = nullptr,
   3646                                      bool AllowUnknownOptions = false);
   3647 
   3648 // Guesses the language from the ``FileName`` and ``Code`` to be formatted.
   3649 // Defaults to FormatStyle::LK_Cpp.
   3650 FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
   3651 
   3652 // Returns a string representation of ``Language``.
   3653 inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
   3654   switch (Language) {
   3655   case FormatStyle::LK_Cpp:
   3656     return "C++";
   3657   case FormatStyle::LK_CSharp:
   3658     return "CSharp";
   3659   case FormatStyle::LK_ObjC:
   3660     return "Objective-C";
   3661   case FormatStyle::LK_Java:
   3662     return "Java";
   3663   case FormatStyle::LK_JavaScript:
   3664     return "JavaScript";
   3665   case FormatStyle::LK_Proto:
   3666     return "Proto";
   3667   case FormatStyle::LK_TableGen:
   3668     return "TableGen";
   3669   case FormatStyle::LK_TextProto:
   3670     return "TextProto";
   3671   default:
   3672     return "Unknown";
   3673   }
   3674 }
   3675 
   3676 } // end namespace format
   3677 } // end namespace clang
   3678 
   3679 namespace std {
   3680 template <>
   3681 struct is_error_code_enum<clang::format::ParseError> : std::true_type {};
   3682 } // namespace std
   3683 
   3684 #endif // LLVM_CLANG_FORMAT_FORMAT_H
   3685