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