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