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