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