clang 19.0.0git
Format.h
Go to the documentation of this file.
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
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/Support/Regex.h"
22#include "llvm/Support/SourceMgr.h"
23#include <optional>
24#include <system_error>
25
26namespace llvm {
27namespace vfs {
28class FileSystem;
29}
30} // namespace llvm
31
32namespace clang {
33namespace format {
34
35enum class ParseError {
36 Success = 0,
37 Error,
44};
45class ParseErrorCategory final : public std::error_category {
46public:
47 const char *name() const noexcept override;
48 std::string message(int EV) const override;
49};
50const std::error_category &getParseCategory();
51std::error_code make_error_code(ParseError e);
52
53/// The ``FormatStyle`` is used to configure the formatting to follow
54/// specific guidelines.
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 ///.
60
61 /// The extra indent or outdent of access modifiers, e.g. ``public:``.
62 /// \version 3.3
64
65 /// Different styles for aligning after open brackets.
66 enum BracketAlignmentStyle : int8_t {
67 /// Align parameters on the open bracket, e.g.:
68 /// \code
69 /// someLongFunction(argument1,
70 /// argument2);
71 /// \endcode
73 /// Don't align, instead use ``ContinuationIndentWidth``, e.g.:
74 /// \code
75 /// someLongFunction(argument1,
76 /// argument2);
77 /// \endcode
79 /// Always break after an open bracket, if the parameters don't fit
80 /// on a single line, e.g.:
81 /// \code
82 /// someLongFunction(
83 /// argument1, argument2);
84 /// \endcode
86 /// Always break after an open bracket, if the parameters don't fit
87 /// on a single line. Closing brackets will be placed on a new line.
88 /// E.g.:
89 /// \code
90 /// someLongFunction(
91 /// argument1, argument2
92 /// )
93 /// \endcode
94 ///
95 /// \note
96 /// This currently only applies to braced initializer lists (when
97 /// ``Cpp11BracedListStyle`` is ``true``) and parentheses.
98 /// \endnote
100 };
101
102 /// If ``true``, horizontally aligns arguments after an open bracket.
103 ///
104 /// This applies to round brackets (parentheses), angle brackets and square
105 /// brackets.
106 /// \version 3.8
108
109 /// Different style for aligning array initializers.
111 /// Align array column and left justify the columns e.g.:
112 /// \code
113 /// struct test demo[] =
114 /// {
115 /// {56, 23, "hello"},
116 /// {-1, 93463, "world"},
117 /// {7, 5, "!!" }
118 /// };
119 /// \endcode
121 /// Align array column and right justify the columns e.g.:
122 /// \code
123 /// struct test demo[] =
124 /// {
125 /// {56, 23, "hello"},
126 /// {-1, 93463, "world"},
127 /// { 7, 5, "!!"}
128 /// };
129 /// \endcode
131 /// Don't align array initializer columns.
133 };
134 /// if not ``None``, when using initialization for an array of structs
135 /// aligns the fields into columns.
136 ///
137 /// \note
138 /// As of clang-format 15 this option only applied to arrays with equal
139 /// number of columns per row.
140 /// \endnote
141 ///
142 /// \version 13
144
145 /// Alignment options.
146 ///
147 /// They can also be read as a whole for compatibility. The choices are:
148 /// - None
149 /// - Consecutive
150 /// - AcrossEmptyLines
151 /// - AcrossComments
152 /// - AcrossEmptyLinesAndComments
153 ///
154 /// For example, to align across empty lines and not across comments, either
155 /// of these work.
156 /// \code
157 /// <option-name>: AcrossEmptyLines
158 ///
159 /// <option-name>:
160 /// Enabled: true
161 /// AcrossEmptyLines: true
162 /// AcrossComments: false
163 /// \endcode
165 /// Whether aligning is enabled.
166 /// \code
167 /// #define SHORT_NAME 42
168 /// #define LONGER_NAME 0x007f
169 /// #define EVEN_LONGER_NAME (2)
170 /// #define foo(x) (x * x)
171 /// #define bar(y, z) (y + z)
172 ///
173 /// int a = 1;
174 /// int somelongname = 2;
175 /// double c = 3;
176 ///
177 /// int aaaa : 1;
178 /// int b : 12;
179 /// int ccc : 8;
180 ///
181 /// int aaaa = 12;
182 /// float b = 23;
183 /// std::string ccc;
184 /// \endcode
186 /// Whether to align across empty lines.
187 /// \code
188 /// true:
189 /// int a = 1;
190 /// int somelongname = 2;
191 /// double c = 3;
192 ///
193 /// int d = 3;
194 ///
195 /// false:
196 /// int a = 1;
197 /// int somelongname = 2;
198 /// double c = 3;
199 ///
200 /// int d = 3;
201 /// \endcode
203 /// Whether to align across comments.
204 /// \code
205 /// true:
206 /// int d = 3;
207 /// /* A comment. */
208 /// double e = 4;
209 ///
210 /// false:
211 /// int d = 3;
212 /// /* A comment. */
213 /// double e = 4;
214 /// \endcode
216 /// Only for ``AlignConsecutiveAssignments``. Whether compound assignments
217 /// like ``+=`` are aligned along with ``=``.
218 /// \code
219 /// true:
220 /// a &= 2;
221 /// bbb = 2;
222 ///
223 /// false:
224 /// a &= 2;
225 /// bbb = 2;
226 /// \endcode
228 /// Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
229 /// aligned.
230 /// \code
231 /// true:
232 /// unsigned i;
233 /// int &r;
234 /// int *p;
235 /// int (*f)();
236 ///
237 /// false:
238 /// unsigned i;
239 /// int &r;
240 /// int *p;
241 /// int (*f)();
242 /// \endcode
244 /// Only for ``AlignConsecutiveAssignments``. Whether short assignment
245 /// operators are left-padded to the same length as long ones in order to
246 /// put all assignment operators to the right of the left hand side.
247 /// \code
248 /// true:
249 /// a >>= 2;
250 /// bbb = 2;
251 ///
252 /// a = 2;
253 /// bbb >>= 2;
254 ///
255 /// false:
256 /// a >>= 2;
257 /// bbb = 2;
258 ///
259 /// a = 2;
260 /// bbb >>= 2;
261 /// \endcode
263 bool operator==(const AlignConsecutiveStyle &R) const {
264 return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
269 }
270 bool operator!=(const AlignConsecutiveStyle &R) const {
271 return !(*this == R);
272 }
273 };
274
275 /// Style of aligning consecutive macro definitions.
276 ///
277 /// ``Consecutive`` will result in formattings like:
278 /// \code
279 /// #define SHORT_NAME 42
280 /// #define LONGER_NAME 0x007f
281 /// #define EVEN_LONGER_NAME (2)
282 /// #define foo(x) (x * x)
283 /// #define bar(y, z) (y + z)
284 /// \endcode
285 /// \version 9
287 /// Style of aligning consecutive assignments.
288 ///
289 /// ``Consecutive`` will result in formattings like:
290 /// \code
291 /// int a = 1;
292 /// int somelongname = 2;
293 /// double c = 3;
294 /// \endcode
295 /// \version 3.8
297 /// Style of aligning consecutive bit fields.
298 ///
299 /// ``Consecutive`` will align the bitfield separators of consecutive lines.
300 /// This will result in formattings like:
301 /// \code
302 /// int aaaa : 1;
303 /// int b : 12;
304 /// int ccc : 8;
305 /// \endcode
306 /// \version 11
308 /// Style of aligning consecutive declarations.
309 ///
310 /// ``Consecutive`` will align the declaration names of consecutive lines.
311 /// This will result in formattings like:
312 /// \code
313 /// int aaaa = 12;
314 /// float b = 23;
315 /// std::string ccc;
316 /// \endcode
317 /// \version 3.8
319
320 /// Alignment options.
321 ///
323 /// Whether aligning is enabled.
324 /// \code
325 /// true:
326 /// switch (level) {
327 /// case log::info: return "info:";
328 /// case log::warning: return "warning:";
329 /// default: return "";
330 /// }
331 ///
332 /// false:
333 /// switch (level) {
334 /// case log::info: return "info:";
335 /// case log::warning: return "warning:";
336 /// default: return "";
337 /// }
338 /// \endcode
340 /// Whether to align across empty lines.
341 /// \code
342 /// true:
343 /// switch (level) {
344 /// case log::info: return "info:";
345 /// case log::warning: return "warning:";
346 ///
347 /// default: return "";
348 /// }
349 ///
350 /// false:
351 /// switch (level) {
352 /// case log::info: return "info:";
353 /// case log::warning: return "warning:";
354 ///
355 /// default: return "";
356 /// }
357 /// \endcode
359 /// Whether to align across comments.
360 /// \code
361 /// true:
362 /// switch (level) {
363 /// case log::info: return "info:";
364 /// case log::warning: return "warning:";
365 /// /* A comment. */
366 /// default: return "";
367 /// }
368 ///
369 /// false:
370 /// switch (level) {
371 /// case log::info: return "info:";
372 /// case log::warning: return "warning:";
373 /// /* A comment. */
374 /// default: return "";
375 /// }
376 /// \endcode
378 /// Whether to align the case arrows when aligning short case expressions.
379 /// \code{.java}
380 /// true:
381 /// i = switch (day) {
382 /// case THURSDAY, SATURDAY -> 8;
383 /// case WEDNESDAY -> 9;
384 /// default -> 0;
385 /// };
386 ///
387 /// false:
388 /// i = switch (day) {
389 /// case THURSDAY, SATURDAY -> 8;
390 /// case WEDNESDAY -> 9;
391 /// default -> 0;
392 /// };
393 /// \endcode
395 /// Whether aligned case labels are aligned on the colon, or on the tokens
396 /// after the colon.
397 /// \code
398 /// true:
399 /// switch (level) {
400 /// case log::info : return "info:";
401 /// case log::warning: return "warning:";
402 /// default : return "";
403 /// }
404 ///
405 /// false:
406 /// switch (level) {
407 /// case log::info: return "info:";
408 /// case log::warning: return "warning:";
409 /// default: return "";
410 /// }
411 /// \endcode
414 return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
418 }
419 };
420
421 /// Style of aligning consecutive short case labels.
422 /// Only applies if ``AllowShortCaseExpressionOnASingleLine`` or
423 /// ``AllowShortCaseLabelsOnASingleLine`` is ``true``.
424 ///
425 /// \code{.yaml}
426 /// # Example of usage:
427 /// AlignConsecutiveShortCaseStatements:
428 /// Enabled: true
429 /// AcrossEmptyLines: true
430 /// AcrossComments: true
431 /// AlignCaseColons: false
432 /// \endcode
433 /// \version 17
435
436 /// Style of aligning consecutive TableGen DAGArg operator colons.
437 /// If enabled, align the colon inside DAGArg which have line break inside.
438 /// This works only when TableGenBreakInsideDAGArg is BreakElements or
439 /// BreakAll and the DAGArg is not excepted by
440 /// TableGenBreakingDAGArgOperators's effect.
441 /// \code
442 /// let dagarg = (ins
443 /// a :$src1,
444 /// aa :$src2,
445 /// aaa:$src3
446 /// )
447 /// \endcode
448 /// \version 19
450
451 /// Style of aligning consecutive TableGen cond operator colons.
452 /// Align the colons of cases inside !cond operators.
453 /// \code
454 /// !cond(!eq(size, 1) : 1,
455 /// !eq(size, 16): 1,
456 /// true : 0)
457 /// \endcode
458 /// \version 19
460
461 /// Style of aligning consecutive TableGen definition colons.
462 /// This aligns the inheritance colons of consecutive definitions.
463 /// \code
464 /// def Def : Parent {}
465 /// def DefDef : Parent {}
466 /// def DefDefDef : Parent {}
467 /// \endcode
468 /// \version 19
470
471 /// Different styles for aligning escaped newlines.
473 /// Don't align escaped newlines.
474 /// \code
475 /// #define A \
476 /// int aaaa; \
477 /// int b; \
478 /// int dddddddddd;
479 /// \endcode
481 /// Align escaped newlines as far left as possible.
482 /// \code
483 /// true:
484 /// #define A \
485 /// int aaaa; \
486 /// int b; \
487 /// int dddddddddd;
488 ///
489 /// false:
490 /// \endcode
492 /// Align escaped newlines in the right-most column.
493 /// \code
494 /// #define A \
495 /// int aaaa; \
496 /// int b; \
497 /// int dddddddddd;
498 /// \endcode
500 };
501
502 /// Options for aligning backslashes in escaped newlines.
503 /// \version 5
505
506 /// Different styles for aligning operands.
507 enum OperandAlignmentStyle : int8_t {
508 /// Do not align operands of binary and ternary expressions.
509 /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
510 /// the start of the line.
512 /// Horizontally align operands of binary and ternary expressions.
513 ///
514 /// Specifically, this aligns operands of a single expression that needs
515 /// to be split over multiple lines, e.g.:
516 /// \code
517 /// int aaa = bbbbbbbbbbbbbbb +
518 /// ccccccccccccccc;
519 /// \endcode
520 ///
521 /// When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is
522 /// aligned with the operand on the first line.
523 /// \code
524 /// int aaa = bbbbbbbbbbbbbbb
525 /// + ccccccccccccccc;
526 /// \endcode
528 /// Horizontally align operands of binary and ternary expressions.
529 ///
530 /// This is similar to ``AO_Align``, except when
531 /// ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so
532 /// that the wrapped operand is aligned with the operand on the first line.
533 /// \code
534 /// int aaa = bbbbbbbbbbbbbbb
535 /// + ccccccccccccccc;
536 /// \endcode
538 };
539
540 /// If ``true``, horizontally align operands of binary and ternary
541 /// expressions.
542 /// \version 3.5
544
545 /// Enums for AlignTrailingComments
547 /// Leave trailing comments as they are.
548 /// \code
549 /// int a; // comment
550 /// int ab; // comment
551 ///
552 /// int abc; // comment
553 /// int abcd; // comment
554 /// \endcode
556 /// Align trailing comments.
557 /// \code
558 /// int a; // comment
559 /// int ab; // comment
560 ///
561 /// int abc; // comment
562 /// int abcd; // comment
563 /// \endcode
565 /// Don't align trailing comments but other formatter applies.
566 /// \code
567 /// int a; // comment
568 /// int ab; // comment
569 ///
570 /// int abc; // comment
571 /// int abcd; // comment
572 /// \endcode
574 };
575
576 /// Alignment options
578 /// Specifies the way to align trailing comments.
580 /// How many empty lines to apply alignment.
581 /// When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
582 /// it formats like below.
583 /// \code
584 /// int a; // all these
585 ///
586 /// int ab; // comments are
587 ///
588 ///
589 /// int abcdef; // aligned
590 /// \endcode
591 ///
592 /// When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
593 /// to 1, it formats like below.
594 /// \code
595 /// int a; // these are
596 ///
597 /// int ab; // aligned
598 ///
599 ///
600 /// int abcdef; // but this isn't
601 /// \endcode
603
605 return Kind == R.Kind && OverEmptyLines == R.OverEmptyLines;
606 }
608 return !(*this == R);
609 }
610 };
611
612 /// Control of trailing comments.
613 ///
614 /// The alignment stops at closing braces after a line break, and only
615 /// followed by other closing braces, a (``do-``) ``while``, a lambda call, or
616 /// a semicolon.
617 ///
618 /// \note
619 /// As of clang-format 16 this option is not a bool but can be set
620 /// to the options. Conventional bool options still can be parsed as before.
621 /// \endnote
622 ///
623 /// \code{.yaml}
624 /// # Example of usage:
625 /// AlignTrailingComments:
626 /// Kind: Always
627 /// OverEmptyLines: 2
628 /// \endcode
629 /// \version 3.7
631
632 /// \brief If a function call or braced initializer list doesn't fit on a
633 /// line, allow putting all arguments onto the next line, even if
634 /// ``BinPackArguments`` is ``false``.
635 /// \code
636 /// true:
637 /// callFunction(
638 /// a, b, c, d);
639 ///
640 /// false:
641 /// callFunction(a,
642 /// b,
643 /// c,
644 /// d);
645 /// \endcode
646 /// \version 9
648
649 /// This option is **deprecated**. See ``NextLine`` of
650 /// ``PackConstructorInitializers``.
651 /// \version 9
652 // bool AllowAllConstructorInitializersOnNextLine;
653
654 /// If the function declaration doesn't fit on a line,
655 /// allow putting all parameters of a function declaration onto
656 /// the next line even if ``BinPackParameters`` is ``false``.
657 /// \code
658 /// true:
659 /// void myFunction(
660 /// int a, int b, int c, int d, int e);
661 ///
662 /// false:
663 /// void myFunction(int a,
664 /// int b,
665 /// int c,
666 /// int d,
667 /// int e);
668 /// \endcode
669 /// \version 3.3
671
672 /// Different ways to break before a noexcept specifier.
674 /// No line break allowed.
675 /// \code
676 /// void foo(int arg1,
677 /// double arg2) noexcept;
678 ///
679 /// void bar(int arg1, double arg2) noexcept(
680 /// noexcept(baz(arg1)) &&
681 /// noexcept(baz(arg2)));
682 /// \endcode
684 /// For a simple ``noexcept`` there is no line break allowed, but when we
685 /// have a condition it is.
686 /// \code
687 /// void foo(int arg1,
688 /// double arg2) noexcept;
689 ///
690 /// void bar(int arg1, double arg2)
691 /// noexcept(noexcept(baz(arg1)) &&
692 /// noexcept(baz(arg2)));
693 /// \endcode
695 /// Line breaks are allowed. But note that because of the associated
696 /// penalties ``clang-format`` often prefers not to break before the
697 /// ``noexcept``.
698 /// \code
699 /// void foo(int arg1,
700 /// double arg2) noexcept;
701 ///
702 /// void bar(int arg1, double arg2)
703 /// noexcept(noexcept(baz(arg1)) &&
704 /// noexcept(baz(arg2)));
705 /// \endcode
707 };
708
709 /// Controls if there could be a line break before a ``noexcept`` specifier.
710 /// \version 18
712
713 /// Different styles for merging short blocks containing at most one
714 /// statement.
715 enum ShortBlockStyle : int8_t {
716 /// Never merge blocks into a single line.
717 /// \code
718 /// while (true) {
719 /// }
720 /// while (true) {
721 /// continue;
722 /// }
723 /// \endcode
725 /// Only merge empty blocks.
726 /// \code
727 /// while (true) {}
728 /// while (true) {
729 /// continue;
730 /// }
731 /// \endcode
733 /// Always merge short blocks into a single line.
734 /// \code
735 /// while (true) {}
736 /// while (true) { continue; }
737 /// \endcode
739 };
740
741 /// Dependent on the value, ``while (true) { continue; }`` can be put on a
742 /// single line.
743 /// \version 3.5
745
746 /// Whether to merge a short switch labeled rule into a single line.
747 /// \code{.java}
748 /// true: false:
749 /// switch (a) { vs. switch (a) {
750 /// case 1 -> 1; case 1 ->
751 /// default -> 0; 1;
752 /// }; default ->
753 /// 0;
754 /// };
755 /// \endcode
756 /// \version 19
758
759 /// If ``true``, short case labels will be contracted to a single line.
760 /// \code
761 /// true: false:
762 /// switch (a) { vs. switch (a) {
763 /// case 1: x = 1; break; case 1:
764 /// case 2: return; x = 1;
765 /// } break;
766 /// case 2:
767 /// return;
768 /// }
769 /// \endcode
770 /// \version 3.6
772
773 /// Allow short compound requirement on a single line.
774 /// \code
775 /// true:
776 /// template <typename T>
777 /// concept c = requires(T x) {
778 /// { x + 1 } -> std::same_as<int>;
779 /// };
780 ///
781 /// false:
782 /// template <typename T>
783 /// concept c = requires(T x) {
784 /// {
785 /// x + 1
786 /// } -> std::same_as<int>;
787 /// };
788 /// \endcode
789 /// \version 18
791
792 /// Allow short enums on a single line.
793 /// \code
794 /// true:
795 /// enum { A, B } myEnum;
796 ///
797 /// false:
798 /// enum {
799 /// A,
800 /// B
801 /// } myEnum;
802 /// \endcode
803 /// \version 11
805
806 /// Different styles for merging short functions containing at most one
807 /// statement.
808 enum ShortFunctionStyle : int8_t {
809 /// Never merge functions into a single line.
811 /// Only merge functions defined inside a class. Same as "inline",
812 /// except it does not implies "empty": i.e. top level empty functions
813 /// are not merged either.
814 /// \code
815 /// class Foo {
816 /// void f() { foo(); }
817 /// };
818 /// void f() {
819 /// foo();
820 /// }
821 /// void f() {
822 /// }
823 /// \endcode
825 /// Only merge empty functions.
826 /// \code
827 /// void f() {}
828 /// void f2() {
829 /// bar2();
830 /// }
831 /// \endcode
833 /// Only merge functions defined inside a class. Implies "empty".
834 /// \code
835 /// class Foo {
836 /// void f() { foo(); }
837 /// };
838 /// void f() {
839 /// foo();
840 /// }
841 /// void f() {}
842 /// \endcode
844 /// Merge all functions fitting on a single line.
845 /// \code
846 /// class Foo {
847 /// void f() { foo(); }
848 /// };
849 /// void f() { bar(); }
850 /// \endcode
852 };
853
854 /// Dependent on the value, ``int f() { return 0; }`` can be put on a
855 /// single line.
856 /// \version 3.5
858
859 /// Different styles for handling short if statements.
860 enum ShortIfStyle : int8_t {
861 /// Never put short ifs on the same line.
862 /// \code
863 /// if (a)
864 /// return;
865 ///
866 /// if (b)
867 /// return;
868 /// else
869 /// return;
870 ///
871 /// if (c)
872 /// return;
873 /// else {
874 /// return;
875 /// }
876 /// \endcode
878 /// Put short ifs on the same line only if there is no else statement.
879 /// \code
880 /// if (a) return;
881 ///
882 /// if (b)
883 /// return;
884 /// else
885 /// return;
886 ///
887 /// if (c)
888 /// return;
889 /// else {
890 /// return;
891 /// }
892 /// \endcode
894 /// Put short ifs, but not else ifs nor else statements, on the same line.
895 /// \code
896 /// if (a) return;
897 ///
898 /// if (b) return;
899 /// else if (b)
900 /// return;
901 /// else
902 /// return;
903 ///
904 /// if (c) return;
905 /// else {
906 /// return;
907 /// }
908 /// \endcode
910 /// Always put short ifs, else ifs and else statements on the same
911 /// line.
912 /// \code
913 /// if (a) return;
914 ///
915 /// if (b) return;
916 /// else return;
917 ///
918 /// if (c) return;
919 /// else {
920 /// return;
921 /// }
922 /// \endcode
924 };
925
926 /// Dependent on the value, ``if (a) return;`` can be put on a single line.
927 /// \version 3.3
929
930 /// Different styles for merging short lambdas containing at most one
931 /// statement.
932 enum ShortLambdaStyle : int8_t {
933 /// Never merge lambdas into a single line.
935 /// Only merge empty lambdas.
936 /// \code
937 /// auto lambda = [](int a) {};
938 /// auto lambda2 = [](int a) {
939 /// return a;
940 /// };
941 /// \endcode
943 /// Merge lambda into a single line if the lambda is argument of a function.
944 /// \code
945 /// auto lambda = [](int x, int y) {
946 /// return x < y;
947 /// };
948 /// sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
949 /// \endcode
951 /// Merge all lambdas fitting on a single line.
952 /// \code
953 /// auto lambda = [](int a) {};
954 /// auto lambda2 = [](int a) { return a; };
955 /// \endcode
957 };
958
959 /// Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
960 /// single line.
961 /// \version 9
963
964 /// If ``true``, ``while (true) continue;`` can be put on a single
965 /// line.
966 /// \version 3.7
968
969 /// Different ways to break after the function definition return type.
970 /// This option is **deprecated** and is retained for backwards compatibility.
972 /// Break after return type automatically.
973 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
975 /// Always break after the return type.
977 /// Always break after the return types of top-level functions.
979 };
980
981 /// Different ways to break after the function definition or
982 /// declaration return type.
984 /// This is **deprecated**. See ``Automatic`` below.
986 /// Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.
987 /// \code
988 /// class A {
989 /// int f() { return 0; };
990 /// };
991 /// int f();
992 /// int f() { return 1; }
993 /// int
994 /// LongName::AnotherLongName();
995 /// \endcode
997 /// Same as ``Automatic`` above, except that there is no break after short
998 /// return types.
999 /// \code
1000 /// class A {
1001 /// int f() { return 0; };
1002 /// };
1003 /// int f();
1004 /// int f() { return 1; }
1005 /// int LongName::
1006 /// AnotherLongName();
1007 /// \endcode
1009 /// Always break after the return type.
1010 /// \code
1011 /// class A {
1012 /// int
1013 /// f() {
1014 /// return 0;
1015 /// };
1016 /// };
1017 /// int
1018 /// f();
1019 /// int
1020 /// f() {
1021 /// return 1;
1022 /// }
1023 /// int
1024 /// LongName::AnotherLongName();
1025 /// \endcode
1027 /// Always break after the return types of top-level functions.
1028 /// \code
1029 /// class A {
1030 /// int f() { return 0; };
1031 /// };
1032 /// int
1033 /// f();
1034 /// int
1035 /// f() {
1036 /// return 1;
1037 /// }
1038 /// int
1039 /// LongName::AnotherLongName();
1040 /// \endcode
1042 /// Always break after the return type of function definitions.
1043 /// \code
1044 /// class A {
1045 /// int
1046 /// f() {
1047 /// return 0;
1048 /// };
1049 /// };
1050 /// int f();
1051 /// int
1052 /// f() {
1053 /// return 1;
1054 /// }
1055 /// int
1056 /// LongName::AnotherLongName();
1057 /// \endcode
1059 /// Always break after the return type of top-level definitions.
1060 /// \code
1061 /// class A {
1062 /// int f() { return 0; };
1063 /// };
1064 /// int f();
1065 /// int
1066 /// f() {
1067 /// return 1;
1068 /// }
1069 /// int
1070 /// LongName::AnotherLongName();
1071 /// \endcode
1073 };
1074
1075 /// The function definition return type breaking style to use. This
1076 /// option is **deprecated** and is retained for backwards compatibility.
1077 /// \version 3.7
1079
1080 /// This option is renamed to ``BreakAfterReturnType``.
1081 /// \version 3.8
1082 /// @deprecated
1083 // ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
1084
1085 /// If ``true``, always break before multiline string literals.
1086 ///
1087 /// This flag is mean to make cases where there are multiple multiline strings
1088 /// in a file look more consistent. Thus, it will only take effect if wrapping
1089 /// the string at that point leads to it being indented
1090 /// ``ContinuationIndentWidth`` spaces from the start of the line.
1091 /// \code
1092 /// true: false:
1093 /// aaaa = vs. aaaa = "bbbb"
1094 /// "bbbb" "cccc";
1095 /// "cccc";
1096 /// \endcode
1097 /// \version 3.4
1099
1100 /// Different ways to break after the template declaration.
1102 /// Do not change the line breaking before the declaration.
1103 /// \code
1104 /// template <typename T>
1105 /// T foo() {
1106 /// }
1107 /// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1108 /// int bbbbbbbbbbbbbbbbbbbbb) {
1109 /// }
1110 /// \endcode
1112 /// Do not force break before declaration.
1113 /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
1114 /// \code
1115 /// template <typename T> T foo() {
1116 /// }
1117 /// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1118 /// int bbbbbbbbbbbbbbbbbbbbb) {
1119 /// }
1120 /// \endcode
1122 /// Force break after template declaration only when the following
1123 /// declaration spans multiple lines.
1124 /// \code
1125 /// template <typename T> T foo() {
1126 /// }
1127 /// template <typename T>
1128 /// T foo(int aaaaaaaaaaaaaaaaaaaaa,
1129 /// int bbbbbbbbbbbbbbbbbbbbb) {
1130 /// }
1131 /// \endcode
1133 /// Always break after template declaration.
1134 /// \code
1135 /// template <typename T>
1136 /// T foo() {
1137 /// }
1138 /// template <typename T>
1139 /// T foo(int aaaaaaaaaaaaaaaaaaaaa,
1140 /// int bbbbbbbbbbbbbbbbbbbbb) {
1141 /// }
1142 /// \endcode
1143 BTDS_Yes
1145
1146 /// This option is renamed to ``BreakTemplateDeclarations``.
1147 /// \version 3.4
1148 /// @deprecated
1149 // BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
1150
1151 /// A vector of strings that should be interpreted as attributes/qualifiers
1152 /// instead of identifiers. This can be useful for language extensions or
1153 /// static analyzer annotations.
1154 ///
1155 /// For example:
1156 /// \code
1157 /// x = (char *__capability)&y;
1158 /// int function(void) __unused;
1159 /// void only_writes_to_buffer(char *__output buffer);
1160 /// \endcode
1161 ///
1162 /// In the .clang-format configuration file, this can be configured like:
1163 /// \code{.yaml}
1164 /// AttributeMacros: ['__capability', '__output', '__unused']
1165 /// \endcode
1166 ///
1167 /// \version 12
1168 std::vector<std::string> AttributeMacros;
1169
1170 /// If ``false``, a function call's arguments will either be all on the
1171 /// same line or will have one line each.
1172 /// \code
1173 /// true:
1174 /// void f() {
1175 /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
1176 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1177 /// }
1178 ///
1179 /// false:
1180 /// void f() {
1181 /// f(aaaaaaaaaaaaaaaaaaaa,
1182 /// aaaaaaaaaaaaaaaaaaaa,
1183 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1184 /// }
1185 /// \endcode
1186 /// \version 3.7
1188
1189 /// If ``false``, a function declaration's or function definition's
1190 /// parameters will either all be on the same line or will have one line each.
1191 /// \code
1192 /// true:
1193 /// void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
1194 /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
1195 ///
1196 /// false:
1197 /// void f(int aaaaaaaaaaaaaaaaaaaa,
1198 /// int aaaaaaaaaaaaaaaaaaaa,
1199 /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
1200 /// \endcode
1201 /// \version 3.7
1203
1204 /// Styles for adding spacing around ``:`` in bitfield definitions.
1206 /// Add one space on each side of the ``:``
1207 /// \code
1208 /// unsigned bf : 2;
1209 /// \endcode
1211 /// Add no space around the ``:`` (except when needed for
1212 /// ``AlignConsecutiveBitFields``).
1213 /// \code
1214 /// unsigned bf:2;
1215 /// \endcode
1217 /// Add space before the ``:`` only
1218 /// \code
1219 /// unsigned bf :2;
1220 /// \endcode
1222 /// Add space after the ``:`` only (space may be added before if
1223 /// needed for ``AlignConsecutiveBitFields``).
1224 /// \code
1225 /// unsigned bf: 2;
1226 /// \endcode
1229 /// The BitFieldColonSpacingStyle to use for bitfields.
1230 /// \version 12
1232
1233 /// The number of columns to use to indent the contents of braced init lists.
1234 /// If unset, ``ContinuationIndentWidth`` is used.
1235 /// \code
1236 /// AlignAfterOpenBracket: AlwaysBreak
1237 /// BracedInitializerIndentWidth: 2
1238 ///
1239 /// void f() {
1240 /// SomeClass c{
1241 /// "foo",
1242 /// "bar",
1243 /// "baz",
1244 /// };
1245 /// auto s = SomeStruct{
1246 /// .foo = "foo",
1247 /// .bar = "bar",
1248 /// .baz = "baz",
1249 /// };
1250 /// SomeArrayT a[3] = {
1251 /// {
1252 /// foo,
1253 /// bar,
1254 /// },
1255 /// {
1256 /// foo,
1257 /// bar,
1258 /// },
1259 /// SomeArrayT{},
1260 /// };
1261 /// }
1262 /// \endcode
1263 /// \version 17
1264 std::optional<unsigned> BracedInitializerIndentWidth;
1265
1266 /// Different ways to wrap braces after control statements.
1268 /// Never wrap braces after a control statement.
1269 /// \code
1270 /// if (foo()) {
1271 /// } else {
1272 /// }
1273 /// for (int i = 0; i < 10; ++i) {
1274 /// }
1275 /// \endcode
1277 /// Only wrap braces after a multi-line control statement.
1278 /// \code
1279 /// if (foo && bar &&
1280 /// baz)
1281 /// {
1282 /// quux();
1283 /// }
1284 /// while (foo || bar) {
1285 /// }
1286 /// \endcode
1288 /// Always wrap braces after a control statement.
1289 /// \code
1290 /// if (foo())
1291 /// {
1292 /// } else
1293 /// {}
1294 /// for (int i = 0; i < 10; ++i)
1295 /// {}
1296 /// \endcode
1299
1300 /// Precise control over the wrapping of braces.
1301 /// \code
1302 /// # Should be declared this way:
1303 /// BreakBeforeBraces: Custom
1304 /// BraceWrapping:
1305 /// AfterClass: true
1306 /// \endcode
1308 /// Wrap case labels.
1309 /// \code
1310 /// false: true:
1311 /// switch (foo) { vs. switch (foo) {
1312 /// case 1: { case 1:
1313 /// bar(); {
1314 /// break; bar();
1315 /// } break;
1316 /// default: { }
1317 /// plop(); default:
1318 /// } {
1319 /// } plop();
1320 /// }
1321 /// }
1322 /// \endcode
1324 /// Wrap class definitions.
1325 /// \code
1326 /// true:
1327 /// class foo
1328 /// {};
1329 ///
1330 /// false:
1331 /// class foo {};
1332 /// \endcode
1334
1335 /// Wrap control statements (``if``/``for``/``while``/``switch``/..).
1337 /// Wrap enum definitions.
1338 /// \code
1339 /// true:
1340 /// enum X : int
1341 /// {
1342 /// B
1343 /// };
1344 ///
1345 /// false:
1346 /// enum X : int { B };
1347 /// \endcode
1349 /// Wrap function definitions.
1350 /// \code
1351 /// true:
1352 /// void foo()
1353 /// {
1354 /// bar();
1355 /// bar2();
1356 /// }
1357 ///
1358 /// false:
1359 /// void foo() {
1360 /// bar();
1361 /// bar2();
1362 /// }
1363 /// \endcode
1365 /// Wrap namespace definitions.
1366 /// \code
1367 /// true:
1368 /// namespace
1369 /// {
1370 /// int foo();
1371 /// int bar();
1372 /// }
1373 ///
1374 /// false:
1375 /// namespace {
1376 /// int foo();
1377 /// int bar();
1378 /// }
1379 /// \endcode
1381 /// Wrap ObjC definitions (interfaces, implementations...).
1382 /// \note
1383 /// @autoreleasepool and @synchronized blocks are wrapped
1384 /// according to ``AfterControlStatement`` flag.
1385 /// \endnote
1387 /// Wrap struct definitions.
1388 /// \code
1389 /// true:
1390 /// struct foo
1391 /// {
1392 /// int x;
1393 /// };
1394 ///
1395 /// false:
1396 /// struct foo {
1397 /// int x;
1398 /// };
1399 /// \endcode
1401 /// Wrap union definitions.
1402 /// \code
1403 /// true:
1404 /// union foo
1405 /// {
1406 /// int x;
1407 /// }
1408 ///
1409 /// false:
1410 /// union foo {
1411 /// int x;
1412 /// }
1413 /// \endcode
1415 /// Wrap extern blocks.
1416 /// \code
1417 /// true:
1418 /// extern "C"
1419 /// {
1420 /// int foo();
1421 /// }
1422 ///
1423 /// false:
1424 /// extern "C" {
1425 /// int foo();
1426 /// }
1427 /// \endcode
1428 bool AfterExternBlock; // Partially superseded by IndentExternBlock
1429 /// Wrap before ``catch``.
1430 /// \code
1431 /// true:
1432 /// try {
1433 /// foo();
1434 /// }
1435 /// catch () {
1436 /// }
1437 ///
1438 /// false:
1439 /// try {
1440 /// foo();
1441 /// } catch () {
1442 /// }
1443 /// \endcode
1445 /// Wrap before ``else``.
1446 /// \code
1447 /// true:
1448 /// if (foo()) {
1449 /// }
1450 /// else {
1451 /// }
1452 ///
1453 /// false:
1454 /// if (foo()) {
1455 /// } else {
1456 /// }
1457 /// \endcode
1459 /// Wrap lambda block.
1460 /// \code
1461 /// true:
1462 /// connect(
1463 /// []()
1464 /// {
1465 /// foo();
1466 /// bar();
1467 /// });
1468 ///
1469 /// false:
1470 /// connect([]() {
1471 /// foo();
1472 /// bar();
1473 /// });
1474 /// \endcode
1476 /// Wrap before ``while``.
1477 /// \code
1478 /// true:
1479 /// do {
1480 /// foo();
1481 /// }
1482 /// while (1);
1483 ///
1484 /// false:
1485 /// do {
1486 /// foo();
1487 /// } while (1);
1488 /// \endcode
1490 /// Indent the wrapped braces themselves.
1492 /// If ``false``, empty function body can be put on a single line.
1493 /// This option is used only if the opening brace of the function has
1494 /// already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
1495 /// set, and the function could/should not be put on a single line (as per
1496 /// ``AllowShortFunctionsOnASingleLine`` and constructor formatting
1497 /// options).
1498 /// \code
1499 /// false: true:
1500 /// int f() vs. int f()
1501 /// {} {
1502 /// }
1503 /// \endcode
1504 ///
1506 /// If ``false``, empty record (e.g. class, struct or union) body
1507 /// can be put on a single line. This option is used only if the opening
1508 /// brace of the record has already been wrapped, i.e. the ``AfterClass``
1509 /// (for classes) brace wrapping mode is set.
1510 /// \code
1511 /// false: true:
1512 /// class Foo vs. class Foo
1513 /// {} {
1514 /// }
1515 /// \endcode
1516 ///
1518 /// If ``false``, empty namespace body can be put on a single line.
1519 /// This option is used only if the opening brace of the namespace has
1520 /// already been wrapped, i.e. the ``AfterNamespace`` brace wrapping mode is
1521 /// set.
1522 /// \code
1523 /// false: true:
1524 /// namespace Foo vs. namespace Foo
1525 /// {} {
1526 /// }
1527 /// \endcode
1528 ///
1530 };
1531
1532 /// Control of individual brace wrapping cases.
1533 ///
1534 /// If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
1535 /// each individual brace case should be handled. Otherwise, this is ignored.
1536 /// \code{.yaml}
1537 /// # Example of usage:
1538 /// BreakBeforeBraces: Custom
1539 /// BraceWrapping:
1540 /// AfterEnum: true
1541 /// AfterStruct: false
1542 /// SplitEmptyFunction: false
1543 /// \endcode
1544 /// \version 3.8
1546
1547 /// Break between adjacent string literals.
1548 /// \code
1549 /// true:
1550 /// return "Code"
1551 /// "\0\52\26\55\55\0"
1552 /// "x013"
1553 /// "\02\xBA";
1554 /// false:
1555 /// return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
1556 /// \endcode
1557 /// \version 18
1559
1560 /// Different ways to break after attributes.
1562 /// Always break after attributes.
1563 /// \code
1564 /// [[maybe_unused]]
1565 /// const int i;
1566 /// [[gnu::const]] [[maybe_unused]]
1567 /// int j;
1568 ///
1569 /// [[nodiscard]]
1570 /// inline int f();
1571 /// [[gnu::const]] [[nodiscard]]
1572 /// int g();
1573 ///
1574 /// [[likely]]
1575 /// if (a)
1576 /// f();
1577 /// else
1578 /// g();
1579 ///
1580 /// switch (b) {
1581 /// [[unlikely]]
1582 /// case 1:
1583 /// ++b;
1584 /// break;
1585 /// [[likely]]
1586 /// default:
1587 /// return;
1588 /// }
1589 /// \endcode
1591 /// Leave the line breaking after attributes as is.
1592 /// \code
1593 /// [[maybe_unused]] const int i;
1594 /// [[gnu::const]] [[maybe_unused]]
1595 /// int j;
1596 ///
1597 /// [[nodiscard]] inline int f();
1598 /// [[gnu::const]] [[nodiscard]]
1599 /// int g();
1600 ///
1601 /// [[likely]] if (a)
1602 /// f();
1603 /// else
1604 /// g();
1605 ///
1606 /// switch (b) {
1607 /// [[unlikely]] case 1:
1608 /// ++b;
1609 /// break;
1610 /// [[likely]]
1611 /// default:
1612 /// return;
1613 /// }
1614 /// \endcode
1616 /// Never break after attributes.
1617 /// \code
1618 /// [[maybe_unused]] const int i;
1619 /// [[gnu::const]] [[maybe_unused]] int j;
1620 ///
1621 /// [[nodiscard]] inline int f();
1622 /// [[gnu::const]] [[nodiscard]] int g();
1623 ///
1624 /// [[likely]] if (a)
1625 /// f();
1626 /// else
1627 /// g();
1628 ///
1629 /// switch (b) {
1630 /// [[unlikely]] case 1:
1631 /// ++b;
1632 /// break;
1633 /// [[likely]] default:
1634 /// return;
1635 /// }
1636 /// \endcode
1638 };
1639
1640 /// Break after a group of C++11 attributes before variable or function
1641 /// (including constructor/destructor) declaration/definition names or before
1642 /// control statements, i.e. ``if``, ``switch`` (including ``case`` and
1643 /// ``default`` labels), ``for``, and ``while`` statements.
1644 /// \version 16
1646
1647 /// The function declaration return type breaking style to use.
1648 /// \version 19
1650
1651 /// If ``true``, clang-format will always break after a Json array ``[``
1652 /// otherwise it will scan until the closing ``]`` to determine if it should
1653 /// add newlines between elements (prettier compatible).
1654 ///
1655 /// \note
1656 /// This is currently only for formatting JSON.
1657 /// \endnote
1658 /// \code
1659 /// true: false:
1660 /// [ vs. [1, 2, 3, 4]
1661 /// 1,
1662 /// 2,
1663 /// 3,
1664 /// 4
1665 /// ]
1666 /// \endcode
1667 /// \version 16
1669
1670 /// The style of wrapping parameters on the same line (bin-packed) or
1671 /// on one line each.
1672 enum BinPackStyle : int8_t {
1673 /// Automatically determine parameter bin-packing behavior.
1675 /// Always bin-pack parameters.
1677 /// Never bin-pack parameters.
1679 };
1680
1681 /// The style of breaking before or after binary operators.
1682 enum BinaryOperatorStyle : int8_t {
1683 /// Break after operators.
1684 /// \code
1685 /// LooooooooooongType loooooooooooooooooooooongVariable =
1686 /// someLooooooooooooooooongFunction();
1687 ///
1688 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
1689 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
1690 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
1691 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
1692 /// ccccccccccccccccccccccccccccccccccccccccc;
1693 /// \endcode
1695 /// Break before operators that aren't assignments.
1696 /// \code
1697 /// LooooooooooongType loooooooooooooooooooooongVariable =
1698 /// someLooooooooooooooooongFunction();
1699 ///
1700 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1701 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1702 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1703 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1704 /// > ccccccccccccccccccccccccccccccccccccccccc;
1705 /// \endcode
1707 /// Break before operators.
1708 /// \code
1709 /// LooooooooooongType loooooooooooooooooooooongVariable
1710 /// = someLooooooooooooooooongFunction();
1711 ///
1712 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1713 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1714 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1715 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1716 /// > ccccccccccccccccccccccccccccccccccccccccc;
1717 /// \endcode
1719 };
1720
1721 /// The way to wrap binary operators.
1722 /// \version 3.6
1724
1725 /// Different ways to attach braces to their surrounding context.
1726 enum BraceBreakingStyle : int8_t {
1727 /// Always attach braces to surrounding context.
1728 /// \code
1729 /// namespace N {
1730 /// enum E {
1731 /// E1,
1732 /// E2,
1733 /// };
1734 ///
1735 /// class C {
1736 /// public:
1737 /// C();
1738 /// };
1739 ///
1740 /// bool baz(int i) {
1741 /// try {
1742 /// do {
1743 /// switch (i) {
1744 /// case 1: {
1745 /// foobar();
1746 /// break;
1747 /// }
1748 /// default: {
1749 /// break;
1750 /// }
1751 /// }
1752 /// } while (--i);
1753 /// return true;
1754 /// } catch (...) {
1755 /// handleError();
1756 /// return false;
1757 /// }
1758 /// }
1759 ///
1760 /// void foo(bool b) {
1761 /// if (b) {
1762 /// baz(2);
1763 /// } else {
1764 /// baz(5);
1765 /// }
1766 /// }
1767 ///
1768 /// void bar() { foo(true); }
1769 /// } // namespace N
1770 /// \endcode
1772 /// Like ``Attach``, but break before braces on function, namespace and
1773 /// class definitions.
1774 /// \code
1775 /// namespace N
1776 /// {
1777 /// enum E {
1778 /// E1,
1779 /// E2,
1780 /// };
1781 ///
1782 /// class C
1783 /// {
1784 /// public:
1785 /// C();
1786 /// };
1787 ///
1788 /// bool baz(int i)
1789 /// {
1790 /// try {
1791 /// do {
1792 /// switch (i) {
1793 /// case 1: {
1794 /// foobar();
1795 /// break;
1796 /// }
1797 /// default: {
1798 /// break;
1799 /// }
1800 /// }
1801 /// } while (--i);
1802 /// return true;
1803 /// } catch (...) {
1804 /// handleError();
1805 /// return false;
1806 /// }
1807 /// }
1808 ///
1809 /// void foo(bool b)
1810 /// {
1811 /// if (b) {
1812 /// baz(2);
1813 /// } else {
1814 /// baz(5);
1815 /// }
1816 /// }
1817 ///
1818 /// void bar() { foo(true); }
1819 /// } // namespace N
1820 /// \endcode
1822 /// Like ``Attach``, but break before braces on enum, function, and record
1823 /// definitions.
1824 /// \code
1825 /// namespace N {
1826 /// enum E
1827 /// {
1828 /// E1,
1829 /// E2,
1830 /// };
1831 ///
1832 /// class C
1833 /// {
1834 /// public:
1835 /// C();
1836 /// };
1837 ///
1838 /// bool baz(int i)
1839 /// {
1840 /// try {
1841 /// do {
1842 /// switch (i) {
1843 /// case 1: {
1844 /// foobar();
1845 /// break;
1846 /// }
1847 /// default: {
1848 /// break;
1849 /// }
1850 /// }
1851 /// } while (--i);
1852 /// return true;
1853 /// } catch (...) {
1854 /// handleError();
1855 /// return false;
1856 /// }
1857 /// }
1858 ///
1859 /// void foo(bool b)
1860 /// {
1861 /// if (b) {
1862 /// baz(2);
1863 /// } else {
1864 /// baz(5);
1865 /// }
1866 /// }
1867 ///
1868 /// void bar() { foo(true); }
1869 /// } // namespace N
1870 /// \endcode
1872 /// Like ``Attach``, but break before function definitions, ``catch``, and
1873 /// ``else``.
1874 /// \code
1875 /// namespace N {
1876 /// enum E {
1877 /// E1,
1878 /// E2,
1879 /// };
1880 ///
1881 /// class C {
1882 /// public:
1883 /// C();
1884 /// };
1885 ///
1886 /// bool baz(int i)
1887 /// {
1888 /// try {
1889 /// do {
1890 /// switch (i) {
1891 /// case 1: {
1892 /// foobar();
1893 /// break;
1894 /// }
1895 /// default: {
1896 /// break;
1897 /// }
1898 /// }
1899 /// } while (--i);
1900 /// return true;
1901 /// }
1902 /// catch (...) {
1903 /// handleError();
1904 /// return false;
1905 /// }
1906 /// }
1907 ///
1908 /// void foo(bool b)
1909 /// {
1910 /// if (b) {
1911 /// baz(2);
1912 /// }
1913 /// else {
1914 /// baz(5);
1915 /// }
1916 /// }
1917 ///
1918 /// void bar() { foo(true); }
1919 /// } // namespace N
1920 /// \endcode
1922 /// Always break before braces.
1923 /// \code
1924 /// namespace N
1925 /// {
1926 /// enum E
1927 /// {
1928 /// E1,
1929 /// E2,
1930 /// };
1931 ///
1932 /// class C
1933 /// {
1934 /// public:
1935 /// C();
1936 /// };
1937 ///
1938 /// bool baz(int i)
1939 /// {
1940 /// try
1941 /// {
1942 /// do
1943 /// {
1944 /// switch (i)
1945 /// {
1946 /// case 1:
1947 /// {
1948 /// foobar();
1949 /// break;
1950 /// }
1951 /// default:
1952 /// {
1953 /// break;
1954 /// }
1955 /// }
1956 /// } while (--i);
1957 /// return true;
1958 /// }
1959 /// catch (...)
1960 /// {
1961 /// handleError();
1962 /// return false;
1963 /// }
1964 /// }
1965 ///
1966 /// void foo(bool b)
1967 /// {
1968 /// if (b)
1969 /// {
1970 /// baz(2);
1971 /// }
1972 /// else
1973 /// {
1974 /// baz(5);
1975 /// }
1976 /// }
1977 ///
1978 /// void bar() { foo(true); }
1979 /// } // namespace N
1980 /// \endcode
1982 /// Like ``Allman`` but always indent braces and line up code with braces.
1983 /// \code
1984 /// namespace N
1985 /// {
1986 /// enum E
1987 /// {
1988 /// E1,
1989 /// E2,
1990 /// };
1991 ///
1992 /// class C
1993 /// {
1994 /// public:
1995 /// C();
1996 /// };
1997 ///
1998 /// bool baz(int i)
1999 /// {
2000 /// try
2001 /// {
2002 /// do
2003 /// {
2004 /// switch (i)
2005 /// {
2006 /// case 1:
2007 /// {
2008 /// foobar();
2009 /// break;
2010 /// }
2011 /// default:
2012 /// {
2013 /// break;
2014 /// }
2015 /// }
2016 /// } while (--i);
2017 /// return true;
2018 /// }
2019 /// catch (...)
2020 /// {
2021 /// handleError();
2022 /// return false;
2023 /// }
2024 /// }
2025 ///
2026 /// void foo(bool b)
2027 /// {
2028 /// if (b)
2029 /// {
2030 /// baz(2);
2031 /// }
2032 /// else
2033 /// {
2034 /// baz(5);
2035 /// }
2036 /// }
2037 ///
2038 /// void bar() { foo(true); }
2039 /// } // namespace N
2040 /// \endcode
2042 /// Always break before braces and add an extra level of indentation to
2043 /// braces of control statements, not to those of class, function
2044 /// or other definitions.
2045 /// \code
2046 /// namespace N
2047 /// {
2048 /// enum E
2049 /// {
2050 /// E1,
2051 /// E2,
2052 /// };
2053 ///
2054 /// class C
2055 /// {
2056 /// public:
2057 /// C();
2058 /// };
2059 ///
2060 /// bool baz(int i)
2061 /// {
2062 /// try
2063 /// {
2064 /// do
2065 /// {
2066 /// switch (i)
2067 /// {
2068 /// case 1:
2069 /// {
2070 /// foobar();
2071 /// break;
2072 /// }
2073 /// default:
2074 /// {
2075 /// break;
2076 /// }
2077 /// }
2078 /// }
2079 /// while (--i);
2080 /// return true;
2081 /// }
2082 /// catch (...)
2083 /// {
2084 /// handleError();
2085 /// return false;
2086 /// }
2087 /// }
2088 ///
2089 /// void foo(bool b)
2090 /// {
2091 /// if (b)
2092 /// {
2093 /// baz(2);
2094 /// }
2095 /// else
2096 /// {
2097 /// baz(5);
2098 /// }
2099 /// }
2100 ///
2101 /// void bar() { foo(true); }
2102 /// } // namespace N
2103 /// \endcode
2105 /// Like ``Attach``, but break before functions.
2106 /// \code
2107 /// namespace N {
2108 /// enum E {
2109 /// E1,
2110 /// E2,
2111 /// };
2112 ///
2113 /// class C {
2114 /// public:
2115 /// C();
2116 /// };
2117 ///
2118 /// bool baz(int i)
2119 /// {
2120 /// try {
2121 /// do {
2122 /// switch (i) {
2123 /// case 1: {
2124 /// foobar();
2125 /// break;
2126 /// }
2127 /// default: {
2128 /// break;
2129 /// }
2130 /// }
2131 /// } while (--i);
2132 /// return true;
2133 /// } catch (...) {
2134 /// handleError();
2135 /// return false;
2136 /// }
2137 /// }
2138 ///
2139 /// void foo(bool b)
2140 /// {
2141 /// if (b) {
2142 /// baz(2);
2143 /// } else {
2144 /// baz(5);
2145 /// }
2146 /// }
2147 ///
2148 /// void bar() { foo(true); }
2149 /// } // namespace N
2150 /// \endcode
2152 /// Configure each individual brace in ``BraceWrapping``.
2153 BS_Custom
2155
2156 /// The brace breaking style to use.
2157 /// \version 3.7
2159
2160 /// Different ways to break before concept declarations.
2162 /// Keep the template declaration line together with ``concept``.
2163 /// \code
2164 /// template <typename T> concept C = ...;
2165 /// \endcode
2167 /// Breaking between template declaration and ``concept`` is allowed. The
2168 /// actual behavior depends on the content and line breaking rules and
2169 /// penalties.
2171 /// Always break before ``concept``, putting it in the line after the
2172 /// template declaration.
2173 /// \code
2174 /// template <typename T>
2175 /// concept C = ...;
2176 /// \endcode
2178 };
2179
2180 /// The concept declaration style to use.
2181 /// \version 12
2183
2184 /// Different ways to break ASM parameters.
2186 /// No break before inline ASM colon.
2187 /// \code
2188 /// asm volatile("string", : : val);
2189 /// \endcode
2191 /// Break before inline ASM colon if the line length is longer than column
2192 /// limit.
2193 /// \code
2194 /// asm volatile("string", : : val);
2195 /// asm("cmoveq %1, %2, %[result]"
2196 /// : [result] "=r"(result)
2197 /// : "r"(test), "r"(new), "[result]"(old));
2198 /// \endcode
2200 /// Always break before inline ASM colon.
2201 /// \code
2202 /// asm volatile("string",
2203 /// :
2204 /// : val);
2205 /// \endcode
2207 };
2208
2209 /// The inline ASM colon style to use.
2210 /// \version 16
2212
2213 /// If ``true``, ternary operators will be placed after line breaks.
2214 /// \code
2215 /// true:
2216 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
2217 /// ? firstValue
2218 /// : SecondValueVeryVeryVeryVeryLong;
2219 ///
2220 /// false:
2221 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
2222 /// firstValue :
2223 /// SecondValueVeryVeryVeryVeryLong;
2224 /// \endcode
2225 /// \version 3.7
2227
2228 /// Different ways to break initializers.
2230 /// Break constructor initializers before the colon and after the commas.
2231 /// \code
2232 /// Constructor()
2233 /// : initializer1(),
2234 /// initializer2()
2235 /// \endcode
2237 /// Break constructor initializers before the colon and commas, and align
2238 /// the commas with the colon.
2239 /// \code
2240 /// Constructor()
2241 /// : initializer1()
2242 /// , initializer2()
2243 /// \endcode
2245 /// Break constructor initializers after the colon and commas.
2246 /// \code
2247 /// Constructor() :
2248 /// initializer1(),
2249 /// initializer2()
2250 /// \endcode
2253
2254 /// The break constructor initializers style to use.
2255 /// \version 5
2257
2258 /// If ``true``, clang-format will always break before function definition
2259 /// parameters.
2260 /// \code
2261 /// true:
2262 /// void functionDefinition(
2263 /// int A, int B) {}
2264 ///
2265 /// false:
2266 /// void functionDefinition(int A, int B) {}
2267 ///
2268 /// \endcode
2269 /// \version 19
2271
2272 /// Break after each annotation on a field in Java files.
2273 /// \code{.java}
2274 /// true: false:
2275 /// @Partial vs. @Partial @Mock DataLoad loader;
2276 /// @Mock
2277 /// DataLoad loader;
2278 /// \endcode
2279 /// \version 3.8
2281
2282 /// Allow breaking string literals when formatting.
2283 ///
2284 /// In C, C++, and Objective-C:
2285 /// \code
2286 /// true:
2287 /// const char* x = "veryVeryVeryVeryVeryVe"
2288 /// "ryVeryVeryVeryVeryVery"
2289 /// "VeryLongString";
2290 ///
2291 /// false:
2292 /// const char* x =
2293 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2294 /// \endcode
2295 ///
2296 /// In C# and Java:
2297 /// \code
2298 /// true:
2299 /// string x = "veryVeryVeryVeryVeryVe" +
2300 /// "ryVeryVeryVeryVeryVery" +
2301 /// "VeryLongString";
2302 ///
2303 /// false:
2304 /// string x =
2305 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2306 /// \endcode
2307 ///
2308 /// C# interpolated strings are not broken.
2309 ///
2310 /// In Verilog:
2311 /// \code
2312 /// true:
2313 /// string x = {"veryVeryVeryVeryVeryVe",
2314 /// "ryVeryVeryVeryVeryVery",
2315 /// "VeryLongString"};
2316 ///
2317 /// false:
2318 /// string x =
2319 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2320 /// \endcode
2321 ///
2322 /// \version 3.9
2324
2325 /// The column limit.
2326 ///
2327 /// A column limit of ``0`` means that there is no column limit. In this case,
2328 /// clang-format will respect the input's line breaking decisions within
2329 /// statements unless they contradict other rules.
2330 /// \version 3.7
2331 unsigned ColumnLimit;
2332
2333 /// A regular expression that describes comments with special meaning,
2334 /// which should not be split into lines or otherwise changed.
2335 /// \code
2336 /// // CommentPragmas: '^ FOOBAR pragma:'
2337 /// // Will leave the following line unaffected
2338 /// #include <vector> // FOOBAR pragma: keep
2339 /// \endcode
2340 /// \version 3.7
2341 std::string CommentPragmas;
2342
2343 /// Different ways to break inheritance list.
2345 /// Break inheritance list before the colon and after the commas.
2346 /// \code
2347 /// class Foo
2348 /// : Base1,
2349 /// Base2
2350 /// {};
2351 /// \endcode
2353 /// Break inheritance list before the colon and commas, and align
2354 /// the commas with the colon.
2355 /// \code
2356 /// class Foo
2357 /// : Base1
2358 /// , Base2
2359 /// {};
2360 /// \endcode
2362 /// Break inheritance list after the colon and commas.
2363 /// \code
2364 /// class Foo :
2365 /// Base1,
2366 /// Base2
2367 /// {};
2368 /// \endcode
2370 /// Break inheritance list only after the commas.
2371 /// \code
2372 /// class Foo : Base1,
2373 /// Base2
2374 /// {};
2375 /// \endcode
2377 };
2378
2379 /// The inheritance list style to use.
2380 /// \version 7
2382
2383 /// The template declaration breaking style to use.
2384 /// \version 19
2386
2387 /// If ``true``, consecutive namespace declarations will be on the same
2388 /// line. If ``false``, each namespace is declared on a new line.
2389 /// \code
2390 /// true:
2391 /// namespace Foo { namespace Bar {
2392 /// }}
2393 ///
2394 /// false:
2395 /// namespace Foo {
2396 /// namespace Bar {
2397 /// }
2398 /// }
2399 /// \endcode
2400 ///
2401 /// If it does not fit on a single line, the overflowing namespaces get
2402 /// wrapped:
2403 /// \code
2404 /// namespace Foo { namespace Bar {
2405 /// namespace Extra {
2406 /// }}}
2407 /// \endcode
2408 /// \version 5
2410
2411 /// This option is **deprecated**. See ``CurrentLine`` of
2412 /// ``PackConstructorInitializers``.
2413 /// \version 3.7
2414 // bool ConstructorInitializerAllOnOneLineOrOnePerLine;
2415
2416 /// The number of characters to use for indentation of constructor
2417 /// initializer lists as well as inheritance lists.
2418 /// \version 3.7
2420
2421 /// Indent width for line continuations.
2422 /// \code
2423 /// ContinuationIndentWidth: 2
2424 ///
2425 /// int i = // VeryVeryVeryVeryVeryLongComment
2426 /// longFunction( // Again a long comment
2427 /// arg);
2428 /// \endcode
2429 /// \version 3.7
2431
2432 /// If ``true``, format braced lists as best suited for C++11 braced
2433 /// lists.
2434 ///
2435 /// Important differences:
2436 /// - No spaces inside the braced list.
2437 /// - No line break before the closing brace.
2438 /// - Indentation with the continuation indent, not with the block indent.
2439 ///
2440 /// Fundamentally, C++11 braced lists are formatted exactly like function
2441 /// calls would be formatted in their place. If the braced list follows a name
2442 /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were
2443 /// the parentheses of a function call with that name. If there is no name,
2444 /// a zero-length name is assumed.
2445 /// \code
2446 /// true: false:
2447 /// vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
2448 /// vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
2449 /// f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
2450 /// new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
2451 /// \endcode
2452 /// \version 3.4
2454
2455 /// This option is **deprecated**. See ``DeriveLF`` and ``DeriveCRLF`` of
2456 /// ``LineEnding``.
2457 /// \version 10
2458 // bool DeriveLineEnding;
2459
2460 /// If ``true``, analyze the formatted file for the most common
2461 /// alignment of ``&`` and ``*``.
2462 /// Pointer and reference alignment styles are going to be updated according
2463 /// to the preferences found in the file.
2464 /// ``PointerAlignment`` is then used only as fallback.
2465 /// \version 3.7
2467
2468 /// Disables formatting completely.
2469 /// \version 3.7
2471
2472 /// Different styles for empty line after access modifiers.
2473 /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2474 /// empty lines between two access modifiers.
2476 /// Remove all empty lines after access modifiers.
2477 /// \code
2478 /// struct foo {
2479 /// private:
2480 /// int i;
2481 /// protected:
2482 /// int j;
2483 /// /* comment */
2484 /// public:
2485 /// foo() {}
2486 /// private:
2487 /// protected:
2488 /// };
2489 /// \endcode
2491 /// Keep existing empty lines after access modifiers.
2492 /// MaxEmptyLinesToKeep is applied instead.
2494 /// Always add empty line after access modifiers if there are none.
2495 /// MaxEmptyLinesToKeep is applied also.
2496 /// \code
2497 /// struct foo {
2498 /// private:
2499 ///
2500 /// int i;
2501 /// protected:
2502 ///
2503 /// int j;
2504 /// /* comment */
2505 /// public:
2506 ///
2507 /// foo() {}
2508 /// private:
2509 ///
2510 /// protected:
2511 ///
2512 /// };
2513 /// \endcode
2515 };
2516
2517 /// Defines when to put an empty line after access modifiers.
2518 /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2519 /// empty lines between two access modifiers.
2520 /// \version 13
2522
2523 /// Different styles for empty line before access modifiers.
2525 /// Remove all empty lines before access modifiers.
2526 /// \code
2527 /// struct foo {
2528 /// private:
2529 /// int i;
2530 /// protected:
2531 /// int j;
2532 /// /* comment */
2533 /// public:
2534 /// foo() {}
2535 /// private:
2536 /// protected:
2537 /// };
2538 /// \endcode
2540 /// Keep existing empty lines before access modifiers.
2542 /// Add empty line only when access modifier starts a new logical block.
2543 /// Logical block is a group of one or more member fields or functions.
2544 /// \code
2545 /// struct foo {
2546 /// private:
2547 /// int i;
2548 ///
2549 /// protected:
2550 /// int j;
2551 /// /* comment */
2552 /// public:
2553 /// foo() {}
2554 ///
2555 /// private:
2556 /// protected:
2557 /// };
2558 /// \endcode
2560 /// Always add empty line before access modifiers unless access modifier
2561 /// is at the start of struct or class definition.
2562 /// \code
2563 /// struct foo {
2564 /// private:
2565 /// int i;
2566 ///
2567 /// protected:
2568 /// int j;
2569 /// /* comment */
2570 ///
2571 /// public:
2572 /// foo() {}
2573 ///
2574 /// private:
2575 ///
2576 /// protected:
2577 /// };
2578 /// \endcode
2580 };
2581
2582 /// Defines in which cases to put empty line before access modifiers.
2583 /// \version 12
2585
2586 /// If ``true``, clang-format detects whether function calls and
2587 /// definitions are formatted with one parameter per line.
2588 ///
2589 /// Each call can be bin-packed, one-per-line or inconclusive. If it is
2590 /// inconclusive, e.g. completely on one line, but a decision needs to be
2591 /// made, clang-format analyzes whether there are other bin-packed cases in
2592 /// the input file and act accordingly.
2593 ///
2594 /// \note
2595 /// This is an experimental flag, that might go away or be renamed. Do
2596 /// not use this in config files, etc. Use at your own risk.
2597 /// \endnote
2598 /// \version 3.7
2600
2601 /// If ``true``, clang-format adds missing namespace end comments for
2602 /// namespaces and fixes invalid existing ones. This doesn't affect short
2603 /// namespaces, which are controlled by ``ShortNamespaceLines``.
2604 /// \code
2605 /// true: false:
2606 /// namespace longNamespace { vs. namespace longNamespace {
2607 /// void foo(); void foo();
2608 /// void bar(); void bar();
2609 /// } // namespace a }
2610 /// namespace shortNamespace { namespace shortNamespace {
2611 /// void baz(); void baz();
2612 /// } }
2613 /// \endcode
2614 /// \version 5
2616
2617 /// A vector of macros that should be interpreted as foreach loops
2618 /// instead of as function calls.
2619 ///
2620 /// These are expected to be macros of the form:
2621 /// \code
2622 /// FOREACH(<variable-declaration>, ...)
2623 /// <loop-body>
2624 /// \endcode
2625 ///
2626 /// In the .clang-format configuration file, this can be configured like:
2627 /// \code{.yaml}
2628 /// ForEachMacros: ['RANGES_FOR', 'FOREACH']
2629 /// \endcode
2630 ///
2631 /// For example: BOOST_FOREACH.
2632 /// \version 3.7
2633 std::vector<std::string> ForEachMacros;
2634
2636
2637 /// A vector of macros that should be interpreted as conditionals
2638 /// instead of as function calls.
2639 ///
2640 /// These are expected to be macros of the form:
2641 /// \code
2642 /// IF(...)
2643 /// <conditional-body>
2644 /// else IF(...)
2645 /// <conditional-body>
2646 /// \endcode
2647 ///
2648 /// In the .clang-format configuration file, this can be configured like:
2649 /// \code{.yaml}
2650 /// IfMacros: ['IF']
2651 /// \endcode
2652 ///
2653 /// For example: `KJ_IF_MAYBE
2654 /// <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_
2655 /// \version 13
2656 std::vector<std::string> IfMacros;
2657
2658 /// Specify whether access modifiers should have their own indentation level.
2659 ///
2660 /// When ``false``, access modifiers are indented (or outdented) relative to
2661 /// the record members, respecting the ``AccessModifierOffset``. Record
2662 /// members are indented one level below the record.
2663 /// When ``true``, access modifiers get their own indentation level. As a
2664 /// consequence, record members are always indented 2 levels below the record,
2665 /// regardless of the access modifier presence. Value of the
2666 /// ``AccessModifierOffset`` is ignored.
2667 /// \code
2668 /// false: true:
2669 /// class C { vs. class C {
2670 /// class D { class D {
2671 /// void bar(); void bar();
2672 /// protected: protected:
2673 /// D(); D();
2674 /// }; };
2675 /// public: public:
2676 /// C(); C();
2677 /// }; };
2678 /// void foo() { void foo() {
2679 /// return 1; return 1;
2680 /// } }
2681 /// \endcode
2682 /// \version 13
2684
2685 /// Indent case label blocks one level from the case label.
2686 ///
2687 /// When ``false``, the block following the case label uses the same
2688 /// indentation level as for the case label, treating the case label the same
2689 /// as an if-statement.
2690 /// When ``true``, the block gets indented as a scope block.
2691 /// \code
2692 /// false: true:
2693 /// switch (fool) { vs. switch (fool) {
2694 /// case 1: { case 1:
2695 /// bar(); {
2696 /// } break; bar();
2697 /// default: { }
2698 /// plop(); break;
2699 /// } default:
2700 /// } {
2701 /// plop();
2702 /// }
2703 /// }
2704 /// \endcode
2705 /// \version 11
2707
2708 /// Indent case labels one level from the switch statement.
2709 ///
2710 /// When ``false``, use the same indentation level as for the switch
2711 /// statement. Switch statement body is always indented one level more than
2712 /// case labels (except the first block following the case label, which
2713 /// itself indents the code - unless IndentCaseBlocks is enabled).
2714 /// \code
2715 /// false: true:
2716 /// switch (fool) { vs. switch (fool) {
2717 /// case 1: case 1:
2718 /// bar(); bar();
2719 /// break; break;
2720 /// default: default:
2721 /// plop(); plop();
2722 /// } }
2723 /// \endcode
2724 /// \version 3.3
2726
2727 /// Indent goto labels.
2728 ///
2729 /// When ``false``, goto labels are flushed left.
2730 /// \code
2731 /// true: false:
2732 /// int f() { vs. int f() {
2733 /// if (foo()) { if (foo()) {
2734 /// label1: label1:
2735 /// bar(); bar();
2736 /// } }
2737 /// label2: label2:
2738 /// return 1; return 1;
2739 /// } }
2740 /// \endcode
2741 /// \version 10
2743
2744 /// Indents extern blocks
2746 /// Backwards compatible with AfterExternBlock's indenting.
2747 /// \code
2748 /// IndentExternBlock: AfterExternBlock
2749 /// BraceWrapping.AfterExternBlock: true
2750 /// extern "C"
2751 /// {
2752 /// void foo();
2753 /// }
2754 /// \endcode
2755 ///
2756 /// \code
2757 /// IndentExternBlock: AfterExternBlock
2758 /// BraceWrapping.AfterExternBlock: false
2759 /// extern "C" {
2760 /// void foo();
2761 /// }
2762 /// \endcode
2764 /// Does not indent extern blocks.
2765 /// \code
2766 /// extern "C" {
2767 /// void foo();
2768 /// }
2769 /// \endcode
2771 /// Indents extern blocks.
2772 /// \code
2773 /// extern "C" {
2774 /// void foo();
2775 /// }
2776 /// \endcode
2778 };
2779
2780 /// IndentExternBlockStyle is the type of indenting of extern blocks.
2781 /// \version 11
2783
2784 /// Options for indenting preprocessor directives.
2786 /// Does not indent any directives.
2787 /// \code
2788 /// #if FOO
2789 /// #if BAR
2790 /// #include <foo>
2791 /// #endif
2792 /// #endif
2793 /// \endcode
2795 /// Indents directives after the hash.
2796 /// \code
2797 /// #if FOO
2798 /// # if BAR
2799 /// # include <foo>
2800 /// # endif
2801 /// #endif
2802 /// \endcode
2804 /// Indents directives before the hash.
2805 /// \code
2806 /// #if FOO
2807 /// #if BAR
2808 /// #include <foo>
2809 /// #endif
2810 /// #endif
2811 /// \endcode
2814
2815 /// The preprocessor directive indenting style to use.
2816 /// \version 6
2818
2819 /// Indent the requires clause in a template. This only applies when
2820 /// ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
2821 ///
2822 /// In clang-format 12, 13 and 14 it was named ``IndentRequires``.
2823 /// \code
2824 /// true:
2825 /// template <typename It>
2826 /// requires Iterator<It>
2827 /// void sort(It begin, It end) {
2828 /// //....
2829 /// }
2830 ///
2831 /// false:
2832 /// template <typename It>
2833 /// requires Iterator<It>
2834 /// void sort(It begin, It end) {
2835 /// //....
2836 /// }
2837 /// \endcode
2838 /// \version 15
2840
2841 /// The number of columns to use for indentation.
2842 /// \code
2843 /// IndentWidth: 3
2844 ///
2845 /// void f() {
2846 /// someFunction();
2847 /// if (true, false) {
2848 /// f();
2849 /// }
2850 /// }
2851 /// \endcode
2852 /// \version 3.7
2853 unsigned IndentWidth;
2854
2855 /// Indent if a function definition or declaration is wrapped after the
2856 /// type.
2857 /// \code
2858 /// true:
2859 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
2860 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2861 ///
2862 /// false:
2863 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
2864 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2865 /// \endcode
2866 /// \version 3.7
2868
2869 /// Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
2870 /// and ``while``) in C++ unless the control statements are inside macro
2871 /// definitions or the braces would enclose preprocessor directives.
2872 /// \warning
2873 /// Setting this option to ``true`` could lead to incorrect code formatting
2874 /// due to clang-format's lack of complete semantic information. As such,
2875 /// extra care should be taken to review code changes made by this option.
2876 /// \endwarning
2877 /// \code
2878 /// false: true:
2879 ///
2880 /// if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
2881 /// handleFunctionDecl(D); handleFunctionDecl(D);
2882 /// else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
2883 /// handleVarDecl(D); handleVarDecl(D);
2884 /// else } else {
2885 /// return; return;
2886 /// }
2887 ///
2888 /// while (i--) vs. while (i--) {
2889 /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
2890 /// handleAttr(A); handleAttr(A);
2891 /// }
2892 /// }
2893 ///
2894 /// do vs. do {
2895 /// --i; --i;
2896 /// while (i); } while (i);
2897 /// \endcode
2898 /// \version 15
2900
2901 /// Insert a newline at end of file if missing.
2902 /// \version 16
2904
2905 /// The style of inserting trailing commas into container literals.
2906 enum TrailingCommaStyle : int8_t {
2907 /// Do not insert trailing commas.
2909 /// Insert trailing commas in container literals that were wrapped over
2910 /// multiple lines. Note that this is conceptually incompatible with
2911 /// bin-packing, because the trailing comma is used as an indicator
2912 /// that a container should be formatted one-per-line (i.e. not bin-packed).
2913 /// So inserting a trailing comma counteracts bin-packing.
2915 };
2916
2917 /// If set to ``TCS_Wrapped`` will insert trailing commas in container
2918 /// literals (arrays and objects) that wrap across multiple lines.
2919 /// It is currently only available for JavaScript
2920 /// and disabled by default ``TCS_None``.
2921 /// ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
2922 /// as inserting the comma disables bin-packing.
2923 /// \code
2924 /// TSC_Wrapped:
2925 /// const someArray = [
2926 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
2927 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
2928 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
2929 /// // ^ inserted
2930 /// ]
2931 /// \endcode
2932 /// \version 11
2934
2935 /// Separator format of integer literals of different bases.
2936 ///
2937 /// If negative, remove separators. If ``0``, leave the literal as is. If
2938 /// positive, insert separators between digits starting from the rightmost
2939 /// digit.
2940 ///
2941 /// For example, the config below will leave separators in binary literals
2942 /// alone, insert separators in decimal literals to separate the digits into
2943 /// groups of 3, and remove separators in hexadecimal literals.
2944 /// \code
2945 /// IntegerLiteralSeparator:
2946 /// Binary: 0
2947 /// Decimal: 3
2948 /// Hex: -1
2949 /// \endcode
2950 ///
2951 /// You can also specify a minimum number of digits (``BinaryMinDigits``,
2952 /// ``DecimalMinDigits``, and ``HexMinDigits``) the integer literal must
2953 /// have in order for the separators to be inserted.
2955 /// Format separators in binary literals.
2956 /// \code{.text}
2957 /// /* -1: */ b = 0b100111101101;
2958 /// /* 0: */ b = 0b10011'11'0110'1;
2959 /// /* 3: */ b = 0b100'111'101'101;
2960 /// /* 4: */ b = 0b1001'1110'1101;
2961 /// \endcode
2962 int8_t Binary;
2963 /// Format separators in binary literals with a minimum number of digits.
2964 /// \code{.text}
2965 /// // Binary: 3
2966 /// // BinaryMinDigits: 7
2967 /// b1 = 0b101101;
2968 /// b2 = 0b1'101'101;
2969 /// \endcode
2971 /// Format separators in decimal literals.
2972 /// \code{.text}
2973 /// /* -1: */ d = 18446744073709550592ull;
2974 /// /* 0: */ d = 184467'440737'0'95505'92ull;
2975 /// /* 3: */ d = 18'446'744'073'709'550'592ull;
2976 /// \endcode
2977 int8_t Decimal;
2978 /// Format separators in decimal literals with a minimum number of digits.
2979 /// \code{.text}
2980 /// // Decimal: 3
2981 /// // DecimalMinDigits: 5
2982 /// d1 = 2023;
2983 /// d2 = 10'000;
2984 /// \endcode
2986 /// Format separators in hexadecimal literals.
2987 /// \code{.text}
2988 /// /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
2989 /// /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
2990 /// /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
2991 /// \endcode
2992 int8_t Hex;
2993 /// Format separators in hexadecimal literals with a minimum number of
2994 /// digits.
2995 /// \code{.text}
2996 /// // Hex: 2
2997 /// // HexMinDigits: 6
2998 /// h1 = 0xABCDE;
2999 /// h2 = 0xAB'CD'EF;
3000 /// \endcode
3003 return Binary == R.Binary && BinaryMinDigits == R.BinaryMinDigits &&
3005 Hex == R.Hex && HexMinDigits == R.HexMinDigits;
3006 }
3007 };
3008
3009 /// Format integer literal separators (``'`` for C++ and ``_`` for C#, Java,
3010 /// and JavaScript).
3011 /// \version 16
3013
3014 /// A vector of prefixes ordered by the desired groups for Java imports.
3015 ///
3016 /// One group's prefix can be a subset of another - the longest prefix is
3017 /// always matched. Within a group, the imports are ordered lexicographically.
3018 /// Static imports are grouped separately and follow the same group rules.
3019 /// By default, static imports are placed before non-static imports,
3020 /// but this behavior is changed by another option,
3021 /// ``SortJavaStaticImport``.
3022 ///
3023 /// In the .clang-format configuration file, this can be configured like
3024 /// in the following yaml example. This will result in imports being
3025 /// formatted as in the Java example below.
3026 /// \code{.yaml}
3027 /// JavaImportGroups: ['com.example', 'com', 'org']
3028 /// \endcode
3029 ///
3030 /// \code{.java}
3031 /// import static com.example.function1;
3032 ///
3033 /// import static com.test.function2;
3034 ///
3035 /// import static org.example.function3;
3036 ///
3037 /// import com.example.ClassA;
3038 /// import com.example.Test;
3039 /// import com.example.a.ClassB;
3040 ///
3041 /// import com.test.ClassC;
3042 ///
3043 /// import org.example.ClassD;
3044 /// \endcode
3045 /// \version 8
3046 std::vector<std::string> JavaImportGroups;
3047
3048 /// Quotation styles for JavaScript strings. Does not affect template
3049 /// strings.
3050 enum JavaScriptQuoteStyle : int8_t {
3051 /// Leave string quotes as they are.
3052 /// \code{.js}
3053 /// string1 = "foo";
3054 /// string2 = 'bar';
3055 /// \endcode
3057 /// Always use single quotes.
3058 /// \code{.js}
3059 /// string1 = 'foo';
3060 /// string2 = 'bar';
3061 /// \endcode
3063 /// Always use double quotes.
3064 /// \code{.js}
3065 /// string1 = "foo";
3066 /// string2 = "bar";
3067 /// \endcode
3070
3071 /// The JavaScriptQuoteStyle to use for JavaScript strings.
3072 /// \version 3.9
3074
3075 // clang-format off
3076 /// Whether to wrap JavaScript import/export statements.
3077 /// \code{.js}
3078 /// true:
3079 /// import {
3080 /// VeryLongImportsAreAnnoying,
3081 /// VeryLongImportsAreAnnoying,
3082 /// VeryLongImportsAreAnnoying,
3083 /// } from 'some/module.js'
3084 ///
3085 /// false:
3086 /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3087 /// \endcode
3088 /// \version 3.9
3090 // clang-format on
3091
3092 /// Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file.
3093 /// \version 17
3095
3096 /// If true, the empty line at the start of blocks is kept.
3097 /// \code
3098 /// true: false:
3099 /// if (foo) { vs. if (foo) {
3100 /// bar();
3101 /// bar(); }
3102 /// }
3103 /// \endcode
3104 /// \version 3.7
3106
3107 /// Indentation logic for lambda bodies.
3109 /// Align lambda body relative to the lambda signature. This is the default.
3110 /// \code
3111 /// someMethod(
3112 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3113 /// return;
3114 /// });
3115 /// \endcode
3117 /// For statements within block scope, align lambda body relative to the
3118 /// indentation level of the outer scope the lambda signature resides in.
3119 /// \code
3120 /// someMethod(
3121 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3122 /// return;
3123 /// });
3124 ///
3125 /// someMethod(someOtherMethod(
3126 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3127 /// return;
3128 /// }));
3129 /// \endcode
3131 };
3132
3133 /// The indentation style of lambda bodies. ``Signature`` (the default)
3134 /// causes the lambda body to be indented one additional level relative to
3135 /// the indentation level of the signature. ``OuterScope`` forces the lambda
3136 /// body to be indented one additional level relative to the parent scope
3137 /// containing the lambda signature.
3138 /// \version 13
3140
3141 /// Supported languages.
3142 ///
3143 /// When stored in a configuration file, specifies the language, that the
3144 /// configuration targets. When passed to the ``reformat()`` function, enables
3145 /// syntax features specific to the language.
3146 enum LanguageKind : int8_t {
3147 /// Do not use.
3149 /// Should be used for C, C++.
3151 /// Should be used for C#.
3153 /// Should be used for Java.
3155 /// Should be used for JavaScript.
3157 /// Should be used for JSON.
3159 /// Should be used for Objective-C, Objective-C++.
3161 /// Should be used for Protocol Buffers
3162 /// (https://developers.google.com/protocol-buffers/).
3164 /// Should be used for TableGen code.
3166 /// Should be used for Protocol Buffer messages in text format
3167 /// (https://developers.google.com/protocol-buffers/).
3169 /// Should be used for Verilog and SystemVerilog.
3170 /// https://standards.ieee.org/ieee/1800/6700/
3171 /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3174 bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
3175 bool isCSharp() const { return Language == LK_CSharp; }
3176 bool isJson() const { return Language == LK_Json; }
3177 bool isJavaScript() const { return Language == LK_JavaScript; }
3178 bool isVerilog() const { return Language == LK_Verilog; }
3179 bool isProto() const {
3180 return Language == LK_Proto || Language == LK_TextProto;
3181 }
3182 bool isTableGen() const { return Language == LK_TableGen; }
3183
3184 /// Language, this format style is targeted at.
3185 /// \version 3.5
3187
3188 /// Line ending style.
3189 enum LineEndingStyle : int8_t {
3190 /// Use ``\n``.
3192 /// Use ``\r\n``.
3194 /// Use ``\n`` unless the input has more lines ending in ``\r\n``.
3196 /// Use ``\r\n`` unless the input has more lines ending in ``\n``.
3198 };
3199
3200 /// Line ending style (``\n`` or ``\r\n``) to use.
3201 /// \version 16
3203
3204 /// A regular expression matching macros that start a block.
3205 /// \code
3206 /// # With:
3207 /// MacroBlockBegin: "^NS_MAP_BEGIN|\
3208 /// NS_TABLE_HEAD$"
3209 /// MacroBlockEnd: "^\
3210 /// NS_MAP_END|\
3211 /// NS_TABLE_.*_END$"
3212 ///
3213 /// NS_MAP_BEGIN
3214 /// foo();
3215 /// NS_MAP_END
3216 ///
3217 /// NS_TABLE_HEAD
3218 /// bar();
3219 /// NS_TABLE_FOO_END
3220 ///
3221 /// # Without:
3222 /// NS_MAP_BEGIN
3223 /// foo();
3224 /// NS_MAP_END
3225 ///
3226 /// NS_TABLE_HEAD
3227 /// bar();
3228 /// NS_TABLE_FOO_END
3229 /// \endcode
3230 /// \version 3.7
3231 std::string MacroBlockBegin;
3232
3233 /// A regular expression matching macros that end a block.
3234 /// \version 3.7
3235 std::string MacroBlockEnd;
3236
3237 /// A list of macros of the form \c <definition>=<expansion> .
3238 ///
3239 /// Code will be parsed with macros expanded, in order to determine how to
3240 /// interpret and format the macro arguments.
3241 ///
3242 /// For example, the code:
3243 /// \code
3244 /// A(a*b);
3245 /// \endcode
3246 ///
3247 /// will usually be interpreted as a call to a function A, and the
3248 /// multiplication expression will be formatted as ``a * b``.
3249 ///
3250 /// If we specify the macro definition:
3251 /// \code{.yaml}
3252 /// Macros:
3253 /// - A(x)=x
3254 /// \endcode
3255 ///
3256 /// the code will now be parsed as a declaration of the variable b of type a*,
3257 /// and formatted as ``a* b`` (depending on pointer-binding rules).
3258 ///
3259 /// Features and restrictions:
3260 /// * Both function-like macros and object-like macros are supported.
3261 /// * Macro arguments must be used exactly once in the expansion.
3262 /// * No recursive expansion; macros referencing other macros will be
3263 /// ignored.
3264 /// * Overloading by arity is supported: for example, given the macro
3265 /// definitions A=x, A()=y, A(a)=a
3266 ///
3267 /// \code
3268 /// A; -> x;
3269 /// A(); -> y;
3270 /// A(z); -> z;
3271 /// A(a, b); // will not be expanded.
3272 /// \endcode
3273 ///
3274 /// \version 17
3275 std::vector<std::string> Macros;
3276
3277 /// The maximum number of consecutive empty lines to keep.
3278 /// \code
3279 /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
3280 /// int f() { int f() {
3281 /// int = 1; int i = 1;
3282 /// i = foo();
3283 /// i = foo(); return i;
3284 /// }
3285 /// return i;
3286 /// }
3287 /// \endcode
3288 /// \version 3.7
3290
3291 /// Different ways to indent namespace contents.
3293 /// Don't indent in namespaces.
3294 /// \code
3295 /// namespace out {
3296 /// int i;
3297 /// namespace in {
3298 /// int i;
3299 /// }
3300 /// }
3301 /// \endcode
3303 /// Indent only in inner namespaces (nested in other namespaces).
3304 /// \code
3305 /// namespace out {
3306 /// int i;
3307 /// namespace in {
3308 /// int i;
3309 /// }
3310 /// }
3311 /// \endcode
3313 /// Indent in all namespaces.
3314 /// \code
3315 /// namespace out {
3316 /// int i;
3317 /// namespace in {
3318 /// int i;
3319 /// }
3320 /// }
3321 /// \endcode
3322 NI_All
3324
3325 /// The indentation used for namespaces.
3326 /// \version 3.7
3328
3329 /// A vector of macros which are used to open namespace blocks.
3330 ///
3331 /// These are expected to be macros of the form:
3332 /// \code
3333 /// NAMESPACE(<namespace-name>, ...) {
3334 /// <namespace-content>
3335 /// }
3336 /// \endcode
3337 ///
3338 /// For example: TESTSUITE
3339 /// \version 9
3340 std::vector<std::string> NamespaceMacros;
3341
3342 /// Controls bin-packing Objective-C protocol conformance list
3343 /// items into as few lines as possible when they go over ``ColumnLimit``.
3344 ///
3345 /// If ``Auto`` (the default), delegates to the value in
3346 /// ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
3347 /// protocol conformance list items into as few lines as possible
3348 /// whenever they go over ``ColumnLimit``.
3349 ///
3350 /// If ``Always``, always bin-packs Objective-C protocol conformance
3351 /// list items into as few lines as possible whenever they go over
3352 /// ``ColumnLimit``.
3353 ///
3354 /// If ``Never``, lays out Objective-C protocol conformance list items
3355 /// onto individual lines whenever they go over ``ColumnLimit``.
3356 ///
3357 /// \code{.objc}
3358 /// Always (or Auto, if BinPackParameters=true):
3359 /// @interface ccccccccccccc () <
3360 /// ccccccccccccc, ccccccccccccc,
3361 /// ccccccccccccc, ccccccccccccc> {
3362 /// }
3363 ///
3364 /// Never (or Auto, if BinPackParameters=false):
3365 /// @interface ddddddddddddd () <
3366 /// ddddddddddddd,
3367 /// ddddddddddddd,
3368 /// ddddddddddddd,
3369 /// ddddddddddddd> {
3370 /// }
3371 /// \endcode
3372 /// \version 7
3374
3375 /// The number of characters to use for indentation of ObjC blocks.
3376 /// \code{.objc}
3377 /// ObjCBlockIndentWidth: 4
3378 ///
3379 /// [operation setCompletionBlock:^{
3380 /// [self onOperationDone];
3381 /// }];
3382 /// \endcode
3383 /// \version 3.7
3385
3386 /// Break parameters list into lines when there is nested block
3387 /// parameters in a function call.
3388 /// \code
3389 /// false:
3390 /// - (void)_aMethod
3391 /// {
3392 /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
3393 /// *u, NSNumber *v) {
3394 /// u = c;
3395 /// }]
3396 /// }
3397 /// true:
3398 /// - (void)_aMethod
3399 /// {
3400 /// [self.test1 t:self
3401 /// w:self
3402 /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
3403 /// u = c;
3404 /// }]
3405 /// }
3406 /// \endcode
3407 /// \version 11
3409
3410 /// The order in which ObjC property attributes should appear.
3411 ///
3412 /// Attributes in code will be sorted in the order specified. Any attributes
3413 /// encountered that are not mentioned in this array will be sorted last, in
3414 /// stable order. Comments between attributes will leave the attributes
3415 /// untouched.
3416 /// \warning
3417 /// Using this option could lead to incorrect code formatting due to
3418 /// clang-format's lack of complete semantic information. As such, extra
3419 /// care should be taken to review code changes made by this option.
3420 /// \endwarning
3421 /// \code{.yaml}
3422 /// ObjCPropertyAttributeOrder: [
3423 /// class, direct,
3424 /// atomic, nonatomic,
3425 /// assign, retain, strong, copy, weak, unsafe_unretained,
3426 /// readonly, readwrite, getter, setter,
3427 /// nullable, nonnull, null_resettable, null_unspecified
3428 /// ]
3429 /// \endcode
3430 /// \version 18
3431 std::vector<std::string> ObjCPropertyAttributeOrder;
3432
3433 /// Add a space after ``@property`` in Objective-C, i.e. use
3434 /// ``@property (readonly)`` instead of ``@property(readonly)``.
3435 /// \version 3.7
3437
3438 /// Add a space in front of an Objective-C protocol list, i.e. use
3439 /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
3440 /// \version 3.7
3442
3443 /// Different ways to try to fit all constructor initializers on a line.
3445 /// Always put each constructor initializer on its own line.
3446 /// \code
3447 /// Constructor()
3448 /// : a(),
3449 /// b()
3450 /// \endcode
3452 /// Bin-pack constructor initializers.
3453 /// \code
3454 /// Constructor()
3455 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
3456 /// cccccccccccccccccccc()
3457 /// \endcode
3459 /// Put all constructor initializers on the current line if they fit.
3460 /// Otherwise, put each one on its own line.
3461 /// \code
3462 /// Constructor() : a(), b()
3463 ///
3464 /// Constructor()
3465 /// : aaaaaaaaaaaaaaaaaaaa(),
3466 /// bbbbbbbbbbbbbbbbbbbb(),
3467 /// ddddddddddddd()
3468 /// \endcode
3470 /// Same as ``PCIS_CurrentLine`` except that if all constructor initializers
3471 /// do not fit on the current line, try to fit them on the next line.
3472 /// \code
3473 /// Constructor() : a(), b()
3474 ///
3475 /// Constructor()
3476 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3477 ///
3478 /// Constructor()
3479 /// : aaaaaaaaaaaaaaaaaaaa(),
3480 /// bbbbbbbbbbbbbbbbbbbb(),
3481 /// cccccccccccccccccccc()
3482 /// \endcode
3484 /// Put all constructor initializers on the next line if they fit.
3485 /// Otherwise, put each one on its own line.
3486 /// \code
3487 /// Constructor()
3488 /// : a(), b()
3489 ///
3490 /// Constructor()
3491 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3492 ///
3493 /// Constructor()
3494 /// : aaaaaaaaaaaaaaaaaaaa(),
3495 /// bbbbbbbbbbbbbbbbbbbb(),
3496 /// cccccccccccccccccccc()
3497 /// \endcode
3499 };
3500
3501 /// The pack constructor initializers style to use.
3502 /// \version 14
3504
3505 /// The penalty for breaking around an assignment operator.
3506 /// \version 5
3508
3509 /// The penalty for breaking a function call after ``call(``.
3510 /// \version 3.7
3512
3513 /// The penalty for each line break introduced inside a comment.
3514 /// \version 3.7
3516
3517 /// The penalty for breaking before the first ``<<``.
3518 /// \version 3.7
3520
3521 /// The penalty for breaking after ``(``.
3522 /// \version 14
3524
3525 /// The penalty for breaking after ``::``.
3526 /// \version 18
3528
3529 /// The penalty for each line break introduced inside a string literal.
3530 /// \version 3.7
3532
3533 /// The penalty for breaking after template declaration.
3534 /// \version 7
3536
3537 /// The penalty for each character outside of the column limit.
3538 /// \version 3.7
3540
3541 /// Penalty for each character of whitespace indentation
3542 /// (counted relative to leading non-whitespace column).
3543 /// \version 12
3545
3546 /// Penalty for putting the return type of a function onto its own line.
3547 /// \version 3.7
3549
3550 /// The ``&``, ``&&`` and ``*`` alignment style.
3552 /// Align pointer to the left.
3553 /// \code
3554 /// int* a;
3555 /// \endcode
3557 /// Align pointer to the right.
3558 /// \code
3559 /// int *a;
3560 /// \endcode
3562 /// Align pointer in the middle.
3563 /// \code
3564 /// int * a;
3565 /// \endcode
3568
3569 /// Pointer and reference alignment style.
3570 /// \version 3.7
3572
3573 /// The number of columns to use for indentation of preprocessor statements.
3574 /// When set to -1 (default) ``IndentWidth`` is used also for preprocessor
3575 /// statements.
3576 /// \code
3577 /// PPIndentWidth: 1
3578 ///
3579 /// #ifdef __linux__
3580 /// # define FOO
3581 /// #else
3582 /// # define BAR
3583 /// #endif
3584 /// \endcode
3585 /// \version 13
3587
3588 /// Different specifiers and qualifiers alignment styles.
3590 /// Don't change specifiers/qualifiers to either Left or Right alignment
3591 /// (default).
3592 /// \code
3593 /// int const a;
3594 /// const int *a;
3595 /// \endcode
3597 /// Change specifiers/qualifiers to be left-aligned.
3598 /// \code
3599 /// const int a;
3600 /// const int *a;
3601 /// \endcode
3603 /// Change specifiers/qualifiers to be right-aligned.
3604 /// \code
3605 /// int const a;
3606 /// int const *a;
3607 /// \endcode
3609 /// Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.
3610 /// With:
3611 /// \code{.yaml}
3612 /// QualifierOrder: ['inline', 'static', 'type', 'const']
3613 /// \endcode
3614 ///
3615 /// \code
3616 ///
3617 /// int const a;
3618 /// int const *a;
3619 /// \endcode
3622
3623 /// Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
3624 /// \warning
3625 /// Setting ``QualifierAlignment`` to something other than ``Leave``, COULD
3626 /// lead to incorrect code formatting due to incorrect decisions made due to
3627 /// clang-formats lack of complete semantic information.
3628 /// As such extra care should be taken to review code changes made by the use
3629 /// of this option.
3630 /// \endwarning
3631 /// \version 14
3633
3634 /// The order in which the qualifiers appear.
3635 /// Order is an array that can contain any of the following:
3636 ///
3637 /// * const
3638 /// * inline
3639 /// * static
3640 /// * friend
3641 /// * constexpr
3642 /// * volatile
3643 /// * restrict
3644 /// * type
3645 ///
3646 /// \note
3647 /// it MUST contain 'type'.
3648 /// \endnote
3649 ///
3650 /// Items to the left of 'type' will be placed to the left of the type and
3651 /// aligned in the order supplied. Items to the right of 'type' will be
3652 /// placed to the right of the type and aligned in the order supplied.
3653 ///
3654 /// \code{.yaml}
3655 /// QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ]
3656 /// \endcode
3657 /// \version 14
3658 std::vector<std::string> QualifierOrder;
3659
3660 /// See documentation of ``RawStringFormats``.
3662 /// The language of this raw string.
3664 /// A list of raw string delimiters that match this language.
3665 std::vector<std::string> Delimiters;
3666 /// A list of enclosing function names that match this language.
3667 std::vector<std::string> EnclosingFunctions;
3668 /// The canonical delimiter for this language.
3670 /// The style name on which this raw string format is based on.
3671 /// If not specified, the raw string format is based on the style that this
3672 /// format is based on.
3673 std::string BasedOnStyle;
3674 bool operator==(const RawStringFormat &Other) const {
3675 return Language == Other.Language && Delimiters == Other.Delimiters &&
3676 EnclosingFunctions == Other.EnclosingFunctions &&
3677 CanonicalDelimiter == Other.CanonicalDelimiter &&
3678 BasedOnStyle == Other.BasedOnStyle;
3679 }
3680 };
3681
3682 /// Defines hints for detecting supported languages code blocks in raw
3683 /// strings.
3684 ///
3685 /// A raw string with a matching delimiter or a matching enclosing function
3686 /// name will be reformatted assuming the specified language based on the
3687 /// style for that language defined in the .clang-format file. If no style has
3688 /// been defined in the .clang-format file for the specific language, a
3689 /// predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
3690 /// found, the formatting is based on llvm style. A matching delimiter takes
3691 /// precedence over a matching enclosing function name for determining the
3692 /// language of the raw string contents.
3693 ///
3694 /// If a canonical delimiter is specified, occurrences of other delimiters for
3695 /// the same language will be updated to the canonical if possible.
3696 ///
3697 /// There should be at most one specification per language and each delimiter
3698 /// and enclosing function should not occur in multiple specifications.
3699 ///
3700 /// To configure this in the .clang-format file, use:
3701 /// \code{.yaml}
3702 /// RawStringFormats:
3703 /// - Language: TextProto
3704 /// Delimiters:
3705 /// - 'pb'
3706 /// - 'proto'
3707 /// EnclosingFunctions:
3708 /// - 'PARSE_TEXT_PROTO'
3709 /// BasedOnStyle: google
3710 /// - Language: Cpp
3711 /// Delimiters:
3712 /// - 'cc'
3713 /// - 'cpp'
3714 /// BasedOnStyle: llvm
3715 /// CanonicalDelimiter: 'cc'
3716 /// \endcode
3717 /// \version 6
3718 std::vector<RawStringFormat> RawStringFormats;
3719
3720 /// \brief The ``&`` and ``&&`` alignment style.
3722 /// Align reference like ``PointerAlignment``.
3724 /// Align reference to the left.
3725 /// \code
3726 /// int& a;
3727 /// \endcode
3729 /// Align reference to the right.
3730 /// \code
3731 /// int &a;
3732 /// \endcode
3734 /// Align reference in the middle.
3735 /// \code
3736 /// int & a;
3737 /// \endcode
3740
3741 /// \brief Reference alignment style (overrides ``PointerAlignment`` for
3742 /// references).
3743 /// \version 13
3745
3746 // clang-format off
3747 /// If ``true``, clang-format will attempt to re-flow comments. That is it
3748 /// will touch a comment and *reflow* long comments into new lines, trying to
3749 /// obey the ``ColumnLimit``.
3750 /// \code
3751 /// false:
3752 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
3753 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
3754 ///
3755 /// true:
3756 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3757 /// // information
3758 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3759 /// * information */
3760 /// \endcode
3761 /// \version 3.8
3763 // clang-format on
3764
3765 /// Remove optional braces of control statements (``if``, ``else``, ``for``,
3766 /// and ``while``) in C++ according to the LLVM coding style.
3767 /// \warning
3768 /// This option will be renamed and expanded to support other styles.
3769 /// \endwarning
3770 /// \warning
3771 /// Setting this option to ``true`` could lead to incorrect code formatting
3772 /// due to clang-format's lack of complete semantic information. As such,
3773 /// extra care should be taken to review code changes made by this option.
3774 /// \endwarning
3775 /// \code
3776 /// false: true:
3777 ///
3778 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3779 /// handleFunctionDecl(D); handleFunctionDecl(D);
3780 /// } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
3781 /// handleVarDecl(D); handleVarDecl(D);
3782 /// }
3783 ///
3784 /// if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
3785 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3786 /// if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
3787 /// handleAttr(A); handleAttr(A);
3788 /// } }
3789 /// }
3790 /// }
3791 ///
3792 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3793 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3794 /// handleAttr(A); handleAttr(A);
3795 /// }
3796 /// }
3797 ///
3798 /// if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
3799 /// if (shouldProcess(D)) { if (shouldProcess(D))
3800 /// handleVarDecl(D); handleVarDecl(D);
3801 /// } else { else
3802 /// markAsIgnored(D); markAsIgnored(D);
3803 /// } }
3804 /// }
3805 ///
3806 /// if (a) { vs. if (a)
3807 /// b(); b();
3808 /// } else { else if (c)
3809 /// if (c) { d();
3810 /// d(); else
3811 /// } else { e();
3812 /// e();
3813 /// }
3814 /// }
3815 /// \endcode
3816 /// \version 14
3818
3819 /// Types of redundant parentheses to remove.
3821 /// Do not remove parentheses.
3822 /// \code
3823 /// class __declspec((dllimport)) X {};
3824 /// co_return (((0)));
3825 /// return ((a + b) - ((c + d)));
3826 /// \endcode
3828 /// Replace multiple parentheses with single parentheses.
3829 /// \code
3830 /// class __declspec(dllimport) X {};
3831 /// co_return (0);
3832 /// return ((a + b) - (c + d));
3833 /// \endcode
3835 /// Also remove parentheses enclosing the expression in a
3836 /// ``return``/``co_return`` statement.
3837 /// \code
3838 /// class __declspec(dllimport) X {};
3839 /// co_return 0;
3840 /// return (a + b) - (c + d);
3841 /// \endcode
3843 };
3844
3845 /// Remove redundant parentheses.
3846 /// \warning
3847 /// Setting this option to any value other than ``Leave`` could lead to
3848 /// incorrect code formatting due to clang-format's lack of complete semantic
3849 /// information. As such, extra care should be taken to review code changes
3850 /// made by this option.
3851 /// \endwarning
3852 /// \version 17
3854
3855 /// Remove semicolons after the closing braces of functions and
3856 /// constructors/destructors.
3857 /// \warning
3858 /// Setting this option to ``true`` could lead to incorrect code formatting
3859 /// due to clang-format's lack of complete semantic information. As such,
3860 /// extra care should be taken to review code changes made by this option.
3861 /// \endwarning
3862 /// \code
3863 /// false: true:
3864 ///
3865 /// int max(int a, int b) { int max(int a, int b) {
3866 /// return a > b ? a : b; return a > b ? a : b;
3867 /// }; }
3868 ///
3869 /// \endcode
3870 /// \version 16
3872
3873 /// \brief The possible positions for the requires clause. The
3874 /// ``IndentRequires`` option is only used if the ``requires`` is put on the
3875 /// start of a line.
3877 /// Always put the ``requires`` clause on its own line.
3878 /// \code
3879 /// template <typename T>
3880 /// requires C<T>
3881 /// struct Foo {...
3882 ///
3883 /// template <typename T>
3884 /// requires C<T>
3885 /// void bar(T t) {...
3886 ///
3887 /// template <typename T>
3888 /// void baz(T t)
3889 /// requires C<T>
3890 /// {...
3891 /// \endcode
3893 /// Try to put the clause together with the preceding part of a declaration.
3894 /// For class templates: stick to the template declaration.
3895 /// For function templates: stick to the template declaration.
3896 /// For function declaration followed by a requires clause: stick to the
3897 /// parameter list.
3898 /// \code
3899 /// template <typename T> requires C<T>
3900 /// struct Foo {...
3901 ///
3902 /// template <typename T> requires C<T>
3903 /// void bar(T t) {...
3904 ///
3905 /// template <typename T>
3906 /// void baz(T t) requires C<T>
3907 /// {...
3908 /// \endcode
3910 /// Try to put the ``requires`` clause together with the class or function
3911 /// declaration.
3912 /// \code
3913 /// template <typename T>
3914 /// requires C<T> struct Foo {...
3915 ///
3916 /// template <typename T>
3917 /// requires C<T> void bar(T t) {...
3918 ///
3919 /// template <typename T>
3920 /// void baz(T t)
3921 /// requires C<T> {...
3922 /// \endcode
3924 /// Try to put everything in the same line if possible. Otherwise normal
3925 /// line breaking rules take over.
3926 /// \code
3927 /// // Fitting:
3928 /// template <typename T> requires C<T> struct Foo {...
3929 ///
3930 /// template <typename T> requires C<T> void bar(T t) {...
3931 ///
3932 /// template <typename T> void bar(T t) requires C<T> {...
3933 ///
3934 /// // Not fitting, one possible example:
3935 /// template <typename LongName>
3936 /// requires C<LongName>
3937 /// struct Foo {...
3938 ///
3939 /// template <typename LongName>
3940 /// requires C<LongName>
3941 /// void bar(LongName ln) {
3942 ///
3943 /// template <typename LongName>
3944 /// void bar(LongName ln)
3945 /// requires C<LongName> {
3946 /// \endcode
3948 };
3949
3950 /// \brief The position of the ``requires`` clause.
3951 /// \version 15
3953
3954 /// Indentation logic for requires expression bodies.
3956 /// Align requires expression body relative to the indentation level of the
3957 /// outer scope the requires expression resides in.
3958 /// This is the default.
3959 /// \code
3960 /// template <typename T>
3961 /// concept C = requires(T t) {
3962 /// ...
3963 /// }
3964 /// \endcode
3966 /// Align requires expression body relative to the ``requires`` keyword.
3967 /// \code
3968 /// template <typename T>
3969 /// concept C = requires(T t) {
3970 /// ...
3971 /// }
3972 /// \endcode
3974 };
3975
3976 /// The indentation used for requires expression bodies.
3977 /// \version 16
3979
3980 /// \brief The style if definition blocks should be separated.
3982 /// Leave definition blocks as they are.
3984 /// Insert an empty line between definition blocks.
3986 /// Remove any empty line between definition blocks.
3987 SDS_Never
3989
3990 /// Specifies the use of empty lines to separate definition blocks, including
3991 /// classes, structs, enums, and functions.
3992 /// \code
3993 /// Never v.s. Always
3994 /// #include <cstring> #include <cstring>
3995 /// struct Foo {
3996 /// int a, b, c; struct Foo {
3997 /// }; int a, b, c;
3998 /// namespace Ns { };
3999 /// class Bar {
4000 /// public: namespace Ns {
4001 /// struct Foobar { class Bar {
4002 /// int a; public:
4003 /// int b; struct Foobar {
4004 /// }; int a;
4005 /// private: int b;
4006 /// int t; };
4007 /// int method1() {
4008 /// // ... private:
4009 /// } int t;
4010 /// enum List {
4011 /// ITEM1, int method1() {
4012 /// ITEM2 // ...
4013 /// }; }
4014 /// template<typename T>
4015 /// int method2(T x) { enum List {
4016 /// // ... ITEM1,
4017 /// } ITEM2
4018 /// int i, j, k; };
4019 /// int method3(int par) {
4020 /// // ... template<typename T>
4021 /// } int method2(T x) {
4022 /// }; // ...
4023 /// class C {}; }
4024 /// }
4025 /// int i, j, k;
4026 ///
4027 /// int method3(int par) {
4028 /// // ...
4029 /// }
4030 /// };
4031 ///
4032 /// class C {};
4033 /// }
4034 /// \endcode
4035 /// \version 14
4037
4038 /// The maximal number of unwrapped lines that a short namespace spans.
4039 /// Defaults to 1.
4040 ///
4041 /// This determines the maximum length of short namespaces by counting
4042 /// unwrapped lines (i.e. containing neither opening nor closing
4043 /// namespace brace) and makes "FixNamespaceComments" omit adding
4044 /// end comments for those.
4045 /// \code
4046 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4047 /// namespace a { namespace a {
4048 /// int foo; int foo;
4049 /// } } // namespace a
4050 ///
4051 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4052 /// namespace b { namespace b {
4053 /// int foo; int foo;
4054 /// int bar; int bar;
4055 /// } // namespace b } // namespace b
4056 /// \endcode
4057 /// \version 13
4059
4060 /// Do not format macro definition body.
4061 /// \version 18
4063
4064 /// Include sorting options.
4065 enum SortIncludesOptions : int8_t {
4066 /// Includes are never sorted.
4067 /// \code
4068 /// #include "B/A.h"
4069 /// #include "A/B.h"
4070 /// #include "a/b.h"
4071 /// #include "A/b.h"
4072 /// #include "B/a.h"
4073 /// \endcode
4075 /// Includes are sorted in an ASCIIbetical or case sensitive fashion.
4076 /// \code
4077 /// #include "A/B.h"
4078 /// #include "A/b.h"
4079 /// #include "B/A.h"
4080 /// #include "B/a.h"
4081 /// #include "a/b.h"
4082 /// \endcode
4084 /// Includes are sorted in an alphabetical or case insensitive fashion.
4085 /// \code
4086 /// #include "A/B.h"
4087 /// #include "A/b.h"
4088 /// #include "a/b.h"
4089 /// #include "B/A.h"
4090 /// #include "B/a.h"
4091 /// \endcode
4093 };
4094
4095 /// Controls if and how clang-format will sort ``#includes``.
4096 /// \version 3.8
4098
4099 /// Position for Java Static imports.
4101 /// Static imports are placed before non-static imports.
4102 /// \code{.java}
4103 /// import static org.example.function1;
4104 ///
4105 /// import org.example.ClassA;
4106 /// \endcode
4108 /// Static imports are placed after non-static imports.
4109 /// \code{.java}
4110 /// import org.example.ClassA;
4111 ///
4112 /// import static org.example.function1;
4113 /// \endcode
4115 };
4116
4117 /// When sorting Java imports, by default static imports are placed before
4118 /// non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
4119 /// static imports are placed after non-static imports.
4120 /// \version 12
4122
4123 /// Using declaration sorting options.
4125 /// Using declarations are never sorted.
4126 /// \code
4127 /// using std::chrono::duration_cast;
4128 /// using std::move;
4129 /// using boost::regex;
4130 /// using boost::regex_constants::icase;
4131 /// using std::string;
4132 /// \endcode
4134 /// Using declarations are sorted in the order defined as follows:
4135 /// Split the strings by "::" and discard any initial empty strings. Sort
4136 /// the lists of names lexicographically, and within those groups, names are
4137 /// in case-insensitive lexicographic order.
4138 /// \code
4139 /// using boost::regex;
4140 /// using boost::regex_constants::icase;
4141 /// using std::chrono::duration_cast;
4142 /// using std::move;
4143 /// using std::string;
4144 /// \endcode
4146 /// Using declarations are sorted in the order defined as follows:
4147 /// Split the strings by "::" and discard any initial empty strings. The
4148 /// last element of each list is a non-namespace name; all others are
4149 /// namespace names. Sort the lists of names lexicographically, where the
4150 /// sort order of individual names is that all non-namespace names come
4151 /// before all namespace names, and within those groups, names are in
4152 /// case-insensitive lexicographic order.
4153 /// \code
4154 /// using boost::regex;
4155 /// using boost::regex_constants::icase;
4156 /// using std::move;
4157 /// using std::string;
4158 /// using std::chrono::duration_cast;
4159 /// \endcode
4161 };
4162
4163 /// Controls if and how clang-format will sort using declarations.
4164 /// \version 5
4166
4167 /// If ``true``, a space is inserted after C style casts.
4168 /// \code
4169 /// true: false:
4170 /// (int) i; vs. (int)i;
4171 /// \endcode
4172 /// \version 3.5
4174
4175 /// If ``true``, a space is inserted after the logical not operator (``!``).
4176 /// \code
4177 /// true: false:
4178 /// ! someExpression(); vs. !someExpression();
4179 /// \endcode
4180 /// \version 9
4182
4183 /// If \c true, a space will be inserted after the 'template' keyword.
4184 /// \code
4185 /// true: false:
4186 /// template <int> void foo(); vs. template<int> void foo();
4187 /// \endcode
4188 /// \version 4
4190
4191 /// Different ways to put a space before opening parentheses.
4193 /// Don't ensure spaces around pointer qualifiers and use PointerAlignment
4194 /// instead.
4195 /// \code
4196 /// PointerAlignment: Left PointerAlignment: Right
4197 /// void* const* x = NULL; vs. void *const *x = NULL;
4198 /// \endcode
4200 /// Ensure that there is a space before pointer qualifiers.
4201 /// \code
4202 /// PointerAlignment: Left PointerAlignment: Right
4203 /// void* const* x = NULL; vs. void * const *x = NULL;
4204 /// \endcode
4206 /// Ensure that there is a space after pointer qualifiers.
4207 /// \code
4208 /// PointerAlignment: Left PointerAlignment: Right
4209 /// void* const * x = NULL; vs. void *const *x = NULL;
4210 /// \endcode
4212 /// Ensure that there is a space both before and after pointer qualifiers.
4213 /// \code
4214 /// PointerAlignment: Left PointerAlignment: Right
4215 /// void* const * x = NULL; vs. void * const *x = NULL;
4216 /// \endcode
4218 };
4219
4220 /// Defines in which cases to put a space before or after pointer qualifiers
4221 /// \version 12
4223
4224 /// If ``false``, spaces will be removed before assignment operators.
4225 /// \code
4226 /// true: false:
4227 /// int a = 5; vs. int a= 5;
4228 /// a += 42; a+= 42;
4229 /// \endcode
4230 /// \version 3.7
4232
4233 /// If ``false``, spaces will be removed before case colon.
4234 /// \code
4235 /// true: false
4236 /// switch (x) { vs. switch (x) {
4237 /// case 1 : break; case 1: break;
4238 /// } }
4239 /// \endcode
4240 /// \version 12
4242
4243 /// If ``true``, a space will be inserted before a C++11 braced list
4244 /// used to initialize an object (after the preceding identifier or type).
4245 /// \code
4246 /// true: false:
4247 /// Foo foo { bar }; vs. Foo foo{ bar };
4248 /// Foo {}; Foo{};
4249 /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
4250 /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
4251 /// \endcode
4252 /// \version 7
4254
4255 /// If ``false``, spaces will be removed before constructor initializer
4256 /// colon.
4257 /// \code
4258 /// true: false:
4259 /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
4260 /// \endcode
4261 /// \version 7
4263
4264 /// If ``false``, spaces will be removed before inheritance colon.
4265 /// \code
4266 /// true: false:
4267 /// class Foo : Bar {} vs. class Foo: Bar {}
4268 /// \endcode
4269 /// \version 7
4271
4272 /// If ``true``, a space will be added before a JSON colon. For other
4273 /// languages, e.g. JavaScript, use ``SpacesInContainerLiterals`` instead.
4274 /// \code
4275 /// true: false:
4276 /// { {
4277 /// "key" : "value" vs. "key": "value"
4278 /// } }
4279 /// \endcode
4280 /// \version 17
4282
4283 /// Different ways to put a space before opening parentheses.
4285 /// This is **deprecated** and replaced by ``Custom`` below, with all
4286 /// ``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
4287 /// ``false``.
4289 /// Put a space before opening parentheses only after control statement
4290 /// keywords (``for/if/while...``).
4291 /// \code
4292 /// void f() {
4293 /// if (true) {
4294 /// f();
4295 /// }
4296 /// }
4297 /// \endcode
4299 /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
4300 /// ForEach and If macros. This is useful in projects where ForEach/If
4301 /// macros are treated as function calls instead of control statements.
4302 /// ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
4303 /// backward compatibility.
4304 /// \code
4305 /// void f() {
4306 /// Q_FOREACH(...) {
4307 /// f();
4308 /// }
4309 /// }
4310 /// \endcode
4312 /// Put a space before opening parentheses only if the parentheses are not
4313 /// empty i.e. '()'
4314 /// \code
4315 /// void() {
4316 /// if (true) {
4317 /// f();
4318 /// g (x, y, z);
4319 /// }
4320 /// }
4321 /// \endcode
4323 /// Always put a space before opening parentheses, except when it's
4324 /// prohibited by the syntax rules (in function-like macro definitions) or
4325 /// when determined by other style rules (after unary operators, opening
4326 /// parentheses, etc.)
4327 /// \code
4328 /// void f () {
4329 /// if (true) {
4330 /// f ();
4331 /// }
4332 /// }
4333 /// \endcode
4335 /// Configure each individual space before parentheses in
4336 /// ``SpaceBeforeParensOptions``.
4338 };
4339
4340 /// Defines in which cases to put a space before opening parentheses.
4341 /// \version 3.5
4343
4344 /// Precise control over the spacing before parentheses.
4345 /// \code
4346 /// # Should be declared this way:
4347 /// SpaceBeforeParens: Custom
4348 /// SpaceBeforeParensOptions:
4349 /// AfterControlStatements: true
4350 /// AfterFunctionDefinitionName: true
4351 /// \endcode
4353 /// If ``true``, put space between control statement keywords
4354 /// (for/if/while...) and opening parentheses.
4355 /// \code
4356 /// true: false:
4357 /// if (...) {} vs. if(...) {}
4358 /// \endcode
4360 /// If ``true``, put space between foreach macros and opening parentheses.
4361 /// \code
4362 /// true: false:
4363 /// FOREACH (...) vs. FOREACH(...)
4364 /// <loop-body> <loop-body>
4365 /// \endcode
4367 /// If ``true``, put a space between function declaration name and opening
4368 /// parentheses.
4369 /// \code
4370 /// true: false:
4371 /// void f (); vs. void f();
4372 /// \endcode
4374 /// If ``true``, put a space between function definition name and opening
4375 /// parentheses.
4376 /// \code
4377 /// true: false:
4378 /// void f () {} vs. void f() {}
4379 /// \endcode
4381 /// If ``true``, put space between if macros and opening parentheses.
4382 /// \code
4383 /// true: false:
4384 /// IF (...) vs. IF(...)
4385 /// <conditional-body> <conditional-body>
4386 /// \endcode
4388 /// If ``true``, put a space between operator overloading and opening
4389 /// parentheses.
4390 /// \code
4391 /// true: false:
4392 /// void operator++ (int a); vs. void operator++(int a);
4393 /// object.operator++ (10); object.operator++(10);
4394 /// \endcode
4396 /// If ``true``, put a space between operator ``new``/``delete`` and opening
4397 /// parenthesis.
4398 /// \code
4399 /// true: false:
4400 /// new (buf) T; vs. new(buf) T;
4401 /// delete (buf) T; delete(buf) T;
4402 /// \endcode
4404 /// If ``true``, put space between requires keyword in a requires clause and
4405 /// opening parentheses, if there is one.
4406 /// \code
4407 /// true: false:
4408 /// template<typename T> vs. template<typename T>
4409 /// requires (A<T> && B<T>) requires(A<T> && B<T>)
4410 /// ... ...
4411 /// \endcode
4413 /// If ``true``, put space between requires keyword in a requires expression
4414 /// and opening parentheses.
4415 /// \code
4416 /// true: false:
4417 /// template<typename T> vs. template<typename T>
4418 /// concept C = requires (T t) { concept C = requires(T t) {
4419 /// ... ...
4420 /// } }
4421 /// \endcode
4423 /// If ``true``, put a space before opening parentheses only if the
4424 /// parentheses are not empty.
4425 /// \code
4426 /// true: false:
4427 /// void f (int a); vs. void f();
4428 /// f (a); f();
4429 /// \endcode
4431
4439
4441 return AfterControlStatements == Other.AfterControlStatements &&
4442 AfterForeachMacros == Other.AfterForeachMacros &&
4444 Other.AfterFunctionDeclarationName &&
4445 AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
4446 AfterIfMacros == Other.AfterIfMacros &&
4447 AfterOverloadedOperator == Other.AfterOverloadedOperator &&
4448 AfterPlacementOperator == Other.AfterPlacementOperator &&
4449 AfterRequiresInClause == Other.AfterRequiresInClause &&
4450 AfterRequiresInExpression == Other.AfterRequiresInExpression &&
4451 BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
4452 }
4453 };
4454
4455 /// Control of individual space before parentheses.
4456 ///
4457 /// If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify
4458 /// how each individual space before parentheses case should be handled.
4459 /// Otherwise, this is ignored.
4460 /// \code{.yaml}
4461 /// # Example of usage:
4462 /// SpaceBeforeParens: Custom
4463 /// SpaceBeforeParensOptions:
4464 /// AfterControlStatements: true
4465 /// AfterFunctionDefinitionName: true
4466 /// \endcode
4467 /// \version 14
4469
4470 /// If ``true``, spaces will be before ``[``.
4471 /// Lambdas will not be affected. Only the first ``[`` will get a space added.
4472 /// \code
4473 /// true: false:
4474 /// int a [5]; vs. int a[5];
4475 /// int a [5][5]; vs. int a[5][5];
4476 /// \endcode
4477 /// \version 10
4479
4480 /// If ``false``, spaces will be removed before range-based for loop
4481 /// colon.
4482 /// \code
4483 /// true: false:
4484 /// for (auto v : values) {} vs. for(auto v: values) {}
4485 /// \endcode
4486 /// \version 7
4488
4489 /// If ``true``, spaces will be inserted into ``{}``.
4490 /// \code
4491 /// true: false:
4492 /// void f() { } vs. void f() {}
4493 /// while (true) { } while (true) {}
4494 /// \endcode
4495 /// \version 10
4497
4498 /// If ``true``, spaces may be inserted into ``()``.
4499 /// This option is **deprecated**. See ``InEmptyParentheses`` of
4500 /// ``SpacesInParensOptions``.
4501 /// \version 3.7
4502 // bool SpaceInEmptyParentheses;
4503
4504 /// The number of spaces before trailing line comments
4505 /// (``//`` - comments).
4506 ///
4507 /// This does not affect trailing block comments (``/*`` - comments) as those
4508 /// commonly have different usage patterns and a number of special cases. In
4509 /// the case of Verilog, it doesn't affect a comment right after the opening
4510 /// parenthesis in the port or parameter list in a module header, because it
4511 /// is probably for the port on the following line instead of the parenthesis
4512 /// it follows.
4513 /// \code
4514 /// SpacesBeforeTrailingComments: 3
4515 /// void f() {
4516 /// if (true) { // foo1
4517 /// f(); // bar
4518 /// } // foo
4519 /// }
4520 /// \endcode
4521 /// \version 3.7
4523
4524 /// Styles for adding spacing after ``<`` and before ``>``
4525 /// in template argument lists.
4526 enum SpacesInAnglesStyle : int8_t {
4527 /// Remove spaces after ``<`` and before ``>``.
4528 /// \code
4529 /// static_cast<int>(arg);
4530 /// std::function<void(int)> fct;
4531 /// \endcode
4533 /// Add spaces after ``<`` and before ``>``.
4534 /// \code
4535 /// static_cast< int >(arg);
4536 /// std::function< void(int) > fct;
4537 /// \endcode
4539 /// Keep a single space after ``<`` and before ``>`` if any spaces were
4540 /// present. Option ``Standard: Cpp03`` takes precedence.
4543 /// The SpacesInAnglesStyle to use for template argument lists.
4544 /// \version 3.4
4546
4547 /// If ``true``, spaces will be inserted around if/for/switch/while
4548 /// conditions.
4549 /// This option is **deprecated**. See ``InConditionalStatements`` of
4550 /// ``SpacesInParensOptions``.
4551 /// \version 10
4552 // bool SpacesInConditionalStatement;
4553
4554 /// If ``true``, spaces are inserted inside container literals (e.g. ObjC and
4555 /// Javascript array and dict literals). For JSON, use
4556 /// ``SpaceBeforeJsonColon`` instead.
4557 /// \code{.js}
4558 /// true: false:
4559 /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
4560 /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
4561 /// \endcode
4562 /// \version 3.7
4564
4565 /// If ``true``, spaces may be inserted into C style casts.
4566 /// This option is **deprecated**. See ``InCStyleCasts`` of
4567 /// ``SpacesInParensOptions``.
4568 /// \version 3.7
4569 // bool SpacesInCStyleCastParentheses;
4570
4571 /// Control of spaces within a single line comment.
4573 /// The minimum number of spaces at the start of the comment.
4574 unsigned Minimum;
4575 /// The maximum number of spaces at the start of the comment.
4576 unsigned Maximum;
4577 };
4578
4579 /// How many spaces are allowed at the start of a line comment. To disable the
4580 /// maximum set it to ``-1``, apart from that the maximum takes precedence
4581 /// over the minimum.
4582 /// \code
4583 /// Minimum = 1
4584 /// Maximum = -1
4585 /// // One space is forced
4586 ///
4587 /// // but more spaces are possible
4588 ///
4589 /// Minimum = 0
4590 /// Maximum = 0
4591 /// //Forces to start every comment directly after the slashes
4592 /// \endcode
4593 ///
4594 /// Note that in line comment sections the relative indent of the subsequent
4595 /// lines is kept, that means the following:
4596 /// \code
4597 /// before: after:
4598 /// Minimum: 1
4599 /// //if (b) { // if (b) {
4600 /// // return true; // return true;
4601 /// //} // }
4602 ///
4603 /// Maximum: 0
4604 /// /// List: ///List:
4605 /// /// - Foo /// - Foo
4606 /// /// - Bar /// - Bar
4607 /// \endcode
4608 ///
4609 /// This option has only effect if ``ReflowComments`` is set to ``true``.
4610 /// \version 13
4612
4613 /// Different ways to put a space before opening and closing parentheses.
4614 enum SpacesInParensStyle : int8_t {
4615 /// Never put a space in parentheses.
4616 /// \code
4617 /// void f() {
4618 /// if(true) {
4619 /// f();
4620 /// }
4621 /// }
4622 /// \endcode
4624 /// Configure each individual space in parentheses in
4625 /// `SpacesInParensOptions`.
4627 };
4628
4629 /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
4630 /// This option is **deprecated**. The previous behavior is preserved by using
4631 /// ``SpacesInParens`` with ``Custom`` and by setting all
4632 /// ``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and
4633 /// ``InEmptyParentheses``.
4634 /// \version 3.7
4635 // bool SpacesInParentheses;
4636
4637 /// Defines in which cases spaces will be inserted after ``(`` and before
4638 /// ``)``.
4639 /// \version 17
4641
4642 /// Precise control over the spacing in parentheses.
4643 /// \code
4644 /// # Should be declared this way:
4645 /// SpacesInParens: Custom
4646 /// SpacesInParensOptions:
4647 /// InConditionalStatements: true
4648 /// Other: true
4649 /// \endcode
4651 /// Put a space in parentheses only inside conditional statements
4652 /// (``for/if/while/switch...``).
4653 /// \code
4654 /// true: false:
4655 /// if ( a ) { ... } vs. if (a) { ... }
4656 /// while ( i < 5 ) { ... } while (i < 5) { ... }
4657 /// \endcode
4659 /// Put a space in C style casts.
4660 /// \code
4661 /// true: false:
4662 /// x = ( int32 )y vs. x = (int32)y
4663 /// \endcode
4665 /// Put a space in parentheses only if the parentheses are empty i.e. '()'
4666 /// \code
4667 /// true: false:
4668 /// void f( ) { vs. void f() {
4669 /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
4670 /// if (true) { if (true) {
4671 /// f( ); f();
4672 /// } }
4673 /// } }
4674 /// \endcode
4676 /// Put a space in parentheses not covered by preceding options.
4677 /// \code
4678 /// true: false:
4679 /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
4680 /// \endcode
4681 bool Other;
4682
4686
4688 bool InEmptyParentheses, bool Other)
4691 Other(Other) {}
4692
4693 bool operator==(const SpacesInParensCustom &R) const {
4697 }
4698 bool operator!=(const SpacesInParensCustom &R) const {
4699 return !(*this == R);
4700 }
4701 };
4702
4703 /// Control of individual spaces in parentheses.
4704 ///
4705 /// If ``SpacesInParens`` is set to ``Custom``, use this to specify
4706 /// how each individual space in parentheses case should be handled.
4707 /// Otherwise, this is ignored.
4708 /// \code{.yaml}
4709 /// # Example of usage:
4710 /// SpacesInParens: Custom
4711 /// SpacesInParensOptions:
4712 /// InConditionalStatements: true
4713 /// InEmptyParentheses: true
4714 /// \endcode
4715 /// \version 17
4717
4718 /// If ``true``, spaces will be inserted after ``[`` and before ``]``.
4719 /// Lambdas without arguments or unspecified size array declarations will not
4720 /// be affected.
4721 /// \code
4722 /// true: false:
4723 /// int a[ 5 ]; vs. int a[5];
4724 /// std::unique_ptr<int[]> foo() {} // Won't be affected
4725 /// \endcode
4726 /// \version 3.7
4728
4729 /// Supported language standards for parsing and formatting C++ constructs.
4730 /// \code
4731 /// Latest: vector<set<int>>
4732 /// c++03 vs. vector<set<int> >
4733 /// \endcode
4734 ///
4735 /// The correct way to spell a specific language version is e.g. ``c++11``.
4736 /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
4737 enum LanguageStandard : int8_t {
4738 /// Parse and format as C++03.
4739 /// ``Cpp03`` is a deprecated alias for ``c++03``
4740 LS_Cpp03, // c++03
4741 /// Parse and format as C++11.
4742 LS_Cpp11, // c++11
4743 /// Parse and format as C++14.
4744 LS_Cpp14, // c++14
4745 /// Parse and format as C++17.
4746 LS_Cpp17, // c++17
4747 /// Parse and format as C++20.
4748 LS_Cpp20, // c++20
4749 /// Parse and format using the latest supported language version.
4750 /// ``Cpp11`` is a deprecated alias for ``Latest``
4752 /// Automatic detection based on the input.
4754 };
4755
4756 /// Parse and format C++ constructs compatible with this standard.
4757 /// \code
4758 /// c++03: latest:
4759 /// vector<set<int> > x; vs. vector<set<int>> x;
4760 /// \endcode
4761 /// \version 3.7
4763
4764 /// Macros which are ignored in front of a statement, as if they were an
4765 /// attribute. So that they are not parsed as identifier, for example for Qts
4766 /// emit.
4767 /// \code
4768 /// AlignConsecutiveDeclarations: true
4769 /// StatementAttributeLikeMacros: []
4770 /// unsigned char data = 'x';
4771 /// emit signal(data); // This is parsed as variable declaration.
4772 ///
4773 /// AlignConsecutiveDeclarations: true
4774 /// StatementAttributeLikeMacros: [emit]
4775 /// unsigned char data = 'x';
4776 /// emit signal(data); // Now it's fine again.
4777 /// \endcode
4778 /// \version 12
4779 std::vector<std::string> StatementAttributeLikeMacros;
4780
4781 /// A vector of macros that should be interpreted as complete
4782 /// statements.
4783 ///
4784 /// Typical macros are expressions, and require a semi-colon to be
4785 /// added; sometimes this is not the case, and this allows to make
4786 /// clang-format aware of such cases.
4787 ///
4788 /// For example: Q_UNUSED
4789 /// \version 8
4790 std::vector<std::string> StatementMacros;
4791
4792 /// Works only when TableGenBreakInsideDAGArg is not DontBreak.
4793 /// The string list needs to consist of identifiers in TableGen.
4794 /// If any identifier is specified, this limits the line breaks by
4795 /// TableGenBreakInsideDAGArg option only on DAGArg values beginning with
4796 /// the specified identifiers.
4797 ///
4798 /// For example the configuration,
4799 /// \code{.yaml}
4800 /// TableGenBreakInsideDAGArg: BreakAll
4801 /// TableGenBreakingDAGArgOperators: ['ins', 'outs']
4802 /// \endcode
4803 ///
4804 /// makes the line break only occurs inside DAGArgs beginning with the
4805 /// specified identifiers 'ins' and 'outs'.
4806 ///
4807 /// \code
4808 /// let DAGArgIns = (ins
4809 /// i32:$src1,
4810 /// i32:$src2
4811 /// );
4812 /// let DAGArgOtherID = (other i32:$other1, i32:$other2);
4813 /// let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)
4814 /// \endcode
4815 /// \version 19
4816 std::vector<std::string> TableGenBreakingDAGArgOperators;
4817
4818 /// Different ways to control the format inside TableGen DAGArg.
4819 enum DAGArgStyle : int8_t {
4820 /// Never break inside DAGArg.
4821 /// \code
4822 /// let DAGArgIns = (ins i32:$src1, i32:$src2);
4823 /// \endcode
4825 /// Break inside DAGArg after each list element but for the last.
4826 /// This aligns to the first element.
4827 /// \code
4828 /// let DAGArgIns = (ins i32:$src1,
4829 /// i32:$src2);
4830 /// \endcode
4832 /// Break inside DAGArg after the operator and the all elements.
4833 /// \code
4834 /// let DAGArgIns = (ins
4835 /// i32:$src1,
4836 /// i32:$src2
4837 /// );
4838 /// \endcode
4840 };
4841
4842 /// The styles of the line break inside the DAGArg in TableGen.
4843 /// \version 19
4845
4846 /// The number of columns used for tab stops.
4847 /// \version 3.7
4848 unsigned TabWidth;
4849
4850 /// A vector of non-keyword identifiers that should be interpreted as type
4851 /// names.
4852 ///
4853 /// A ``*``, ``&``, or ``&&`` between a type name and another non-keyword
4854 /// identifier is annotated as a pointer or reference token instead of a
4855 /// binary operator.
4856 ///
4857 /// \version 17
4858 std::vector<std::string> TypeNames;
4859
4860 /// \brief A vector of macros that should be interpreted as type declarations
4861 /// instead of as function calls.
4862 ///
4863 /// These are expected to be macros of the form:
4864 /// \code
4865 /// STACK_OF(...)
4866 /// \endcode
4867 ///
4868 /// In the .clang-format configuration file, this can be configured like:
4869 /// \code{.yaml}
4870 /// TypenameMacros: ['STACK_OF', 'LIST']
4871 /// \endcode
4872 ///
4873 /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
4874 /// \version 9
4875 std::vector<std::string> TypenameMacros;
4876
4877 /// This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``.
4878 /// \version 10
4879 // bool UseCRLF;
4880
4881 /// Different ways to use tab in formatting.
4882 enum UseTabStyle : int8_t {
4883 /// Never use tab.
4885 /// Use tabs only for indentation.
4887 /// Fill all leading whitespace with tabs, and use spaces for alignment that
4888 /// appears within a line (e.g. consecutive assignments and declarations).
4890 /// Use tabs for line continuation and indentation, and spaces for
4891 /// alignment.
4893 /// Use tabs whenever we need to fill whitespace that spans at least from
4894 /// one tab stop to the next one.
4895 UT_Always
4897
4898 /// The way to use tab characters in the resulting file.
4899 /// \version 3.7
4901
4902 /// For Verilog, put each port on its own line in module instantiations.
4903 /// \code
4904 /// true:
4905 /// ffnand ff1(.q(),
4906 /// .qbar(out1),
4907 /// .clear(in1),
4908 /// .preset(in2));
4909 ///
4910 /// false:
4911 /// ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
4912 /// \endcode
4913 /// \version 17
4915
4916 /// A vector of macros which are whitespace-sensitive and should not
4917 /// be touched.
4918 ///
4919 /// These are expected to be macros of the form:
4920 /// \code
4921 /// STRINGIZE(...)
4922 /// \endcode
4923 ///
4924 /// In the .clang-format configuration file, this can be configured like:
4925 /// \code{.yaml}
4926 /// WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']
4927 /// \endcode
4928 ///
4929 /// For example: BOOST_PP_STRINGIZE
4930 /// \version 11
4931 std::vector<std::string> WhitespaceSensitiveMacros;
4932
4933 bool operator==(const FormatStyle &R) const {
4982 BreakArrays == R.BreakArrays &&
5022 IndentWidth == R.IndentWidth &&
5033 Language == R.Language &&
5102 Standard == R.Standard &&
5108 TabWidth == R.TabWidth && TypeNames == R.TypeNames &&
5113 }
5114
5115 std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
5116
5117 // Stores per-language styles. A FormatStyle instance inside has an empty
5118 // StyleSet. A FormatStyle instance returned by the Get method has its
5119 // StyleSet set to a copy of the originating StyleSet, effectively keeping the
5120 // internal representation of that StyleSet alive.
5121 //
5122 // The memory management and ownership reminds of a birds nest: chicks
5123 // leaving the nest take photos of the nest with them.
5125 typedef std::map<FormatStyle::LanguageKind, FormatStyle> MapType;
5126
5127 std::optional<FormatStyle> Get(FormatStyle::LanguageKind Language) const;
5128
5129 // Adds \p Style to this FormatStyleSet. Style must not have an associated
5130 // FormatStyleSet.
5131 // Style.Language should be different than LK_None. If this FormatStyleSet
5132 // already contains an entry for Style.Language, that gets replaced with the
5133 // passed Style.
5134 void Add(FormatStyle Style);
5135
5136 // Clears this FormatStyleSet.
5137 void Clear();
5138
5139 private:
5140 std::shared_ptr<MapType> Styles;
5141 };
5142
5144 const FormatStyle &MainStyle,
5145 const std::vector<FormatStyle> &ConfigurationStyles);
5146
5147private:
5148 FormatStyleSet StyleSet;
5149
5150 friend std::error_code
5151 parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
5152 bool AllowUnknownOptions,
5153 llvm::SourceMgr::DiagHandlerTy DiagHandler,
5154 void *DiagHandlerCtxt);
5155};
5156
5157/// Returns a format style complying with the LLVM coding standards:
5158/// http://llvm.org/docs/CodingStandards.html.
5161
5162/// Returns a format style complying with one of Google's style guides:
5163/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
5164/// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
5165/// https://developers.google.com/protocol-buffers/docs/style.
5167
5168/// Returns a format style complying with Chromium's style guide:
5169/// http://www.chromium.org/developers/coding-style.
5171
5172/// Returns a format style complying with Mozilla's style guide:
5173/// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html.
5175
5176/// Returns a format style complying with Webkit's style guide:
5177/// http://www.webkit.org/coding/coding-style.html
5179
5180/// Returns a format style complying with GNU Coding Standards:
5181/// http://www.gnu.org/prep/standards/standards.html
5183
5184/// Returns a format style complying with Microsoft style guide:
5185/// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
5187
5189
5190/// Returns style indicating formatting should be not applied at all.
5192
5193/// Gets a predefined style for the specified language by name.
5194///
5195/// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
5196/// compared case-insensitively.
5197///
5198/// Returns ``true`` if the Style has been set.
5200 FormatStyle *Style);
5201
5202/// Parse configuration from YAML-formatted text.
5203///
5204/// Style->Language is used to get the base style, if the ``BasedOnStyle``
5205/// option is present.
5206///
5207/// The FormatStyleSet of Style is reset.
5208///
5209/// When ``BasedOnStyle`` is not present, options not present in the YAML
5210/// document, are retained in \p Style.
5211///
5212/// If AllowUnknownOptions is true, no errors are emitted if unknown
5213/// format options are occurred.
5214///
5215/// If set all diagnostics are emitted through the DiagHandler.
5216std::error_code
5217parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
5218 bool AllowUnknownOptions = false,
5219 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
5220 void *DiagHandlerCtx = nullptr);
5221
5222/// Like above but accepts an unnamed buffer.
5223inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
5224 bool AllowUnknownOptions = false) {
5225 return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
5226 AllowUnknownOptions);
5227}
5228
5229/// Gets configuration in a YAML string.
5230std::string configurationAsText(const FormatStyle &Style);
5231
5232/// Returns the replacements necessary to sort all ``#include`` blocks
5233/// that are affected by ``Ranges``.
5234tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
5236 StringRef FileName,
5237 unsigned *Cursor = nullptr);
5238
5239/// Returns the replacements corresponding to applying and formatting
5240/// \p Replaces on success; otheriwse, return an llvm::Error carrying
5241/// llvm::StringError.
5243formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
5244 const FormatStyle &Style);
5245
5246/// Returns the replacements corresponding to applying \p Replaces and
5247/// cleaning up the code after that on success; otherwise, return an llvm::Error
5248/// carrying llvm::StringError.
5249/// This also supports inserting/deleting C++ #include directives:
5250/// - If a replacement has offset UINT_MAX, length 0, and a replacement text
5251/// that is an #include directive, this will insert the #include into the
5252/// correct block in the \p Code.
5253/// - If a replacement has offset UINT_MAX, length 1, and a replacement text
5254/// that is the name of the header to be removed, the header will be removed
5255/// from \p Code if it exists.
5256/// The include manipulation is done via ``tooling::HeaderInclude``, see its
5257/// documentation for more details on how include insertion points are found and
5258/// what edits are produced.
5260cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
5261 const FormatStyle &Style);
5262
5263/// Represents the status of a formatting attempt.
5265 /// A value of ``false`` means that any of the affected ranges were not
5266 /// formatted due to a non-recoverable syntax error.
5267 bool FormatComplete = true;
5268
5269 /// If ``FormatComplete`` is false, ``Line`` records a one-based
5270 /// original line number at which a syntax error might have occurred. This is
5271 /// based on a best-effort analysis and could be imprecise.
5272 unsigned Line = 0;
5273};
5274
5275/// Reformats the given \p Ranges in \p Code.
5276///
5277/// Each range is extended on either end to its next bigger logic unit, i.e.
5278/// everything that might influence its formatting or might be influenced by its
5279/// formatting.
5280///
5281/// Returns the ``Replacements`` necessary to make all \p Ranges comply with
5282/// \p Style.
5283///
5284/// If ``Status`` is non-null, its value will be populated with the status of
5285/// this formatting attempt. See \c FormattingAttemptStatus.
5286tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
5288 StringRef FileName = "<stdin>",
5289 FormattingAttemptStatus *Status = nullptr);
5290
5291/// Same as above, except if ``IncompleteFormat`` is non-null, its value
5292/// will be set to true if any of the affected ranges were not formatted due to
5293/// a non-recoverable syntax error.
5294tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
5296 StringRef FileName, bool *IncompleteFormat);
5297
5298/// Clean up any erroneous/redundant code in the given \p Ranges in \p
5299/// Code.
5300///
5301/// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
5302tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
5304 StringRef FileName = "<stdin>");
5305
5306/// Fix namespace end comments in the given \p Ranges in \p Code.
5307///
5308/// Returns the ``Replacements`` that fix the namespace comments in all
5309/// \p Ranges in \p Code.
5311 StringRef Code,
5313 StringRef FileName = "<stdin>");
5314
5315/// Inserts or removes empty lines separating definition blocks including
5316/// classes, structs, functions, namespaces, and enums in the given \p Ranges in
5317/// \p Code.
5318///
5319/// Returns the ``Replacements`` that inserts or removes empty lines separating
5320/// definition blocks in all \p Ranges in \p Code.
5322 StringRef Code,
5324 StringRef FileName = "<stdin>");
5325
5326/// Sort consecutive using declarations in the given \p Ranges in
5327/// \p Code.
5328///
5329/// Returns the ``Replacements`` that sort the using declarations in all
5330/// \p Ranges in \p Code.
5332 StringRef Code,
5334 StringRef FileName = "<stdin>");
5335
5336/// Returns the ``LangOpts`` that the formatter expects you to set.
5337///
5338/// \param Style determines specific settings for lexing mode.
5340
5341/// Description to be used for help text for a ``llvm::cl`` option for
5342/// specifying format style. The description is closely related to the operation
5343/// of ``getStyle()``.
5344extern const char *StyleOptionHelpDescription;
5345
5346/// The suggested format style to use by default. This allows tools using
5347/// ``getStyle`` to have a consistent default style.
5348/// Different builds can modify the value to the preferred styles.
5349extern const char *DefaultFormatStyle;
5350
5351/// The suggested predefined style to use as the fallback style in ``getStyle``.
5352/// Different builds can modify the value to the preferred styles.
5353extern const char *DefaultFallbackStyle;
5354
5355/// Construct a FormatStyle based on ``StyleName``.
5356///
5357/// ``StyleName`` can take several forms:
5358/// * "{<key>: <value>, ...}" - Set specic style parameters.
5359/// * "<style name>" - One of the style names supported by
5360/// getPredefinedStyle().
5361/// * "file" - Load style configuration from a file called ``.clang-format``
5362/// located in one of the parent directories of ``FileName`` or the current
5363/// directory if ``FileName`` is empty.
5364/// * "file:<format_file_path>" to explicitly specify the configuration file to
5365/// use.
5366///
5367/// \param[in] StyleName Style name to interpret according to the description
5368/// above.
5369/// \param[in] FileName Path to start search for .clang-format if ``StyleName``
5370/// == "file".
5371/// \param[in] FallbackStyle The name of a predefined style used to fallback to
5372/// in case \p StyleName is "file" and no file can be found.
5373/// \param[in] Code The actual code to be formatted. Used to determine the
5374/// language if the filename isn't sufficient.
5375/// \param[in] FS The underlying file system, in which the file resides. By
5376/// default, the file system is the real file system.
5377/// \param[in] AllowUnknownOptions If true, unknown format options only
5378/// emit a warning. If false, errors are emitted on unknown format
5379/// options.
5380///
5381/// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
5382/// "file" and no file is found, returns ``FallbackStyle``. If no style could be
5383/// determined, returns an Error.
5384llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
5385 StringRef FallbackStyle,
5386 StringRef Code = "",
5387 llvm::vfs::FileSystem *FS = nullptr,
5388 bool AllowUnknownOptions = false);
5389
5390// Guesses the language from the ``FileName`` and ``Code`` to be formatted.
5391// Defaults to FormatStyle::LK_Cpp.
5392FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
5393
5394// Returns a string representation of ``Language``.
5396 switch (Language) {
5398 return "C++";
5400 return "CSharp";
5402 return "Objective-C";
5404 return "Java";
5406 return "JavaScript";
5408 return "Json";
5410 return "Proto";
5412 return "TableGen";
5414 return "TextProto";
5416 return "Verilog";
5417 default:
5418 return "Unknown";
5419 }
5420}
5421
5422bool isClangFormatOn(StringRef Comment);
5423bool isClangFormatOff(StringRef Comment);
5424
5425} // end namespace format
5426} // end namespace clang
5427
5428namespace std {
5429template <>
5430struct is_error_code_enum<clang::format::ParseError> : std::true_type {};
5431} // namespace std
5432
5433#endif // LLVM_CLANG_FORMAT_FORMAT_H
Defines the clang::LangOptions interface.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:461
const char * name() const noexcept override
Definition: Format.cpp:1243
std::string message(int EV) const override
Definition: Format.cpp:1247
Maintains a set of replacements that are conflict-free.
Definition: Replacement.h:212
const char * StyleOptionHelpDescription
Description to be used for help text for a llvm::cl option for specifying format style.
Definition: Format.cpp:3870
const char * DefaultFallbackStyle
The suggested predefined style to use as the fallback style in getStyle.
Definition: Format.cpp:3945
FormatStyle getWebKitStyle()
Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style...
Definition: Format.cpp:1846
llvm::Expected< tooling::Replacements > cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
Returns the replacements corresponding to applying Replaces and cleaning up the code after that on su...
Definition: Format.cpp:3585
std::error_code make_error_code(ParseError e)
Definition: Format.cpp:1234
FormatStyle getClangFormatStyle()
Definition: Format.cpp:1914
FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language=FormatStyle::LanguageKind::LK_Cpp)
Returns a format