Coverage Report

Created: 2022-01-25 06:29

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