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