Coverage Report

Created: 2021-08-24 07:12

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