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