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