/
Format.h
4727 lines (4477 loc) · 151 KB
/
Format.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===--- Format.h - Format C++ code -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Various functions to configurably format source code.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_FORMAT_FORMAT_H
#define LLVM_CLANG_FORMAT_FORMAT_H
#include "clang/Basic/LangOptions.h"
#include "clang/Tooling/Core/Replacement.h"
#include "clang/Tooling/Inclusions/IncludeStyle.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/SourceMgr.h"
#include <optional>
#include <system_error>
namespace llvm {
namespace vfs {
class FileSystem;
}
} // namespace llvm
namespace clang {
namespace format {
enum class ParseError {
Success = 0,
Error,
Unsuitable,
BinPackTrailingCommaConflict,
InvalidQualifierSpecified,
DuplicateQualifierSpecified,
MissingQualifierType,
MissingQualifierOrder
};
class ParseErrorCategory final : public std::error_category {
public:
const char *name() const noexcept override;
std::string message(int EV) const override;
};
const std::error_category &getParseCategory();
std::error_code make_error_code(ParseError e);
/// The ``FormatStyle`` is used to configure the formatting to follow
/// specific guidelines.
struct FormatStyle {
// If the BasedOn: was InheritParentConfig and this style needs the file from
// the parent directories. It is not part of the actual style for formatting.
// Thus the // instead of ///.
bool InheritsParentConfig;
/// The extra indent or outdent of access modifiers, e.g. ``public:``.
/// \version 3.3
int AccessModifierOffset;
/// Different styles for aligning after open brackets.
enum BracketAlignmentStyle : int8_t {
/// Align parameters on the open bracket, e.g.:
/// \code
/// someLongFunction(argument1,
/// argument2);
/// \endcode
BAS_Align,
/// Don't align, instead use ``ContinuationIndentWidth``, e.g.:
/// \code
/// someLongFunction(argument1,
/// argument2);
/// \endcode
BAS_DontAlign,
/// Always break after an open bracket, if the parameters don't fit
/// on a single line, e.g.:
/// \code
/// someLongFunction(
/// argument1, argument2);
/// \endcode
BAS_AlwaysBreak,
/// Always break after an open bracket, if the parameters don't fit
/// on a single line. Closing brackets will be placed on a new line.
/// E.g.:
/// \code
/// someLongFunction(
/// argument1, argument2
/// )
/// \endcode
///
/// \warning
/// Note: This currently only applies to parentheses.
/// \endwarning
BAS_BlockIndent,
};
/// If ``true``, horizontally aligns arguments after an open bracket.
///
/// This applies to round brackets (parentheses), angle brackets and square
/// brackets.
/// \version 3.8
BracketAlignmentStyle AlignAfterOpenBracket;
/// Different style for aligning array initializers.
enum ArrayInitializerAlignmentStyle : int8_t {
/// Align array column and left justify the columns e.g.:
/// \code
/// struct test demo[] =
/// {
/// {56, 23, "hello"},
/// {-1, 93463, "world"},
/// {7, 5, "!!" }
/// };
/// \endcode
AIAS_Left,
/// Align array column and right justify the columns e.g.:
/// \code
/// struct test demo[] =
/// {
/// {56, 23, "hello"},
/// {-1, 93463, "world"},
/// { 7, 5, "!!"}
/// };
/// \endcode
AIAS_Right,
/// Don't align array initializer columns.
AIAS_None
};
/// if not ``None``, when using initialization for an array of structs
/// aligns the fields into columns.
///
/// NOTE: As of clang-format 15 this option only applied to arrays with equal
/// number of columns per row.
///
/// \version 13
ArrayInitializerAlignmentStyle AlignArrayOfStructures;
/// Alignment options.
///
/// They can also be read as a whole for compatibility. The choices are:
/// - None
/// - Consecutive
/// - AcrossEmptyLines
/// - AcrossComments
/// - AcrossEmptyLinesAndComments
///
/// For example, to align across empty lines and not across comments, either
/// of these work.
/// \code
/// AlignConsecutiveMacros: AcrossEmptyLines
///
/// AlignConsecutiveMacros:
/// Enabled: true
/// AcrossEmptyLines: true
/// AcrossComments: false
/// \endcode
struct AlignConsecutiveStyle {
/// Whether aligning is enabled.
/// \code
/// #define SHORT_NAME 42
/// #define LONGER_NAME 0x007f
/// #define EVEN_LONGER_NAME (2)
/// #define foo(x) (x * x)
/// #define bar(y, z) (y + z)
///
/// int a = 1;
/// int somelongname = 2;
/// double c = 3;
///
/// int aaaa : 1;
/// int b : 12;
/// int ccc : 8;
///
/// int aaaa = 12;
/// float b = 23;
/// std::string ccc;
/// \endcode
bool Enabled;
/// Whether to align across empty lines.
/// \code
/// true:
/// int a = 1;
/// int somelongname = 2;
/// double c = 3;
///
/// int d = 3;
///
/// false:
/// int a = 1;
/// int somelongname = 2;
/// double c = 3;
///
/// int d = 3;
/// \endcode
bool AcrossEmptyLines;
/// Whether to align across comments.
/// \code
/// true:
/// int d = 3;
/// /* A comment. */
/// double e = 4;
///
/// false:
/// int d = 3;
/// /* A comment. */
/// double e = 4;
/// \endcode
bool AcrossComments;
/// Only for ``AlignConsecutiveAssignments``. Whether compound assignments
/// like ``+=`` are aligned along with ``=``.
/// \code
/// true:
/// a &= 2;
/// bbb = 2;
///
/// false:
/// a &= 2;
/// bbb = 2;
/// \endcode
bool AlignCompound;
/// Only for ``AlignConsecutiveAssignments``. Whether short assignment
/// operators are left-padded to the same length as long ones in order to
/// put all assignment operators to the right of the left hand side.
/// \code
/// true:
/// a >>= 2;
/// bbb = 2;
///
/// a = 2;
/// bbb >>= 2;
///
/// false:
/// a >>= 2;
/// bbb = 2;
///
/// a = 2;
/// bbb >>= 2;
/// \endcode
bool PadOperators;
bool operator==(const AlignConsecutiveStyle &R) const {
return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
AcrossComments == R.AcrossComments &&
AlignCompound == R.AlignCompound && PadOperators == R.PadOperators;
}
bool operator!=(const AlignConsecutiveStyle &R) const {
return !(*this == R);
}
};
/// Style of aligning consecutive macro definitions.
///
/// ``Consecutive`` will result in formattings like:
/// \code
/// #define SHORT_NAME 42
/// #define LONGER_NAME 0x007f
/// #define EVEN_LONGER_NAME (2)
/// #define foo(x) (x * x)
/// #define bar(y, z) (y + z)
/// \endcode
/// \version 9
AlignConsecutiveStyle AlignConsecutiveMacros;
/// Style of aligning consecutive assignments.
///
/// ``Consecutive`` will result in formattings like:
/// \code
/// int a = 1;
/// int somelongname = 2;
/// double c = 3;
/// \endcode
/// \version 3.8
AlignConsecutiveStyle AlignConsecutiveAssignments;
/// Style of aligning consecutive bit fields.
///
/// ``Consecutive`` will align the bitfield separators of consecutive lines.
/// This will result in formattings like:
/// \code
/// int aaaa : 1;
/// int b : 12;
/// int ccc : 8;
/// \endcode
/// \version 11
AlignConsecutiveStyle AlignConsecutiveBitFields;
/// Style of aligning consecutive declarations.
///
/// ``Consecutive`` will align the declaration names of consecutive lines.
/// This will result in formattings like:
/// \code
/// int aaaa = 12;
/// float b = 23;
/// std::string ccc;
/// \endcode
/// \version 3.8
AlignConsecutiveStyle AlignConsecutiveDeclarations;
/// Different styles for aligning escaped newlines.
enum EscapedNewlineAlignmentStyle : int8_t {
/// Don't align escaped newlines.
/// \code
/// #define A \
/// int aaaa; \
/// int b; \
/// int dddddddddd;
/// \endcode
ENAS_DontAlign,
/// Align escaped newlines as far left as possible.
/// \code
/// true:
/// #define A \
/// int aaaa; \
/// int b; \
/// int dddddddddd;
///
/// false:
/// \endcode
ENAS_Left,
/// Align escaped newlines in the right-most column.
/// \code
/// #define A \
/// int aaaa; \
/// int b; \
/// int dddddddddd;
/// \endcode
ENAS_Right,
};
/// Options for aligning backslashes in escaped newlines.
/// \version 5
EscapedNewlineAlignmentStyle AlignEscapedNewlines;
/// Different styles for aligning operands.
enum OperandAlignmentStyle : int8_t {
/// Do not align operands of binary and ternary expressions.
/// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
/// the start of the line.
OAS_DontAlign,
/// Horizontally align operands of binary and ternary expressions.
///
/// Specifically, this aligns operands of a single expression that needs
/// to be split over multiple lines, e.g.:
/// \code
/// int aaa = bbbbbbbbbbbbbbb +
/// ccccccccccccccc;
/// \endcode
///
/// When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is
/// aligned with the operand on the first line.
/// \code
/// int aaa = bbbbbbbbbbbbbbb
/// + ccccccccccccccc;
/// \endcode
OAS_Align,
/// Horizontally align operands of binary and ternary expressions.
///
/// This is similar to ``AO_Align``, except when
/// ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so
/// that the wrapped operand is aligned with the operand on the first line.
/// \code
/// int aaa = bbbbbbbbbbbbbbb
/// + ccccccccccccccc;
/// \endcode
OAS_AlignAfterOperator,
};
/// If ``true``, horizontally align operands of binary and ternary
/// expressions.
/// \version 3.5
OperandAlignmentStyle AlignOperands;
/// Enums for AlignTrailingComments
enum TrailingCommentsAlignmentKinds : int8_t {
/// Leave trailing comments as they are.
/// \code
/// int a; // comment
/// int ab; // comment
///
/// int abc; // comment
/// int abcd; // comment
/// \endcode
TCAS_Leave,
/// Align trailing comments.
/// \code
/// int a; // comment
/// int ab; // comment
///
/// int abc; // comment
/// int abcd; // comment
/// \endcode
TCAS_Always,
/// Don't align trailing comments but other formatter applies.
/// \code
/// int a; // comment
/// int ab; // comment
///
/// int abc; // comment
/// int abcd; // comment
/// \endcode
TCAS_Never,
};
/// Alignment options
struct TrailingCommentsAlignmentStyle {
/// Specifies the way to align trailing comments.
TrailingCommentsAlignmentKinds Kind;
/// How many empty lines to apply alignment.
/// When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
/// it formats like below.
/// \code
/// int a; // all these
///
/// int ab; // comments are
///
///
/// int abcdef; // aligned
/// \endcode
///
/// When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
/// to 1, it formats like below.
/// \code
/// int a; // these are
///
/// int ab; // aligned
///
///
/// int abcdef; // but this isn't
/// \endcode
unsigned OverEmptyLines;
bool operator==(const TrailingCommentsAlignmentStyle &R) const {
return Kind == R.Kind && OverEmptyLines == R.OverEmptyLines;
}
bool operator!=(const TrailingCommentsAlignmentStyle &R) const {
return !(*this == R);
}
};
/// Control of trailing comments.
///
/// NOTE: As of clang-format 16 this option is not a bool but can be set
/// to the options. Conventional bool options still can be parsed as before.
///
/// \code{.yaml}
/// # Example of usage:
/// AlignTrailingComments:
/// Kind: Always
/// OverEmptyLines: 2
/// \endcode
/// \version 3.7
TrailingCommentsAlignmentStyle AlignTrailingComments;
/// \brief If a function call or braced initializer list doesn't fit on a
/// line, allow putting all arguments onto the next line, even if
/// ``BinPackArguments`` is ``false``.
/// \code
/// true:
/// callFunction(
/// a, b, c, d);
///
/// false:
/// callFunction(a,
/// b,
/// c,
/// d);
/// \endcode
/// \version 9
bool AllowAllArgumentsOnNextLine;
/// This option is **deprecated**. See ``NextLine`` of
/// ``PackConstructorInitializers``.
/// \version 9
// bool AllowAllConstructorInitializersOnNextLine;
/// If the function declaration doesn't fit on a line,
/// allow putting all parameters of a function declaration onto
/// the next line even if ``BinPackParameters`` is ``false``.
/// \code
/// true:
/// void myFunction(
/// int a, int b, int c, int d, int e);
///
/// false:
/// void myFunction(int a,
/// int b,
/// int c,
/// int d,
/// int e);
/// \endcode
/// \version 3.3
bool AllowAllParametersOfDeclarationOnNextLine;
/// Different styles for merging short blocks containing at most one
/// statement.
enum ShortBlockStyle : int8_t {
/// Never merge blocks into a single line.
/// \code
/// while (true) {
/// }
/// while (true) {
/// continue;
/// }
/// \endcode
SBS_Never,
/// Only merge empty blocks.
/// \code
/// while (true) {}
/// while (true) {
/// continue;
/// }
/// \endcode
SBS_Empty,
/// Always merge short blocks into a single line.
/// \code
/// while (true) {}
/// while (true) { continue; }
/// \endcode
SBS_Always,
};
/// Dependent on the value, ``while (true) { continue; }`` can be put on a
/// single line.
/// \version 3.5
ShortBlockStyle AllowShortBlocksOnASingleLine;
/// If ``true``, short case labels will be contracted to a single line.
/// \code
/// true: false:
/// switch (a) { vs. switch (a) {
/// case 1: x = 1; break; case 1:
/// case 2: return; x = 1;
/// } break;
/// case 2:
/// return;
/// }
/// \endcode
/// \version 3.6
bool AllowShortCaseLabelsOnASingleLine;
/// Allow short enums on a single line.
/// \code
/// true:
/// enum { A, B } myEnum;
///
/// false:
/// enum {
/// A,
/// B
/// } myEnum;
/// \endcode
/// \version 11
bool AllowShortEnumsOnASingleLine;
/// Different styles for merging short functions containing at most one
/// statement.
enum ShortFunctionStyle : int8_t {
/// Never merge functions into a single line.
SFS_None,
/// Only merge functions defined inside a class. Same as "inline",
/// except it does not implies "empty": i.e. top level empty functions
/// are not merged either.
/// \code
/// class Foo {
/// void f() { foo(); }
/// };
/// void f() {
/// foo();
/// }
/// void f() {
/// }
/// \endcode
SFS_InlineOnly,
/// Only merge empty functions.
/// \code
/// void f() {}
/// void f2() {
/// bar2();
/// }
/// \endcode
SFS_Empty,
/// Only merge functions defined inside a class. Implies "empty".
/// \code
/// class Foo {
/// void f() { foo(); }
/// };
/// void f() {
/// foo();
/// }
/// void f() {}
/// \endcode
SFS_Inline,
/// Merge all functions fitting on a single line.
/// \code
/// class Foo {
/// void f() { foo(); }
/// };
/// void f() { bar(); }
/// \endcode
SFS_All,
};
/// Dependent on the value, ``int f() { return 0; }`` can be put on a
/// single line.
/// \version 3.5
ShortFunctionStyle AllowShortFunctionsOnASingleLine;
/// Different styles for handling short if statements.
enum ShortIfStyle : int8_t {
/// Never put short ifs on the same line.
/// \code
/// if (a)
/// return;
///
/// if (b)
/// return;
/// else
/// return;
///
/// if (c)
/// return;
/// else {
/// return;
/// }
/// \endcode
SIS_Never,
/// Put short ifs on the same line only if there is no else statement.
/// \code
/// if (a) return;
///
/// if (b)
/// return;
/// else
/// return;
///
/// if (c)
/// return;
/// else {
/// return;
/// }
/// \endcode
SIS_WithoutElse,
/// Put short ifs, but not else ifs nor else statements, on the same line.
/// \code
/// if (a) return;
///
/// if (b) return;
/// else if (b)
/// return;
/// else
/// return;
///
/// if (c) return;
/// else {
/// return;
/// }
/// \endcode
SIS_OnlyFirstIf,
/// Always put short ifs, else ifs and else statements on the same
/// line.
/// \code
/// if (a) return;
///
/// if (b) return;
/// else return;
///
/// if (c) return;
/// else {
/// return;
/// }
/// \endcode
SIS_AllIfsAndElse,
};
/// Dependent on the value, ``if (a) return;`` can be put on a single line.
/// \version 3.3
ShortIfStyle AllowShortIfStatementsOnASingleLine;
/// Different styles for merging short lambdas containing at most one
/// statement.
enum ShortLambdaStyle : int8_t {
/// Never merge lambdas into a single line.
SLS_None,
/// Only merge empty lambdas.
/// \code
/// auto lambda = [](int a) {};
/// auto lambda2 = [](int a) {
/// return a;
/// };
/// \endcode
SLS_Empty,
/// Merge lambda into a single line if the lambda is argument of a function.
/// \code
/// auto lambda = [](int x, int y) {
/// return x < y;
/// };
/// sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
/// \endcode
SLS_Inline,
/// Merge all lambdas fitting on a single line.
/// \code
/// auto lambda = [](int a) {};
/// auto lambda2 = [](int a) { return a; };
/// \endcode
SLS_All,
};
/// Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
/// single line.
/// \version 9
ShortLambdaStyle AllowShortLambdasOnASingleLine;
/// If ``true``, ``while (true) continue;`` can be put on a single
/// line.
/// \version 3.7
bool AllowShortLoopsOnASingleLine;
/// Different ways to break after the function definition return type.
/// This option is **deprecated** and is retained for backwards compatibility.
enum DefinitionReturnTypeBreakingStyle : int8_t {
/// Break after return type automatically.
/// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
DRTBS_None,
/// Always break after the return type.
DRTBS_All,
/// Always break after the return types of top-level functions.
DRTBS_TopLevel,
};
/// Different ways to break after the function definition or
/// declaration return type.
enum ReturnTypeBreakingStyle : int8_t {
/// Break after return type automatically.
/// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
/// \code
/// class A {
/// int f() { return 0; };
/// };
/// int f();
/// int f() { return 1; }
/// \endcode
RTBS_None,
/// Always break after the return type.
/// \code
/// class A {
/// int
/// f() {
/// return 0;
/// };
/// };
/// int
/// f();
/// int
/// f() {
/// return 1;
/// }
/// \endcode
RTBS_All,
/// Always break after the return types of top-level functions.
/// \code
/// class A {
/// int f() { return 0; };
/// };
/// int
/// f();
/// int
/// f() {
/// return 1;
/// }
/// \endcode
RTBS_TopLevel,
/// Always break after the return type of function definitions.
/// \code
/// class A {
/// int
/// f() {
/// return 0;
/// };
/// };
/// int f();
/// int
/// f() {
/// return 1;
/// }
/// \endcode
RTBS_AllDefinitions,
/// Always break after the return type of top-level definitions.
/// \code
/// class A {
/// int f() { return 0; };
/// };
/// int f();
/// int
/// f() {
/// return 1;
/// }
/// \endcode
RTBS_TopLevelDefinitions,
};
/// The function definition return type breaking style to use. This
/// option is **deprecated** and is retained for backwards compatibility.
/// \version 3.7
DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
/// The function declaration return type breaking style to use.
/// \version 3.8
ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
/// If ``true``, always break before multiline string literals.
///
/// This flag is mean to make cases where there are multiple multiline strings
/// in a file look more consistent. Thus, it will only take effect if wrapping
/// the string at that point leads to it being indented
/// ``ContinuationIndentWidth`` spaces from the start of the line.
/// \code
/// true: false:
/// aaaa = vs. aaaa = "bbbb"
/// "bbbb" "cccc";
/// "cccc";
/// \endcode
/// \version 3.4
bool AlwaysBreakBeforeMultilineStrings;
/// Different ways to break after the template declaration.
enum BreakTemplateDeclarationsStyle : int8_t {
/// Do not force break before declaration.
/// ``PenaltyBreakTemplateDeclaration`` is taken into account.
/// \code
/// template <typename T> T foo() {
/// }
/// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
/// int bbbbbbbbbbbbbbbbbbbbb) {
/// }
/// \endcode
BTDS_No,
/// Force break after template declaration only when the following
/// declaration spans multiple lines.
/// \code
/// template <typename T> T foo() {
/// }
/// template <typename T>
/// T foo(int aaaaaaaaaaaaaaaaaaaaa,
/// int bbbbbbbbbbbbbbbbbbbbb) {
/// }
/// \endcode
BTDS_MultiLine,
/// Always break after template declaration.
/// \code
/// template <typename T>
/// T foo() {
/// }
/// template <typename T>
/// T foo(int aaaaaaaaaaaaaaaaaaaaa,
/// int bbbbbbbbbbbbbbbbbbbbb) {
/// }
/// \endcode
BTDS_Yes
};
/// The template declaration breaking style to use.
/// \version 3.4
BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
/// A vector of strings that should be interpreted as attributes/qualifiers
/// instead of identifiers. This can be useful for language extensions or
/// static analyzer annotations.
///
/// For example:
/// \code
/// x = (char *__capability)&y;
/// int function(void) __ununsed;
/// void only_writes_to_buffer(char *__output buffer);
/// \endcode
///
/// In the .clang-format configuration file, this can be configured like:
/// \code{.yaml}
/// AttributeMacros: ['__capability', '__output', '__ununsed']
/// \endcode
///
/// \version 12
std::vector<std::string> AttributeMacros;
/// If ``false``, a function call's arguments will either be all on the
/// same line or will have one line each.
/// \code
/// true:
/// void f() {
/// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
/// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
/// }
///
/// false:
/// void f() {
/// f(aaaaaaaaaaaaaaaaaaaa,
/// aaaaaaaaaaaaaaaaaaaa,
/// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
/// }
/// \endcode
/// \version 3.7
bool BinPackArguments;
/// If ``false``, a function declaration's or function definition's
/// parameters will either all be on the same line or will have one line each.
/// \code
/// true:
/// void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
/// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
///
/// false:
/// void f(int aaaaaaaaaaaaaaaaaaaa,
/// int aaaaaaaaaaaaaaaaaaaa,
/// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
/// \endcode
/// \version 3.7
bool BinPackParameters;
/// Styles for adding spacing around ``:`` in bitfield definitions.
enum BitFieldColonSpacingStyle : int8_t {
/// Add one space on each side of the ``:``
/// \code
/// unsigned bf : 2;
/// \endcode
BFCS_Both,
/// Add no space around the ``:`` (except when needed for
/// ``AlignConsecutiveBitFields``).
/// \code
/// unsigned bf:2;
/// \endcode
BFCS_None,
/// Add space before the ``:`` only
/// \code
/// unsigned bf :2;
/// \endcode
BFCS_Before,
/// Add space after the ``:`` only (space may be added before if
/// needed for ``AlignConsecutiveBitFields``).
/// \code
/// unsigned bf: 2;
/// \endcode
BFCS_After
};
/// The BitFieldColonSpacingStyle to use for bitfields.
/// \version 12
BitFieldColonSpacingStyle BitFieldColonSpacing;
/// Different ways to wrap braces after control statements.
enum BraceWrappingAfterControlStatementStyle : int8_t {
/// Never wrap braces after a control statement.
/// \code
/// if (foo()) {
/// } else {
/// }
/// for (int i = 0; i < 10; ++i) {
/// }
/// \endcode
BWACS_Never,
/// Only wrap braces after a multi-line control statement.
/// \code
/// if (foo && bar &&
/// baz)
/// {
/// quux();
/// }
/// while (foo || bar) {
/// }
/// \endcode
BWACS_MultiLine,
/// Always wrap braces after a control statement.
/// \code
/// if (foo())
/// {
/// } else
/// {}
/// for (int i = 0; i < 10; ++i)
/// {}
/// \endcode
BWACS_Always
};
/// Precise control over the wrapping of braces.
/// \code
/// # Should be declared this way:
/// BreakBeforeBraces: Custom
/// BraceWrapping:
/// AfterClass: true
/// \endcode
struct BraceWrappingFlags {
/// Wrap case labels.
/// \code
/// false: true:
/// switch (foo) { vs. switch (foo) {
/// case 1: { case 1:
/// bar(); {
/// break; bar();
/// } break;
/// default: { }
/// plop(); default:
/// } {
/// } plop();