clang 20.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 ///
149 /// * ``None``
150 /// * ``Consecutive``
151 /// * ``AcrossEmptyLines``
152 /// * ``AcrossComments``
153 /// * ``AcrossEmptyLinesAndComments``
154 ///
155 /// For example, to align across empty lines and not across comments, either
156 /// of these work.
157 /// \code
158 /// <option-name>: AcrossEmptyLines
159 ///
160 /// <option-name>:
161 /// Enabled: true
162 /// AcrossEmptyLines: true
163 /// AcrossComments: false
164 /// \endcode
166 /// Whether aligning is enabled.
167 /// \code
168 /// #define SHORT_NAME 42
169 /// #define LONGER_NAME 0x007f
170 /// #define EVEN_LONGER_NAME (2)
171 /// #define foo(x) (x * x)
172 /// #define bar(y, z) (y + z)
173 ///
174 /// int a = 1;
175 /// int somelongname = 2;
176 /// double c = 3;
177 ///
178 /// int aaaa : 1;
179 /// int b : 12;
180 /// int ccc : 8;
181 ///
182 /// int aaaa = 12;
183 /// float b = 23;
184 /// std::string ccc;
185 /// \endcode
187 /// Whether to align across empty lines.
188 /// \code
189 /// true:
190 /// int a = 1;
191 /// int somelongname = 2;
192 /// double c = 3;
193 ///
194 /// int d = 3;
195 ///
196 /// false:
197 /// int a = 1;
198 /// int somelongname = 2;
199 /// double c = 3;
200 ///
201 /// int d = 3;
202 /// \endcode
204 /// Whether to align across comments.
205 /// \code
206 /// true:
207 /// int d = 3;
208 /// /* A comment. */
209 /// double e = 4;
210 ///
211 /// false:
212 /// int d = 3;
213 /// /* A comment. */
214 /// double e = 4;
215 /// \endcode
217 /// Only for ``AlignConsecutiveAssignments``. Whether compound assignments
218 /// like ``+=`` are aligned along with ``=``.
219 /// \code
220 /// true:
221 /// a &= 2;
222 /// bbb = 2;
223 ///
224 /// false:
225 /// a &= 2;
226 /// bbb = 2;
227 /// \endcode
229 /// Only for ``AlignConsecutiveDeclarations``. Whether function declarations
230 /// are aligned.
231 /// \code
232 /// true:
233 /// unsigned int f1(void);
234 /// void f2(void);
235 /// size_t f3(void);
236 ///
237 /// false:
238 /// unsigned int f1(void);
239 /// void f2(void);
240 /// size_t f3(void);
241 /// \endcode
243 /// Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
244 /// aligned.
245 /// \code
246 /// true:
247 /// unsigned i;
248 /// int &r;
249 /// int *p;
250 /// int (*f)();
251 ///
252 /// false:
253 /// unsigned i;
254 /// int &r;
255 /// int *p;
256 /// int (*f)();
257 /// \endcode
259 /// Only for ``AlignConsecutiveAssignments``. Whether short assignment
260 /// operators are left-padded to the same length as long ones in order to
261 /// put all assignment operators to the right of the left hand side.
262 /// \code
263 /// true:
264 /// a >>= 2;
265 /// bbb = 2;
266 ///
267 /// a = 2;
268 /// bbb >>= 2;
269 ///
270 /// false:
271 /// a >>= 2;
272 /// bbb = 2;
273 ///
274 /// a = 2;
275 /// bbb >>= 2;
276 /// \endcode
278 bool operator==(const AlignConsecutiveStyle &R) const {
279 return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
285 }
286 bool operator!=(const AlignConsecutiveStyle &R) const {
287 return !(*this == R);
288 }
289 };
290
291 /// Style of aligning consecutive macro definitions.
292 ///
293 /// ``Consecutive`` will result in formattings like:
294 /// \code
295 /// #define SHORT_NAME 42
296 /// #define LONGER_NAME 0x007f
297 /// #define EVEN_LONGER_NAME (2)
298 /// #define foo(x) (x * x)
299 /// #define bar(y, z) (y + z)
300 /// \endcode
301 /// \version 9
303 /// Style of aligning consecutive assignments.
304 ///
305 /// ``Consecutive`` will result in formattings like:
306 /// \code
307 /// int a = 1;
308 /// int somelongname = 2;
309 /// double c = 3;
310 /// \endcode
311 /// \version 3.8
313 /// Style of aligning consecutive bit fields.
314 ///
315 /// ``Consecutive`` will align the bitfield separators of consecutive lines.
316 /// This will result in formattings like:
317 /// \code
318 /// int aaaa : 1;
319 /// int b : 12;
320 /// int ccc : 8;
321 /// \endcode
322 /// \version 11
324 /// Style of aligning consecutive declarations.
325 ///
326 /// ``Consecutive`` will align the declaration names of consecutive lines.
327 /// This will result in formattings like:
328 /// \code
329 /// int aaaa = 12;
330 /// float b = 23;
331 /// std::string ccc;
332 /// \endcode
333 /// \version 3.8
335
336 /// Alignment options.
337 ///
339 /// Whether aligning is enabled.
340 /// \code
341 /// true:
342 /// switch (level) {
343 /// case log::info: return "info:";
344 /// case log::warning: return "warning:";
345 /// default: return "";
346 /// }
347 ///
348 /// false:
349 /// switch (level) {
350 /// case log::info: return "info:";
351 /// case log::warning: return "warning:";
352 /// default: return "";
353 /// }
354 /// \endcode
356 /// Whether to align across empty lines.
357 /// \code
358 /// true:
359 /// switch (level) {
360 /// case log::info: return "info:";
361 /// case log::warning: return "warning:";
362 ///
363 /// default: return "";
364 /// }
365 ///
366 /// false:
367 /// switch (level) {
368 /// case log::info: return "info:";
369 /// case log::warning: return "warning:";
370 ///
371 /// default: return "";
372 /// }
373 /// \endcode
375 /// Whether to align across comments.
376 /// \code
377 /// true:
378 /// switch (level) {
379 /// case log::info: return "info:";
380 /// case log::warning: return "warning:";
381 /// /* A comment. */
382 /// default: return "";
383 /// }
384 ///
385 /// false:
386 /// switch (level) {
387 /// case log::info: return "info:";
388 /// case log::warning: return "warning:";
389 /// /* A comment. */
390 /// default: return "";
391 /// }
392 /// \endcode
394 /// Whether to align the case arrows when aligning short case expressions.
395 /// \code{.java}
396 /// true:
397 /// i = switch (day) {
398 /// case THURSDAY, SATURDAY -> 8;
399 /// case WEDNESDAY -> 9;
400 /// default -> 0;
401 /// };
402 ///
403 /// false:
404 /// i = switch (day) {
405 /// case THURSDAY, SATURDAY -> 8;
406 /// case WEDNESDAY -> 9;
407 /// default -> 0;
408 /// };
409 /// \endcode
411 /// Whether aligned case labels are aligned on the colon, or on the tokens
412 /// after the colon.
413 /// \code
414 /// true:
415 /// switch (level) {
416 /// case log::info : return "info:";
417 /// case log::warning: return "warning:";
418 /// default : return "";
419 /// }
420 ///
421 /// false:
422 /// switch (level) {
423 /// case log::info: return "info:";
424 /// case log::warning: return "warning:";
425 /// default: return "";
426 /// }
427 /// \endcode
430 return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
434 }
435 };
436
437 /// Style of aligning consecutive short case labels.
438 /// Only applies if ``AllowShortCaseExpressionOnASingleLine`` or
439 /// ``AllowShortCaseLabelsOnASingleLine`` is ``true``.
440 ///
441 /// \code{.yaml}
442 /// # Example of usage:
443 /// AlignConsecutiveShortCaseStatements:
444 /// Enabled: true
445 /// AcrossEmptyLines: true
446 /// AcrossComments: true
447 /// AlignCaseColons: false
448 /// \endcode
449 /// \version 17
451
452 /// Style of aligning consecutive TableGen DAGArg operator colons.
453 /// If enabled, align the colon inside DAGArg which have line break inside.
454 /// This works only when TableGenBreakInsideDAGArg is BreakElements or
455 /// BreakAll and the DAGArg is not excepted by
456 /// TableGenBreakingDAGArgOperators's effect.
457 /// \code
458 /// let dagarg = (ins
459 /// a :$src1,
460 /// aa :$src2,
461 /// aaa:$src3
462 /// )
463 /// \endcode
464 /// \version 19
466
467 /// Style of aligning consecutive TableGen cond operator colons.
468 /// Align the colons of cases inside !cond operators.
469 /// \code
470 /// !cond(!eq(size, 1) : 1,
471 /// !eq(size, 16): 1,
472 /// true : 0)
473 /// \endcode
474 /// \version 19
476
477 /// Style of aligning consecutive TableGen definition colons.
478 /// This aligns the inheritance colons of consecutive definitions.
479 /// \code
480 /// def Def : Parent {}
481 /// def DefDef : Parent {}
482 /// def DefDefDef : Parent {}
483 /// \endcode
484 /// \version 19
486
487 /// Different styles for aligning escaped newlines.
489 /// Don't align escaped newlines.
490 /// \code
491 /// #define A \
492 /// int aaaa; \
493 /// int b; \
494 /// int dddddddddd;
495 /// \endcode
497 /// Align escaped newlines as far left as possible.
498 /// \code
499 /// #define A \
500 /// int aaaa; \
501 /// int b; \
502 /// int dddddddddd;
503 /// \endcode
505 /// Align escaped newlines as far left as possible, using the last line of
506 /// the preprocessor directive as the reference if it's the longest.
507 /// \code
508 /// #define A \
509 /// int aaaa; \
510 /// int b; \
511 /// int dddddddddd;
512 /// \endcode
514 /// Align escaped newlines in the right-most column.
515 /// \code
516 /// #define A \
517 /// int aaaa; \
518 /// int b; \
519 /// int dddddddddd;
520 /// \endcode
522 };
523
524 /// Options for aligning backslashes in escaped newlines.
525 /// \version 5
527
528 /// Different styles for aligning operands.
529 enum OperandAlignmentStyle : int8_t {
530 /// Do not align operands of binary and ternary expressions.
531 /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
532 /// the start of the line.
534 /// Horizontally align operands of binary and ternary expressions.
535 ///
536 /// Specifically, this aligns operands of a single expression that needs
537 /// to be split over multiple lines, e.g.:
538 /// \code
539 /// int aaa = bbbbbbbbbbbbbbb +
540 /// ccccccccccccccc;
541 /// \endcode
542 ///
543 /// When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is
544 /// aligned with the operand on the first line.
545 /// \code
546 /// int aaa = bbbbbbbbbbbbbbb
547 /// + ccccccccccccccc;
548 /// \endcode
550 /// Horizontally align operands of binary and ternary expressions.
551 ///
552 /// This is similar to ``OAS_Align``, except when
553 /// ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so
554 /// that the wrapped operand is aligned with the operand on the first line.
555 /// \code
556 /// int aaa = bbbbbbbbbbbbbbb
557 /// + ccccccccccccccc;
558 /// \endcode
560 };
561
562 /// If ``true``, horizontally align operands of binary and ternary
563 /// expressions.
564 /// \version 3.5
566
567 /// Enums for AlignTrailingComments
569 /// Leave trailing comments as they are.
570 /// \code
571 /// int a; // comment
572 /// int ab; // comment
573 ///
574 /// int abc; // comment
575 /// int abcd; // comment
576 /// \endcode
578 /// Align trailing comments.
579 /// \code
580 /// int a; // comment
581 /// int ab; // comment
582 ///
583 /// int abc; // comment
584 /// int abcd; // comment
585 /// \endcode
587 /// Don't align trailing comments but other formatter applies.
588 /// \code
589 /// int a; // comment
590 /// int ab; // comment
591 ///
592 /// int abc; // comment
593 /// int abcd; // comment
594 /// \endcode
596 };
597
598 /// Alignment options
600 /// Specifies the way to align trailing comments.
602 /// How many empty lines to apply alignment.
603 /// When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
604 /// it formats like below.
605 /// \code
606 /// int a; // all these
607 ///
608 /// int ab; // comments are
609 ///
610 ///
611 /// int abcdef; // aligned
612 /// \endcode
613 ///
614 /// When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
615 /// to 1, it formats like below.
616 /// \code
617 /// int a; // these are
618 ///
619 /// int ab; // aligned
620 ///
621 ///
622 /// int abcdef; // but this isn't
623 /// \endcode
625
627 return Kind == R.Kind && OverEmptyLines == R.OverEmptyLines;
628 }
630 return !(*this == R);
631 }
632 };
633
634 /// Control of trailing comments.
635 ///
636 /// The alignment stops at closing braces after a line break, and only
637 /// followed by other closing braces, a (``do-``) ``while``, a lambda call, or
638 /// a semicolon.
639 ///
640 /// \note
641 /// As of clang-format 16 this option is not a bool but can be set
642 /// to the options. Conventional bool options still can be parsed as before.
643 /// \endnote
644 ///
645 /// \code{.yaml}
646 /// # Example of usage:
647 /// AlignTrailingComments:
648 /// Kind: Always
649 /// OverEmptyLines: 2
650 /// \endcode
651 /// \version 3.7
653
654 /// \brief If a function call or braced initializer list doesn't fit on a
655 /// line, allow putting all arguments onto the next line, even if
656 /// ``BinPackArguments`` is ``false``.
657 /// \code
658 /// true:
659 /// callFunction(
660 /// a, b, c, d);
661 ///
662 /// false:
663 /// callFunction(a,
664 /// b,
665 /// c,
666 /// d);
667 /// \endcode
668 /// \version 9
670
671 /// This option is **deprecated**. See ``NextLine`` of
672 /// ``PackConstructorInitializers``.
673 /// \version 9
674 // bool AllowAllConstructorInitializersOnNextLine;
675
676 /// If the function declaration doesn't fit on a line,
677 /// allow putting all parameters of a function declaration onto
678 /// the next line even if ``BinPackParameters`` is ``OnePerLine``.
679 /// \code
680 /// true:
681 /// void myFunction(
682 /// int a, int b, int c, int d, int e);
683 ///
684 /// false:
685 /// void myFunction(int a,
686 /// int b,
687 /// int c,
688 /// int d,
689 /// int e);
690 /// \endcode
691 /// \version 3.3
693
694 /// Different ways to break before a noexcept specifier.
696 /// No line break allowed.
697 /// \code
698 /// void foo(int arg1,
699 /// double arg2) noexcept;
700 ///
701 /// void bar(int arg1, double arg2) noexcept(
702 /// noexcept(baz(arg1)) &&
703 /// noexcept(baz(arg2)));
704 /// \endcode
706 /// For a simple ``noexcept`` there is no line break allowed, but when we
707 /// have a condition it is.
708 /// \code
709 /// void foo(int arg1,
710 /// double arg2) noexcept;
711 ///
712 /// void bar(int arg1, double arg2)
713 /// noexcept(noexcept(baz(arg1)) &&
714 /// noexcept(baz(arg2)));
715 /// \endcode
717 /// Line breaks are allowed. But note that because of the associated
718 /// penalties ``clang-format`` often prefers not to break before the
719 /// ``noexcept``.
720 /// \code
721 /// void foo(int arg1,
722 /// double arg2) noexcept;
723 ///
724 /// void bar(int arg1, double arg2)
725 /// noexcept(noexcept(baz(arg1)) &&
726 /// noexcept(baz(arg2)));
727 /// \endcode
729 };
730
731 /// Controls if there could be a line break before a ``noexcept`` specifier.
732 /// \version 18
734
735 /// Different styles for merging short blocks containing at most one
736 /// statement.
737 enum ShortBlockStyle : int8_t {
738 /// Never merge blocks into a single line.
739 /// \code
740 /// while (true) {
741 /// }
742 /// while (true) {
743 /// continue;
744 /// }
745 /// \endcode
747 /// Only merge empty blocks.
748 /// \code
749 /// while (true) {}
750 /// while (true) {
751 /// continue;
752 /// }
753 /// \endcode
755 /// Always merge short blocks into a single line.
756 /// \code
757 /// while (true) {}
758 /// while (true) { continue; }
759 /// \endcode
761 };
762
763 /// Dependent on the value, ``while (true) { continue; }`` can be put on a
764 /// single line.
765 /// \version 3.5
767
768 /// Whether to merge a short switch labeled rule into a single line.
769 /// \code{.java}
770 /// true: false:
771 /// switch (a) { vs. switch (a) {
772 /// case 1 -> 1; case 1 ->
773 /// default -> 0; 1;
774 /// }; default ->
775 /// 0;
776 /// };
777 /// \endcode
778 /// \version 19
780
781 /// If ``true``, short case labels will be contracted to a single line.
782 /// \code
783 /// true: false:
784 /// switch (a) { vs. switch (a) {
785 /// case 1: x = 1; break; case 1:
786 /// case 2: return; x = 1;
787 /// } break;
788 /// case 2:
789 /// return;
790 /// }
791 /// \endcode
792 /// \version 3.6
794
795 /// Allow short compound requirement on a single line.
796 /// \code
797 /// true:
798 /// template <typename T>
799 /// concept c = requires(T x) {
800 /// { x + 1 } -> std::same_as<int>;
801 /// };
802 ///
803 /// false:
804 /// template <typename T>
805 /// concept c = requires(T x) {
806 /// {
807 /// x + 1
808 /// } -> std::same_as<int>;
809 /// };
810 /// \endcode
811 /// \version 18
813
814 /// Allow short enums on a single line.
815 /// \code
816 /// true:
817 /// enum { A, B } myEnum;
818 ///
819 /// false:
820 /// enum {
821 /// A,
822 /// B
823 /// } myEnum;
824 /// \endcode
825 /// \version 11
827
828 /// Different styles for merging short functions containing at most one
829 /// statement.
830 enum ShortFunctionStyle : int8_t {
831 /// Never merge functions into a single line.
833 /// Only merge functions defined inside a class. Same as ``inline``,
834 /// except it does not implies ``empty``: i.e. top level empty functions
835 /// are not merged either.
836 /// \code
837 /// class Foo {
838 /// void f() { foo(); }
839 /// };
840 /// void f() {
841 /// foo();
842 /// }
843 /// void f() {
844 /// }
845 /// \endcode
847 /// Only merge empty functions.
848 /// \code
849 /// void f() {}
850 /// void f2() {
851 /// bar2();
852 /// }
853 /// \endcode
855 /// Only merge functions defined inside a class. Implies ``empty``.
856 /// \code
857 /// class Foo {
858 /// void f() { foo(); }
859 /// };
860 /// void f() {
861 /// foo();
862 /// }
863 /// void f() {}
864 /// \endcode
866 /// Merge all functions fitting on a single line.
867 /// \code
868 /// class Foo {
869 /// void f() { foo(); }
870 /// };
871 /// void f() { bar(); }
872 /// \endcode
874 };
875
876 /// Dependent on the value, ``int f() { return 0; }`` can be put on a
877 /// single line.
878 /// \version 3.5
880
881 /// Different styles for handling short if statements.
882 enum ShortIfStyle : int8_t {
883 /// Never put short ifs on the same line.
884 /// \code
885 /// if (a)
886 /// return;
887 ///
888 /// if (b)
889 /// return;
890 /// else
891 /// return;
892 ///
893 /// if (c)
894 /// return;
895 /// else {
896 /// return;
897 /// }
898 /// \endcode
900 /// Put short ifs on the same line only if there is no else statement.
901 /// \code
902 /// if (a) return;
903 ///
904 /// if (b)
905 /// return;
906 /// else
907 /// return;
908 ///
909 /// if (c)
910 /// return;
911 /// else {
912 /// return;
913 /// }
914 /// \endcode
916 /// Put short ifs, but not else ifs nor else statements, on the same line.
917 /// \code
918 /// if (a) return;
919 ///
920 /// if (b) return;
921 /// else if (b)
922 /// return;
923 /// else
924 /// return;
925 ///
926 /// if (c) return;
927 /// else {
928 /// return;
929 /// }
930 /// \endcode
932 /// Always put short ifs, else ifs and else statements on the same
933 /// line.
934 /// \code
935 /// if (a) return;
936 ///
937 /// if (b) return;
938 /// else return;
939 ///
940 /// if (c) return;
941 /// else {
942 /// return;
943 /// }
944 /// \endcode
946 };
947
948 /// Dependent on the value, ``if (a) return;`` can be put on a single line.
949 /// \version 3.3
951
952 /// Different styles for merging short lambdas containing at most one
953 /// statement.
954 enum ShortLambdaStyle : int8_t {
955 /// Never merge lambdas into a single line.
957 /// Only merge empty lambdas.
958 /// \code
959 /// auto lambda = [](int a) {};
960 /// auto lambda2 = [](int a) {
961 /// return a;
962 /// };
963 /// \endcode
965 /// Merge lambda into a single line if the lambda is argument of a function.
966 /// \code
967 /// auto lambda = [](int x, int y) {
968 /// return x < y;
969 /// };
970 /// sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
971 /// \endcode
973 /// Merge all lambdas fitting on a single line.
974 /// \code
975 /// auto lambda = [](int a) {};
976 /// auto lambda2 = [](int a) { return a; };
977 /// \endcode
979 };
980
981 /// Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
982 /// single line.
983 /// \version 9
985
986 /// If ``true``, ``while (true) continue;`` can be put on a single
987 /// line.
988 /// \version 3.7
990
991 /// Different ways to break after the function definition return type.
992 /// This option is **deprecated** and is retained for backwards compatibility.
994 /// Break after return type automatically.
995 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
997 /// Always break after the return type.
999 /// Always break after the return types of top-level functions.
1001 };
1002
1003 /// Different ways to break after the function definition or
1004 /// declaration return type.
1006 /// This is **deprecated**. See ``Automatic`` below.
1008 /// Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.
1009 /// \code
1010 /// class A {
1011 /// int f() { return 0; };
1012 /// };
1013 /// int f();
1014 /// int f() { return 1; }
1015 /// int
1016 /// LongName::AnotherLongName();
1017 /// \endcode
1019 /// Same as ``Automatic`` above, except that there is no break after short
1020 /// return types.
1021 /// \code
1022 /// class A {
1023 /// int f() { return 0; };
1024 /// };
1025 /// int f();
1026 /// int f() { return 1; }
1027 /// int LongName::
1028 /// AnotherLongName();
1029 /// \endcode
1031 /// Always break after the return type.
1032 /// \code
1033 /// class A {
1034 /// int
1035 /// f() {
1036 /// return 0;
1037 /// };
1038 /// };
1039 /// int
1040 /// f();
1041 /// int
1042 /// f() {
1043 /// return 1;
1044 /// }
1045 /// int
1046 /// LongName::AnotherLongName();
1047 /// \endcode
1049 /// Always break after the return types of top-level functions.
1050 /// \code
1051 /// class A {
1052 /// int f() { return 0; };
1053 /// };
1054 /// int
1055 /// f();
1056 /// int
1057 /// f() {
1058 /// return 1;
1059 /// }
1060 /// int
1061 /// LongName::AnotherLongName();
1062 /// \endcode
1064 /// Always break after the return type of function definitions.
1065 /// \code
1066 /// class A {
1067 /// int
1068 /// f() {
1069 /// return 0;
1070 /// };
1071 /// };
1072 /// int f();
1073 /// int
1074 /// f() {
1075 /// return 1;
1076 /// }
1077 /// int
1078 /// LongName::AnotherLongName();
1079 /// \endcode
1081 /// Always break after the return type of top-level definitions.
1082 /// \code
1083 /// class A {
1084 /// int f() { return 0; };
1085 /// };
1086 /// int f();
1087 /// int
1088 /// f() {
1089 /// return 1;
1090 /// }
1091 /// int
1092 /// LongName::AnotherLongName();
1093 /// \endcode
1095 };
1096
1097 /// The function definition return type breaking style to use. This
1098 /// option is **deprecated** and is retained for backwards compatibility.
1099 /// \version 3.7
1101
1102 /// This option is renamed to ``BreakAfterReturnType``.
1103 /// \version 3.8
1104 /// @deprecated
1105 // ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
1106
1107 /// If ``true``, always break before multiline string literals.
1108 ///
1109 /// This flag is mean to make cases where there are multiple multiline strings
1110 /// in a file look more consistent. Thus, it will only take effect if wrapping
1111 /// the string at that point leads to it being indented
1112 /// ``ContinuationIndentWidth`` spaces from the start of the line.
1113 /// \code
1114 /// true: false:
1115 /// aaaa = vs. aaaa = "bbbb"
1116 /// "bbbb" "cccc";
1117 /// "cccc";
1118 /// \endcode
1119 /// \version 3.4
1121
1122 /// Different ways to break after the template declaration.
1124 /// Do not change the line breaking before the declaration.
1125 /// \code
1126 /// template <typename T>
1127 /// T foo() {
1128 /// }
1129 /// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1130 /// int bbbbbbbbbbbbbbbbbbbbb) {
1131 /// }
1132 /// \endcode
1134 /// Do not force break before declaration.
1135 /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
1136 /// \code
1137 /// template <typename T> T foo() {
1138 /// }
1139 /// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1140 /// int bbbbbbbbbbbbbbbbbbbbb) {
1141 /// }
1142 /// \endcode
1144 /// Force break after template declaration only when the following
1145 /// declaration spans multiple lines.
1146 /// \code
1147 /// template <typename T> T foo() {
1148 /// }
1149 /// template <typename T>
1150 /// T foo(int aaaaaaaaaaaaaaaaaaaaa,
1151 /// int bbbbbbbbbbbbbbbbbbbbb) {
1152 /// }
1153 /// \endcode
1155 /// Always break after template declaration.
1156 /// \code
1157 /// template <typename T>
1158 /// T foo() {
1159 /// }
1160 /// template <typename T>
1161 /// T foo(int aaaaaaaaaaaaaaaaaaaaa,
1162 /// int bbbbbbbbbbbbbbbbbbbbb) {
1163 /// }
1164 /// \endcode
1165 BTDS_Yes
1167
1168 /// This option is renamed to ``BreakTemplateDeclarations``.
1169 /// \version 3.4
1170 /// @deprecated
1171 // BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
1172
1173 /// A vector of strings that should be interpreted as attributes/qualifiers
1174 /// instead of identifiers. This can be useful for language extensions or
1175 /// static analyzer annotations.
1176 ///
1177 /// For example:
1178 /// \code
1179 /// x = (char *__capability)&y;
1180 /// int function(void) __unused;
1181 /// void only_writes_to_buffer(char *__output buffer);
1182 /// \endcode
1183 ///
1184 /// In the .clang-format configuration file, this can be configured like:
1185 /// \code{.yaml}
1186 /// AttributeMacros: [__capability, __output, __unused]
1187 /// \endcode
1188 ///
1189 /// \version 12
1190 std::vector<std::string> AttributeMacros;
1191
1192 /// If ``false``, a function call's arguments will either be all on the
1193 /// same line or will have one line each.
1194 /// \code
1195 /// true:
1196 /// void f() {
1197 /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
1198 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1199 /// }
1200 ///
1201 /// false:
1202 /// void f() {
1203 /// f(aaaaaaaaaaaaaaaaaaaa,
1204 /// aaaaaaaaaaaaaaaaaaaa,
1205 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1206 /// }
1207 /// \endcode
1208 /// \version 3.7
1210
1211 /// Different way to try to fit all parameters on a line.
1213 /// Bin-pack parameters.
1214 /// \code
1215 /// void f(int a, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
1216 /// int ccccccccccccccccccccccccccccccccccccccccccc);
1217 /// \endcode
1219 /// Put all parameters on the current line if they fit.
1220 /// Otherwise, put each one on its own line.
1221 /// \code
1222 /// void f(int a, int b, int c);
1223 ///
1224 /// void f(int a,
1225 /// int b,
1226 /// int ccccccccccccccccccccccccccccccccccccc);
1227 /// \endcode
1229 /// Always put each parameter on its own line.
1230 /// \code
1231 /// void f(int a,
1232 /// int b,
1233 /// int c);
1234 /// \endcode
1236 };
1237
1238 /// The bin pack parameters style to use.
1239 /// \version 3.7
1241
1242 /// Styles for adding spacing around ``:`` in bitfield definitions.
1244 /// Add one space on each side of the ``:``
1245 /// \code
1246 /// unsigned bf : 2;
1247 /// \endcode
1249 /// Add no space around the ``:`` (except when needed for
1250 /// ``AlignConsecutiveBitFields``).
1251 /// \code
1252 /// unsigned bf:2;
1253 /// \endcode
1255 /// Add space before the ``:`` only
1256 /// \code
1257 /// unsigned bf :2;
1258 /// \endcode
1260 /// Add space after the ``:`` only (space may be added before if
1261 /// needed for ``AlignConsecutiveBitFields``).
1262 /// \code
1263 /// unsigned bf: 2;
1264 /// \endcode
1267 /// The BitFieldColonSpacingStyle to use for bitfields.
1268 /// \version 12
1270
1271 /// The number of columns to use to indent the contents of braced init lists.
1272 /// If unset, ``ContinuationIndentWidth`` is used.
1273 /// \code
1274 /// AlignAfterOpenBracket: AlwaysBreak
1275 /// BracedInitializerIndentWidth: 2
1276 ///
1277 /// void f() {
1278 /// SomeClass c{
1279 /// "foo",
1280 /// "bar",
1281 /// "baz",
1282 /// };
1283 /// auto s = SomeStruct{
1284 /// .foo = "foo",
1285 /// .bar = "bar",
1286 /// .baz = "baz",
1287 /// };
1288 /// SomeArrayT a[3] = {
1289 /// {
1290 /// foo,
1291 /// bar,
1292 /// },
1293 /// {
1294 /// foo,
1295 /// bar,
1296 /// },
1297 /// SomeArrayT{},
1298 /// };
1299 /// }
1300 /// \endcode
1301 /// \version 17
1302 std::optional<unsigned> BracedInitializerIndentWidth;
1303
1304 /// Different ways to wrap braces after control statements.
1306 /// Never wrap braces after a control statement.
1307 /// \code
1308 /// if (foo()) {
1309 /// } else {
1310 /// }
1311 /// for (int i = 0; i < 10; ++i) {
1312 /// }
1313 /// \endcode
1315 /// Only wrap braces after a multi-line control statement.
1316 /// \code
1317 /// if (foo && bar &&
1318 /// baz)
1319 /// {
1320 /// quux();
1321 /// }
1322 /// while (foo || bar) {
1323 /// }
1324 /// \endcode
1326 /// Always wrap braces after a control statement.
1327 /// \code
1328 /// if (foo())
1329 /// {
1330 /// } else
1331 /// {}
1332 /// for (int i = 0; i < 10; ++i)
1333 /// {}
1334 /// \endcode
1337
1338 /// Precise control over the wrapping of braces.
1339 /// \code
1340 /// # Should be declared this way:
1341 /// BreakBeforeBraces: Custom
1342 /// BraceWrapping:
1343 /// AfterClass: true
1344 /// \endcode
1346 /// Wrap case labels.
1347 /// \code
1348 /// false: true:
1349 /// switch (foo) { vs. switch (foo) {
1350 /// case 1: { case 1:
1351 /// bar(); {
1352 /// break; bar();
1353 /// } break;
1354 /// default: { }
1355 /// plop(); default:
1356 /// } {
1357 /// } plop();
1358 /// }
1359 /// }
1360 /// \endcode
1362 /// Wrap class definitions.
1363 /// \code
1364 /// true:
1365 /// class foo
1366 /// {};
1367 ///
1368 /// false:
1369 /// class foo {};
1370 /// \endcode
1372
1373 /// Wrap control statements (``if``/``for``/``while``/``switch``/..).
1375 /// Wrap enum definitions.
1376 /// \code
1377 /// true:
1378 /// enum X : int
1379 /// {
1380 /// B
1381 /// };
1382 ///
1383 /// false:
1384 /// enum X : int { B };
1385 /// \endcode
1387 /// Wrap function definitions.
1388 /// \code
1389 /// true:
1390 /// void foo()
1391 /// {
1392 /// bar();
1393 /// bar2();
1394 /// }
1395 ///
1396 /// false:
1397 /// void foo() {
1398 /// bar();
1399 /// bar2();
1400 /// }
1401 /// \endcode
1403 /// Wrap namespace definitions.
1404 /// \code
1405 /// true:
1406 /// namespace
1407 /// {
1408 /// int foo();
1409 /// int bar();
1410 /// }
1411 ///
1412 /// false:
1413 /// namespace {
1414 /// int foo();
1415 /// int bar();
1416 /// }
1417 /// \endcode
1419 /// Wrap ObjC definitions (interfaces, implementations...).
1420 /// \note
1421 /// @autoreleasepool and @synchronized blocks are wrapped
1422 /// according to ``AfterControlStatement`` flag.
1423 /// \endnote
1425 /// Wrap struct definitions.
1426 /// \code
1427 /// true:
1428 /// struct foo
1429 /// {
1430 /// int x;
1431 /// };
1432 ///
1433 /// false:
1434 /// struct foo {
1435 /// int x;
1436 /// };
1437 /// \endcode
1439 /// Wrap union definitions.
1440 /// \code
1441 /// true:
1442 /// union foo
1443 /// {
1444 /// int x;
1445 /// }
1446 ///
1447 /// false:
1448 /// union foo {
1449 /// int x;
1450 /// }
1451 /// \endcode
1453 /// Wrap extern blocks.
1454 /// \code
1455 /// true:
1456 /// extern "C"
1457 /// {
1458 /// int foo();
1459 /// }
1460 ///
1461 /// false:
1462 /// extern "C" {
1463 /// int foo();
1464 /// }
1465 /// \endcode
1466 bool AfterExternBlock; // Partially superseded by IndentExternBlock
1467 /// Wrap before ``catch``.
1468 /// \code
1469 /// true:
1470 /// try {
1471 /// foo();
1472 /// }
1473 /// catch () {
1474 /// }
1475 ///
1476 /// false:
1477 /// try {
1478 /// foo();
1479 /// } catch () {
1480 /// }
1481 /// \endcode
1483 /// Wrap before ``else``.
1484 /// \code
1485 /// true:
1486 /// if (foo()) {
1487 /// }
1488 /// else {
1489 /// }
1490 ///
1491 /// false:
1492 /// if (foo()) {
1493 /// } else {
1494 /// }
1495 /// \endcode
1497 /// Wrap lambda block.
1498 /// \code
1499 /// true:
1500 /// connect(
1501 /// []()
1502 /// {
1503 /// foo();
1504 /// bar();
1505 /// });
1506 ///
1507 /// false:
1508 /// connect([]() {
1509 /// foo();
1510 /// bar();
1511 /// });
1512 /// \endcode
1514 /// Wrap before ``while``.
1515 /// \code
1516 /// true:
1517 /// do {
1518 /// foo();
1519 /// }
1520 /// while (1);
1521 ///
1522 /// false:
1523 /// do {
1524 /// foo();
1525 /// } while (1);
1526 /// \endcode
1528 /// Indent the wrapped braces themselves.
1530 /// If ``false``, empty function body can be put on a single line.
1531 /// This option is used only if the opening brace of the function has
1532 /// already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
1533 /// set, and the function could/should not be put on a single line (as per
1534 /// ``AllowShortFunctionsOnASingleLine`` and constructor formatting
1535 /// options).
1536 /// \code
1537 /// false: true:
1538 /// int f() vs. int f()
1539 /// {} {
1540 /// }
1541 /// \endcode
1542 ///
1544 /// If ``false``, empty record (e.g. class, struct or union) body
1545 /// can be put on a single line. This option is used only if the opening
1546 /// brace of the record has already been wrapped, i.e. the ``AfterClass``
1547 /// (for classes) brace wrapping mode is set.
1548 /// \code
1549 /// false: true:
1550 /// class Foo vs. class Foo
1551 /// {} {
1552 /// }
1553 /// \endcode
1554 ///
1556 /// If ``false``, empty namespace body can be put on a single line.
1557 /// This option is used only if the opening brace of the namespace has
1558 /// already been wrapped, i.e. the ``AfterNamespace`` brace wrapping mode is
1559 /// set.
1560 /// \code
1561 /// false: true:
1562 /// namespace Foo vs. namespace Foo
1563 /// {} {
1564 /// }
1565 /// \endcode
1566 ///
1568 };
1569
1570 /// Control of individual brace wrapping cases.
1571 ///
1572 /// If ``BreakBeforeBraces`` is set to ``Custom``, use this to specify how
1573 /// each individual brace case should be handled. Otherwise, this is ignored.
1574 /// \code{.yaml}
1575 /// # Example of usage:
1576 /// BreakBeforeBraces: Custom
1577 /// BraceWrapping:
1578 /// AfterEnum: true
1579 /// AfterStruct: false
1580 /// SplitEmptyFunction: false
1581 /// \endcode
1582 /// \version 3.8
1584
1585 /// Break between adjacent string literals.
1586 /// \code
1587 /// true:
1588 /// return "Code"
1589 /// "\0\52\26\55\55\0"
1590 /// "x013"
1591 /// "\02\xBA";
1592 /// false:
1593 /// return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
1594 /// \endcode
1595 /// \version 18
1597
1598 /// Different ways to break after attributes.
1600 /// Always break after attributes.
1601 /// \code
1602 /// [[maybe_unused]]
1603 /// const int i;
1604 /// [[gnu::const]] [[maybe_unused]]
1605 /// int j;
1606 ///
1607 /// [[nodiscard]]
1608 /// inline int f();
1609 /// [[gnu::const]] [[nodiscard]]
1610 /// int g();
1611 ///
1612 /// [[likely]]
1613 /// if (a)
1614 /// f();
1615 /// else
1616 /// g();
1617 ///
1618 /// switch (b) {
1619 /// [[unlikely]]
1620 /// case 1:
1621 /// ++b;
1622 /// break;
1623 /// [[likely]]
1624 /// default:
1625 /// return;
1626 /// }
1627 /// \endcode
1629 /// Leave the line breaking after attributes as is.
1630 /// \code
1631 /// [[maybe_unused]] const int i;
1632 /// [[gnu::const]] [[maybe_unused]]
1633 /// int j;
1634 ///
1635 /// [[nodiscard]] inline int f();
1636 /// [[gnu::const]] [[nodiscard]]
1637 /// int g();
1638 ///
1639 /// [[likely]] if (a)
1640 /// f();
1641 /// else
1642 /// g();
1643 ///
1644 /// switch (b) {
1645 /// [[unlikely]] case 1:
1646 /// ++b;
1647 /// break;
1648 /// [[likely]]
1649 /// default:
1650 /// return;
1651 /// }
1652 /// \endcode
1654 /// Never break after attributes.
1655 /// \code
1656 /// [[maybe_unused]] const int i;
1657 /// [[gnu::const]] [[maybe_unused]] int j;
1658 ///
1659 /// [[nodiscard]] inline int f();
1660 /// [[gnu::const]] [[nodiscard]] int g();
1661 ///
1662 /// [[likely]] if (a)
1663 /// f();
1664 /// else
1665 /// g();
1666 ///
1667 /// switch (b) {
1668 /// [[unlikely]] case 1:
1669 /// ++b;
1670 /// break;
1671 /// [[likely]] default:
1672 /// return;
1673 /// }
1674 /// \endcode
1676 };
1677
1678 /// Break after a group of C++11 attributes before variable or function
1679 /// (including constructor/destructor) declaration/definition names or before
1680 /// control statements, i.e. ``if``, ``switch`` (including ``case`` and
1681 /// ``default`` labels), ``for``, and ``while`` statements.
1682 /// \version 16
1684
1685 /// The function declaration return type breaking style to use.
1686 /// \version 19
1688
1689 /// If ``true``, clang-format will always break after a Json array ``[``
1690 /// otherwise it will scan until the closing ``]`` to determine if it should
1691 /// add newlines between elements (prettier compatible).
1692 ///
1693 /// \note
1694 /// This is currently only for formatting JSON.
1695 /// \endnote
1696 /// \code
1697 /// true: false:
1698 /// [ vs. [1, 2, 3, 4]
1699 /// 1,
1700 /// 2,
1701 /// 3,
1702 /// 4
1703 /// ]
1704 /// \endcode
1705 /// \version 16
1707
1708 /// The style of wrapping parameters on the same line (bin-packed) or
1709 /// on one line each.
1710 enum BinPackStyle : int8_t {
1711 /// Automatically determine parameter bin-packing behavior.
1713 /// Always bin-pack parameters.
1715 /// Never bin-pack parameters.
1717 };
1718
1719 /// The style of breaking before or after binary operators.
1720 enum BinaryOperatorStyle : int8_t {
1721 /// Break after operators.
1722 /// \code
1723 /// LooooooooooongType loooooooooooooooooooooongVariable =
1724 /// someLooooooooooooooooongFunction();
1725 ///
1726 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
1727 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
1728 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
1729 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
1730 /// ccccccccccccccccccccccccccccccccccccccccc;
1731 /// \endcode
1733 /// Break before operators that aren't assignments.
1734 /// \code
1735 /// LooooooooooongType loooooooooooooooooooooongVariable =
1736 /// someLooooooooooooooooongFunction();
1737 ///
1738 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1739 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1740 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1741 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1742 /// > ccccccccccccccccccccccccccccccccccccccccc;
1743 /// \endcode
1745 /// Break before operators.
1746 /// \code
1747 /// LooooooooooongType loooooooooooooooooooooongVariable
1748 /// = someLooooooooooooooooongFunction();
1749 ///
1750 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1751 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1752 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1753 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1754 /// > ccccccccccccccccccccccccccccccccccccccccc;
1755 /// \endcode
1757 };
1758
1759 /// The way to wrap binary operators.
1760 /// \version 3.6
1762
1763 /// Different ways to attach braces to their surrounding context.
1764 enum BraceBreakingStyle : int8_t {
1765 /// Always attach braces to surrounding context.
1766 /// \code
1767 /// namespace N {
1768 /// enum E {
1769 /// E1,
1770 /// E2,
1771 /// };
1772 ///
1773 /// class C {
1774 /// public:
1775 /// C();
1776 /// };
1777 ///
1778 /// bool baz(int i) {
1779 /// try {
1780 /// do {
1781 /// switch (i) {
1782 /// case 1: {
1783 /// foobar();
1784 /// break;
1785 /// }
1786 /// default: {
1787 /// break;
1788 /// }
1789 /// }
1790 /// } while (--i);
1791 /// return true;
1792 /// } catch (...) {
1793 /// handleError();
1794 /// return false;
1795 /// }
1796 /// }
1797 ///
1798 /// void foo(bool b) {
1799 /// if (b) {
1800 /// baz(2);
1801 /// } else {
1802 /// baz(5);
1803 /// }
1804 /// }
1805 ///
1806 /// void bar() { foo(true); }
1807 /// } // namespace N
1808 /// \endcode
1810 /// Like ``Attach``, but break before braces on function, namespace and
1811 /// class definitions.
1812 /// \code
1813 /// namespace N
1814 /// {
1815 /// enum E {
1816 /// E1,
1817 /// E2,
1818 /// };
1819 ///
1820 /// class C
1821 /// {
1822 /// public:
1823 /// C();
1824 /// };
1825 ///
1826 /// bool baz(int i)
1827 /// {
1828 /// try {
1829 /// do {
1830 /// switch (i) {
1831 /// case 1: {
1832 /// foobar();
1833 /// break;
1834 /// }
1835 /// default: {
1836 /// break;
1837 /// }
1838 /// }
1839 /// } while (--i);
1840 /// return true;
1841 /// } catch (...) {
1842 /// handleError();
1843 /// return false;
1844 /// }
1845 /// }
1846 ///
1847 /// void foo(bool b)
1848 /// {
1849 /// if (b) {
1850 /// baz(2);
1851 /// } else {
1852 /// baz(5);
1853 /// }
1854 /// }
1855 ///
1856 /// void bar() { foo(true); }
1857 /// } // namespace N
1858 /// \endcode
1860 /// Like ``Attach``, but break before braces on enum, function, and record
1861 /// definitions.
1862 /// \code
1863 /// namespace N {
1864 /// enum E
1865 /// {
1866 /// E1,
1867 /// E2,
1868 /// };
1869 ///
1870 /// class C
1871 /// {
1872 /// public:
1873 /// C();
1874 /// };
1875 ///
1876 /// bool baz(int i)
1877 /// {
1878 /// try {
1879 /// do {
1880 /// switch (i) {
1881 /// case 1: {
1882 /// foobar();
1883 /// break;
1884 /// }
1885 /// default: {
1886 /// break;
1887 /// }
1888 /// }
1889 /// } while (--i);
1890 /// return true;
1891 /// } catch (...) {
1892 /// handleError();
1893 /// return false;
1894 /// }
1895 /// }
1896 ///
1897 /// void foo(bool b)
1898 /// {
1899 /// if (b) {
1900 /// baz(2);
1901 /// } else {
1902 /// baz(5);
1903 /// }
1904 /// }
1905 ///
1906 /// void bar() { foo(true); }
1907 /// } // namespace N
1908 /// \endcode
1910 /// Like ``Attach``, but break before function definitions, ``catch``, and
1911 /// ``else``.
1912 /// \code
1913 /// namespace N {
1914 /// enum E {
1915 /// E1,
1916 /// E2,
1917 /// };
1918 ///
1919 /// class C {
1920 /// public:
1921 /// C();
1922 /// };
1923 ///
1924 /// bool baz(int i)
1925 /// {
1926 /// try {
1927 /// do {
1928 /// switch (i) {
1929 /// case 1: {
1930 /// foobar();
1931 /// break;
1932 /// }
1933 /// default: {
1934 /// break;
1935 /// }
1936 /// }
1937 /// } while (--i);
1938 /// return true;
1939 /// }
1940 /// catch (...) {
1941 /// handleError();
1942 /// return false;
1943 /// }
1944 /// }
1945 ///
1946 /// void foo(bool b)
1947 /// {
1948 /// if (b) {
1949 /// baz(2);
1950 /// }
1951 /// else {
1952 /// baz(5);
1953 /// }
1954 /// }
1955 ///
1956 /// void bar() { foo(true); }
1957 /// } // namespace N
1958 /// \endcode
1960 /// Always break before braces.
1961 /// \code
1962 /// namespace N
1963 /// {
1964 /// enum E
1965 /// {
1966 /// E1,
1967 /// E2,
1968 /// };
1969 ///
1970 /// class C
1971 /// {
1972 /// public:
1973 /// C();
1974 /// };
1975 ///
1976 /// bool baz(int i)
1977 /// {
1978 /// try
1979 /// {
1980 /// do
1981 /// {
1982 /// switch (i)
1983 /// {
1984 /// case 1:
1985 /// {
1986 /// foobar();
1987 /// break;
1988 /// }
1989 /// default:
1990 /// {
1991 /// break;
1992 /// }
1993 /// }
1994 /// } while (--i);
1995 /// return true;
1996 /// }
1997 /// catch (...)
1998 /// {
1999 /// handleError();
2000 /// return false;
2001 /// }
2002 /// }
2003 ///
2004 /// void foo(bool b)
2005 /// {
2006 /// if (b)
2007 /// {
2008 /// baz(2);
2009 /// }
2010 /// else
2011 /// {
2012 /// baz(5);
2013 /// }
2014 /// }
2015 ///
2016 /// void bar() { foo(true); }
2017 /// } // namespace N
2018 /// \endcode
2020 /// Like ``Allman`` but always indent braces and line up code with braces.
2021 /// \code
2022 /// namespace N
2023 /// {
2024 /// enum E
2025 /// {
2026 /// E1,
2027 /// E2,
2028 /// };
2029 ///
2030 /// class C
2031 /// {
2032 /// public:
2033 /// C();
2034 /// };
2035 ///
2036 /// bool baz(int i)
2037 /// {
2038 /// try
2039 /// {
2040 /// do
2041 /// {
2042 /// switch (i)
2043 /// {
2044 /// case 1:
2045 /// {
2046 /// foobar();
2047 /// break;
2048 /// }
2049 /// default:
2050 /// {
2051 /// break;
2052 /// }
2053 /// }
2054 /// } while (--i);
2055 /// return true;
2056 /// }
2057 /// catch (...)
2058 /// {
2059 /// handleError();
2060 /// return false;
2061 /// }
2062 /// }
2063 ///
2064 /// void foo(bool b)
2065 /// {
2066 /// if (b)
2067 /// {
2068 /// baz(2);
2069 /// }
2070 /// else
2071 /// {
2072 /// baz(5);
2073 /// }
2074 /// }
2075 ///
2076 /// void bar() { foo(true); }
2077 /// } // namespace N
2078 /// \endcode
2080 /// Always break before braces and add an extra level of indentation to
2081 /// braces of control statements, not to those of class, function
2082 /// or other definitions.
2083 /// \code
2084 /// namespace N
2085 /// {
2086 /// enum E
2087 /// {
2088 /// E1,
2089 /// E2,
2090 /// };
2091 ///
2092 /// class C
2093 /// {
2094 /// public:
2095 /// C();
2096 /// };
2097 ///
2098 /// bool baz(int i)
2099 /// {
2100 /// try
2101 /// {
2102 /// do
2103 /// {
2104 /// switch (i)
2105 /// {
2106 /// case 1:
2107 /// {
2108 /// foobar();
2109 /// break;
2110 /// }
2111 /// default:
2112 /// {
2113 /// break;
2114 /// }
2115 /// }
2116 /// }
2117 /// while (--i);
2118 /// return true;
2119 /// }
2120 /// catch (...)
2121 /// {
2122 /// handleError();
2123 /// return false;
2124 /// }
2125 /// }
2126 ///
2127 /// void foo(bool b)
2128 /// {
2129 /// if (b)
2130 /// {
2131 /// baz(2);
2132 /// }
2133 /// else
2134 /// {
2135 /// baz(5);
2136 /// }
2137 /// }
2138 ///
2139 /// void bar() { foo(true); }
2140 /// } // namespace N
2141 /// \endcode
2143 /// Like ``Attach``, but break before functions.
2144 /// \code
2145 /// namespace N {
2146 /// enum E {
2147 /// E1,
2148 /// E2,
2149 /// };
2150 ///
2151 /// class C {
2152 /// public:
2153 /// C();
2154 /// };
2155 ///
2156 /// bool baz(int i)
2157 /// {
2158 /// try {
2159 /// do {
2160 /// switch (i) {
2161 /// case 1: {
2162 /// foobar();
2163 /// break;
2164 /// }
2165 /// default: {
2166 /// break;
2167 /// }
2168 /// }
2169 /// } while (--i);
2170 /// return true;
2171 /// } catch (...) {
2172 /// handleError();
2173 /// return false;
2174 /// }
2175 /// }
2176 ///
2177 /// void foo(bool b)
2178 /// {
2179 /// if (b) {
2180 /// baz(2);
2181 /// } else {
2182 /// baz(5);
2183 /// }
2184 /// }
2185 ///
2186 /// void bar() { foo(true); }
2187 /// } // namespace N
2188 /// \endcode
2190 /// Configure each individual brace in ``BraceWrapping``.
2191 BS_Custom
2193
2194 /// The brace breaking style to use.
2195 /// \version 3.7
2197
2198 /// Different ways to break before concept declarations.
2200 /// Keep the template declaration line together with ``concept``.
2201 /// \code
2202 /// template <typename T> concept C = ...;
2203 /// \endcode
2205 /// Breaking between template declaration and ``concept`` is allowed. The
2206 /// actual behavior depends on the content and line breaking rules and
2207 /// penalties.
2209 /// Always break before ``concept``, putting it in the line after the
2210 /// template declaration.
2211 /// \code
2212 /// template <typename T>
2213 /// concept C = ...;
2214 /// \endcode
2216 };
2217
2218 /// The concept declaration style to use.
2219 /// \version 12
2221
2222 /// Different ways to break ASM parameters.
2224 /// No break before inline ASM colon.
2225 /// \code
2226 /// asm volatile("string", : : val);
2227 /// \endcode
2229 /// Break before inline ASM colon if the line length is longer than column
2230 /// limit.
2231 /// \code
2232 /// asm volatile("string", : : val);
2233 /// asm("cmoveq %1, %2, %[result]"
2234 /// : [result] "=r"(result)
2235 /// : "r"(test), "r"(new), "[result]"(old));
2236 /// \endcode
2238 /// Always break before inline ASM colon.
2239 /// \code
2240 /// asm volatile("string",
2241 /// :
2242 /// : val);
2243 /// \endcode
2245 };
2246
2247 /// The inline ASM colon style to use.
2248 /// \version 16
2250
2251 /// If ``true``, ternary operators will be placed after line breaks.
2252 /// \code
2253 /// true:
2254 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
2255 /// ? firstValue
2256 /// : SecondValueVeryVeryVeryVeryLong;
2257 ///
2258 /// false:
2259 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
2260 /// firstValue :
2261 /// SecondValueVeryVeryVeryVeryLong;
2262 /// \endcode
2263 /// \version 3.7
2265
2266 /// Different ways to break binary operations.
2268 /// Don't break binary operations
2269 /// \code
2270 /// aaa + bbbb * ccccc - ddddd +
2271 /// eeeeeeeeeeeeeeee;
2272 /// \endcode
2274
2275 /// Binary operations will either be all on the same line, or each operation
2276 /// will have one line each.
2277 /// \code
2278 /// aaa +
2279 /// bbbb *
2280 /// ccccc -
2281 /// ddddd +
2282 /// eeeeeeeeeeeeeeee;
2283 /// \endcode
2285
2286 /// Binary operations of a particular precedence that exceed the column
2287 /// limit will have one line each.
2288 /// \code
2289 /// aaa +
2290 /// bbbb * ccccc -
2291 /// ddddd +
2292 /// eeeeeeeeeeeeeeee;
2293 /// \endcode
2296
2297 /// The break constructor initializers style to use.
2298 /// \version 20
2300
2301 /// Different ways to break initializers.
2303 /// Break constructor initializers before the colon and after the commas.
2304 /// \code
2305 /// Constructor()
2306 /// : initializer1(),
2307 /// initializer2()
2308 /// \endcode
2310 /// Break constructor initializers before the colon and commas, and align
2311 /// the commas with the colon.
2312 /// \code
2313 /// Constructor()
2314 /// : initializer1()
2315 /// , initializer2()
2316 /// \endcode
2318 /// Break constructor initializers after the colon and commas.
2319 /// \code
2320 /// Constructor() :
2321 /// initializer1(),
2322 /// initializer2()
2323 /// \endcode
2326
2327 /// The break constructor initializers style to use.
2328 /// \version 5
2330
2331 /// If ``true``, clang-format will always break before function definition
2332 /// parameters.
2333 /// \code
2334 /// true:
2335 /// void functionDefinition(
2336 /// int A, int B) {}
2337 ///
2338 /// false:
2339 /// void functionDefinition(int A, int B) {}
2340 ///
2341 /// \endcode
2342 /// \version 19
2344
2345 /// Break after each annotation on a field in Java files.
2346 /// \code{.java}
2347 /// true: false:
2348 /// @Partial vs. @Partial @Mock DataLoad loader;
2349 /// @Mock
2350 /// DataLoad loader;
2351 /// \endcode
2352 /// \version 3.8
2354
2355 /// Allow breaking string literals when formatting.
2356 ///
2357 /// In C, C++, and Objective-C:
2358 /// \code
2359 /// true:
2360 /// const char* x = "veryVeryVeryVeryVeryVe"
2361 /// "ryVeryVeryVeryVeryVery"
2362 /// "VeryLongString";
2363 ///
2364 /// false:
2365 /// const char* x =
2366 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2367 /// \endcode
2368 ///
2369 /// In C# and Java:
2370 /// \code
2371 /// true:
2372 /// string x = "veryVeryVeryVeryVeryVe" +
2373 /// "ryVeryVeryVeryVeryVery" +
2374 /// "VeryLongString";
2375 ///
2376 /// false:
2377 /// string x =
2378 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2379 /// \endcode
2380 ///
2381 /// C# interpolated strings are not broken.
2382 ///
2383 /// In Verilog:
2384 /// \code
2385 /// true:
2386 /// string x = {"veryVeryVeryVeryVeryVe",
2387 /// "ryVeryVeryVeryVeryVery",
2388 /// "VeryLongString"};
2389 ///
2390 /// false:
2391 /// string x =
2392 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2393 /// \endcode
2394 ///
2395 /// \version 3.9
2397
2398 /// The column limit.
2399 ///
2400 /// A column limit of ``0`` means that there is no column limit. In this case,
2401 /// clang-format will respect the input's line breaking decisions within
2402 /// statements unless they contradict other rules.
2403 /// \version 3.7
2404 unsigned ColumnLimit;
2405
2406 /// A regular expression that describes comments with special meaning,
2407 /// which should not be split into lines or otherwise changed.
2408 /// \code
2409 /// // CommentPragmas: '^ FOOBAR pragma:'
2410 /// // Will leave the following line unaffected
2411 /// #include <vector> // FOOBAR pragma: keep
2412 /// \endcode
2413 /// \version 3.7
2414 std::string CommentPragmas;
2415
2416 /// Different ways to break inheritance list.
2418 /// Break inheritance list before the colon and after the commas.
2419 /// \code
2420 /// class Foo
2421 /// : Base1,
2422 /// Base2
2423 /// {};
2424 /// \endcode
2426 /// Break inheritance list before the colon and commas, and align
2427 /// the commas with the colon.
2428 /// \code
2429 /// class Foo
2430 /// : Base1
2431 /// , Base2
2432 /// {};
2433 /// \endcode
2435 /// Break inheritance list after the colon and commas.
2436 /// \code
2437 /// class Foo :
2438 /// Base1,
2439 /// Base2
2440 /// {};
2441 /// \endcode
2443 /// Break inheritance list only after the commas.
2444 /// \code
2445 /// class Foo : Base1,
2446 /// Base2
2447 /// {};
2448 /// \endcode
2450 };
2451
2452 /// The inheritance list style to use.
2453 /// \version 7
2455
2456 /// The template declaration breaking style to use.
2457 /// \version 19
2459
2460 /// If ``true``, consecutive namespace declarations will be on the same
2461 /// line. If ``false``, each namespace is declared on a new line.
2462 /// \code
2463 /// true:
2464 /// namespace Foo { namespace Bar {
2465 /// }}
2466 ///
2467 /// false:
2468 /// namespace Foo {
2469 /// namespace Bar {
2470 /// }
2471 /// }
2472 /// \endcode
2473 ///
2474 /// If it does not fit on a single line, the overflowing namespaces get
2475 /// wrapped:
2476 /// \code
2477 /// namespace Foo { namespace Bar {
2478 /// namespace Extra {
2479 /// }}}
2480 /// \endcode
2481 /// \version 5
2483
2484 /// This option is **deprecated**. See ``CurrentLine`` of
2485 /// ``PackConstructorInitializers``.
2486 /// \version 3.7
2487 // bool ConstructorInitializerAllOnOneLineOrOnePerLine;
2488
2489 /// The number of characters to use for indentation of constructor
2490 /// initializer lists as well as inheritance lists.
2491 /// \version 3.7
2493
2494 /// Indent width for line continuations.
2495 /// \code
2496 /// ContinuationIndentWidth: 2
2497 ///
2498 /// int i = // VeryVeryVeryVeryVeryLongComment
2499 /// longFunction( // Again a long comment
2500 /// arg);
2501 /// \endcode
2502 /// \version 3.7
2504
2505 /// If ``true``, format braced lists as best suited for C++11 braced
2506 /// lists.
2507 ///
2508 /// Important differences:
2509 /// * No spaces inside the braced list.
2510 /// * No line break before the closing brace.
2511 /// * Indentation with the continuation indent, not with the block indent.
2512 ///
2513 /// Fundamentally, C++11 braced lists are formatted exactly like function
2514 /// calls would be formatted in their place. If the braced list follows a name
2515 /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were
2516 /// the parentheses of a function call with that name. If there is no name,
2517 /// a zero-length name is assumed.
2518 /// \code
2519 /// true: false:
2520 /// vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
2521 /// vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
2522 /// f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
2523 /// new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
2524 /// \endcode
2525 /// \version 3.4
2527
2528 /// This option is **deprecated**. See ``DeriveLF`` and ``DeriveCRLF`` of
2529 /// ``LineEnding``.
2530 /// \version 10
2531 // bool DeriveLineEnding;
2532
2533 /// If ``true``, analyze the formatted file for the most common
2534 /// alignment of ``&`` and ``*``.
2535 /// Pointer and reference alignment styles are going to be updated according
2536 /// to the preferences found in the file.
2537 /// ``PointerAlignment`` is then used only as fallback.
2538 /// \version 3.7
2540
2541 /// Disables formatting completely.
2542 /// \version 3.7
2544
2545 /// Different styles for empty line after access modifiers.
2546 /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2547 /// empty lines between two access modifiers.
2549 /// Remove all empty lines after access modifiers.
2550 /// \code
2551 /// struct foo {
2552 /// private:
2553 /// int i;
2554 /// protected:
2555 /// int j;
2556 /// /* comment */
2557 /// public:
2558 /// foo() {}
2559 /// private:
2560 /// protected:
2561 /// };
2562 /// \endcode
2564 /// Keep existing empty lines after access modifiers.
2565 /// MaxEmptyLinesToKeep is applied instead.
2567 /// Always add empty line after access modifiers if there are none.
2568 /// MaxEmptyLinesToKeep is applied also.
2569 /// \code
2570 /// struct foo {
2571 /// private:
2572 ///
2573 /// int i;
2574 /// protected:
2575 ///
2576 /// int j;
2577 /// /* comment */
2578 /// public:
2579 ///
2580 /// foo() {}
2581 /// private:
2582 ///
2583 /// protected:
2584 ///
2585 /// };
2586 /// \endcode
2588 };
2589
2590 /// Defines when to put an empty line after access modifiers.
2591 /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2592 /// empty lines between two access modifiers.
2593 /// \version 13
2595
2596 /// Different styles for empty line before access modifiers.
2598 /// Remove all empty lines before access modifiers.
2599 /// \code
2600 /// struct foo {
2601 /// private:
2602 /// int i;
2603 /// protected:
2604 /// int j;
2605 /// /* comment */
2606 /// public:
2607 /// foo() {}
2608 /// private:
2609 /// protected:
2610 /// };
2611 /// \endcode
2613 /// Keep existing empty lines before access modifiers.
2615 /// Add empty line only when access modifier starts a new logical block.
2616 /// Logical block is a group of one or more member fields or functions.
2617 /// \code
2618 /// struct foo {
2619 /// private:
2620 /// int i;
2621 ///
2622 /// protected:
2623 /// int j;
2624 /// /* comment */
2625 /// public:
2626 /// foo() {}
2627 ///
2628 /// private:
2629 /// protected:
2630 /// };
2631 /// \endcode
2633 /// Always add empty line before access modifiers unless access modifier
2634 /// is at the start of struct or class definition.
2635 /// \code
2636 /// struct foo {
2637 /// private:
2638 /// int i;
2639 ///
2640 /// protected:
2641 /// int j;
2642 /// /* comment */
2643 ///
2644 /// public:
2645 /// foo() {}
2646 ///
2647 /// private:
2648 ///
2649 /// protected:
2650 /// };
2651 /// \endcode
2653 };
2654
2655 /// Defines in which cases to put empty line before access modifiers.
2656 /// \version 12
2658
2659 /// If ``true``, clang-format detects whether function calls and
2660 /// definitions are formatted with one parameter per line.
2661 ///
2662 /// Each call can be bin-packed, one-per-line or inconclusive. If it is
2663 /// inconclusive, e.g. completely on one line, but a decision needs to be
2664 /// made, clang-format analyzes whether there are other bin-packed cases in
2665 /// the input file and act accordingly.
2666 ///
2667 /// \note
2668 /// This is an experimental flag, that might go away or be renamed. Do
2669 /// not use this in config files, etc. Use at your own risk.
2670 /// \endnote
2671 /// \version 3.7
2673
2674 /// If ``true``, clang-format adds missing namespace end comments for
2675 /// namespaces and fixes invalid existing ones. This doesn't affect short
2676 /// namespaces, which are controlled by ``ShortNamespaceLines``.
2677 /// \code
2678 /// true: false:
2679 /// namespace longNamespace { vs. namespace longNamespace {
2680 /// void foo(); void foo();
2681 /// void bar(); void bar();
2682 /// } // namespace a }
2683 /// namespace shortNamespace { namespace shortNamespace {
2684 /// void baz(); void baz();
2685 /// } }
2686 /// \endcode
2687 /// \version 5
2689
2690 /// A vector of macros that should be interpreted as foreach loops
2691 /// instead of as function calls.
2692 ///
2693 /// These are expected to be macros of the form:
2694 /// \code
2695 /// FOREACH(<variable-declaration>, ...)
2696 /// <loop-body>
2697 /// \endcode
2698 ///
2699 /// In the .clang-format configuration file, this can be configured like:
2700 /// \code{.yaml}
2701 /// ForEachMacros: [RANGES_FOR, FOREACH]
2702 /// \endcode
2703 ///
2704 /// For example: BOOST_FOREACH.
2705 /// \version 3.7
2706 std::vector<std::string> ForEachMacros;
2707
2709
2710 /// A vector of macros that should be interpreted as conditionals
2711 /// instead of as function calls.
2712 ///
2713 /// These are expected to be macros of the form:
2714 /// \code
2715 /// IF(...)
2716 /// <conditional-body>
2717 /// else IF(...)
2718 /// <conditional-body>
2719 /// \endcode
2720 ///
2721 /// In the .clang-format configuration file, this can be configured like:
2722 /// \code{.yaml}
2723 /// IfMacros: [IF]
2724 /// \endcode
2725 ///
2726 /// For example: `KJ_IF_MAYBE
2727 /// <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_
2728 /// \version 13
2729 std::vector<std::string> IfMacros;
2730
2731 /// Specify whether access modifiers should have their own indentation level.
2732 ///
2733 /// When ``false``, access modifiers are indented (or outdented) relative to
2734 /// the record members, respecting the ``AccessModifierOffset``. Record
2735 /// members are indented one level below the record.
2736 /// When ``true``, access modifiers get their own indentation level. As a
2737 /// consequence, record members are always indented 2 levels below the record,
2738 /// regardless of the access modifier presence. Value of the
2739 /// ``AccessModifierOffset`` is ignored.
2740 /// \code
2741 /// false: true:
2742 /// class C { vs. class C {
2743 /// class D { class D {
2744 /// void bar(); void bar();
2745 /// protected: protected:
2746 /// D(); D();
2747 /// }; };
2748 /// public: public:
2749 /// C(); C();
2750 /// }; };
2751 /// void foo() { void foo() {
2752 /// return 1; return 1;
2753 /// } }
2754 /// \endcode
2755 /// \version 13
2757
2758 /// Indent case label blocks one level from the case label.
2759 ///
2760 /// When ``false``, the block following the case label uses the same
2761 /// indentation level as for the case label, treating the case label the same
2762 /// as an if-statement.
2763 /// When ``true``, the block gets indented as a scope block.
2764 /// \code
2765 /// false: true:
2766 /// switch (fool) { vs. switch (fool) {
2767 /// case 1: { case 1:
2768 /// bar(); {
2769 /// } break; bar();
2770 /// default: { }
2771 /// plop(); break;
2772 /// } default:
2773 /// } {
2774 /// plop();
2775 /// }
2776 /// }
2777 /// \endcode
2778 /// \version 11
2780
2781 /// Indent case labels one level from the switch statement.
2782 ///
2783 /// When ``false``, use the same indentation level as for the switch
2784 /// statement. Switch statement body is always indented one level more than
2785 /// case labels (except the first block following the case label, which
2786 /// itself indents the code - unless IndentCaseBlocks is enabled).
2787 /// \code
2788 /// false: true:
2789 /// switch (fool) { vs. switch (fool) {
2790 /// case 1: case 1:
2791 /// bar(); bar();
2792 /// break; break;
2793 /// default: default:
2794 /// plop(); plop();
2795 /// } }
2796 /// \endcode
2797 /// \version 3.3
2799
2800 /// Indent goto labels.
2801 ///
2802 /// When ``false``, goto labels are flushed left.
2803 /// \code
2804 /// true: false:
2805 /// int f() { vs. int f() {
2806 /// if (foo()) { if (foo()) {
2807 /// label1: label1:
2808 /// bar(); bar();
2809 /// } }
2810 /// label2: label2:
2811 /// return 1; return 1;
2812 /// } }
2813 /// \endcode
2814 /// \version 10
2816
2817 /// Indents extern blocks
2819 /// Backwards compatible with AfterExternBlock's indenting.
2820 /// \code
2821 /// IndentExternBlock: AfterExternBlock
2822 /// BraceWrapping.AfterExternBlock: true
2823 /// extern "C"
2824 /// {
2825 /// void foo();
2826 /// }
2827 /// \endcode
2828 ///
2829 /// \code
2830 /// IndentExternBlock: AfterExternBlock
2831 /// BraceWrapping.AfterExternBlock: false
2832 /// extern "C" {
2833 /// void foo();
2834 /// }
2835 /// \endcode
2837 /// Does not indent extern blocks.
2838 /// \code
2839 /// extern "C" {
2840 /// void foo();
2841 /// }
2842 /// \endcode
2844 /// Indents extern blocks.
2845 /// \code
2846 /// extern "C" {
2847 /// void foo();
2848 /// }
2849 /// \endcode
2851 };
2852
2853 /// IndentExternBlockStyle is the type of indenting of extern blocks.
2854 /// \version 11
2856
2857 /// Options for indenting preprocessor directives.
2859 /// Does not indent any directives.
2860 /// \code
2861 /// #if FOO
2862 /// #if BAR
2863 /// #include <foo>
2864 /// #endif
2865 /// #endif
2866 /// \endcode
2868 /// Indents directives after the hash.
2869 /// \code
2870 /// #if FOO
2871 /// # if BAR
2872 /// # include <foo>
2873 /// # endif
2874 /// #endif
2875 /// \endcode
2877 /// Indents directives before the hash.
2878 /// \code
2879 /// #if FOO
2880 /// #if BAR
2881 /// #include <foo>
2882 /// #endif
2883 /// #endif
2884 /// \endcode
2887
2888 /// The preprocessor directive indenting style to use.
2889 /// \version 6
2891
2892 /// Indent the requires clause in a template. This only applies when
2893 /// ``RequiresClausePosition`` is ``OwnLine``, ``OwnLineWithBrace``,
2894 /// or ``WithFollowing``.
2895 ///
2896 /// In clang-format 12, 13 and 14 it was named ``IndentRequires``.
2897 /// \code
2898 /// true:
2899 /// template <typename It>
2900 /// requires Iterator<It>
2901 /// void sort(It begin, It end) {
2902 /// //....
2903 /// }
2904 ///
2905 /// false:
2906 /// template <typename It>
2907 /// requires Iterator<It>
2908 /// void sort(It begin, It end) {
2909 /// //....
2910 /// }
2911 /// \endcode
2912 /// \version 15
2914
2915 /// The number of columns to use for indentation.
2916 /// \code
2917 /// IndentWidth: 3
2918 ///
2919 /// void f() {
2920 /// someFunction();
2921 /// if (true, false) {
2922 /// f();
2923 /// }
2924 /// }
2925 /// \endcode
2926 /// \version 3.7
2927 unsigned IndentWidth;
2928
2929 /// Indent if a function definition or declaration is wrapped after the
2930 /// type.
2931 /// \code
2932 /// true:
2933 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
2934 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2935 ///
2936 /// false:
2937 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
2938 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2939 /// \endcode
2940 /// \version 3.7
2942
2943 /// Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
2944 /// and ``while``) in C++ unless the control statements are inside macro
2945 /// definitions or the braces would enclose preprocessor directives.
2946 /// \warning
2947 /// Setting this option to ``true`` could lead to incorrect code formatting
2948 /// due to clang-format's lack of complete semantic information. As such,
2949 /// extra care should be taken to review code changes made by this option.
2950 /// \endwarning
2951 /// \code
2952 /// false: true:
2953 ///
2954 /// if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
2955 /// handleFunctionDecl(D); handleFunctionDecl(D);
2956 /// else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
2957 /// handleVarDecl(D); handleVarDecl(D);
2958 /// else } else {
2959 /// return; return;
2960 /// }
2961 ///
2962 /// while (i--) vs. while (i--) {
2963 /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
2964 /// handleAttr(A); handleAttr(A);
2965 /// }
2966 /// }
2967 ///
2968 /// do vs. do {
2969 /// --i; --i;
2970 /// while (i); } while (i);
2971 /// \endcode
2972 /// \version 15
2974
2975 /// Insert a newline at end of file if missing.
2976 /// \version 16
2978
2979 /// The style of inserting trailing commas into container literals.
2980 enum TrailingCommaStyle : int8_t {
2981 /// Do not insert trailing commas.
2983 /// Insert trailing commas in container literals that were wrapped over
2984 /// multiple lines. Note that this is conceptually incompatible with
2985 /// bin-packing, because the trailing comma is used as an indicator
2986 /// that a container should be formatted one-per-line (i.e. not bin-packed).
2987 /// So inserting a trailing comma counteracts bin-packing.
2989 };
2990
2991 /// If set to ``TCS_Wrapped`` will insert trailing commas in container
2992 /// literals (arrays and objects) that wrap across multiple lines.
2993 /// It is currently only available for JavaScript
2994 /// and disabled by default ``TCS_None``.
2995 /// ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
2996 /// as inserting the comma disables bin-packing.
2997 /// \code
2998 /// TSC_Wrapped:
2999 /// const someArray = [
3000 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3001 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3002 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3003 /// // ^ inserted
3004 /// ]
3005 /// \endcode
3006 /// \version 11
3008
3009 /// Separator format of integer literals of different bases.
3010 ///
3011 /// If negative, remove separators. If ``0``, leave the literal as is. If
3012 /// positive, insert separators between digits starting from the rightmost
3013 /// digit.
3014 ///
3015 /// For example, the config below will leave separators in binary literals
3016 /// alone, insert separators in decimal literals to separate the digits into
3017 /// groups of 3, and remove separators in hexadecimal literals.
3018 /// \code
3019 /// IntegerLiteralSeparator:
3020 /// Binary: 0
3021 /// Decimal: 3
3022 /// Hex: -1
3023 /// \endcode
3024 ///
3025 /// You can also specify a minimum number of digits (``BinaryMinDigits``,
3026 /// ``DecimalMinDigits``, and ``HexMinDigits``) the integer literal must
3027 /// have in order for the separators to be inserted.
3029 /// Format separators in binary literals.
3030 /// \code{.text}
3031 /// /* -1: */ b = 0b100111101101;
3032 /// /* 0: */ b = 0b10011'11'0110'1;
3033 /// /* 3: */ b = 0b100'111'101'101;
3034 /// /* 4: */ b = 0b1001'1110'1101;
3035 /// \endcode
3036 int8_t Binary;
3037 /// Format separators in binary literals with a minimum number of digits.
3038 /// \code{.text}
3039 /// // Binary: 3
3040 /// // BinaryMinDigits: 7
3041 /// b1 = 0b101101;
3042 /// b2 = 0b1'101'101;
3043 /// \endcode
3045 /// Format separators in decimal literals.
3046 /// \code{.text}
3047 /// /* -1: */ d = 18446744073709550592ull;
3048 /// /* 0: */ d = 184467'440737'0'95505'92ull;
3049 /// /* 3: */ d = 18'446'744'073'709'550'592ull;
3050 /// \endcode
3051 int8_t Decimal;
3052 /// Format separators in decimal literals with a minimum number of digits.
3053 /// \code{.text}
3054 /// // Decimal: 3
3055 /// // DecimalMinDigits: 5
3056 /// d1 = 2023;
3057 /// d2 = 10'000;
3058 /// \endcode
3060 /// Format separators in hexadecimal literals.
3061 /// \code{.text}
3062 /// /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
3063 /// /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
3064 /// /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
3065 /// \endcode
3066 int8_t Hex;
3067 /// Format separators in hexadecimal literals with a minimum number of
3068 /// digits.
3069 /// \code{.text}
3070 /// // Hex: 2
3071 /// // HexMinDigits: 6
3072 /// h1 = 0xABCDE;
3073 /// h2 = 0xAB'CD'EF;
3074 /// \endcode
3077 return Binary == R.Binary && BinaryMinDigits == R.BinaryMinDigits &&
3079 Hex == R.Hex && HexMinDigits == R.HexMinDigits;
3080 }
3081 };
3082
3083 /// Format integer literal separators (``'`` for C++ and ``_`` for C#, Java,
3084 /// and JavaScript).
3085 /// \version 16
3087
3088 /// A vector of prefixes ordered by the desired groups for Java imports.
3089 ///
3090 /// One group's prefix can be a subset of another - the longest prefix is
3091 /// always matched. Within a group, the imports are ordered lexicographically.
3092 /// Static imports are grouped separately and follow the same group rules.
3093 /// By default, static imports are placed before non-static imports,
3094 /// but this behavior is changed by another option,
3095 /// ``SortJavaStaticImport``.
3096 ///
3097 /// In the .clang-format configuration file, this can be configured like
3098 /// in the following yaml example. This will result in imports being
3099 /// formatted as in the Java example below.
3100 /// \code{.yaml}
3101 /// JavaImportGroups: [com.example, com, org]
3102 /// \endcode
3103 ///
3104 /// \code{.java}
3105 /// import static com.example.function1;
3106 ///
3107 /// import static com.test.function2;
3108 ///
3109 /// import static org.example.function3;
3110 ///
3111 /// import com.example.ClassA;
3112 /// import com.example.Test;
3113 /// import com.example.a.ClassB;
3114 ///
3115 /// import com.test.ClassC;
3116 ///
3117 /// import org.example.ClassD;
3118 /// \endcode
3119 /// \version 8
3120 std::vector<std::string> JavaImportGroups;
3121
3122 /// Quotation styles for JavaScript strings. Does not affect template
3123 /// strings.
3124 enum JavaScriptQuoteStyle : int8_t {
3125 /// Leave string quotes as they are.
3126 /// \code{.js}
3127 /// string1 = "foo";
3128 /// string2 = 'bar';
3129 /// \endcode
3131 /// Always use single quotes.
3132 /// \code{.js}
3133 /// string1 = 'foo';
3134 /// string2 = 'bar';
3135 /// \endcode
3137 /// Always use double quotes.
3138 /// \code{.js}
3139 /// string1 = "foo";
3140 /// string2 = "bar";
3141 /// \endcode
3144
3145 /// The JavaScriptQuoteStyle to use for JavaScript strings.
3146 /// \version 3.9
3148
3149 // clang-format off
3150 /// Whether to wrap JavaScript import/export statements.
3151 /// \code{.js}
3152 /// true:
3153 /// import {
3154 /// VeryLongImportsAreAnnoying,
3155 /// VeryLongImportsAreAnnoying,
3156 /// VeryLongImportsAreAnnoying,
3157 /// } from "some/module.js"
3158 ///
3159 /// false:
3160 /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3161 /// \endcode
3162 /// \version 3.9
3164 // clang-format on
3165
3166 /// Options regarding which empty lines are kept.
3167 ///
3168 /// For example, the config below will remove empty lines at start of the
3169 /// file, end of the file, and start of blocks.
3170 ///
3171 /// \code
3172 /// KeepEmptyLines:
3173 /// AtEndOfFile: false
3174 /// AtStartOfBlock: false
3175 /// AtStartOfFile: false
3176 /// \endcode
3178 /// Keep empty lines at end of file.
3180 /// Keep empty lines at start of a block.
3181 /// \code
3182 /// true: false:
3183 /// if (foo) { vs. if (foo) {
3184 /// bar();
3185 /// bar(); }
3186 /// }
3187 /// \endcode
3189 /// Keep empty lines at start of file.
3191 bool operator==(const KeepEmptyLinesStyle &R) const {
3192 return AtEndOfFile == R.AtEndOfFile &&
3195 }
3196 };
3197 /// Which empty lines are kept. See ``MaxEmptyLinesToKeep`` for how many
3198 /// consecutive empty lines are kept.
3199 /// \version 19
3201
3202 /// This option is deprecated. See ``AtEndOfFile`` of ``KeepEmptyLines``.
3203 /// \version 17
3204 // bool KeepEmptyLinesAtEOF;
3205
3206 /// This option is deprecated. See ``AtStartOfBlock`` of ``KeepEmptyLines``.
3207 /// \version 3.7
3208 // bool KeepEmptyLinesAtTheStartOfBlocks;
3209
3210 /// Keep the form feed character if it's immediately preceded and followed by
3211 /// a newline. Multiple form feeds and newlines within a whitespace range are
3212 /// replaced with a single newline and form feed followed by the remaining
3213 /// newlines.
3214 /// \version 20
3216
3217 /// Indentation logic for lambda bodies.
3219 /// Align lambda body relative to the lambda signature. This is the default.
3220 /// \code
3221 /// someMethod(
3222 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3223 /// return;
3224 /// });
3225 /// \endcode
3227 /// For statements within block scope, align lambda body relative to the
3228 /// indentation level of the outer scope the lambda signature resides in.
3229 /// \code
3230 /// someMethod(
3231 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3232 /// return;
3233 /// });
3234 ///
3235 /// someMethod(someOtherMethod(
3236 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3237 /// return;
3238 /// }));
3239 /// \endcode
3241 };
3242
3243 /// The indentation style of lambda bodies. ``Signature`` (the default)
3244 /// causes the lambda body to be indented one additional level relative to
3245 /// the indentation level of the signature. ``OuterScope`` forces the lambda
3246 /// body to be indented one additional level relative to the parent scope
3247 /// containing the lambda signature.
3248 /// \version 13
3250
3251 /// Supported languages.
3252 ///
3253 /// When stored in a configuration file, specifies the language, that the
3254 /// configuration targets. When passed to the ``reformat()`` function, enables
3255 /// syntax features specific to the language.
3256 enum LanguageKind : int8_t {
3257 /// Do not use.
3259 /// Should be used for C, C++.
3261 /// Should be used for C#.
3263 /// Should be used for Java.
3265 /// Should be used for JavaScript.
3267 /// Should be used for JSON.
3269 /// Should be used for Objective-C, Objective-C++.
3271 /// Should be used for Protocol Buffers
3272 /// (https://developers.google.com/protocol-buffers/).
3274 /// Should be used for TableGen code.
3276 /// Should be used for Protocol Buffer messages in text format
3277 /// (https://developers.google.com/protocol-buffers/).
3279 /// Should be used for Verilog and SystemVerilog.
3280 /// https://standards.ieee.org/ieee/1800/6700/
3281 /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3284 bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
3285 bool isCSharp() const { return Language == LK_CSharp; }
3286 bool isJson() const { return Language == LK_Json; }
3287 bool isJavaScript() const { return Language == LK_JavaScript; }
3288 bool isVerilog() const { return Language == LK_Verilog; }
3289 bool isProto() const {
3290 return Language == LK_Proto || Language == LK_TextProto;
3291 }
3292 bool isTableGen() const { return Language == LK_TableGen; }
3293
3294 /// Language, this format style is targeted at.
3295 /// \version 3.5
3297
3298 /// Line ending style.
3299 enum LineEndingStyle : int8_t {
3300 /// Use ``\n``.
3302 /// Use ``\r\n``.
3304 /// Use ``\n`` unless the input has more lines ending in ``\r\n``.
3306 /// Use ``\r\n`` unless the input has more lines ending in ``\n``.
3308 };
3309
3310 /// Line ending style (``\n`` or ``\r\n``) to use.
3311 /// \version 16
3313
3314 /// A regular expression matching macros that start a block.
3315 /// \code
3316 /// # With:
3317 /// MacroBlockBegin: "^NS_MAP_BEGIN|\
3318 /// NS_TABLE_HEAD$"
3319 /// MacroBlockEnd: "^\
3320 /// NS_MAP_END|\
3321 /// NS_TABLE_.*_END$"
3322 ///
3323 /// NS_MAP_BEGIN
3324 /// foo();
3325 /// NS_MAP_END
3326 ///
3327 /// NS_TABLE_HEAD
3328 /// bar();
3329 /// NS_TABLE_FOO_END
3330 ///
3331 /// # Without:
3332 /// NS_MAP_BEGIN
3333 /// foo();
3334 /// NS_MAP_END
3335 ///
3336 /// NS_TABLE_HEAD
3337 /// bar();
3338 /// NS_TABLE_FOO_END
3339 /// \endcode
3340 /// \version 3.7
3341 std::string MacroBlockBegin;
3342
3343 /// A regular expression matching macros that end a block.
3344 /// \version 3.7
3345 std::string MacroBlockEnd;
3346
3347 /// A list of macros of the form \c <definition>=<expansion> .
3348 ///
3349 /// Code will be parsed with macros expanded, in order to determine how to
3350 /// interpret and format the macro arguments.
3351 ///
3352 /// For example, the code:
3353 /// \code
3354 /// A(a*b);
3355 /// \endcode
3356 ///
3357 /// will usually be interpreted as a call to a function A, and the
3358 /// multiplication expression will be formatted as ``a * b``.
3359 ///
3360 /// If we specify the macro definition:
3361 /// \code{.yaml}
3362 /// Macros:
3363 /// - A(x)=x
3364 /// \endcode
3365 ///
3366 /// the code will now be parsed as a declaration of the variable b of type a*,
3367 /// and formatted as ``a* b`` (depending on pointer-binding rules).
3368 ///
3369 /// Features and restrictions:
3370 /// * Both function-like macros and object-like macros are supported.
3371 /// * Macro arguments must be used exactly once in the expansion.
3372 /// * No recursive expansion; macros referencing other macros will be
3373 /// ignored.
3374 /// * Overloading by arity is supported: for example, given the macro
3375 /// definitions A=x, A()=y, A(a)=a
3376 ///
3377 /// \code
3378 /// A; -> x;
3379 /// A(); -> y;
3380 /// A(z); -> z;
3381 /// A(a, b); // will not be expanded.
3382 /// \endcode
3383 ///
3384 /// \version 17
3385 std::vector<std::string> Macros;
3386
3387 /// The maximum number of consecutive empty lines to keep.
3388 /// \code
3389 /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
3390 /// int f() { int f() {
3391 /// int = 1; int i = 1;
3392 /// i = foo();
3393 /// i = foo(); return i;
3394 /// }
3395 /// return i;
3396 /// }
3397 /// \endcode
3398 /// \version 3.7
3400
3401 /// Different ways to indent namespace contents.
3403 /// Don't indent in namespaces.
3404 /// \code
3405 /// namespace out {
3406 /// int i;
3407 /// namespace in {
3408 /// int i;
3409 /// }
3410 /// }
3411 /// \endcode
3413 /// Indent only in inner namespaces (nested in other namespaces).
3414 /// \code
3415 /// namespace out {
3416 /// int i;
3417 /// namespace in {
3418 /// int i;
3419 /// }
3420 /// }
3421 /// \endcode
3423 /// Indent in all namespaces.
3424 /// \code
3425 /// namespace out {
3426 /// int i;
3427 /// namespace in {
3428 /// int i;
3429 /// }
3430 /// }
3431 /// \endcode
3432 NI_All
3434
3435 /// The indentation used for namespaces.
3436 /// \version 3.7
3438
3439 /// A vector of macros which are used to open namespace blocks.
3440 ///
3441 /// These are expected to be macros of the form:
3442 /// \code
3443 /// NAMESPACE(<namespace-name>, ...) {
3444 /// <namespace-content>
3445 /// }
3446 /// \endcode
3447 ///
3448 /// For example: TESTSUITE
3449 /// \version 9
3450 std::vector<std::string> NamespaceMacros;
3451
3452 /// Controls bin-packing Objective-C protocol conformance list
3453 /// items into as few lines as possible when they go over ``ColumnLimit``.
3454 ///
3455 /// If ``Auto`` (the default), delegates to the value in
3456 /// ``BinPackParameters``. If that is ``BinPack``, bin-packs Objective-C
3457 /// protocol conformance list items into as few lines as possible
3458 /// whenever they go over ``ColumnLimit``.
3459 ///
3460 /// If ``Always``, always bin-packs Objective-C protocol conformance
3461 /// list items into as few lines as possible whenever they go over
3462 /// ``ColumnLimit``.
3463 ///
3464 /// If ``Never``, lays out Objective-C protocol conformance list items
3465 /// onto individual lines whenever they go over ``ColumnLimit``.
3466 ///
3467 /// \code{.objc}
3468 /// Always (or Auto, if BinPackParameters==BinPack):
3469 /// @interface ccccccccccccc () <
3470 /// ccccccccccccc, ccccccccccccc,
3471 /// ccccccccccccc, ccccccccccccc> {
3472 /// }
3473 ///
3474 /// Never (or Auto, if BinPackParameters!=BinPack):
3475 /// @interface ddddddddddddd () <
3476 /// ddddddddddddd,
3477 /// ddddddddddddd,
3478 /// ddddddddddddd,
3479 /// ddddddddddddd> {
3480 /// }
3481 /// \endcode
3482 /// \version 7
3484
3485 /// The number of characters to use for indentation of ObjC blocks.
3486 /// \code{.objc}
3487 /// ObjCBlockIndentWidth: 4
3488 ///
3489 /// [operation setCompletionBlock:^{
3490 /// [self onOperationDone];
3491 /// }];
3492 /// \endcode
3493 /// \version 3.7
3495
3496 /// Break parameters list into lines when there is nested block
3497 /// parameters in a function call.
3498 /// \code
3499 /// false:
3500 /// - (void)_aMethod
3501 /// {
3502 /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
3503 /// *u, NSNumber *v) {
3504 /// u = c;
3505 /// }]
3506 /// }
3507 /// true:
3508 /// - (void)_aMethod
3509 /// {
3510 /// [self.test1 t:self
3511 /// w:self
3512 /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
3513 /// u = c;
3514 /// }]
3515 /// }
3516 /// \endcode
3517 /// \version 11
3519
3520 /// The order in which ObjC property attributes should appear.
3521 ///
3522 /// Attributes in code will be sorted in the order specified. Any attributes
3523 /// encountered that are not mentioned in this array will be sorted last, in
3524 /// stable order. Comments between attributes will leave the attributes
3525 /// untouched.
3526 /// \warning
3527 /// Using this option could lead to incorrect code formatting due to
3528 /// clang-format's lack of complete semantic information. As such, extra
3529 /// care should be taken to review code changes made by this option.
3530 /// \endwarning
3531 /// \code{.yaml}
3532 /// ObjCPropertyAttributeOrder: [
3533 /// class, direct,
3534 /// atomic, nonatomic,
3535 /// assign, retain, strong, copy, weak, unsafe_unretained,
3536 /// readonly, readwrite, getter, setter,
3537 /// nullable, nonnull, null_resettable, null_unspecified
3538 /// ]
3539 /// \endcode
3540 /// \version 18
3541 std::vector<std::string> ObjCPropertyAttributeOrder;
3542
3543 /// Add a space after ``@property`` in Objective-C, i.e. use
3544 /// ``@property (readonly)`` instead of ``@property(readonly)``.
3545 /// \version 3.7
3547
3548 /// Add a space in front of an Objective-C protocol list, i.e. use
3549 /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
3550 /// \version 3.7
3552
3553 /// Different ways to try to fit all constructor initializers on a line.
3555 /// Always put each constructor initializer on its own line.
3556 /// \code
3557 /// Constructor()
3558 /// : a(),
3559 /// b()
3560 /// \endcode
3562 /// Bin-pack constructor initializers.
3563 /// \code
3564 /// Constructor()
3565 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
3566 /// cccccccccccccccccccc()
3567 /// \endcode
3569 /// Put all constructor initializers on the current line if they fit.
3570 /// Otherwise, put each one on its own line.
3571 /// \code
3572 /// Constructor() : a(), b()
3573 ///
3574 /// Constructor()
3575 /// : aaaaaaaaaaaaaaaaaaaa(),
3576 /// bbbbbbbbbbbbbbbbbbbb(),
3577 /// ddddddddddddd()
3578 /// \endcode
3580 /// Same as ``PCIS_CurrentLine`` except that if all constructor initializers
3581 /// do not fit on the current line, try to fit them on the next line.
3582 /// \code
3583 /// Constructor() : a(), b()
3584 ///
3585 /// Constructor()
3586 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3587 ///
3588 /// Constructor()
3589 /// : aaaaaaaaaaaaaaaaaaaa(),
3590 /// bbbbbbbbbbbbbbbbbbbb(),
3591 /// cccccccccccccccccccc()
3592 /// \endcode
3594 /// Put all constructor initializers on the next line if they fit.
3595 /// Otherwise, put each one on its own line.
3596 /// \code
3597 /// Constructor()
3598 /// : a(), b()
3599 ///
3600 /// Constructor()
3601 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3602 ///
3603 /// Constructor()
3604 /// : aaaaaaaaaaaaaaaaaaaa(),
3605 /// bbbbbbbbbbbbbbbbbbbb(),
3606 /// cccccccccccccccccccc()
3607 /// \endcode
3609 };
3610
3611 /// The pack constructor initializers style to use.
3612 /// \version 14
3614
3615 /// The penalty for breaking around an assignment operator.
3616 /// \version 5
3618
3619 /// The penalty for breaking a function call after ``call(``.
3620 /// \version 3.7
3622
3623 /// The penalty for each line break introduced inside a comment.
3624 /// \version 3.7
3626
3627 /// The penalty for breaking before the first ``<<``.
3628 /// \version 3.7
3630
3631 /// The penalty for breaking after ``(``.
3632 /// \version 14
3634
3635 /// The penalty for breaking after ``::``.
3636 /// \version 18
3638
3639 /// The penalty for each line break introduced inside a string literal.
3640 /// \version 3.7
3642
3643 /// The penalty for breaking after template declaration.
3644 /// \version 7
3646
3647 /// The penalty for each character outside of the column limit.
3648 /// \version 3.7
3650
3651 /// Penalty for each character of whitespace indentation
3652 /// (counted relative to leading non-whitespace column).
3653 /// \version 12
3655
3656 /// Penalty for putting the return type of a function onto its own line.
3657 /// \version 3.7
3659
3660 /// The ``&``, ``&&`` and ``*`` alignment style.
3662 /// Align pointer to the left.
3663 /// \code
3664 /// int* a;
3665 /// \endcode
3667 /// Align pointer to the right.
3668 /// \code
3669 /// int *a;
3670 /// \endcode
3672 /// Align pointer in the middle.
3673 /// \code
3674 /// int * a;
3675 /// \endcode
3678
3679 /// Pointer and reference alignment style.
3680 /// \version 3.7
3682
3683 /// The number of columns to use for indentation of preprocessor statements.
3684 /// When set to -1 (default) ``IndentWidth`` is used also for preprocessor
3685 /// statements.
3686 /// \code
3687 /// PPIndentWidth: 1
3688 ///
3689 /// #ifdef __linux__
3690 /// # define FOO
3691 /// #else
3692 /// # define BAR
3693 /// #endif
3694 /// \endcode
3695 /// \version 13
3697
3698 /// Different specifiers and qualifiers alignment styles.
3700 /// Don't change specifiers/qualifiers to either Left or Right alignment
3701 /// (default).
3702 /// \code
3703 /// int const a;
3704 /// const int *a;
3705 /// \endcode
3707 /// Change specifiers/qualifiers to be left-aligned.
3708 /// \code
3709 /// const int a;
3710 /// const int *a;
3711 /// \endcode
3713 /// Change specifiers/qualifiers to be right-aligned.
3714 /// \code
3715 /// int const a;
3716 /// int const *a;
3717 /// \endcode
3719 /// Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.
3720 /// With:
3721 /// \code{.yaml}
3722 /// QualifierOrder: [inline, static, type, const]
3723 /// \endcode
3724 ///
3725 /// \code
3726 ///
3727 /// int const a;
3728 /// int const *a;
3729 /// \endcode
3732
3733 /// Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
3734 /// \warning
3735 /// Setting ``QualifierAlignment`` to something other than ``Leave``, COULD
3736 /// lead to incorrect code formatting due to incorrect decisions made due to
3737 /// clang-formats lack of complete semantic information.
3738 /// As such extra care should be taken to review code changes made by the use
3739 /// of this option.
3740 /// \endwarning
3741 /// \version 14
3743
3744 /// The order in which the qualifiers appear.
3745 /// The order is an array that can contain any of the following:
3746 ///
3747 /// * ``const``
3748 /// * ``inline``
3749 /// * ``static``
3750 /// * ``friend``
3751 /// * ``constexpr``
3752 /// * ``volatile``
3753 /// * ``restrict``
3754 /// * ``type``
3755 ///
3756 /// \note
3757 /// It must contain ``type``.
3758 /// \endnote
3759 ///
3760 /// Items to the left of ``type`` will be placed to the left of the type and
3761 /// aligned in the order supplied. Items to the right of ``type`` will be
3762 /// placed to the right of the type and aligned in the order supplied.
3763 ///
3764 /// \code{.yaml}
3765 /// QualifierOrder: [inline, static, type, const, volatile]
3766 /// \endcode
3767 /// \version 14
3768 std::vector<std::string> QualifierOrder;
3769
3770 /// See documentation of ``RawStringFormats``.
3772 /// The language of this raw string.
3774 /// A list of raw string delimiters that match this language.
3775 std::vector<std::string> Delimiters;
3776 /// A list of enclosing function names that match this language.
3777 std::vector<std::string> EnclosingFunctions;
3778 /// The canonical delimiter for this language.
3780 /// The style name on which this raw string format is based on.
3781 /// If not specified, the raw string format is based on the style that this
3782 /// format is based on.
3783 std::string BasedOnStyle;
3784 bool operator==(const RawStringFormat &Other) const {
3785 return Language == Other.Language && Delimiters == Other.Delimiters &&
3786 EnclosingFunctions == Other.EnclosingFunctions &&
3787 CanonicalDelimiter == Other.CanonicalDelimiter &&
3788 BasedOnStyle == Other.BasedOnStyle;
3789 }
3790 };
3791
3792 /// Defines hints for detecting supported languages code blocks in raw
3793 /// strings.
3794 ///
3795 /// A raw string with a matching delimiter or a matching enclosing function
3796 /// name will be reformatted assuming the specified language based on the
3797 /// style for that language defined in the .clang-format file. If no style has
3798 /// been defined in the .clang-format file for the specific language, a
3799 /// predefined style given by ``BasedOnStyle`` is used. If ``BasedOnStyle`` is
3800 /// not found, the formatting is based on ``LLVM`` style. A matching delimiter
3801 /// takes precedence over a matching enclosing function name for determining
3802 /// the language of the raw string contents.
3803 ///
3804 /// If a canonical delimiter is specified, occurrences of other delimiters for
3805 /// the same language will be updated to the canonical if possible.
3806 ///
3807 /// There should be at most one specification per language and each delimiter
3808 /// and enclosing function should not occur in multiple specifications.
3809 ///
3810 /// To configure this in the .clang-format file, use:
3811 /// \code{.yaml}
3812 /// RawStringFormats:
3813 /// - Language: TextProto
3814 /// Delimiters:
3815 /// - pb
3816 /// - proto
3817 /// EnclosingFunctions:
3818 /// - PARSE_TEXT_PROTO
3819 /// BasedOnStyle: google
3820 /// - Language: Cpp
3821 /// Delimiters:
3822 /// - cc
3823 /// - cpp
3824 /// BasedOnStyle: LLVM
3825 /// CanonicalDelimiter: cc
3826 /// \endcode
3827 /// \version 6
3828 std::vector<RawStringFormat> RawStringFormats;
3829
3830 /// \brief The ``&`` and ``&&`` alignment style.
3832 /// Align reference like ``PointerAlignment``.
3834 /// Align reference to the left.
3835 /// \code
3836 /// int& a;
3837 /// \endcode
3839 /// Align reference to the right.
3840 /// \code
3841 /// int &a;
3842 /// \endcode
3844 /// Align reference in the middle.
3845 /// \code
3846 /// int & a;
3847 /// \endcode
3850
3851 /// \brief Reference alignment style (overrides ``PointerAlignment`` for
3852 /// references).
3853 /// \version 13
3855
3856 // clang-format off
3857 /// \brief Types of comment reflow style.
3858 enum ReflowCommentsStyle : int8_t {
3859 /// Leave comments untouched.
3860 /// \code
3861 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
3862 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
3863 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
3864 /// * and a misaligned second line */
3865 /// \endcode
3867 /// Only apply indentation rules, moving comments left or right, without
3868 /// changing formatting inside the comments.
3869 /// \code
3870 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
3871 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
3872 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
3873 /// * and a misaligned second line */
3874 /// \endcode
3876 /// Apply indentation rules and reflow long comments into new lines, trying
3877 /// to obey the ``ColumnLimit``.
3878 /// \code
3879 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3880 /// // information
3881 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3882 /// * information */
3883 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3884 /// * information and a misaligned second line */
3885 /// \endcode
3888 // clang-format on
3889
3890 /// \brief Comment reformatting style.
3891 /// \version 3.8
3893
3894 /// Remove optional braces of control statements (``if``, ``else``, ``for``,
3895 /// and ``while``) in C++ according to the LLVM coding style.
3896 /// \warning
3897 /// This option will be renamed and expanded to support other styles.
3898 /// \endwarning
3899 /// \warning
3900 /// Setting this option to ``true`` could lead to incorrect code formatting
3901 /// due to clang-format's lack of complete semantic information. As such,
3902 /// extra care should be taken to review code changes made by this option.
3903 /// \endwarning
3904 /// \code
3905 /// false: true:
3906 ///
3907 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3908 /// handleFunctionDecl(D); handleFunctionDecl(D);
3909 /// } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
3910 /// handleVarDecl(D); handleVarDecl(D);
3911 /// }
3912 ///
3913 /// if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
3914 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3915 /// if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
3916 /// handleAttr(A); handleAttr(A);
3917 /// } }
3918 /// }
3919 /// }
3920 ///
3921 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3922 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3923 /// handleAttr(A); handleAttr(A);
3924 /// }
3925 /// }
3926 ///
3927 /// if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
3928 /// if (shouldProcess(D)) { if (shouldProcess(D))
3929 /// handleVarDecl(D); handleVarDecl(D);
3930 /// } else { else
3931 /// markAsIgnored(D); markAsIgnored(D);
3932 /// } }
3933 /// }
3934 ///
3935 /// if (a) { vs. if (a)
3936 /// b(); b();
3937 /// } else { else if (c)
3938 /// if (c) { d();
3939 /// d(); else
3940 /// } else { e();
3941 /// e();
3942 /// }
3943 /// }
3944 /// \endcode
3945 /// \version 14
3947
3948 /// Remove empty lines within unwrapped lines.
3949 /// \code
3950 /// false: true:
3951 ///
3952 /// int c vs. int c = a + b;
3953 ///
3954 /// = a + b;
3955 ///
3956 /// enum : unsigned vs. enum : unsigned {
3957 /// AA = 0,
3958 /// { BB
3959 /// AA = 0, } myEnum;
3960 /// BB
3961 /// } myEnum;
3962 ///
3963 /// while ( vs. while (true) {
3964 /// }
3965 /// true) {
3966 /// }
3967 /// \endcode
3968 /// \version 20
3970
3971 /// Types of redundant parentheses to remove.
3973 /// Do not remove parentheses.
3974 /// \code
3975 /// class __declspec((dllimport)) X {};
3976 /// co_return (((0)));
3977 /// return ((a + b) - ((c + d)));
3978 /// \endcode
3980 /// Replace multiple parentheses with single parentheses.
3981 /// \code
3982 /// class __declspec(dllimport) X {};
3983 /// co_return (0);
3984 /// return ((a + b) - (c + d));
3985 /// \endcode
3987 /// Also remove parentheses enclosing the expression in a
3988 /// ``return``/``co_return`` statement.
3989 /// \code
3990 /// class __declspec(dllimport) X {};
3991 /// co_return 0;
3992 /// return (a + b) - (c + d);
3993 /// \endcode
3995 };
3996
3997 /// Remove redundant parentheses.
3998 /// \warning
3999 /// Setting this option to any value other than ``Leave`` could lead to
4000 /// incorrect code formatting due to clang-format's lack of complete semantic
4001 /// information. As such, extra care should be taken to review code changes
4002 /// made by this option.
4003 /// \endwarning
4004 /// \version 17
4006
4007 /// Remove semicolons after the closing braces of functions and
4008 /// constructors/destructors.
4009 /// \warning
4010 /// Setting this option to ``true`` could lead to incorrect code formatting
4011 /// due to clang-format's lack of complete semantic information. As such,
4012 /// extra care should be taken to review code changes made by this option.
4013 /// \endwarning
4014 /// \code
4015 /// false: true:
4016 ///
4017 /// int max(int a, int b) { int max(int a, int b) {
4018 /// return a > b ? a : b; return a > b ? a : b;
4019 /// }; }
4020 ///
4021 /// \endcode
4022 /// \version 16
4024
4025 /// \brief The possible positions for the requires clause. The
4026 /// ``IndentRequires`` option is only used if the ``requires`` is put on the
4027 /// start of a line.
4029 /// Always put the ``requires`` clause on its own line (possibly followed by
4030 /// a semicolon).
4031 /// \code
4032 /// template <typename T>
4033 /// requires C<T>
4034 /// struct Foo {...
4035 ///
4036 /// template <typename T>
4037 /// void bar(T t)
4038 /// requires C<T>;
4039 ///
4040 /// template <typename T>
4041 /// requires C<T>
4042 /// void bar(T t) {...
4043 ///
4044 /// template <typename T>
4045 /// void baz(T t)
4046 /// requires C<T>
4047 /// {...
4048 /// \endcode
4050 /// As with ``OwnLine``, except, unless otherwise prohibited, place a
4051 /// following open brace (of a function definition) to follow on the same
4052 /// line.
4053 /// \code
4054 /// void bar(T t)
4055 /// requires C<T> {
4056 /// return;
4057 /// }
4058 ///
4059 /// void bar(T t)
4060 /// requires C<T> {}
4061 ///
4062 /// template <typename T>
4063 /// requires C<T>
4064 /// void baz(T t) {
4065 /// ...
4066 /// \endcode
4068 /// Try to put the clause together with the preceding part of a declaration.
4069 /// For class templates: stick to the template declaration.
4070 /// For function templates: stick to the template declaration.
4071 /// For function declaration followed by a requires clause: stick to the
4072 /// parameter list.
4073 /// \code
4074 /// template <typename T> requires C<T>
4075 /// struct Foo {...
4076 ///
4077 /// template <typename T> requires C<T>
4078 /// void bar(T t) {...
4079 ///
4080 /// template <typename T>
4081 /// void baz(T t) requires C<T>
4082 /// {...
4083 /// \endcode
4085 /// Try to put the ``requires`` clause together with the class or function
4086 /// declaration.
4087 /// \code
4088 /// template <typename T>
4089 /// requires C<T> struct Foo {...
4090 ///
4091 /// template <typename T>
4092 /// requires C<T> void bar(T t) {...
4093 ///
4094 /// template <typename T>
4095 /// void baz(T t)
4096 /// requires C<T> {...
4097 /// \endcode
4099 /// Try to put everything in the same line if possible. Otherwise normal
4100 /// line breaking rules take over.
4101 /// \code
4102 /// // Fitting:
4103 /// template <typename T> requires C<T> struct Foo {...
4104 ///
4105 /// template <typename T> requires C<T> void bar(T t) {...
4106 ///
4107 /// template <typename T> void bar(T t) requires C<T> {...
4108 ///
4109 /// // Not fitting, one possible example:
4110 /// template <typename LongName>
4111 /// requires C<LongName>
4112 /// struct Foo {...
4113 ///
4114 /// template <typename LongName>
4115 /// requires C<LongName>
4116 /// void bar(LongName ln) {
4117 ///
4118 /// template <typename LongName>
4119 /// void bar(LongName ln)
4120 /// requires C<LongName> {
4121 /// \endcode
4123 };
4124
4125 /// \brief The position of the ``requires`` clause.
4126 /// \version 15
4128
4129 /// Indentation logic for requires expression bodies.
4131 /// Align requires expression body relative to the indentation level of the
4132 /// outer scope the requires expression resides in.
4133 /// This is the default.
4134 /// \code
4135 /// template <typename T>
4136 /// concept C = requires(T t) {
4137 /// ...
4138 /// }
4139 /// \endcode
4141 /// Align requires expression body relative to the ``requires`` keyword.
4142 /// \code
4143 /// template <typename T>
4144 /// concept C = requires(T t) {
4145 /// ...
4146 /// }
4147 /// \endcode
4149 };
4150
4151 /// The indentation used for requires expression bodies.
4152 /// \version 16
4154
4155 /// \brief The style if definition blocks should be separated.
4157 /// Leave definition blocks as they are.
4159 /// Insert an empty line between definition blocks.
4161 /// Remove any empty line between definition blocks.
4162 SDS_Never
4164
4165 /// Specifies the use of empty lines to separate definition blocks, including
4166 /// classes, structs, enums, and functions.
4167 /// \code
4168 /// Never v.s. Always
4169 /// #include <cstring> #include <cstring>
4170 /// struct Foo {
4171 /// int a, b, c; struct Foo {
4172 /// }; int a, b, c;
4173 /// namespace Ns { };
4174 /// class Bar {
4175 /// public: namespace Ns {
4176 /// struct Foobar { class Bar {
4177 /// int a; public:
4178 /// int b; struct Foobar {
4179 /// }; int a;
4180 /// private: int b;
4181 /// int t; };
4182 /// int method1() {
4183 /// // ... private:
4184 /// } int t;
4185 /// enum List {
4186 /// ITEM1, int method1() {
4187 /// ITEM2 // ...
4188 /// }; }
4189 /// template<typename T>
4190 /// int method2(T x) { enum List {
4191 /// // ... ITEM1,
4192 /// } ITEM2
4193 /// int i, j, k; };
4194 /// int method3(int par) {
4195 /// // ... template<typename T>
4196 /// } int method2(T x) {
4197 /// }; // ...
4198 /// class C {}; }
4199 /// }
4200 /// int i, j, k;
4201 ///
4202 /// int method3(int par) {
4203 /// // ...
4204 /// }
4205 /// };
4206 ///
4207 /// class C {};
4208 /// }
4209 /// \endcode
4210 /// \version 14
4212
4213 /// The maximal number of unwrapped lines that a short namespace spans.
4214 /// Defaults to 1.
4215 ///
4216 /// This determines the maximum length of short namespaces by counting
4217 /// unwrapped lines (i.e. containing neither opening nor closing
4218 /// namespace brace) and makes ``FixNamespaceComments`` omit adding
4219 /// end comments for those.
4220 /// \code
4221 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4222 /// namespace a { namespace a {
4223 /// int foo; int foo;
4224 /// } } // namespace a
4225 ///
4226 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4227 /// namespace b { namespace b {
4228 /// int foo; int foo;
4229 /// int bar; int bar;
4230 /// } // namespace b } // namespace b
4231 /// \endcode
4232 /// \version 13
4234
4235 /// Do not format macro definition body.
4236 /// \version 18
4238
4239 /// Include sorting options.
4240 enum SortIncludesOptions : int8_t {
4241 /// Includes are never sorted.
4242 /// \code
4243 /// #include "B/A.h"
4244 /// #include "A/B.h"
4245 /// #include "a/b.h"
4246 /// #include "A/b.h"
4247 /// #include "B/a.h"
4248 /// \endcode
4250 /// Includes are sorted in an ASCIIbetical or case sensitive fashion.
4251 /// \code
4252 /// #include "A/B.h"
4253 /// #include "A/b.h"
4254 /// #include "B/A.h"
4255 /// #include "B/a.h"
4256 /// #include "a/b.h"
4257 /// \endcode
4259 /// Includes are sorted in an alphabetical or case insensitive fashion.
4260 /// \code
4261 /// #include "A/B.h"
4262 /// #include "A/b.h"
4263 /// #include "a/b.h"
4264 /// #include "B/A.h"
4265 /// #include "B/a.h"
4266 /// \endcode
4268 };
4269
4270 /// Controls if and how clang-format will sort ``#includes``.
4271 /// \version 3.8
4273
4274 /// Position for Java Static imports.
4276 /// Static imports are placed before non-static imports.
4277 /// \code{.java}
4278 /// import static org.example.function1;
4279 ///
4280 /// import org.example.ClassA;
4281 /// \endcode
4283 /// Static imports are placed after non-static imports.
4284 /// \code{.java}
4285 /// import org.example.ClassA;
4286 ///
4287 /// import static org.example.function1;
4288 /// \endcode
4290 };
4291
4292 /// When sorting Java imports, by default static imports are placed before
4293 /// non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
4294 /// static imports are placed after non-static imports.
4295 /// \version 12
4297
4298 /// Using declaration sorting options.
4300 /// Using declarations are never sorted.
4301 /// \code
4302 /// using std::chrono::duration_cast;
4303 /// using std::move;
4304 /// using boost::regex;
4305 /// using boost::regex_constants::icase;
4306 /// using std::string;
4307 /// \endcode
4309 /// Using declarations are sorted in the order defined as follows:
4310 /// Split the strings by ``::`` and discard any initial empty strings. Sort
4311 /// the lists of names lexicographically, and within those groups, names are
4312 /// in case-insensitive lexicographic order.
4313 /// \code
4314 /// using boost::regex;
4315 /// using boost::regex_constants::icase;
4316 /// using std::chrono::duration_cast;
4317 /// using std::move;
4318 /// using std::string;
4319 /// \endcode
4321 /// Using declarations are sorted in the order defined as follows:
4322 /// Split the strings by ``::`` and discard any initial empty strings. The
4323 /// last element of each list is a non-namespace name; all others are
4324 /// namespace names. Sort the lists of names lexicographically, where the
4325 /// sort order of individual names is that all non-namespace names come
4326 /// before all namespace names, and within those groups, names are in
4327 /// case-insensitive lexicographic order.
4328 /// \code
4329 /// using boost::regex;
4330 /// using boost::regex_constants::icase;
4331 /// using std::move;
4332 /// using std::string;
4333 /// using std::chrono::duration_cast;
4334 /// \endcode
4336 };
4337
4338 /// Controls if and how clang-format will sort using declarations.
4339 /// \version 5
4341
4342 /// If ``true``, a space is inserted after C style casts.
4343 /// \code
4344 /// true: false:
4345 /// (int) i; vs. (int)i;
4346 /// \endcode
4347 /// \version 3.5
4349
4350 /// If ``true``, a space is inserted after the logical not operator (``!``).
4351 /// \code
4352 /// true: false:
4353 /// ! someExpression(); vs. !someExpression();
4354 /// \endcode
4355 /// \version 9
4357
4358 /// If \c true, a space will be inserted after the ``template`` keyword.
4359 /// \code
4360 /// true: false:
4361 /// template <int> void foo(); vs. template<int> void foo();
4362 /// \endcode
4363 /// \version 4
4365
4366 /// Different ways to put a space before opening parentheses.
4368 /// Don't ensure spaces around pointer qualifiers and use PointerAlignment
4369 /// instead.
4370 /// \code
4371 /// PointerAlignment: Left PointerAlignment: Right
4372 /// void* const* x = NULL; vs. void *const *x = NULL;
4373 /// \endcode
4375 /// Ensure that there is a space before pointer qualifiers.
4376 /// \code
4377 /// PointerAlignment: Left PointerAlignment: Right
4378 /// void* const* x = NULL; vs. void * const *x = NULL;
4379 /// \endcode
4381 /// Ensure that there is a space after pointer qualifiers.
4382 /// \code
4383 /// PointerAlignment: Left PointerAlignment: Right
4384 /// void* const * x = NULL; vs. void *const *x = NULL;
4385 /// \endcode
4387 /// Ensure that there is a space both before and after pointer qualifiers.
4388 /// \code
4389 /// PointerAlignment: Left PointerAlignment: Right
4390 /// void* const * x = NULL; vs. void * const *x = NULL;
4391 /// \endcode
4393 };
4394
4395 /// Defines in which cases to put a space before or after pointer qualifiers
4396 /// \version 12
4398
4399 /// If ``false``, spaces will be removed before assignment operators.
4400 /// \code
4401 /// true: false:
4402 /// int a = 5; vs. int a= 5;
4403 /// a += 42; a+= 42;
4404 /// \endcode
4405 /// \version 3.7
4407
4408 /// If ``false``, spaces will be removed before case colon.
4409 /// \code
4410 /// true: false
4411 /// switch (x) { vs. switch (x) {
4412 /// case 1 : break; case 1: break;
4413 /// } }
4414 /// \endcode
4415 /// \version 12
4417
4418 /// If ``true``, a space will be inserted before a C++11 braced list
4419 /// used to initialize an object (after the preceding identifier or type).
4420 /// \code
4421 /// true: false:
4422 /// Foo foo { bar }; vs. Foo foo{ bar };
4423 /// Foo {}; Foo{};
4424 /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
4425 /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
4426 /// \endcode
4427 /// \version 7
4429
4430 /// If ``false``, spaces will be removed before constructor initializer
4431 /// colon.
4432 /// \code
4433 /// true: false:
4434 /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
4435 /// \endcode
4436 /// \version 7
4438
4439 /// If ``false``, spaces will be removed before inheritance colon.
4440 /// \code
4441 /// true: false:
4442 /// class Foo : Bar {} vs. class Foo: Bar {}
4443 /// \endcode
4444 /// \version 7
4446
4447 /// If ``true``, a space will be added before a JSON colon. For other
4448 /// languages, e.g. JavaScript, use ``SpacesInContainerLiterals`` instead.
4449 /// \code
4450 /// true: false:
4451 /// { {
4452 /// "key" : "value" vs. "key": "value"
4453 /// } }
4454 /// \endcode
4455 /// \version 17
4457
4458 /// Different ways to put a space before opening parentheses.
4460 /// This is **deprecated** and replaced by ``Custom`` below, with all
4461 /// ``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
4462 /// ``false``.
4464 /// Put a space before opening parentheses only after control statement
4465 /// keywords (``for/if/while...``).
4466 /// \code
4467 /// void f() {
4468 /// if (true) {
4469 /// f();
4470 /// }
4471 /// }
4472 /// \endcode
4474 /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
4475 /// ForEach and If macros. This is useful in projects where ForEach/If
4476 /// macros are treated as function calls instead of control statements.
4477 /// ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
4478 /// backward compatibility.
4479 /// \code
4480 /// void f() {
4481 /// Q_FOREACH(...) {
4482 /// f();
4483 /// }
4484 /// }
4485 /// \endcode
4487 /// Put a space before opening parentheses only if the parentheses are not
4488 /// empty.
4489 /// \code
4490 /// void() {
4491 /// if (true) {
4492 /// f();
4493 /// g (x, y, z);
4494 /// }
4495 /// }
4496 /// \endcode
4498 /// Always put a space before opening parentheses, except when it's
4499 /// prohibited by the syntax rules (in function-like macro definitions) or
4500 /// when determined by other style rules (after unary operators, opening
4501 /// parentheses, etc.)
4502 /// \code
4503 /// void f () {
4504 /// if (true) {
4505 /// f ();
4506 /// }
4507 /// }
4508 /// \endcode
4510 /// Configure each individual space before parentheses in
4511 /// ``SpaceBeforeParensOptions``.
4513 };
4514
4515 /// Defines in which cases to put a space before opening parentheses.
4516 /// \version 3.5
4518
4519 /// Precise control over the spacing before parentheses.
4520 /// \code
4521 /// # Should be declared this way:
4522 /// SpaceBeforeParens: Custom
4523 /// SpaceBeforeParensOptions:
4524 /// AfterControlStatements: true
4525 /// AfterFunctionDefinitionName: true
4526 /// \endcode
4528 /// If ``true``, put space between control statement keywords
4529 /// (for/if/while...) and opening parentheses.
4530 /// \code
4531 /// true: false:
4532 /// if (...) {} vs. if(...) {}
4533 /// \endcode
4535 /// If ``true``, put space between foreach macros and opening parentheses.
4536 /// \code
4537 /// true: false:
4538 /// FOREACH (...) vs. FOREACH(...)
4539 /// <loop-body> <loop-body>
4540 /// \endcode
4542 /// If ``true``, put a space between function declaration name and opening
4543 /// parentheses.
4544 /// \code
4545 /// true: false:
4546 /// void f (); vs. void f();
4547 /// \endcode
4549 /// If ``true``, put a space between function definition name and opening
4550 /// parentheses.
4551 /// \code
4552 /// true: false:
4553 /// void f () {} vs. void f() {}
4554 /// \endcode
4556 /// If ``true``, put space between if macros and opening parentheses.
4557 /// \code
4558 /// true: false:
4559 /// IF (...) vs. IF(...)
4560 /// <conditional-body> <conditional-body>
4561 /// \endcode
4563 /// If ``true``, put a space between operator overloading and opening
4564 /// parentheses.
4565 /// \code
4566 /// true: false:
4567 /// void operator++ (int a); vs. void operator++(int a);
4568 /// object.operator++ (10); object.operator++(10);
4569 /// \endcode
4571 /// If ``true``, put a space between operator ``new``/``delete`` and opening
4572 /// parenthesis.
4573 /// \code
4574 /// true: false:
4575 /// new (buf) T; vs. new(buf) T;
4576 /// delete (buf) T; delete(buf) T;
4577 /// \endcode
4579 /// If ``true``, put space between requires keyword in a requires clause and
4580 /// opening parentheses, if there is one.
4581 /// \code
4582 /// true: false:
4583 /// template<typename T> vs. template<typename T>
4584 /// requires (A<T> && B<T>) requires(A<T> && B<T>)
4585 /// ... ...
4586 /// \endcode
4588 /// If ``true``, put space between requires keyword in a requires expression
4589 /// and opening parentheses.
4590 /// \code
4591 /// true: false:
4592 /// template<typename T> vs. template<typename T>
4593 /// concept C = requires (T t) { concept C = requires(T t) {
4594 /// ... ...
4595 /// } }
4596 /// \endcode
4598 /// If ``true``, put a space before opening parentheses only if the
4599 /// parentheses are not empty.
4600 /// \code
4601 /// true: false:
4602 /// void f (int a); vs. void f();
4603 /// f (a); f();
4604 /// \endcode
4606
4614
4616 return AfterControlStatements == Other.AfterControlStatements &&
4617 AfterForeachMacros == Other.AfterForeachMacros &&
4619 Other.AfterFunctionDeclarationName &&
4620 AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
4621 AfterIfMacros == Other.AfterIfMacros &&
4622 AfterOverloadedOperator == Other.AfterOverloadedOperator &&
4623 AfterPlacementOperator == Other.AfterPlacementOperator &&
4624 AfterRequiresInClause == Other.AfterRequiresInClause &&
4625 AfterRequiresInExpression == Other.AfterRequiresInExpression &&
4626 BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
4627 }
4628 };
4629
4630 /// Control of individual space before parentheses.
4631 ///
4632 /// If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify
4633 /// how each individual space before parentheses case should be handled.
4634 /// Otherwise, this is ignored.
4635 /// \code{.yaml}
4636 /// # Example of usage:
4637 /// SpaceBeforeParens: Custom
4638 /// SpaceBeforeParensOptions:
4639 /// AfterControlStatements: true
4640 /// AfterFunctionDefinitionName: true
4641 /// \endcode
4642 /// \version 14
4644
4645 /// If ``true``, spaces will be before ``[``.
4646 /// Lambdas will not be affected. Only the first ``[`` will get a space added.
4647 /// \code
4648 /// true: false:
4649 /// int a [5]; vs. int a[5];
4650 /// int a [5][5]; vs. int a[5][5];
4651 /// \endcode
4652 /// \version 10
4654
4655 /// If ``false``, spaces will be removed before range-based for loop
4656 /// colon.
4657 /// \code
4658 /// true: false:
4659 /// for (auto v : values) {} vs. for(auto v: values) {}
4660 /// \endcode
4661 /// \version 7
4663
4664 /// If ``true``, spaces will be inserted into ``{}``.
4665 /// \code
4666 /// true: false:
4667 /// void f() { } vs. void f() {}
4668 /// while (true) { } while (true) {}
4669 /// \endcode
4670 /// \version 10
4672
4673 /// If ``true``, spaces may be inserted into ``()``.
4674 /// This option is **deprecated**. See ``InEmptyParentheses`` of
4675 /// ``SpacesInParensOptions``.
4676 /// \version 3.7
4677 // bool SpaceInEmptyParentheses;
4678
4679 /// The number of spaces before trailing line comments
4680 /// (``//`` - comments).
4681 ///
4682 /// This does not affect trailing block comments (``/*`` - comments) as those
4683 /// commonly have different usage patterns and a number of special cases. In
4684 /// the case of Verilog, it doesn't affect a comment right after the opening
4685 /// parenthesis in the port or parameter list in a module header, because it
4686 /// is probably for the port on the following line instead of the parenthesis
4687 /// it follows.
4688 /// \code
4689 /// SpacesBeforeTrailingComments: 3
4690 /// void f() {
4691 /// if (true) { // foo1
4692 /// f(); // bar
4693 /// } // foo
4694 /// }
4695 /// \endcode
4696 /// \version 3.7
4698
4699 /// Styles for adding spacing after ``<`` and before ``>``
4700 /// in template argument lists.
4701 enum SpacesInAnglesStyle : int8_t {
4702 /// Remove spaces after ``<`` and before ``>``.
4703 /// \code
4704 /// static_cast<int>(arg);
4705 /// std::function<void(int)> fct;
4706 /// \endcode
4708 /// Add spaces after ``<`` and before ``>``.
4709 /// \code
4710 /// static_cast< int >(arg);
4711 /// std::function< void(int) > fct;
4712 /// \endcode
4714 /// Keep a single space after ``<`` and before ``>`` if any spaces were
4715 /// present. Option ``Standard: Cpp03`` takes precedence.
4718 /// The SpacesInAnglesStyle to use for template argument lists.
4719 /// \version 3.4
4721
4722 /// If ``true``, spaces will be inserted around if/for/switch/while
4723 /// conditions.
4724 /// This option is **deprecated**. See ``InConditionalStatements`` of
4725 /// ``SpacesInParensOptions``.
4726 /// \version 10
4727 // bool SpacesInConditionalStatement;
4728
4729 /// If ``true``, spaces are inserted inside container literals (e.g. ObjC and
4730 /// Javascript array and dict literals). For JSON, use
4731 /// ``SpaceBeforeJsonColon`` instead.
4732 /// \code{.js}
4733 /// true: false:
4734 /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
4735 /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
4736 /// \endcode
4737 /// \version 3.7
4739
4740 /// If ``true``, spaces may be inserted into C style casts.
4741 /// This option is **deprecated**. See ``InCStyleCasts`` of
4742 /// ``SpacesInParensOptions``.
4743 /// \version 3.7
4744 // bool SpacesInCStyleCastParentheses;
4745
4746 /// Control of spaces within a single line comment.
4748 /// The minimum number of spaces at the start of the comment.
4749 unsigned Minimum;
4750 /// The maximum number of spaces at the start of the comment.
4751 unsigned Maximum;
4752 };
4753
4754 /// How many spaces are allowed at the start of a line comment. To disable the
4755 /// maximum set it to ``-1``, apart from that the maximum takes precedence
4756 /// over the minimum.
4757 /// \code
4758 /// Minimum = 1
4759 /// Maximum = -1
4760 /// // One space is forced
4761 ///
4762 /// // but more spaces are possible
4763 ///
4764 /// Minimum = 0
4765 /// Maximum = 0
4766 /// //Forces to start every comment directly after the slashes
4767 /// \endcode
4768 ///
4769 /// Note that in line comment sections the relative indent of the subsequent
4770 /// lines is kept, that means the following:
4771 /// \code
4772 /// before: after:
4773 /// Minimum: 1
4774 /// //if (b) { // if (b) {
4775 /// // return true; // return true;
4776 /// //} // }
4777 ///
4778 /// Maximum: 0
4779 /// /// List: ///List:
4780 /// /// - Foo /// - Foo
4781 /// /// - Bar /// - Bar
4782 /// \endcode
4783 ///
4784 /// This option has only effect if ``ReflowComments`` is set to ``true``.
4785 /// \version 13
4787
4788 /// Different ways to put a space before opening and closing parentheses.
4789 enum SpacesInParensStyle : int8_t {
4790 /// Never put a space in parentheses.
4791 /// \code
4792 /// void f() {
4793 /// if(true) {
4794 /// f();
4795 /// }
4796 /// }
4797 /// \endcode
4799 /// Configure each individual space in parentheses in
4800 /// `SpacesInParensOptions`.
4802 };
4803
4804 /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
4805 /// This option is **deprecated**. The previous behavior is preserved by using
4806 /// ``SpacesInParens`` with ``Custom`` and by setting all
4807 /// ``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and
4808 /// ``InEmptyParentheses``.
4809 /// \version 3.7
4810 // bool SpacesInParentheses;
4811
4812 /// Defines in which cases spaces will be inserted after ``(`` and before
4813 /// ``)``.
4814 /// \version 17
4816
4817 /// Precise control over the spacing in parentheses.
4818 /// \code
4819 /// # Should be declared this way:
4820 /// SpacesInParens: Custom
4821 /// SpacesInParensOptions:
4822 /// ExceptDoubleParentheses: false
4823 /// InConditionalStatements: true
4824 /// Other: true
4825 /// \endcode
4827 /// Override any of the following options to prevent addition of space
4828 /// when both opening and closing parentheses use multiple parentheses.
4829 /// \code
4830 /// true:
4831 /// __attribute__(( noreturn ))
4832 /// __decltype__(( x ))
4833 /// if (( a = b ))
4834 /// \endcode
4835 /// false:
4836 /// Uses the applicable option.
4838 /// Put a space in parentheses only inside conditional statements
4839 /// (``for/if/while/switch...``).
4840 /// \code
4841 /// true: false:
4842 /// if ( a ) { ... } vs. if (a) { ... }
4843 /// while ( i < 5 ) { ... } while (i < 5) { ... }
4844 /// \endcode
4846 /// Put a space in C style casts.
4847 /// \code
4848 /// true: false:
4849 /// x = ( int32 )y vs. x = (int32)y
4850 /// y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x);
4851 /// \endcode
4853 /// Insert a space in empty parentheses, i.e. ``()``.
4854 /// \code
4855 /// true: false:
4856 /// void f( ) { vs. void f() {
4857 /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
4858 /// if (true) { if (true) {
4859 /// f( ); f();
4860 /// } }
4861 /// } }
4862 /// \endcode
4864 /// Put a space in parentheses not covered by preceding options.
4865 /// \code
4866 /// true: false:
4867 /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
4868 /// \endcode
4869 bool Other;
4870
4874
4877 bool InEmptyParentheses, bool Other)
4881 Other(Other) {}
4882
4883 bool operator==(const SpacesInParensCustom &R) const {
4888 }
4889 bool operator!=(const SpacesInParensCustom &R) const {
4890 return !(*this == R);
4891 }
4892 };
4893
4894 /// Control of individual spaces in parentheses.
4895 ///
4896 /// If ``SpacesInParens`` is set to ``Custom``, use this to specify
4897 /// how each individual space in parentheses case should be handled.
4898 /// Otherwise, this is ignored.
4899 /// \code{.yaml}
4900 /// # Example of usage:
4901 /// SpacesInParens: Custom
4902 /// SpacesInParensOptions:
4903 /// ExceptDoubleParentheses: false
4904 /// InConditionalStatements: true
4905 /// InEmptyParentheses: true
4906 /// \endcode
4907 /// \version 17
4909
4910 /// If ``true``, spaces will be inserted after ``[`` and before ``]``.
4911 /// Lambdas without arguments or unspecified size array declarations will not
4912 /// be affected.
4913 /// \code
4914 /// true: false:
4915 /// int a[ 5 ]; vs. int a[5];
4916 /// std::unique_ptr<int[]> foo() {} // Won't be affected
4917 /// \endcode
4918 /// \version 3.7
4920
4921 /// Supported language standards for parsing and formatting C++ constructs.
4922 /// \code
4923 /// Latest: vector<set<int>>
4924 /// c++03 vs. vector<set<int> >
4925 /// \endcode
4926 ///
4927 /// The correct way to spell a specific language version is e.g. ``c++11``.
4928 /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
4929 enum LanguageStandard : int8_t {
4930 /// Parse and format as C++03.
4931 /// ``Cpp03`` is a deprecated alias for ``c++03``
4932 LS_Cpp03, // c++03
4933 /// Parse and format as C++11.
4934 LS_Cpp11, // c++11
4935 /// Parse and format as C++14.
4936 LS_Cpp14, // c++14
4937 /// Parse and format as C++17.
4938 LS_Cpp17, // c++17
4939 /// Parse and format as C++20.
4940 LS_Cpp20, // c++20
4941 /// Parse and format using the latest supported language version.
4942 /// ``Cpp11`` is a deprecated alias for ``Latest``
4944 /// Automatic detection based on the input.
4946 };
4947
4948 /// Parse and format C++ constructs compatible with this standard.
4949 /// \code
4950 /// c++03: latest:
4951 /// vector<set<int> > x; vs. vector<set<int>> x;
4952 /// \endcode
4953 /// \version 3.7
4955
4956 /// Macros which are ignored in front of a statement, as if they were an
4957 /// attribute. So that they are not parsed as identifier, for example for Qts
4958 /// emit.
4959 /// \code
4960 /// AlignConsecutiveDeclarations: true
4961 /// StatementAttributeLikeMacros: []
4962 /// unsigned char data = 'x';
4963 /// emit signal(data); // This is parsed as variable declaration.
4964 ///
4965 /// AlignConsecutiveDeclarations: true
4966 /// StatementAttributeLikeMacros: [emit]
4967 /// unsigned char data = 'x';
4968 /// emit signal(data); // Now it's fine again.
4969 /// \endcode
4970 /// \version 12
4971 std::vector<std::string> StatementAttributeLikeMacros;
4972
4973 /// A vector of macros that should be interpreted as complete statements.
4974 ///
4975 /// Typical macros are expressions and require a semicolon to be added.
4976 /// Sometimes this is not the case, and this allows to make clang-format aware
4977 /// of such cases.
4978 ///
4979 /// For example: Q_UNUSED
4980 /// \version 8
4981 std::vector<std::string> StatementMacros;
4982
4983 /// Works only when TableGenBreakInsideDAGArg is not DontBreak.
4984 /// The string list needs to consist of identifiers in TableGen.
4985 /// If any identifier is specified, this limits the line breaks by
4986 /// TableGenBreakInsideDAGArg option only on DAGArg values beginning with
4987 /// the specified identifiers.
4988 ///
4989 /// For example the configuration,
4990 /// \code{.yaml}
4991 /// TableGenBreakInsideDAGArg: BreakAll
4992 /// TableGenBreakingDAGArgOperators: [ins, outs]
4993 /// \endcode
4994 ///
4995 /// makes the line break only occurs inside DAGArgs beginning with the
4996 /// specified identifiers ``ins`` and ``outs``.
4997 ///
4998 /// \code
4999 /// let DAGArgIns = (ins
5000 /// i32:$src1,
5001 /// i32:$src2
5002 /// );
5003 /// let DAGArgOtherID = (other i32:$other1, i32:$other2);
5004 /// let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)
5005 /// \endcode
5006 /// \version 19
5007 std::vector<std::string> TableGenBreakingDAGArgOperators;
5008
5009 /// Different ways to control the format inside TableGen DAGArg.
5010 enum DAGArgStyle : int8_t {
5011 /// Never break inside DAGArg.
5012 /// \code
5013 /// let DAGArgIns = (ins i32:$src1, i32:$src2);
5014 /// \endcode
5016 /// Break inside DAGArg after each list element but for the last.
5017 /// This aligns to the first element.
5018 /// \code
5019 /// let DAGArgIns = (ins i32:$src1,
5020 /// i32:$src2);
5021 /// \endcode
5023 /// Break inside DAGArg after the operator and the all elements.
5024 /// \code
5025 /// let DAGArgIns = (ins
5026 /// i32:$src1,
5027 /// i32:$src2
5028 /// );
5029 /// \endcode
5031 };
5032
5033 /// The styles of the line break inside the DAGArg in TableGen.
5034 /// \version 19
5036
5037 /// The number of columns used for tab stops.
5038 /// \version 3.7
5039 unsigned TabWidth;
5040
5041 /// A vector of non-keyword identifiers that should be interpreted as
5042 /// template names.
5043 ///
5044 /// A ``<`` after a template name is annotated as a template opener instead of
5045 /// a binary operator.
5046 ///
5047 /// \version 20
5048 std::vector<std::string> TemplateNames;
5049
5050 /// A vector of non-keyword identifiers that should be interpreted as type
5051 /// names.
5052 ///
5053 /// A ``*``, ``&``, or ``&&`` between a type name and another non-keyword
5054 /// identifier is annotated as a pointer or reference token instead of a
5055 /// binary operator.
5056 ///
5057 /// \version 17
5058 std::vector<std::string> TypeNames;
5059
5060 /// \brief A vector of macros that should be interpreted as type declarations
5061 /// instead of as function calls.
5062 ///
5063 /// These are expected to be macros of the form:
5064 /// \code
5065 /// STACK_OF(...)
5066 /// \endcode
5067 ///
5068 /// In the .clang-format configuration file, this can be configured like:
5069 /// \code{.yaml}
5070 /// TypenameMacros: [STACK_OF, LIST]
5071 /// \endcode
5072 ///
5073 /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
5074 /// \version 9
5075 std::vector<std::string> TypenameMacros;
5076
5077 /// This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``.
5078 /// \version 10
5079 // bool UseCRLF;
5080
5081 /// Different ways to use tab in formatting.
5082 enum UseTabStyle : int8_t {
5083 /// Never use tab.
5085 /// Use tabs only for indentation.
5087 /// Fill all leading whitespace with tabs, and use spaces for alignment that
5088 /// appears within a line (e.g. consecutive assignments and declarations).
5090 /// Use tabs for line continuation and indentation, and spaces for
5091 /// alignment.
5093 /// Use tabs whenever we need to fill whitespace that spans at least from
5094 /// one tab stop to the next one.
5095 UT_Always
5097
5098 /// The way to use tab characters in the resulting file.
5099 /// \version 3.7
5101
5102 /// For Verilog, put each port on its own line in module instantiations.
5103 /// \code
5104 /// true:
5105 /// ffnand ff1(.q(),
5106 /// .qbar(out1),
5107 /// .clear(in1),
5108 /// .preset(in2));
5109 ///
5110 /// false:
5111 /// ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
5112 /// \endcode
5113 /// \version 17
5115
5116 /// A vector of macros which are whitespace-sensitive and should not
5117 /// be touched.
5118 ///
5119 /// These are expected to be macros of the form:
5120 /// \code
5121 /// STRINGIZE(...)
5122 /// \endcode
5123 ///
5124 /// In the .clang-format configuration file, this can be configured like:
5125 /// \code{.yaml}
5126 /// WhitespaceSensitiveMacros: [STRINGIZE, PP_STRINGIZE]
5127 /// \endcode
5128 ///
5129 /// For example: BOOST_PP_STRINGIZE
5130 /// \version 11
5131 std::vector<std::string> WhitespaceSensitiveMacros;
5132
5133 bool operator==(const FormatStyle &R) const {
5182 BreakArrays == R.BreakArrays &&
5223 IndentWidth == R.IndentWidth &&
5303 Standard == R.Standard &&
5311 UseTab == R.UseTab &&
5315 }
5316
5317 std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
5318
5319 // Stores per-language styles. A FormatStyle instance inside has an empty
5320 // StyleSet. A FormatStyle instance returned by the Get method has its
5321 // StyleSet set to a copy of the originating StyleSet, effectively keeping the
5322 // internal representation of that StyleSet alive.
5323 //
5324 // The memory management and ownership reminds of a birds nest: chicks
5325 // leaving the nest take photos of the nest with them.
5327 typedef std::map<FormatStyle::LanguageKind, FormatStyle> MapType;
5328
5329 std::optional<FormatStyle> Get(FormatStyle::LanguageKind Language) const;
5330
5331 // Adds \p Style to this FormatStyleSet. Style must not have an associated
5332 // FormatStyleSet.
5333 // Style.Language should be different than LK_None. If this FormatStyleSet
5334 // already contains an entry for Style.Language, that gets replaced with the
5335 // passed Style.
5336 void Add(FormatStyle Style);
5337
5338 // Clears this FormatStyleSet.
5339 void Clear();
5340
5341 private:
5342 std::shared_ptr<MapType> Styles;
5343 };
5344
5346 const FormatStyle &MainStyle,
5347 const std::vector<FormatStyle> &ConfigurationStyles);
5348
5349private:
5350 FormatStyleSet StyleSet;
5351
5352 friend std::error_code
5353 parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
5354 bool AllowUnknownOptions,
5355 llvm::SourceMgr::DiagHandlerTy DiagHandler,
5356 void *DiagHandlerCtxt);
5357};
5358
5359/// Returns a format style complying with the LLVM coding standards:
5360/// http://llvm.org/docs/CodingStandards.html.
5363
5364/// Returns a format style complying with one of Google's style guides:
5365/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
5366/// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
5367/// https://developers.google.com/protocol-buffers/docs/style.
5369
5370/// Returns a format style complying with Chromium's style guide:
5371/// http://www.chromium.org/developers/coding-style.
5373
5374/// Returns a format style complying with Mozilla's style guide:
5375/// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html.
5377
5378/// Returns a format style complying with Webkit's style guide:
5379/// http://www.webkit.org/coding/coding-style.html
5381
5382/// Returns a format style complying with GNU Coding Standards:
5383/// http://www.gnu.org/prep/standards/standards.html
5385
5386/// Returns a format style complying with Microsoft style guide:
5387/// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
5389
5391
5392/// Returns style indicating formatting should be not applied at all.
5394
5395/// Gets a predefined style for the specified language by name.
5396///
5397/// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
5398/// compared case-insensitively.
5399///
5400/// Returns ``true`` if the Style has been set.
5402 FormatStyle *Style);
5403
5404/// Parse configuration from YAML-formatted text.
5405///
5406/// Style->Language is used to get the base style, if the ``BasedOnStyle``
5407/// option is present.
5408///
5409/// The FormatStyleSet of Style is reset.
5410///
5411/// When ``BasedOnStyle`` is not present, options not present in the YAML
5412/// document, are retained in \p Style.
5413///
5414/// If AllowUnknownOptions is true, no errors are emitted if unknown
5415/// format options are occurred.
5416///
5417/// If set all diagnostics are emitted through the DiagHandler.
5418std::error_code
5419parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
5420 bool AllowUnknownOptions = false,
5421 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
5422 void *DiagHandlerCtx = nullptr);
5423
5424/// Like above but accepts an unnamed buffer.
5425inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
5426 bool AllowUnknownOptions = false) {
5427 return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
5428 AllowUnknownOptions);
5429}
5430
5431/// Gets configuration in a YAML string.
5432std::string configurationAsText(const FormatStyle &Style);
5433
5434/// Returns the replacements necessary to sort all ``#include`` blocks
5435/// that are affected by ``Ranges``.
5436tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
5438 StringRef FileName,
5439 unsigned *Cursor = nullptr);
5440
5441/// Returns the replacements corresponding to applying and formatting
5442/// \p Replaces on success; otheriwse, return an llvm::Error carrying
5443/// llvm::StringError.
5445formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
5446 const FormatStyle &Style);
5447
5448/// Returns the replacements corresponding to applying \p Replaces and
5449/// cleaning up the code after that on success; otherwise, return an llvm::Error
5450/// carrying llvm::StringError.
5451/// This also supports inserting/deleting C++ #include directives:
5452/// * If a replacement has offset UINT_MAX, length 0, and a replacement text
5453/// that is an #include directive, this will insert the #include into the
5454/// correct block in the \p Code.
5455/// * If a replacement has offset UINT_MAX, length 1, and a replacement text
5456/// that is the name of the header to be removed, the header will be removed
5457/// from \p Code if it exists.
5458/// The include manipulation is done via ``tooling::HeaderInclude``, see its
5459/// documentation for more details on how include insertion points are found and
5460/// what edits are produced.
5462cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
5463 const FormatStyle &Style);
5464
5465/// Represents the status of a formatting attempt.
5467 /// A value of ``false`` means that any of the affected ranges were not
5468 /// formatted due to a non-recoverable syntax error.
5469 bool FormatComplete = true;
5470
5471 /// If ``FormatComplete`` is false, ``Line`` records a one-based
5472 /// original