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