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 the last attribute of a group before a
1721 /// declaration or control statement.
1722 enum AttributeBreakingStyle : int8_t {
1723 /// Always break after the last attribute of the group.
1724 /// \code
1725 /// [[maybe_unused]]
1726 /// const int i;
1727 /// [[gnu::const]] [[maybe_unused]]
1728 /// int j;
1729 ///
1730 /// [[nodiscard]]
1731 /// inline int f();
1732 /// [[gnu::const]] [[nodiscard]]
1733 /// int g();
1734 ///
1735 /// [[likely]]
1736 /// if (a)
1737 /// f();
1738 /// else
1739 /// g();
1740 ///
1741 /// switch (b) {
1742 /// [[unlikely]]
1743 /// case 1:
1744 /// ++b;
1745 /// break;
1746 /// [[likely]]
1747 /// default:
1748 /// return;
1749 /// }
1750 /// \endcode
1751 ABS_Always,
1752 /// Leave the line breaking after the last attribute of the group as is.
1753 /// \code
1754 /// [[maybe_unused]] const int i;
1755 /// [[gnu::const]] [[maybe_unused]]
1756 /// int j;
1757 ///
1758 /// [[nodiscard]] inline int f();
1759 /// [[gnu::const]] [[nodiscard]]
1760 /// int g();
1761 ///
1762 /// [[likely]] if (a)
1763 /// f();
1764 /// else
1765 /// g();
1766 ///
1767 /// switch (b) {
1768 /// [[unlikely]] case 1:
1769 /// ++b;
1770 /// break;
1771 /// [[likely]]
1772 /// default:
1773 /// return;
1774 /// }
1775 /// \endcode
1776 ABS_Leave,
1777 /// Same as ``Leave`` except that it applies to all attributes of the group.
1778 /// \code
1779 /// [[deprecated("Don't use this version")]]
1780 /// [[nodiscard]]
1781 /// bool foo() {
1782 /// return true;
1783 /// }
1784 ///
1785 /// [[deprecated("Don't use this version")]]
1786 /// [[nodiscard]] bool bar() {
1787 /// return true;
1788 /// }
1789 /// \endcode
1790 ABS_LeaveAll,
1791 /// Never break after the last attribute of the group.
1792 /// \code
1793 /// [[maybe_unused]] const int i;
1794 /// [[gnu::const]] [[maybe_unused]] int j;
1795 ///
1796 /// [[nodiscard]] inline int f();
1797 /// [[gnu::const]] [[nodiscard]] int g();
1798 ///
1799 /// [[likely]] if (a)
1800 /// f();
1801 /// else
1802 /// g();
1803 ///
1804 /// switch (b) {
1805 /// [[unlikely]] case 1:
1806 /// ++b;
1807 /// break;
1808 /// [[likely]] default:
1809 /// return;
1810 /// }
1811 /// \endcode
1812 ABS_Never,
1813 };
1814
1815 /// Break after a group of C++11 attributes before variable or function
1816 /// (including constructor/destructor) declaration/definition names or before
1817 /// control statements, i.e. ``if``, ``switch`` (including ``case`` and
1818 /// ``default`` labels), ``for``, and ``while`` statements.
1819 /// \version 16
1820 AttributeBreakingStyle BreakAfterAttributes;
1821
1822 /// Force break after the left bracket of a braced initializer list (when
1823 /// ``Cpp11BracedListStyle`` is ``true``) when the list exceeds the column
1824 /// limit.
1825 /// \code
1826 /// true: false:
1827 /// vector<int> x { vs. vector<int> x {1,
1828 /// 1, 2, 3} 2, 3}
1829 /// \endcode
1830 /// \version 22
1831 bool BreakAfterOpenBracketBracedList;
1832
1833 /// Force break after the left parenthesis of a function (declaration,
1834 /// definition, call) when the parameters exceed the column limit.
1835 /// \code
1836 /// true: false:
1837 /// foo ( vs. foo (a,
1838 /// a , b) b)
1839 /// \endcode
1840 /// \version 22
1841 bool BreakAfterOpenBracketFunction;
1842
1843 /// Force break after the left parenthesis of an if control statement
1844 /// when the expression exceeds the column limit.
1845 /// \code
1846 /// true: false:
1847 /// if constexpr ( vs. if constexpr (a ||
1848 /// a || b) b)
1849 /// \endcode
1850 /// \version 22
1851 bool BreakAfterOpenBracketIf;
1852
1853 /// Force break after the left parenthesis of a loop control statement
1854 /// when the expression exceeds the column limit.
1855 /// \code
1856 /// true: false:
1857 /// while ( vs. while (a &&
1858 /// a && b) { b) {
1859 /// \endcode
1860 /// \version 22
1861 bool BreakAfterOpenBracketLoop;
1862
1863 /// Force break after the left parenthesis of a switch control statement
1864 /// when the expression exceeds the column limit.
1865 /// \code
1866 /// true: false:
1867 /// switch ( vs. switch (a +
1868 /// a + b) { b) {
1869 /// \endcode
1870 /// \version 22
1871 bool BreakAfterOpenBracketSwitch;
1872
1873 /// The function declaration return type breaking style to use.
1874 /// \version 19
1875 ReturnTypeBreakingStyle BreakAfterReturnType;
1876
1877 /// If ``true``, clang-format will always break after a Json array ``[``
1878 /// otherwise it will scan until the closing ``]`` to determine if it should
1879 /// add newlines between elements (prettier compatible).
1880 ///
1881 /// \note
1882 /// This is currently only for formatting JSON.
1883 /// \endnote
1884 /// \code
1885 /// true: false:
1886 /// [ vs. [1, 2, 3, 4]
1887 /// 1,
1888 /// 2,
1889 /// 3,
1890 /// 4
1891 /// ]
1892 /// \endcode
1893 /// \version 16
1894 bool BreakArrays;
1895
1896 /// The style of wrapping parameters on the same line (bin-packed) or
1897 /// on one line each.
1898 enum BinPackStyle : int8_t {
1899 /// Automatically determine parameter bin-packing behavior.
1900 BPS_Auto,
1901 /// Always bin-pack parameters.
1902 BPS_Always,
1903 /// Never bin-pack parameters.
1904 BPS_Never,
1905 };
1906
1907 /// The style of breaking before or after binary operators.
1908 enum BinaryOperatorStyle : int8_t {
1909 /// Break after operators.
1910 /// \code
1911 /// LooooooooooongType loooooooooooooooooooooongVariable =
1912 /// someLooooooooooooooooongFunction();
1913 ///
1914 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
1915 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
1916 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
1917 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
1918 /// ccccccccccccccccccccccccccccccccccccccccc;
1919 /// \endcode
1920 BOS_None,
1921 /// Break before operators that aren't assignments.
1922 /// \code
1923 /// LooooooooooongType loooooooooooooooooooooongVariable =
1924 /// someLooooooooooooooooongFunction();
1925 ///
1926 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1927 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1928 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1929 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1930 /// > ccccccccccccccccccccccccccccccccccccccccc;
1931 /// \endcode
1932 BOS_NonAssignment,
1933 /// Break before operators.
1934 /// \code
1935 /// LooooooooooongType loooooooooooooooooooooongVariable
1936 /// = someLooooooooooooooooongFunction();
1937 ///
1938 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1939 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1940 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1941 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1942 /// > ccccccccccccccccccccccccccccccccccccccccc;
1943 /// \endcode
1944 BOS_All,
1945 };
1946
1947 /// The way to wrap binary operators.
1948 /// \version 3.6
1949 BinaryOperatorStyle BreakBeforeBinaryOperators;
1950
1951 /// Different ways to attach braces to their surrounding context.
1952 enum BraceBreakingStyle : int8_t {
1953 /// Always attach braces to surrounding context.
1954 /// \code
1955 /// namespace N {
1956 /// enum E {
1957 /// E1,
1958 /// E2,
1959 /// };
1960 ///
1961 /// class C {
1962 /// public:
1963 /// C();
1964 /// };
1965 ///
1966 /// bool baz(int i) {
1967 /// try {
1968 /// do {
1969 /// switch (i) {
1970 /// case 1: {
1971 /// foobar();
1972 /// break;
1973 /// }
1974 /// default: {
1975 /// break;
1976 /// }
1977 /// }
1978 /// } while (--i);
1979 /// return true;
1980 /// } catch (...) {
1981 /// handleError();
1982 /// return false;
1983 /// }
1984 /// }
1985 ///
1986 /// void foo(bool b) {
1987 /// if (b) {
1988 /// baz(2);
1989 /// } else {
1990 /// baz(5);
1991 /// }
1992 /// }
1993 ///
1994 /// void bar() { foo(true); }
1995 /// } // namespace N
1996 /// \endcode
1997 BS_Attach,
1998 /// Like ``Attach``, but break before braces on function, namespace and
1999 /// class definitions.
2000 /// \code
2001 /// namespace N
2002 /// {
2003 /// enum E {
2004 /// E1,
2005 /// E2,
2006 /// };
2007 ///
2008 /// class C
2009 /// {
2010 /// public:
2011 /// C();
2012 /// };
2013 ///
2014 /// bool baz(int i)
2015 /// {
2016 /// try {
2017 /// do {
2018 /// switch (i) {
2019 /// case 1: {
2020 /// foobar();
2021 /// break;
2022 /// }
2023 /// default: {
2024 /// break;
2025 /// }
2026 /// }
2027 /// } while (--i);
2028 /// return true;
2029 /// } catch (...) {
2030 /// handleError();
2031 /// return false;
2032 /// }
2033 /// }
2034 ///
2035 /// void foo(bool b)
2036 /// {
2037 /// if (b) {
2038 /// baz(2);
2039 /// } else {
2040 /// baz(5);
2041 /// }
2042 /// }
2043 ///
2044 /// void bar() { foo(true); }
2045 /// } // namespace N
2046 /// \endcode
2047 BS_Linux,
2048 /// Like ``Attach``, but break before braces on enum, function, and record
2049 /// definitions.
2050 /// \code
2051 /// namespace N {
2052 /// enum E
2053 /// {
2054 /// E1,
2055 /// E2,
2056 /// };
2057 ///
2058 /// class C
2059 /// {
2060 /// public:
2061 /// C();
2062 /// };
2063 ///
2064 /// bool baz(int i)
2065 /// {
2066 /// try {
2067 /// do {
2068 /// switch (i) {
2069 /// case 1: {
2070 /// foobar();
2071 /// break;
2072 /// }
2073 /// default: {
2074 /// break;
2075 /// }
2076 /// }
2077 /// } while (--i);
2078 /// return true;
2079 /// } catch (...) {
2080 /// handleError();
2081 /// return false;
2082 /// }
2083 /// }
2084 ///
2085 /// void foo(bool b)
2086 /// {
2087 /// if (b) {
2088 /// baz(2);
2089 /// } else {
2090 /// baz(5);
2091 /// }
2092 /// }
2093 ///
2094 /// void bar() { foo(true); }
2095 /// } // namespace N
2096 /// \endcode
2097 BS_Mozilla,
2098 /// Like ``Attach``, but break before function definitions, ``catch``, and
2099 /// ``else``.
2100 /// \code
2101 /// namespace N {
2102 /// enum E {
2103 /// E1,
2104 /// E2,
2105 /// };
2106 ///
2107 /// class C {
2108 /// public:
2109 /// C();
2110 /// };
2111 ///
2112 /// bool baz(int i)
2113 /// {
2114 /// try {
2115 /// do {
2116 /// switch (i) {
2117 /// case 1: {
2118 /// foobar();
2119 /// break;
2120 /// }
2121 /// default: {
2122 /// break;
2123 /// }
2124 /// }
2125 /// } while (--i);
2126 /// return true;
2127 /// }
2128 /// catch (...) {
2129 /// handleError();
2130 /// return false;
2131 /// }
2132 /// }
2133 ///
2134 /// void foo(bool b)
2135 /// {
2136 /// if (b) {
2137 /// baz(2);
2138 /// }
2139 /// else {
2140 /// baz(5);
2141 /// }
2142 /// }
2143 ///
2144 /// void bar() { foo(true); }
2145 /// } // namespace N
2146 /// \endcode
2147 BS_Stroustrup,
2148 /// Always break before braces.
2149 /// \code
2150 /// namespace N
2151 /// {
2152 /// enum E
2153 /// {
2154 /// E1,
2155 /// E2,
2156 /// };
2157 ///
2158 /// class C
2159 /// {
2160 /// public:
2161 /// C();
2162 /// };
2163 ///
2164 /// bool baz(int i)
2165 /// {
2166 /// try
2167 /// {
2168 /// do
2169 /// {
2170 /// switch (i)
2171 /// {
2172 /// case 1:
2173 /// {
2174 /// foobar();
2175 /// break;
2176 /// }
2177 /// default:
2178 /// {
2179 /// break;
2180 /// }
2181 /// }
2182 /// } while (--i);
2183 /// return true;
2184 /// }
2185 /// catch (...)
2186 /// {
2187 /// handleError();
2188 /// return false;
2189 /// }
2190 /// }
2191 ///
2192 /// void foo(bool b)
2193 /// {
2194 /// if (b)
2195 /// {
2196 /// baz(2);
2197 /// }
2198 /// else
2199 /// {
2200 /// baz(5);
2201 /// }
2202 /// }
2203 ///
2204 /// void bar() { foo(true); }
2205 /// } // namespace N
2206 /// \endcode
2207 BS_Allman,
2208 /// Like ``Allman`` but always indent braces and line up code with braces.
2209 /// \code
2210 /// namespace N
2211 /// {
2212 /// enum E
2213 /// {
2214 /// E1,
2215 /// E2,
2216 /// };
2217 ///
2218 /// class C
2219 /// {
2220 /// public:
2221 /// C();
2222 /// };
2223 ///
2224 /// bool baz(int i)
2225 /// {
2226 /// try
2227 /// {
2228 /// do
2229 /// {
2230 /// switch (i)
2231 /// {
2232 /// case 1:
2233 /// {
2234 /// foobar();
2235 /// break;
2236 /// }
2237 /// default:
2238 /// {
2239 /// break;
2240 /// }
2241 /// }
2242 /// } while (--i);
2243 /// return true;
2244 /// }
2245 /// catch (...)
2246 /// {
2247 /// handleError();
2248 /// return false;
2249 /// }
2250 /// }
2251 ///
2252 /// void foo(bool b)
2253 /// {
2254 /// if (b)
2255 /// {
2256 /// baz(2);
2257 /// }
2258 /// else
2259 /// {
2260 /// baz(5);
2261 /// }
2262 /// }
2263 ///
2264 /// void bar() { foo(true); }
2265 /// } // namespace N
2266 /// \endcode
2267 BS_Whitesmiths,
2268 /// Always break before braces and add an extra level of indentation to
2269 /// braces of control statements, not to those of class, function
2270 /// or other definitions.
2271 /// \code
2272 /// namespace N
2273 /// {
2274 /// enum E
2275 /// {
2276 /// E1,
2277 /// E2,
2278 /// };
2279 ///
2280 /// class C
2281 /// {
2282 /// public:
2283 /// C();
2284 /// };
2285 ///
2286 /// bool baz(int i)
2287 /// {
2288 /// try
2289 /// {
2290 /// do
2291 /// {
2292 /// switch (i)
2293 /// {
2294 /// case 1:
2295 /// {
2296 /// foobar();
2297 /// break;
2298 /// }
2299 /// default:
2300 /// {
2301 /// break;
2302 /// }
2303 /// }
2304 /// }
2305 /// while (--i);
2306 /// return true;
2307 /// }
2308 /// catch (...)
2309 /// {
2310 /// handleError();
2311 /// return false;
2312 /// }
2313 /// }
2314 ///
2315 /// void foo(bool b)
2316 /// {
2317 /// if (b)
2318 /// {
2319 /// baz(2);
2320 /// }
2321 /// else
2322 /// {
2323 /// baz(5);
2324 /// }
2325 /// }
2326 ///
2327 /// void bar() { foo(true); }
2328 /// } // namespace N
2329 /// \endcode
2330 BS_GNU,
2331 /// Like ``Attach``, but break before functions.
2332 /// \code
2333 /// namespace N {
2334 /// enum E {
2335 /// E1,
2336 /// E2,
2337 /// };
2338 ///
2339 /// class C {
2340 /// public:
2341 /// C();
2342 /// };
2343 ///
2344 /// bool baz(int i)
2345 /// {
2346 /// try {
2347 /// do {
2348 /// switch (i) {
2349 /// case 1: {
2350 /// foobar();
2351 /// break;
2352 /// }
2353 /// default: {
2354 /// break;
2355 /// }
2356 /// }
2357 /// } while (--i);
2358 /// return true;
2359 /// } catch (...) {
2360 /// handleError();
2361 /// return false;
2362 /// }
2363 /// }
2364 ///
2365 /// void foo(bool b)
2366 /// {
2367 /// if (b) {
2368 /// baz(2);
2369 /// } else {
2370 /// baz(5);
2371 /// }
2372 /// }
2373 ///
2374 /// void bar() { foo(true); }
2375 /// } // namespace N
2376 /// \endcode
2377 BS_WebKit,
2378 /// Configure each individual brace in ``BraceWrapping``.
2379 BS_Custom
2380 };
2381
2382 /// The brace breaking style to use.
2383 /// \version 3.7
2384 BraceBreakingStyle BreakBeforeBraces;
2385
2386 /// Force break before the right bracket of a braced initializer list (when
2387 /// ``Cpp11BracedListStyle`` is ``true``) when the list exceeds the column
2388 /// limit. The break before the right bracket is only made if there is a
2389 /// break after the opening bracket.
2390 /// \code
2391 /// true: false:
2392 /// vector<int> x { vs. vector<int> x {
2393 /// 1, 2, 3 1, 2, 3}
2394 /// }
2395 /// \endcode
2396 /// \version 22
2397 bool BreakBeforeCloseBracketBracedList;
2398
2399 /// Force break before the right parenthesis of a function (declaration,
2400 /// definition, call) when the parameters exceed the column limit.
2401 /// \code
2402 /// true: false:
2403 /// foo ( vs. foo (
2404 /// a , b a , b)
2405 /// )
2406 /// \endcode
2407 /// \version 22
2408 bool BreakBeforeCloseBracketFunction;
2409
2410 /// Force break before the right parenthesis of an if control statement
2411 /// when the expression exceeds the column limit. The break before the
2412 /// closing parenthesis is only made if there is a break after the opening
2413 /// parenthesis.
2414 /// \code
2415 /// true: false:
2416 /// if constexpr ( vs. if constexpr (
2417 /// a || b a || b )
2418 /// )
2419 /// \endcode
2420 /// \version 22
2421 bool BreakBeforeCloseBracketIf;
2422
2423 /// Force break before the right parenthesis of a loop control statement
2424 /// when the expression exceeds the column limit. The break before the
2425 /// closing parenthesis is only made if there is a break after the opening
2426 /// parenthesis.
2427 /// \code
2428 /// true: false:
2429 /// while ( vs. while (
2430 /// a && b a && b) {
2431 /// ) {
2432 /// \endcode
2433 /// \version 22
2434 bool BreakBeforeCloseBracketLoop;
2435
2436 /// Force break before the right parenthesis of a switch control statement
2437 /// when the expression exceeds the column limit. The break before the
2438 /// closing parenthesis is only made if there is a break after the opening
2439 /// parenthesis.
2440 /// \code
2441 /// true: false:
2442 /// switch ( vs. switch (
2443 /// a + b a + b) {
2444 /// ) {
2445 /// \endcode
2446 /// \version 22
2447 bool BreakBeforeCloseBracketSwitch;
2448
2449 /// Different ways to break before concept declarations.
2450 enum BreakBeforeConceptDeclarationsStyle : int8_t {
2451 /// Keep the template declaration line together with ``concept``.
2452 /// \code
2453 /// template <typename T> concept C = ...;
2454 /// \endcode
2455 BBCDS_Never,
2456 /// Breaking between template declaration and ``concept`` is allowed. The
2457 /// actual behavior depends on the content and line breaking rules and
2458 /// penalties.
2459 BBCDS_Allowed,
2460 /// Always break before ``concept``, putting it in the line after the
2461 /// template declaration.
2462 /// \code
2463 /// template <typename T>
2464 /// concept C = ...;
2465 /// \endcode
2466 BBCDS_Always,
2467 };
2468
2469 /// The concept declaration style to use.
2470 /// \version 12
2471 BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations;
2472
2473 /// Different ways to break ASM parameters.
2474 enum BreakBeforeInlineASMColonStyle : int8_t {
2475 /// No break before inline ASM colon.
2476 /// \code
2477 /// asm volatile("string", : : val);
2478 /// \endcode
2479 BBIAS_Never,
2480 /// Break before inline ASM colon if the line length is longer than column
2481 /// limit.
2482 /// \code
2483 /// asm volatile("string", : : val);
2484 /// asm("cmoveq %1, %2, %[result]"
2485 /// : [result] "=r"(result)
2486 /// : "r"(test), "r"(new), "[result]"(old));
2487 /// \endcode
2488 BBIAS_OnlyMultiline,
2489 /// Always break before inline ASM colon.
2490 /// \code
2491 /// asm volatile("string",
2492 /// :
2493 /// : val);
2494 /// \endcode
2495 BBIAS_Always,
2496 };
2497
2498 /// The inline ASM colon style to use.
2499 /// \version 16
2500 BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
2501
2502 /// If ``true``, break before a template closing bracket (``>``) when there is
2503 /// a line break after the matching opening bracket (``<``).
2504 /// \code
2505 /// true:
2506 /// template <typename Foo, typename Bar>
2507 ///
2508 /// template <typename Foo,
2509 /// typename Bar>
2510 ///
2511 /// template <
2512 /// typename Foo,
2513 /// typename Bar
2514 /// >
2515 ///
2516 /// false:
2517 /// template <typename Foo, typename Bar>
2518 ///
2519 /// template <typename Foo,
2520 /// typename Bar>
2521 ///
2522 /// template <
2523 /// typename Foo,
2524 /// typename Bar>
2525 /// \endcode
2526 /// \version 21
2527 bool BreakBeforeTemplateCloser;
2528
2529 /// If ``true``, ternary operators will be placed after line breaks.
2530 /// \code
2531 /// true:
2532 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
2533 /// ? firstValue
2534 /// : SecondValueVeryVeryVeryVeryLong;
2535 ///
2536 /// false:
2537 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
2538 /// firstValue :
2539 /// SecondValueVeryVeryVeryVeryLong;
2540 /// \endcode
2541 /// \version 3.7
2542 bool BreakBeforeTernaryOperators;
2543
2544 /// Different ways to break binary operations.
2545 enum BreakBinaryOperationsStyle : int8_t {
2546 /// Don't break binary operations
2547 /// \code
2548 /// aaa + bbbb * ccccc - ddddd +
2549 /// eeeeeeeeeeeeeeee;
2550 /// \endcode
2551 BBO_Never,
2552
2553 /// Binary operations will either be all on the same line, or each operation
2554 /// will have one line each.
2555 /// \code
2556 /// aaa +
2557 /// bbbb *
2558 /// ccccc -
2559 /// ddddd +
2560 /// eeeeeeeeeeeeeeee;
2561 /// \endcode
2562 BBO_OnePerLine,
2563
2564 /// Binary operations of a particular precedence that exceed the column
2565 /// limit will have one line each.
2566 /// \code
2567 /// aaa +
2568 /// bbbb * ccccc -
2569 /// ddddd +
2570 /// eeeeeeeeeeeeeeee;
2571 /// \endcode
2572 BBO_RespectPrecedence
2573 };
2574
2575 /// A rule that specifies how to break a specific set of binary operators.
2576 /// \version 23
2577 struct BinaryOperationBreakRule {
2578 /// The list of operators this rule applies to, e.g. ``&&``, ``||``, ``|``.
2579 /// Alternative spellings (e.g. ``and`` for ``&&``) are accepted.
2580 std::vector<tok::TokenKind> Operators;
2581 /// The break style for these operators (defaults to ``OnePerLine``).
2582 BreakBinaryOperationsStyle Style;
2583 /// Minimum number of operands in a chain before the rule triggers.
2584 /// For example, ``a && b && c`` is a chain of length 3.
2585 /// ``0`` means always break (when the line is too long).
2586 unsigned MinChainLength;
2587 bool operator==(const BinaryOperationBreakRule &R) const {
2588 return Operators == R.Operators && Style == R.Style &&
2589 MinChainLength == R.MinChainLength;
2590 }
2591 bool operator!=(const BinaryOperationBreakRule &R) const {
2592 return !(*this == R);
2593 }
2594 };
2595
2596 /// Options for ``BreakBinaryOperations``.
2597 ///
2598 /// If specified as a simple string (e.g. ``OnePerLine``), it behaves like
2599 /// the original enum and applies to all binary operators.
2600 ///
2601 /// If specified as a struct, allows per-operator configuration:
2602 /// \code{.yaml}
2603 /// BreakBinaryOperations:
2604 /// Default: Never
2605 /// PerOperator:
2606 /// - Operators: ['&&', '||']
2607 /// Style: OnePerLine
2608 /// MinChainLength: 3
2609 /// \endcode
2610 /// \version 23
2611 struct BreakBinaryOperationsOptions {
2612 /// The default break style for operators not covered by ``PerOperator``.
2613 BreakBinaryOperationsStyle Default;
2614 /// Per-operator override rules.
2615 std::vector<BinaryOperationBreakRule> PerOperator;
2616 const BinaryOperationBreakRule *
2617 findRuleForOperator(tok::TokenKind Kind) const {
2618 for (const auto &Rule : PerOperator) {
2619 if (llvm::find(Rule.Operators, Kind) != Rule.Operators.end())
2620 return &Rule;
2621 // clang-format splits ">>" into two ">" tokens for template parsing.
2622 // Match ">" against ">>" rules so that per-operator rules for ">>"
2623 // (stream extraction / right shift) work correctly.
2624 if (Kind == tok::greater &&
2625 llvm::find(Rule.Operators, tok::greatergreater) !=
2626 Rule.Operators.end()) {
2627 return &Rule;
2628 }
2629 }
2630 return nullptr;
2631 }
2632 BreakBinaryOperationsStyle getStyleForOperator(tok::TokenKind Kind) const {
2633 if (const auto *Rule = findRuleForOperator(Kind))
2634 return Rule->Style;
2635 return Default;
2636 }
2637 unsigned getMinChainLengthForOperator(tok::TokenKind Kind) const {
2638 if (const auto *Rule = findRuleForOperator(Kind))
2639 return Rule->MinChainLength;
2640 return 0;
2641 }
2642 bool operator==(const BreakBinaryOperationsOptions &R) const {
2643 return Default == R.Default && PerOperator == R.PerOperator;
2644 }
2645 bool operator!=(const BreakBinaryOperationsOptions &R) const {
2646 return !(*this == R);
2647 }
2648 };
2649
2650 /// The break binary operations style to use.
2651 /// \version 20
2652 BreakBinaryOperationsOptions BreakBinaryOperations;
2653
2654 /// Different ways to break initializers.
2655 enum BreakConstructorInitializersStyle : int8_t {
2656 /// Break constructor initializers before the colon and after the commas.
2657 /// \code
2658 /// Constructor()
2659 /// : initializer1(),
2660 /// initializer2()
2661 /// \endcode
2662 BCIS_BeforeColon,
2663 /// Break constructor initializers before the colon and commas, and align
2664 /// the commas with the colon.
2665 /// \code
2666 /// Constructor()
2667 /// : initializer1()
2668 /// , initializer2()
2669 /// \endcode
2670 BCIS_BeforeComma,
2671 /// Break constructor initializers after the colon and commas.
2672 /// \code
2673 /// Constructor() :
2674 /// initializer1(),
2675 /// initializer2()
2676 /// \endcode
2677 BCIS_AfterColon,
2678 /// Break constructor initializers only after the commas.
2679 /// \code
2680 /// Constructor() : initializer1(),
2681 /// initializer2()
2682 /// \endcode
2683 BCIS_AfterComma
2684 };
2685
2686 /// The break constructor initializers style to use.
2687 /// \version 5
2688 BreakConstructorInitializersStyle BreakConstructorInitializers;
2689
2690 /// If ``true``, clang-format will always break before function definition
2691 /// parameters.
2692 /// \code
2693 /// true:
2694 /// void functionDefinition(
2695 /// int A, int B) {}
2696 ///
2697 /// false:
2698 /// void functionDefinition(int A, int B) {}
2699 ///
2700 /// \endcode
2701 /// \version 19
2702 bool BreakFunctionDefinitionParameters;
2703
2704 /// Break after each annotation on a field in Java files.
2705 /// \code{.java}
2706 /// true: false:
2707 /// @Partial vs. @Partial @Mock DataLoad loader;
2708 /// @Mock
2709 /// DataLoad loader;
2710 /// \endcode
2711 /// \version 3.8
2712 bool BreakAfterJavaFieldAnnotations;
2713
2714 /// Allow breaking string literals when formatting.
2715 ///
2716 /// In C, C++, and Objective-C:
2717 /// \code
2718 /// true:
2719 /// const char* x = "veryVeryVeryVeryVeryVe"
2720 /// "ryVeryVeryVeryVeryVery"
2721 /// "VeryLongString";
2722 ///
2723 /// false:
2724 /// const char* x =
2725 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2726 /// \endcode
2727 ///
2728 /// In C# and Java:
2729 /// \code
2730 /// true:
2731 /// string x = "veryVeryVeryVeryVeryVe" +
2732 /// "ryVeryVeryVeryVeryVery" +
2733 /// "VeryLongString";
2734 ///
2735 /// false:
2736 /// string x =
2737 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2738 /// \endcode
2739 ///
2740 /// C# interpolated strings are not broken.
2741 ///
2742 /// In Verilog:
2743 /// \code
2744 /// true:
2745 /// string x = {"veryVeryVeryVeryVeryVe",
2746 /// "ryVeryVeryVeryVeryVery",
2747 /// "VeryLongString"};
2748 ///
2749 /// false:
2750 /// string x =
2751 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2752 /// \endcode
2753 ///
2754 /// \version 3.9
2755 bool BreakStringLiterals;
2756
2757 /// The column limit.
2758 ///
2759 /// A column limit of ``0`` means that there is no column limit. In this case,
2760 /// clang-format will respect the input's line breaking decisions within
2761 /// statements unless they contradict other rules.
2762 /// \version 3.7
2763 unsigned ColumnLimit;
2764
2765 /// A regular expression that describes comments with special meaning,
2766 /// which should not be split into lines or otherwise changed.
2767 /// \code
2768 /// // CommentPragmas: '^ FOOBAR pragma:'
2769 /// // Will leave the following line unaffected
2770 /// #include <vector> // FOOBAR pragma: keep
2771 /// \endcode
2772 /// \version 3.7
2773 std::string CommentPragmas;
2774
2775 /// Different ways to break inheritance list.
2776 enum BreakInheritanceListStyle : int8_t {
2777 /// Break inheritance list before the colon and after the commas.
2778 /// \code
2779 /// class Foo
2780 /// : Base1,
2781 /// Base2
2782 /// {};
2783 /// \endcode
2784 BILS_BeforeColon,
2785 /// Break inheritance list before the colon and commas, and align
2786 /// the commas with the colon.
2787 /// \code
2788 /// class Foo
2789 /// : Base1
2790 /// , Base2
2791 /// {};
2792 /// \endcode
2793 BILS_BeforeComma,
2794 /// Break inheritance list after the colon and commas.
2795 /// \code
2796 /// class Foo :
2797 /// Base1,
2798 /// Base2
2799 /// {};
2800 /// \endcode
2801 BILS_AfterColon,
2802 /// Break inheritance list only after the commas.
2803 /// \code
2804 /// class Foo : Base1,
2805 /// Base2
2806 /// {};
2807 /// \endcode
2808 BILS_AfterComma,
2809 };
2810
2811 /// The inheritance list style to use.
2812 /// \version 7
2813 BreakInheritanceListStyle BreakInheritanceList;
2814
2815 /// The template declaration breaking style to use.
2816 /// \version 19
2817 BreakTemplateDeclarationsStyle BreakTemplateDeclarations;
2818
2819 /// If ``true``, consecutive namespace declarations will be on the same
2820 /// line. If ``false``, each namespace is declared on a new line.
2821 /// \code
2822 /// true:
2823 /// namespace Foo { namespace Bar {
2824 /// }}
2825 ///
2826 /// false:
2827 /// namespace Foo {
2828 /// namespace Bar {
2829 /// }
2830 /// }
2831 /// \endcode
2832 ///
2833 /// If it does not fit on a single line, the overflowing namespaces get
2834 /// wrapped:
2835 /// \code
2836 /// namespace Foo { namespace Bar {
2837 /// namespace Extra {
2838 /// }}}
2839 /// \endcode
2840 /// \version 5
2841 bool CompactNamespaces;
2842
2843 /// This option is **deprecated**. See ``CurrentLine`` of
2844 /// ``PackConstructorInitializers``.
2845 /// \version 3.7
2846 // bool ConstructorInitializerAllOnOneLineOrOnePerLine;
2847
2848 /// The number of characters to use for indentation of constructor
2849 /// initializer lists as well as inheritance lists.
2850 /// \version 3.7
2851 unsigned ConstructorInitializerIndentWidth;
2852
2853 /// Indent width for line continuations.
2854 /// \code
2855 /// ContinuationIndentWidth: 2
2856 ///
2857 /// int i = // VeryVeryVeryVeryVeryLongComment
2858 /// longFunction( // Again a long comment
2859 /// arg);
2860 /// \endcode
2861 /// \version 3.7
2862 unsigned ContinuationIndentWidth;
2863
2864 /// Different ways to handle braced lists.
2865 enum BracedListStyle : int8_t {
2866 /// Best suited for pre C++11 braced lists.
2867 ///
2868 /// * Spaces inside the braced list.
2869 /// * Line break before the closing brace.
2870 /// * Indentation with the block indent.
2871 ///
2872 /// \code
2873 /// vector<int> x{ 1, 2, 3, 4 };
2874 /// vector<T> x{ {}, {}, {}, {} };
2875 /// f(MyMap[{ composite, key }]);
2876 /// new int[3]{ 1, 2, 3 };
2877 /// Type name{ // Comment
2878 /// value
2879 /// };
2880 /// \endcode
2881 BLS_Block,
2882 /// Best suited for C++11 braced lists.
2883 ///
2884 /// * No spaces inside the braced list.
2885 /// * No line break before the closing brace.
2886 /// * Indentation with the continuation indent.
2887 ///
2888 /// Fundamentally, C++11 braced lists are formatted exactly like function
2889 /// calls would be formatted in their place. If the braced list follows a
2890 /// name (e.g. a type or variable name), clang-format formats as if the
2891 /// ``{}`` were the parentheses of a function call with that name. If there
2892 /// is no name, a zero-length name is assumed.
2893 /// \code
2894 /// vector<int> x{1, 2, 3, 4};
2895 /// vector<T> x{{}, {}, {}, {}};
2896 /// f(MyMap[{composite, key}]);
2897 /// new int[3]{1, 2, 3};
2898 /// Type name{ // Comment
2899 /// value};
2900 /// \endcode
2901 BLS_FunctionCall,
2902 /// Same as ``FunctionCall``, except for the handling of a comment at the
2903 /// begin, it then aligns everything following with the comment.
2904 ///
2905 /// * No spaces inside the braced list. (Even for a comment at the first
2906 /// position.)
2907 /// * No line break before the closing brace.
2908 /// * Indentation with the continuation indent, except when followed by a
2909 /// line comment, then it uses the block indent.
2910 ///
2911 /// \code
2912 /// vector<int> x{1, 2, 3, 4};
2913 /// vector<T> x{{}, {}, {}, {}};
2914 /// f(MyMap[{composite, key}]);
2915 /// new int[3]{1, 2, 3};
2916 /// Type name{// Comment
2917 /// value};
2918 /// \endcode
2919 BLS_AlignFirstComment,
2920 };
2921
2922 /// The style to handle braced lists.
2923 /// \version 3.4
2924 BracedListStyle Cpp11BracedListStyle;
2925
2926 /// This option is **deprecated**. See ``DeriveLF`` and ``DeriveCRLF`` of
2927 /// ``LineEnding``.
2928 /// \version 10
2929 // bool DeriveLineEnding;
2930
2931 /// If ``true``, analyze the formatted file for the most common
2932 /// alignment of ``&`` and ``*``.
2933 /// Pointer and reference alignment styles are going to be updated according
2934 /// to the preferences found in the file.
2935 /// ``PointerAlignment`` is then used only as fallback.
2936 /// \version 3.7
2937 bool DerivePointerAlignment;
2938
2939 /// Disables formatting completely.
2940 /// \version 3.7
2941 bool DisableFormat;
2942
2943 /// Different styles for empty line after access modifiers.
2944 /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2945 /// empty lines between two access modifiers.
2946 enum EmptyLineAfterAccessModifierStyle : int8_t {
2947 /// Remove all empty lines after access modifiers.
2948 /// \code
2949 /// struct foo {
2950 /// private:
2951 /// int i;
2952 /// protected:
2953 /// int j;
2954 /// /* comment */
2955 /// public:
2956 /// foo() {}
2957 /// private:
2958 /// protected:
2959 /// };
2960 /// \endcode
2961 ELAAMS_Never,
2962 /// Keep existing empty lines after access modifiers.
2963 /// MaxEmptyLinesToKeep is applied instead.
2964 ELAAMS_Leave,
2965 /// Always add empty line after access modifiers if there are none.
2966 /// MaxEmptyLinesToKeep is applied also.
2967 /// \code
2968 /// struct foo {
2969 /// private:
2970 ///
2971 /// int i;
2972 /// protected:
2973 ///
2974 /// int j;
2975 /// /* comment */
2976 /// public:
2977 ///
2978 /// foo() {}
2979 /// private:
2980 ///
2981 /// protected:
2982 ///
2983 /// };
2984 /// \endcode
2985 ELAAMS_Always,
2986 };
2987
2988 /// Defines when to put an empty line after access modifiers.
2989 /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2990 /// empty lines between two access modifiers.
2991 /// \version 13
2992 EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier;
2993
2994 /// Different styles for empty line before access modifiers.
2995 enum EmptyLineBeforeAccessModifierStyle : int8_t {
2996 /// Remove all empty lines before access modifiers.
2997 /// \code
2998 /// struct foo {
2999 /// private:
3000 /// int i;
3001 /// protected:
3002 /// int j;
3003 /// /* comment */
3004 /// public:
3005 /// foo() {}
3006 /// private:
3007 /// protected:
3008 /// };
3009 /// \endcode
3010 ELBAMS_Never,
3011 /// Keep existing empty lines before access modifiers.
3012 ELBAMS_Leave,
3013 /// Add empty line only when access modifier starts a new logical block.
3014 /// Logical block is a group of one or more member fields or functions.
3015 /// \code
3016 /// struct foo {
3017 /// private:
3018 /// int i;
3019 ///
3020 /// protected:
3021 /// int j;
3022 /// /* comment */
3023 /// public:
3024 /// foo() {}
3025 ///
3026 /// private:
3027 /// protected:
3028 /// };
3029 /// \endcode
3030 ELBAMS_LogicalBlock,
3031 /// Always add empty line before access modifiers unless access modifier
3032 /// is at the start of struct or class definition.
3033 /// \code
3034 /// struct foo {
3035 /// private:
3036 /// int i;
3037 ///
3038 /// protected:
3039 /// int j;
3040 /// /* comment */
3041 ///
3042 /// public:
3043 /// foo() {}
3044 ///
3045 /// private:
3046 ///
3047 /// protected:
3048 /// };
3049 /// \endcode
3050 ELBAMS_Always,
3051 };
3052
3053 /// Defines in which cases to put empty line before access modifiers.
3054 /// \version 12
3055 EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
3056
3057 /// Styles for ``enum`` trailing commas.
3058 enum EnumTrailingCommaStyle : int8_t {
3059 /// Don't insert or remove trailing commas.
3060 /// \code
3061 /// enum { a, b, c, };
3062 /// enum Color { red, green, blue };
3063 /// \endcode
3064 ETC_Leave,
3065 /// Insert trailing commas.
3066 /// \code
3067 /// enum { a, b, c, };
3068 /// enum Color { red, green, blue, };
3069 /// \endcode
3070 ETC_Insert,
3071 /// Remove trailing commas.
3072 /// \code
3073 /// enum { a, b, c };
3074 /// enum Color { red, green, blue };
3075 /// \endcode
3076 ETC_Remove,
3077 };
3078
3079 /// Insert a comma (if missing) or remove the comma at the end of an ``enum``
3080 /// enumerator list.
3081 /// \warning
3082 /// Setting this option to any value other than ``Leave`` could lead to
3083 /// incorrect code formatting due to clang-format's lack of complete semantic
3084 /// information. As such, extra care should be taken to review code changes
3085 /// made by this option.
3086 /// \endwarning
3087 /// \version 21
3088 EnumTrailingCommaStyle EnumTrailingComma;
3089
3090 /// If ``true``, clang-format detects whether function calls and
3091 /// definitions are formatted with one parameter per line.
3092 ///
3093 /// Each call can be bin-packed, one-per-line or inconclusive. If it is
3094 /// inconclusive, e.g. completely on one line, but a decision needs to be
3095 /// made, clang-format analyzes whether there are other bin-packed cases in
3096 /// the input file and act accordingly.
3097 ///
3098 /// \note
3099 /// This is an experimental flag, that might go away or be renamed. Do
3100 /// not use this in config files, etc. Use at your own risk.
3101 /// \endnote
3102 /// \version 3.7
3103 bool ExperimentalAutoDetectBinPacking;
3104
3105 /// If ``true``, clang-format adds missing namespace end comments for
3106 /// namespaces and fixes invalid existing ones. This doesn't affect short
3107 /// namespaces, which are controlled by ``ShortNamespaceLines``.
3108 /// \code
3109 /// true: false:
3110 /// namespace longNamespace { vs. namespace longNamespace {
3111 /// void foo(); void foo();
3112 /// void bar(); void bar();
3113 /// } // namespace a }
3114 /// namespace shortNamespace { namespace shortNamespace {
3115 /// void baz(); void baz();
3116 /// } }
3117 /// \endcode
3118 /// \version 5
3119 bool FixNamespaceComments;
3120
3121 /// A vector of macros that should be interpreted as foreach loops
3122 /// instead of as function calls.
3123 ///
3124 /// These are expected to be macros of the form:
3125 /// \code
3126 /// FOREACH(<variable-declaration>, ...)
3127 /// <loop-body>
3128 /// \endcode
3129 ///
3130 /// In the .clang-format configuration file, this can be configured like:
3131 /// \code{.yaml}
3132 /// ForEachMacros: [RANGES_FOR, FOREACH]
3133 /// \endcode
3134 ///
3135 /// For example: BOOST_FOREACH.
3136 /// \version 3.7
3137 std::vector<std::string> ForEachMacros;
3138
3139 tooling::IncludeStyle IncludeStyle;
3140
3141 /// A vector of macros that should be interpreted as conditionals
3142 /// instead of as function calls.
3143 ///
3144 /// These are expected to be macros of the form:
3145 /// \code
3146 /// IF(...)
3147 /// <conditional-body>
3148 /// else IF(...)
3149 /// <conditional-body>
3150 /// \endcode
3151 ///
3152 /// In the .clang-format configuration file, this can be configured like:
3153 /// \code{.yaml}
3154 /// IfMacros: [IF]
3155 /// \endcode
3156 ///
3157 /// For example: `KJ_IF_MAYBE
3158 /// <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_
3159 /// \version 13
3160 std::vector<std::string> IfMacros;
3161
3162 /// Specify whether access modifiers should have their own indentation level.
3163 ///
3164 /// When ``false``, access modifiers are indented (or outdented) relative to
3165 /// the record members, respecting the ``AccessModifierOffset``. Record
3166 /// members are indented one level below the record.
3167 /// When ``true``, access modifiers get their own indentation level. As a
3168 /// consequence, record members are always indented 2 levels below the record,
3169 /// regardless of the access modifier presence. Value of the
3170 /// ``AccessModifierOffset`` is ignored.
3171 /// \code
3172 /// false: true:
3173 /// class C { vs. class C {
3174 /// class D { class D {
3175 /// void bar(); void bar();
3176 /// protected: protected:
3177 /// D(); D();
3178 /// }; };
3179 /// public: public:
3180 /// C(); C();
3181 /// }; };
3182 /// void foo() { void foo() {
3183 /// return 1; return 1;
3184 /// } }
3185 /// \endcode
3186 /// \version 13
3187 bool IndentAccessModifiers;
3188
3189 /// Indent case label blocks one level from the case label.
3190 ///
3191 /// When ``false``, the block following the case label uses the same
3192 /// indentation level as for the case label, treating the case label the same
3193 /// as an if-statement.
3194 /// When ``true``, the block gets indented as a scope block.
3195 /// \code
3196 /// false: true:
3197 /// switch (fool) { vs. switch (fool) {
3198 /// case 1: { case 1:
3199 /// bar(); {
3200 /// } break; bar();
3201 /// default: { }
3202 /// plop(); break;
3203 /// } default:
3204 /// } {
3205 /// plop();
3206 /// }
3207 /// }
3208 /// \endcode
3209 /// \version 11
3210 bool IndentCaseBlocks;
3211
3212 /// Indent case labels one level from the switch statement.
3213 ///
3214 /// When ``false``, use the same indentation level as for the switch
3215 /// statement. Switch statement body is always indented one level more than
3216 /// case labels (except the first block following the case label, which
3217 /// itself indents the code - unless IndentCaseBlocks is enabled).
3218 /// \code
3219 /// false: true:
3220 /// switch (fool) { vs. switch (fool) {
3221 /// case 1: case 1:
3222 /// bar(); bar();
3223 /// break; break;
3224 /// default: default:
3225 /// plop(); plop();
3226 /// } }
3227 /// \endcode
3228 /// \version 3.3
3229 bool IndentCaseLabels;
3230
3231 /// If ``true``, clang-format will indent the body of an ``export { ... }``
3232 /// block. This doesn't affect the formatting of anything else related to
3233 /// exported declarations.
3234 /// \code
3235 /// true: false:
3236 /// export { vs. export {
3237 /// void foo(); void foo();
3238 /// void bar(); void bar();
3239 /// } }
3240 /// \endcode
3241 /// \version 20
3242 bool IndentExportBlock;
3243
3244 /// Indents extern blocks
3245 enum IndentExternBlockStyle : int8_t {
3246 /// Backwards compatible with AfterExternBlock's indenting.
3247 /// \code
3248 /// IndentExternBlock: AfterExternBlock
3249 /// BraceWrapping.AfterExternBlock: true
3250 /// extern "C"
3251 /// {
3252 /// void foo();
3253 /// }
3254 /// \endcode
3255 ///
3256 /// \code
3257 /// IndentExternBlock: AfterExternBlock
3258 /// BraceWrapping.AfterExternBlock: false
3259 /// extern "C" {
3260 /// void foo();
3261 /// }
3262 /// \endcode
3263 IEBS_AfterExternBlock,
3264 /// Does not indent extern blocks.
3265 /// \code
3266 /// extern "C" {
3267 /// void foo();
3268 /// }
3269 /// \endcode
3270 IEBS_NoIndent,
3271 /// Indents extern blocks.
3272 /// \code
3273 /// extern "C" {
3274 /// void foo();
3275 /// }
3276 /// \endcode
3277 IEBS_Indent,
3278 };
3279
3280 /// IndentExternBlockStyle is the type of indenting of extern blocks.
3281 /// \version 11
3282 IndentExternBlockStyle IndentExternBlock;
3283
3284 /// Options for indenting goto labels.
3285 enum IndentGotoLabelStyle : int8_t {
3286 /// Do not indent goto labels.
3287 /// \code
3288 /// int f() {
3289 /// if (foo()) {
3290 /// label1:
3291 /// bar();
3292 /// }
3293 /// label2:
3294 /// return 1;
3295 /// }
3296 /// \endcode
3297 IGLS_NoIndent,
3298 /// Indent goto labels to the enclosing block (previous indenting level).
3299 /// \code
3300 /// int f() {
3301 /// if (foo()) {
3302 /// label1:
3303 /// bar();
3304 /// }
3305 /// label2:
3306 /// return 1;
3307 /// }
3308 /// \endcode
3309 IGLS_OuterIndent,
3310 /// Indent goto labels to the surrounding statements (current indenting
3311 /// level).
3312 /// \code
3313 /// int f() {
3314 /// if (foo()) {
3315 /// label1:
3316 /// bar();
3317 /// }
3318 /// label2:
3319 /// return 1;
3320 /// }
3321 /// \endcode
3322 IGLS_InnerIndent,
3323 /// Indent goto labels to half the indentation of the surrounding code.
3324 /// If the indentation width is an odd number, it will round up.
3325 /// \code
3326 /// int f() {
3327 /// if (foo()) {
3328 /// label1:
3329 /// bar();
3330 /// }
3331 /// label2:
3332 /// return 1;
3333 /// }
3334 /// \endcode
3335 IGLS_HalfIndent,
3336 };
3337
3338 /// The goto label indenting style to use.
3339 /// \version 10
3340 IndentGotoLabelStyle IndentGotoLabels;
3341
3342 /// Options for indenting preprocessor directives.
3343 enum PPDirectiveIndentStyle : int8_t {
3344 /// Does not indent any directives.
3345 /// \code
3346 /// #if FOO
3347 /// #if BAR
3348 /// #include <foo>
3349 /// #endif
3350 /// #endif
3351 /// \endcode
3352 PPDIS_None,
3353 /// Indents directives after the hash.
3354 /// \code
3355 /// #if FOO
3356 /// # if BAR
3357 /// # include <foo>
3358 /// # endif
3359 /// #endif
3360 /// \endcode
3361 PPDIS_AfterHash,
3362 /// Indents directives before the hash.
3363 /// \code
3364 /// #if FOO
3365 /// #if BAR
3366 /// #include <foo>
3367 /// #endif
3368 /// #endif
3369 /// \endcode
3370 PPDIS_BeforeHash,
3371 /// Leaves indentation of directives as-is.
3372 /// \note
3373 /// Ignores ``PPIndentWidth``.
3374 /// \endnote
3375 /// \code
3376 /// #if FOO
3377 /// #if BAR
3378 /// #include <foo>
3379 /// #endif
3380 /// #endif
3381 /// \endcode
3382 PPDIS_Leave
3383 };
3384
3385 /// The preprocessor directive indenting style to use.
3386 /// \version 6
3387 PPDirectiveIndentStyle IndentPPDirectives;
3388
3389 /// Indent the requires clause in a template. This only applies when
3390 /// ``RequiresClausePosition`` is ``OwnLine``, ``OwnLineWithBrace``,
3391 /// or ``WithFollowing``.
3392 ///
3393 /// In clang-format 12, 13 and 14 it was named ``IndentRequires``.
3394 /// \code
3395 /// true:
3396 /// template <typename It>
3397 /// requires Iterator<It>
3398 /// void sort(It begin, It end) {
3399 /// //....
3400 /// }
3401 ///
3402 /// false:
3403 /// template <typename It>
3404 /// requires Iterator<It>
3405 /// void sort(It begin, It end) {
3406 /// //....
3407 /// }
3408 /// \endcode
3409 /// \version 15
3410 bool IndentRequiresClause;
3411
3412 /// The number of columns to use for indentation.
3413 /// \code
3414 /// IndentWidth: 3
3415 ///
3416 /// void f() {
3417 /// someFunction();
3418 /// if (true, false) {
3419 /// f();
3420 /// }
3421 /// }
3422 /// \endcode
3423 /// \version 3.7
3424 unsigned IndentWidth;
3425
3426 /// Indent if a function definition or declaration is wrapped after the
3427 /// type.
3428 /// \code
3429 /// true:
3430 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
3431 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3432 ///
3433 /// false:
3434 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
3435 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3436 /// \endcode
3437 /// \version 3.7
3438 bool IndentWrappedFunctionNames;
3439
3440 /// Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
3441 /// and ``while``) in C++ unless the control statements are inside macro
3442 /// definitions or the braces would enclose preprocessor directives.
3443 /// \warning
3444 /// Setting this option to ``true`` could lead to incorrect code formatting
3445 /// due to clang-format's lack of complete semantic information. As such,
3446 /// extra care should be taken to review code changes made by this option.
3447 /// \endwarning
3448 /// \code
3449 /// false: true:
3450 ///
3451 /// if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
3452 /// handleFunctionDecl(D); handleFunctionDecl(D);
3453 /// else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
3454 /// handleVarDecl(D); handleVarDecl(D);
3455 /// else } else {
3456 /// return; return;
3457 /// }
3458 ///
3459 /// while (i--) vs. while (i--) {
3460 /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
3461 /// handleAttr(A); handleAttr(A);
3462 /// }
3463 /// }
3464 ///
3465 /// do vs. do {
3466 /// --i; --i;
3467 /// while (i); } while (i);
3468 /// \endcode
3469 /// \version 15
3470 bool InsertBraces;
3471
3472 /// Insert a newline at end of file if missing.
3473 /// \version 16
3474 bool InsertNewlineAtEOF;
3475
3476 /// The style of inserting trailing commas into container literals.
3477 enum TrailingCommaStyle : int8_t {
3478 /// Do not insert trailing commas.
3479 TCS_None,
3480 /// Insert trailing commas in container literals that were wrapped over
3481 /// multiple lines. Note that this is conceptually incompatible with
3482 /// bin-packing, because the trailing comma is used as an indicator
3483 /// that a container should be formatted one-per-line (i.e. not bin-packed).
3484 /// So inserting a trailing comma counteracts bin-packing.
3485 TCS_Wrapped,
3486 };
3487
3488 /// If set to ``TCS_Wrapped`` will insert trailing commas in container
3489 /// literals (arrays and objects) that wrap across multiple lines.
3490 /// It is currently only available for JavaScript
3491 /// and disabled by default ``TCS_None``.
3492 /// ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
3493 /// as inserting the comma disables bin-packing.
3494 /// \code
3495 /// TSC_Wrapped:
3496 /// const someArray = [
3497 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3498 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3499 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3500 /// // ^ inserted
3501 /// ]
3502 /// \endcode
3503 /// \version 11
3504 TrailingCommaStyle InsertTrailingCommas;
3505
3506 /// Separator format of integer literals of different bases.
3507 ///
3508 /// If negative, remove separators. If ``0``, leave the literal as is. If
3509 /// positive, insert separators between digits starting from the rightmost
3510 /// digit.
3511 ///
3512 /// For example, the config below will leave separators in binary literals
3513 /// alone, insert separators in decimal literals to separate the digits into
3514 /// groups of 3, and remove separators in hexadecimal literals.
3515 /// \code
3516 /// IntegerLiteralSeparator:
3517 /// Binary: 0
3518 /// Decimal: 3
3519 /// Hex: -1
3520 /// \endcode
3521 ///
3522 /// You can also specify a minimum number of digits
3523 /// (``BinaryMinDigitsInsert``, ``DecimalMinDigitsInsert``, and
3524 /// ``HexMinDigitsInsert``) the integer literal must have in order for the
3525 /// separators to be inserted, and a maximum number of digits
3526 /// (``BinaryMaxDigitsRemove``, ``DecimalMaxDigitsRemove``, and
3527 /// ``HexMaxDigitsRemove``) until the separators are removed. This divides the
3528 /// literals in 3 regions, always without separator (up until including
3529 /// ``xxxMaxDigitsRemove``), maybe with, or without separators (up until
3530 /// excluding ``xxxMinDigitsInsert``), and finally always with separators.
3531 /// \note
3532 /// ``BinaryMinDigits``, ``DecimalMinDigits``, and ``HexMinDigits`` are
3533 /// deprecated and renamed to ``BinaryMinDigitsInsert``,
3534 /// ``DecimalMinDigitsInsert``, and ``HexMinDigitsInsert``, respectively.
3535 /// \endnote
3536 struct IntegerLiteralSeparatorStyle {
3537 /// Format separators in binary literals.
3538 /// \code{.text}
3539 /// /* -1: */ b = 0b100111101101;
3540 /// /* 0: */ b = 0b10011'11'0110'1;
3541 /// /* 3: */ b = 0b100'111'101'101;
3542 /// /* 4: */ b = 0b1001'1110'1101;
3543 /// \endcode
3544 int8_t Binary;
3545 /// Format separators in binary literals with a minimum number of digits.
3546 /// \code{.text}
3547 /// // Binary: 3
3548 /// // BinaryMinDigitsInsert: 7
3549 /// b1 = 0b101101;
3550 /// b2 = 0b1'101'101;
3551 /// \endcode
3552 int8_t BinaryMinDigitsInsert;
3553 /// Remove separators in binary literals with a maximum number of digits.
3554 /// \code{.text}
3555 /// // Binary: 3
3556 /// // BinaryMinDigitsInsert: 7
3557 /// // BinaryMaxDigitsRemove: 4
3558 /// b0 = 0b1011; // Always removed.
3559 /// b1 = 0b101101; // Not added.
3560 /// b2 = 0b1'01'101; // Not removed, not corrected.
3561 /// b3 = 0b1'101'101; // Always added.
3562 /// b4 = 0b10'1101; // Corrected to 0b101'101.
3563 /// \endcode
3564 int8_t BinaryMaxDigitsRemove;
3565 /// Format separators in decimal literals.
3566 /// \code{.text}
3567 /// /* -1: */ d = 18446744073709550592ull;
3568 /// /* 0: */ d = 184467'440737'0'95505'92ull;
3569 /// /* 3: */ d = 18'446'744'073'709'550'592ull;
3570 /// \endcode
3571 int8_t Decimal;
3572 /// Format separators in decimal literals with a minimum number of digits.
3573 /// \code{.text}
3574 /// // Decimal: 3
3575 /// // DecimalMinDigitsInsert: 5
3576 /// d1 = 2023;
3577 /// d2 = 10'000;
3578 /// \endcode
3579 int8_t DecimalMinDigitsInsert;
3580 /// Remove separators in decimal literals with a maximum number of digits.
3581 /// \code{.text}
3582 /// // Decimal: 3
3583 /// // DecimalMinDigitsInsert: 7
3584 /// // DecimalMaxDigitsRemove: 4
3585 /// d0 = 2023; // Always removed.
3586 /// d1 = 123456; // Not added.
3587 /// d2 = 1'23'456; // Not removed, not corrected.
3588 /// d3 = 5'000'000; // Always added.
3589 /// d4 = 1'23'45; // Corrected to 12'345.
3590 /// \endcode
3591 int8_t DecimalMaxDigitsRemove;
3592 /// Format separators in hexadecimal literals.
3593 /// \code{.text}
3594 /// /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
3595 /// /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
3596 /// /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
3597 /// \endcode
3598 int8_t Hex;
3599 /// Format separators in hexadecimal literals with a minimum number of
3600 /// digits.
3601 /// \code{.text}
3602 /// // Hex: 2
3603 /// // HexMinDigitsInsert: 6
3604 /// h1 = 0xABCDE;
3605 /// h2 = 0xAB'CD'EF;
3606 /// \endcode
3607 int8_t HexMinDigitsInsert;
3608 /// Remove separators in hexadecimal literals with a maximum number of
3609 /// digits.
3610 /// \code{.text}
3611 /// // Hex: 2
3612 /// // HexMinDigitsInsert: 6
3613 /// // HexMaxDigitsRemove: 4
3614 /// h0 = 0xAFFE; // Always removed.
3615 /// h1 = 0xABCDE; // Not added.
3616 /// h2 = 0xABC'DE; // Not removed, not corrected.
3617 /// h3 = 0xAB'CD'EF; // Always added.
3618 /// h4 = 0xABCD'E; // Corrected to 0xA'BC'DE.
3619 /// \endcode
3620 int8_t HexMaxDigitsRemove;
3621 bool operator==(const IntegerLiteralSeparatorStyle &R) const {
3622 return Binary == R.Binary &&
3623 BinaryMinDigitsInsert == R.BinaryMinDigitsInsert &&
3624 BinaryMaxDigitsRemove == R.BinaryMaxDigitsRemove &&
3625 Decimal == R.Decimal &&
3626 DecimalMinDigitsInsert == R.DecimalMinDigitsInsert &&
3627 DecimalMaxDigitsRemove == R.DecimalMaxDigitsRemove &&
3628 Hex == R.Hex && HexMinDigitsInsert == R.HexMinDigitsInsert &&
3629 HexMaxDigitsRemove == R.HexMaxDigitsRemove;
3630 }
3631 bool operator!=(const IntegerLiteralSeparatorStyle &R) const {
3632 return !operator==(R);
3633 }
3634 };
3635
3636 /// Format integer literal separators (``'`` for C/C++ and ``_`` for C#, Java,
3637 /// and JavaScript).
3638 /// \version 16
3639 IntegerLiteralSeparatorStyle IntegerLiteralSeparator;
3640
3641 /// A vector of prefixes ordered by the desired groups for Java imports.
3642 ///
3643 /// One group's prefix can be a subset of another - the longest prefix is
3644 /// always matched. Within a group, the imports are ordered lexicographically.
3645 /// Static imports are grouped separately and follow the same group rules.
3646 /// By default, static imports are placed before non-static imports,
3647 /// but this behavior is changed by another option,
3648 /// ``SortJavaStaticImport``.
3649 ///
3650 /// In the .clang-format configuration file, this can be configured like
3651 /// in the following yaml example. This will result in imports being
3652 /// formatted as in the Java example below.
3653 /// \code{.yaml}
3654 /// JavaImportGroups: [com.example, com, org]
3655 /// \endcode
3656 ///
3657 /// \code{.java}
3658 /// import static com.example.function1;
3659 ///
3660 /// import static com.test.function2;
3661 ///
3662 /// import static org.example.function3;
3663 ///
3664 /// import com.example.ClassA;
3665 /// import com.example.Test;
3666 /// import com.example.a.ClassB;
3667 ///
3668 /// import com.test.ClassC;
3669 ///
3670 /// import org.example.ClassD;
3671 /// \endcode
3672 /// \version 8
3673 std::vector<std::string> JavaImportGroups;
3674
3675 /// Quotation styles for JavaScript strings. Does not affect template
3676 /// strings.
3677 enum JavaScriptQuoteStyle : int8_t {
3678 /// Leave string quotes as they are.
3679 /// \code{.js}
3680 /// string1 = "foo";
3681 /// string2 = 'bar';
3682 /// \endcode
3684 /// Always use single quotes.
3685 /// \code{.js}
3686 /// string1 = 'foo';
3687 /// string2 = 'bar';
3688 /// \endcode
3690 /// Always use double quotes.
3691 /// \code{.js}
3692 /// string1 = "foo";
3693 /// string2 = "bar";
3694 /// \endcode
3696 };
3697
3698 /// The JavaScriptQuoteStyle to use for JavaScript strings.
3699 /// \version 3.9
3701
3702 // clang-format off
3703 /// Whether to wrap JavaScript import/export statements.
3704 /// \code{.js}
3705 /// true:
3706 /// import {
3707 /// VeryLongImportsAreAnnoying,
3708 /// VeryLongImportsAreAnnoying,
3709 /// VeryLongImportsAreAnnoying,
3710 /// } from "some/module.js"
3711 ///
3712 /// false:
3713 /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3714 /// \endcode
3715 /// \version 3.9
3717 // clang-format on
3718
3719 /// Options regarding which empty lines are kept.
3720 ///
3721 /// For example, the config below will remove empty lines at start of the
3722 /// file, end of the file, and start of blocks.
3723 ///
3724 /// \code
3725 /// KeepEmptyLines:
3726 /// AtEndOfFile: false
3727 /// AtStartOfBlock: false
3728 /// AtStartOfFile: false
3729 /// \endcode
3731 /// Keep empty lines at end of file.
3733 /// Keep empty lines at start of a block.
3734 /// \code
3735 /// true: false:
3736 /// if (foo) { vs. if (foo) {
3737 /// bar();
3738 /// bar(); }
3739 /// }
3740 /// \endcode
3742 /// Keep empty lines at start of file.
3744 bool operator==(const KeepEmptyLinesStyle &R) const {
3745 return AtEndOfFile == R.AtEndOfFile &&
3746 AtStartOfBlock == R.AtStartOfBlock &&
3747 AtStartOfFile == R.AtStartOfFile;
3748 }
3749 };
3750 /// Which empty lines are kept. See ``MaxEmptyLinesToKeep`` for how many
3751 /// consecutive empty lines are kept.
3752 /// \version 19
3754
3755 /// This option is **deprecated**. See ``AtEndOfFile`` of ``KeepEmptyLines``.
3756 /// \version 17
3757 // bool KeepEmptyLinesAtEOF;
3758
3759 /// This option is **deprecated**. See ``AtStartOfBlock`` of
3760 /// ``KeepEmptyLines``.
3761 /// \version 3.7
3762 // bool KeepEmptyLinesAtTheStartOfBlocks;
3763
3764 /// Keep the form feed character if it's immediately preceded and followed by
3765 /// a newline. Multiple form feeds and newlines within a whitespace range are
3766 /// replaced with a single newline and form feed followed by the remaining
3767 /// newlines. (See
3768 /// www.gnu.org/prep/standards/html_node/Formatting.html#:~:text=formfeed.)
3769 /// \version 20
3771
3772 /// Indentation logic for lambda bodies.
3774 /// Align lambda body relative to the lambda signature. This is the default.
3775 /// \code
3776 /// someMethod(
3777 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3778 /// return;
3779 /// });
3780 /// \endcode
3782 /// For statements within block scope, align lambda body relative to the
3783 /// indentation level of the outer scope the lambda signature resides in.
3784 /// \code
3785 /// someMethod(
3786 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3787 /// return;
3788 /// });
3789 ///
3790 /// someMethod(someOtherMethod(
3791 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3792 /// return;
3793 /// }));
3794 /// \endcode
3796 };
3797
3798 /// The indentation style of lambda bodies. ``Signature`` (the default)
3799 /// causes the lambda body to be indented one additional level relative to
3800 /// the indentation level of the signature. ``OuterScope`` forces the lambda
3801 /// body to be indented one additional level relative to the parent scope
3802 /// containing the lambda signature.
3803 /// \version 13
3805
3806 /// Supported languages.
3807 ///
3808 /// When stored in a configuration file, specifies the language, that the
3809 /// configuration targets. When passed to the ``reformat()`` function, enables
3810 /// syntax features specific to the language.
3811 enum LanguageKind : int8_t {
3812 /// Do not use.
3814 /// Should be used for C.
3816 /// Should be used for C++.
3818 /// Should be used for C#.
3820 /// Should be used for Java.
3822 /// Should be used for JavaScript.
3824 /// Should be used for JSON.
3826 /// Should be used for Objective-C, Objective-C++.
3828 /// Should be used for Protocol Buffers
3829 /// (https://developers.google.com/protocol-buffers/).
3831 /// Should be used for TableGen code.
3833 /// Should be used for Protocol Buffer messages in text format
3834 /// (https://developers.google.com/protocol-buffers/).
3836 /// Should be used for Verilog and SystemVerilog.
3837 /// https://standards.ieee.org/ieee/1800/6700/
3838 /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3840 };
3841 bool isCpp() const {
3842 return Language == LK_Cpp || Language == LK_C || Language == LK_ObjC;
3843 }
3844 bool isCSharp() const { return Language == LK_CSharp; }
3845 bool isJson() const { return Language == LK_Json; }
3846 bool isJava() const { return Language == LK_Java; }
3847 bool isJavaScript() const { return Language == LK_JavaScript; }
3848 bool isVerilog() const { return Language == LK_Verilog; }
3849 bool isTextProto() const { return Language == LK_TextProto; }
3850 bool isProto() const { return Language == LK_Proto || isTextProto(); }
3851 bool isTableGen() const { return Language == LK_TableGen; }
3852
3853 /// The language that this format style targets.
3854 /// \note
3855 /// You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h``
3856 /// files by adding a ``// clang-format Language:`` line before the first
3857 /// non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``.
3858 /// \endnote
3859 /// \version 3.5
3861
3862 /// Line ending style.
3863 enum LineEndingStyle : int8_t {
3864 /// Use ``\n``.
3866 /// Use ``\r\n``.
3868 /// Use ``\n`` unless the input has more lines ending in ``\r\n``.
3870 /// Use ``\r\n`` unless the input has more lines ending in ``\n``.
3872 };
3873
3874 /// Line ending style (``\n`` or ``\r\n``) to use.
3875 /// \version 16
3877
3878 /// A regular expression matching macros that start a block.
3879 /// \code
3880 /// # With:
3881 /// MacroBlockBegin: "^NS_MAP_BEGIN|\
3882 /// NS_TABLE_HEAD$"
3883 /// MacroBlockEnd: "^\
3884 /// NS_MAP_END|\
3885 /// NS_TABLE_.*_END$"
3886 ///
3887 /// NS_MAP_BEGIN
3888 /// foo();
3889 /// NS_MAP_END
3890 ///
3891 /// NS_TABLE_HEAD
3892 /// bar();
3893 /// NS_TABLE_FOO_END
3894 ///
3895 /// # Without:
3896 /// NS_MAP_BEGIN
3897 /// foo();
3898 /// NS_MAP_END
3899 ///
3900 /// NS_TABLE_HEAD
3901 /// bar();
3902 /// NS_TABLE_FOO_END
3903 /// \endcode
3904 /// \version 3.7
3905 std::string MacroBlockBegin;
3906
3907 /// A regular expression matching macros that end a block.
3908 /// \version 3.7
3909 std::string MacroBlockEnd;
3910
3911 /// A list of macros of the form \c <definition>=<expansion> .
3912 ///
3913 /// Code will be parsed with macros expanded, in order to determine how to
3914 /// interpret and format the macro arguments.
3915 ///
3916 /// For example, the code:
3917 /// \code
3918 /// A(a*b);
3919 /// \endcode
3920 ///
3921 /// will usually be interpreted as a call to a function A, and the
3922 /// multiplication expression will be formatted as ``a * b``.
3923 ///
3924 /// If we specify the macro definition:
3925 /// \code{.yaml}
3926 /// Macros:
3927 /// - A(x)=x
3928 /// \endcode
3929 ///
3930 /// the code will now be parsed as a declaration of the variable b of type a*,
3931 /// and formatted as ``a* b`` (depending on pointer-binding rules).
3932 ///
3933 /// Features and restrictions:
3934 /// * Both function-like macros and object-like macros are supported.
3935 /// * Macro arguments must be used exactly once in the expansion.
3936 /// * No recursive expansion; macros referencing other macros will be
3937 /// ignored.
3938 /// * Overloading by arity is supported: for example, given the macro
3939 /// definitions A=x, A()=y, A(a)=a
3940 ///
3941 /// \code
3942 /// A; -> x;
3943 /// A(); -> y;
3944 /// A(z); -> z;
3945 /// A(a, b); // will not be expanded.
3946 /// \endcode
3947 ///
3948 /// \version 17
3949 std::vector<std::string> Macros;
3950
3951 /// A vector of function-like macros whose invocations should be skipped by
3952 /// ``RemoveParentheses``.
3953 /// \version 21
3954 std::vector<std::string> MacrosSkippedByRemoveParentheses;
3955
3956 /// The maximum number of consecutive empty lines to keep.
3957 /// \code
3958 /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
3959 /// int f() { int f() {
3960 /// int = 1; int i = 1;
3961 /// i = foo();
3962 /// i = foo(); return i;
3963 /// }
3964 /// return i;
3965 /// }
3966 /// \endcode
3967 /// \version 3.7
3969
3970 /// Different ways to indent namespace contents.
3972 /// Don't indent in namespaces.
3973 /// \code
3974 /// namespace out {
3975 /// int i;
3976 /// namespace in {
3977 /// int i;
3978 /// }
3979 /// }
3980 /// \endcode
3982 /// Indent only in inner namespaces (nested in other namespaces).
3983 /// \code
3984 /// namespace out {
3985 /// int i;
3986 /// namespace in {
3987 /// int i;
3988 /// }
3989 /// }
3990 /// \endcode
3992 /// Indent in all namespaces.
3993 /// \code
3994 /// namespace out {
3995 /// int i;
3996 /// namespace in {
3997 /// int i;
3998 /// }
3999 /// }
4000 /// \endcode
4002 };
4003
4004 /// The indentation used for namespaces.
4005 /// \version 3.7
4007
4008 /// A vector of macros which are used to open namespace blocks.
4009 ///
4010 /// These are expected to be macros of the form:
4011 /// \code
4012 /// NAMESPACE(<namespace-name>, ...) {
4013 /// <namespace-content>
4014 /// }
4015 /// \endcode
4016 ///
4017 /// For example: TESTSUITE
4018 /// \version 9
4019 std::vector<std::string> NamespaceMacros;
4020
4021 /// Control over each component in a numeric literal.
4023 /// Leave this component of the literal as is.
4025 /// Format this component with uppercase characters.
4027 /// Format this component with lowercase characters.
4029 };
4030
4031 /// Separate control for each numeric literal component.
4032 ///
4033 /// For example, the config below will leave exponent letters alone, reformat
4034 /// hexadecimal digits in lowercase, reformat numeric literal prefixes in
4035 /// uppercase, and reformat suffixes in lowercase.
4036 /// \code
4037 /// NumericLiteralCase:
4038 /// ExponentLetter: Leave
4039 /// HexDigit: Lower
4040 /// Prefix: Upper
4041 /// Suffix: Lower
4042 /// \endcode
4044 /// Format floating point exponent separator letter case.
4045 /// \code
4046 /// float a = 6.02e23 + 1.0E10; // Leave
4047 /// float a = 6.02E23 + 1.0E10; // Upper
4048 /// float a = 6.02e23 + 1.0e10; // Lower
4049 /// \endcode
4051 /// Format hexadecimal digit case.
4052 /// \code
4053 /// a = 0xaBcDeF; // Leave
4054 /// a = 0xABCDEF; // Upper
4055 /// a = 0xabcdef; // Lower
4056 /// \endcode
4058 /// Format integer prefix case.
4059 /// \code
4060 /// a = 0XF0 | 0b1; // Leave
4061 /// a = 0XF0 | 0B1; // Upper
4062 /// a = 0xF0 | 0b1; // Lower
4063 /// \endcode
4065 /// Format suffix case. This option excludes case-sensitive reserved
4066 /// suffixes, such as ``min`` in C++.
4067 /// \code
4068 /// a = 1uLL; // Leave
4069 /// a = 1ULL; // Upper
4070 /// a = 1ull; // Lower
4071 /// \endcode
4073
4075 return ExponentLetter == R.ExponentLetter && HexDigit == R.HexDigit &&
4076 Prefix == R.Prefix && Suffix == R.Suffix;
4077 }
4078
4080 return !(*this == R);
4081 }
4082 };
4083
4084 /// Capitalization style for numeric literals.
4085 /// \version 22
4087
4088 /// Controls bin-packing Objective-C protocol conformance list
4089 /// items into as few lines as possible when they go over ``ColumnLimit``.
4090 ///
4091 /// If ``Auto`` (the default), delegates to the value in
4092 /// ``BinPackParameters``. If that is ``BinPack``, bin-packs Objective-C
4093 /// protocol conformance list items into as few lines as possible
4094 /// whenever they go over ``ColumnLimit``.
4095 ///
4096 /// If ``Always``, always bin-packs Objective-C protocol conformance
4097 /// list items into as few lines as possible whenever they go over
4098 /// ``ColumnLimit``.
4099 ///
4100 /// If ``Never``, lays out Objective-C protocol conformance list items
4101 /// onto individual lines whenever they go over ``ColumnLimit``.
4102 ///
4103 /// \code{.objc}
4104 /// Always (or Auto, if BinPackParameters==BinPack):
4105 /// @interface ccccccccccccc () <
4106 /// ccccccccccccc, ccccccccccccc,
4107 /// ccccccccccccc, ccccccccccccc> {
4108 /// }
4109 ///
4110 /// Never (or Auto, if BinPackParameters!=BinPack):
4111 /// @interface ddddddddddddd () <
4112 /// ddddddddddddd,
4113 /// ddddddddddddd,
4114 /// ddddddddddddd,
4115 /// ddddddddddddd> {
4116 /// }
4117 /// \endcode
4118 /// \version 7
4120
4121 /// The number of characters to use for indentation of ObjC blocks.
4122 /// \code{.objc}
4123 /// ObjCBlockIndentWidth: 4
4124 ///
4125 /// [operation setCompletionBlock:^{
4126 /// [self onOperationDone];
4127 /// }];
4128 /// \endcode
4129 /// \version 3.7
4131
4132 /// Break parameters list into lines when there is nested block
4133 /// parameters in a function call.
4134 /// \code
4135 /// false:
4136 /// - (void)_aMethod
4137 /// {
4138 /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
4139 /// *u, NSNumber *v) {
4140 /// u = c;
4141 /// }]
4142 /// }
4143 /// true:
4144 /// - (void)_aMethod
4145 /// {
4146 /// [self.test1 t:self
4147 /// w:self
4148 /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
4149 /// u = c;
4150 /// }]
4151 /// }
4152 /// \endcode
4153 /// \version 11
4155
4156 /// The order in which ObjC property attributes should appear.
4157 ///
4158 /// Attributes in code will be sorted in the order specified. Any attributes
4159 /// encountered that are not mentioned in this array will be sorted last, in
4160 /// stable order. Comments between attributes will leave the attributes
4161 /// untouched.
4162 /// \warning
4163 /// Using this option could lead to incorrect code formatting due to
4164 /// clang-format's lack of complete semantic information. As such, extra
4165 /// care should be taken to review code changes made by this option.
4166 /// \endwarning
4167 /// \code{.yaml}
4168 /// ObjCPropertyAttributeOrder: [
4169 /// class, direct,
4170 /// atomic, nonatomic,
4171 /// assign, retain, strong, copy, weak, unsafe_unretained,
4172 /// readonly, readwrite, getter, setter,
4173 /// nullable, nonnull, null_resettable, null_unspecified
4174 /// ]
4175 /// \endcode
4176 /// \version 18
4177 std::vector<std::string> ObjCPropertyAttributeOrder;
4178
4179 /// Add or remove a space between the '-'/'+' and the return type in
4180 /// Objective-C method declarations. i.e
4181 /// \code{.objc}
4182 /// false: true:
4183 ///
4184 /// -(void)method vs. - (void)method
4185 /// \endcode
4186 /// \version 23
4188
4189 /// Add a space after ``@property`` in Objective-C, i.e. use
4190 /// ``@property (readonly)`` instead of ``@property(readonly)``.
4191 /// \version 3.7
4193
4194 /// Add a space in front of an Objective-C protocol list, i.e. use
4195 /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
4196 /// \version 3.7
4198
4199 /// A regular expression that describes markers for turning formatting off for
4200 /// one line. If it matches a comment that is the only token of a line,
4201 /// clang-format skips the comment and the next line. Otherwise, clang-format
4202 /// skips lines containing a matched token.
4203 /// \note
4204 /// This option does not apply to ``IntegerLiteralSeparator`` and
4205 /// ``NumericLiteralCase``.
4206 /// \endnote
4207 /// \code
4208 /// // OneLineFormatOffRegex: ^(// NOLINT|logger$)
4209 /// // results in the output below:
4210 /// int a;
4211 /// int b ; // NOLINT
4212 /// int c;
4213 /// // NOLINTNEXTLINE
4214 /// int d ;
4215 /// int e;
4216 /// s = "// NOLINT";
4217 /// logger() ;
4218 /// logger2();
4219 /// my_logger();
4220 /// \endcode
4221 /// \version 21
4223
4224 /// Different ways to try to fit all constructor initializers on a line.
4226 /// Always put each constructor initializer on its own line.
4227 /// \code
4228 /// Constructor()
4229 /// : a(),
4230 /// b()
4231 /// \endcode
4233 /// Bin-pack constructor initializers.
4234 /// \code
4235 /// Constructor()
4236 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
4237 /// cccccccccccccccccccc()
4238 /// \endcode
4240 /// Put all constructor initializers on the current line if they fit.
4241 /// Otherwise, put each one on its own line.
4242 /// \code
4243 /// Constructor() : a(), b()
4244 ///
4245 /// Constructor()
4246 /// : aaaaaaaaaaaaaaaaaaaa(),
4247 /// bbbbbbbbbbbbbbbbbbbb(),
4248 /// ddddddddddddd()
4249 /// \endcode
4251 /// Same as ``PCIS_CurrentLine`` except that if all constructor initializers
4252 /// do not fit on the current line, try to fit them on the next line.
4253 /// \code
4254 /// Constructor() : a(), b()
4255 ///
4256 /// Constructor()
4257 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
4258 ///
4259 /// Constructor()
4260 /// : aaaaaaaaaaaaaaaaaaaa(),
4261 /// bbbbbbbbbbbbbbbbbbbb(),
4262 /// cccccccccccccccccccc()
4263 /// \endcode
4265 /// Put all constructor initializers on the next line if they fit.
4266 /// Otherwise, put each one on its own line.
4267 /// \code
4268 /// Constructor()
4269 /// : a(), b()
4270 ///
4271 /// Constructor()
4272 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
4273 ///
4274 /// Constructor()
4275 /// : aaaaaaaaaaaaaaaaaaaa(),
4276 /// bbbbbbbbbbbbbbbbbbbb(),
4277 /// cccccccccccccccccccc()
4278 /// \endcode
4280 };
4281
4282 /// The pack constructor initializers style to use.
4283 /// \version 14
4285
4286 /// The penalty for breaking around an assignment operator.
4287 /// \version 5
4289
4290 /// The penalty for breaking a function call after ``call(``.
4291 /// \version 3.7
4293
4294 /// The penalty for breaking before a member access operator (``.``, ``->``).
4295 /// \version 20
4297
4298 /// The penalty for each line break introduced inside a comment.
4299 /// \version 3.7
4301
4302 /// The penalty for breaking before the first ``<<``.
4303 /// \version 3.7
4305
4306 /// The penalty for breaking after ``(``.
4307 /// \version 14
4309
4310 /// The penalty for breaking after ``::``.
4311 /// \version 18
4313
4314 /// The penalty for each line break introduced inside a string literal.
4315 /// \version 3.7
4317
4318 /// The penalty for breaking after template declaration.
4319 /// \version 7
4321
4322 /// The penalty for each character outside of the column limit.
4323 /// \version 3.7
4325
4326 /// Penalty for each character of whitespace indentation
4327 /// (counted relative to leading non-whitespace column).
4328 /// \version 12
4330
4331 /// Penalty for putting the return type of a function onto its own line.
4332 /// \version 3.7
4334
4335 /// The ``&``, ``&&`` and ``*`` alignment style.
4337 /// Align pointer to the left.
4338 /// \code
4339 /// int* a;
4340 /// \endcode
4342 /// Align pointer to the right.
4343 /// \code
4344 /// int *a;
4345 /// \endcode
4347 /// Align pointer in the middle.
4348 /// \code
4349 /// int * a;
4350 /// \endcode
4352 };
4353
4354 /// Pointer and reference alignment style.
4355 /// \version 3.7
4357
4358 /// The number of columns to use for indentation of preprocessor statements.
4359 /// When set to -1 (default) ``IndentWidth`` is used also for preprocessor
4360 /// statements.
4361 /// \code
4362 /// PPIndentWidth: 1
4363 ///
4364 /// #ifdef __linux__
4365 /// # define FOO
4366 /// #else
4367 /// # define BAR
4368 /// #endif
4369 /// \endcode
4370 /// \version 13
4372
4373 /// Different specifiers and qualifiers alignment styles.
4375 /// Don't change specifiers/qualifiers to either Left or Right alignment
4376 /// (default).
4377 /// \code
4378 /// int const a;
4379 /// const int *a;
4380 /// \endcode
4382 /// Change specifiers/qualifiers to be left-aligned.
4383 /// \code
4384 /// const int a;
4385 /// const int *a;
4386 /// \endcode
4388 /// Change specifiers/qualifiers to be right-aligned.
4389 /// \code
4390 /// int const a;
4391 /// int const *a;
4392 /// \endcode
4394 /// Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.
4395 /// With:
4396 /// \code{.yaml}
4397 /// QualifierOrder: [inline, static, type, const]
4398 /// \endcode
4399 ///
4400 /// \code
4401 ///
4402 /// int const a;
4403 /// int const *a;
4404 /// \endcode
4406 };
4407
4408 /// Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
4409 /// \warning
4410 /// Setting ``QualifierAlignment`` to something other than ``Leave``, COULD
4411 /// lead to incorrect code formatting due to incorrect decisions made due to
4412 /// clang-formats lack of complete semantic information.
4413 /// As such extra care should be taken to review code changes made by the use
4414 /// of this option.
4415 /// \endwarning
4416 /// \version 14
4418
4419 /// The order in which the qualifiers appear.
4420 /// The order is an array that can contain any of the following:
4421 ///
4422 /// * ``const``
4423 /// * ``inline``
4424 /// * ``static``
4425 /// * ``friend``
4426 /// * ``constexpr``
4427 /// * ``volatile``
4428 /// * ``restrict``
4429 /// * ``type``
4430 ///
4431 /// \note
4432 /// It must contain ``type``.
4433 /// \endnote
4434 ///
4435 /// Items to the left of ``type`` will be placed to the left of the type and
4436 /// aligned in the order supplied. Items to the right of ``type`` will be
4437 /// placed to the right of the type and aligned in the order supplied.
4438 ///
4439 /// \code{.yaml}
4440 /// QualifierOrder: [inline, static, type, const, volatile]
4441 /// \endcode
4442 /// \version 14
4443 std::vector<std::string> QualifierOrder;
4444
4445 /// See documentation of ``RawStringFormats``.
4447 /// The language of this raw string.
4449 /// A list of raw string delimiters that match this language.
4450 std::vector<std::string> Delimiters;
4451 /// A list of enclosing function names that match this language.
4452 std::vector<std::string> EnclosingFunctions;
4453 /// The canonical delimiter for this language.
4455 /// The style name on which this raw string format is based on.
4456 /// If not specified, the raw string format is based on the style that this
4457 /// format is based on.
4458 std::string BasedOnStyle;
4459 bool operator==(const RawStringFormat &Other) const {
4460 return Language == Other.Language && Delimiters == Other.Delimiters &&
4461 EnclosingFunctions == Other.EnclosingFunctions &&
4462 CanonicalDelimiter == Other.CanonicalDelimiter &&
4463 BasedOnStyle == Other.BasedOnStyle;
4464 }
4465 };
4466
4467 /// Defines hints for detecting supported languages code blocks in raw
4468 /// strings.
4469 ///
4470 /// A raw string with a matching delimiter or a matching enclosing function
4471 /// name will be reformatted assuming the specified language based on the
4472 /// style for that language defined in the .clang-format file. If no style has
4473 /// been defined in the .clang-format file for the specific language, a
4474 /// predefined style given by ``BasedOnStyle`` is used. If ``BasedOnStyle`` is
4475 /// not found, the formatting is based on ``LLVM`` style. A matching delimiter
4476 /// takes precedence over a matching enclosing function name for determining
4477 /// the language of the raw string contents.
4478 ///
4479 /// If a canonical delimiter is specified, occurrences of other delimiters for
4480 /// the same language will be updated to the canonical if possible.
4481 ///
4482 /// There should be at most one specification per language and each delimiter
4483 /// and enclosing function should not occur in multiple specifications.
4484 ///
4485 /// To configure this in the .clang-format file, use:
4486 /// \code{.yaml}
4487 /// RawStringFormats:
4488 /// - Language: TextProto
4489 /// Delimiters:
4490 /// - pb
4491 /// - proto
4492 /// EnclosingFunctions:
4493 /// - PARSE_TEXT_PROTO
4494 /// BasedOnStyle: google
4495 /// - Language: Cpp
4496 /// Delimiters:
4497 /// - cc
4498 /// - cpp
4499 /// BasedOnStyle: LLVM
4500 /// CanonicalDelimiter: cc
4501 /// \endcode
4502 /// \version 6
4503 std::vector<RawStringFormat> RawStringFormats;
4504
4505 /// The ``&`` and ``&&`` alignment style.
4507 /// Align reference like ``PointerAlignment``.
4509 /// Align reference to the left.
4510 /// \code
4511 /// int& a;
4512 /// \endcode
4514 /// Align reference to the right.
4515 /// \code
4516 /// int &a;
4517 /// \endcode
4519 /// Align reference in the middle.
4520 /// \code
4521 /// int & a;
4522 /// \endcode
4524 };
4525
4526 /// Reference alignment style (overrides ``PointerAlignment`` for references).
4527 /// \version 13
4529
4530 // clang-format off
4531 /// Types of comment reflow style.
4532 enum ReflowCommentsStyle : int8_t {
4533 /// Leave comments untouched.
4534 /// \code
4535 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4536 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
4537 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4538 /// * and a misaligned second line */
4539 /// \endcode
4541 /// Only apply indentation rules, moving comments left or right, without
4542 /// changing formatting inside the comments.
4543 /// \code
4544 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4545 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
4546 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4547 /// * and a misaligned second line */
4548 /// \endcode
4550 /// Apply indentation rules and reflow long comments into new lines, trying
4551 /// to obey the ``ColumnLimit``.
4552 /// \code
4553 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4554 /// // information
4555 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4556 /// * information */
4557 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4558 /// * information and a misaligned second line */
4559 /// \endcode
4561 };
4562 // clang-format on
4563
4564 /// Comment reformatting style.
4565 /// \version 3.8
4567
4568 /// Remove optional braces of control statements (``if``, ``else``, ``for``,
4569 /// and ``while``) in C++ according to the LLVM coding style.
4570 /// \warning
4571 /// This option will be renamed and expanded to support other styles.
4572 /// \endwarning
4573 /// \warning
4574 /// Setting this option to ``true`` could lead to incorrect code formatting
4575 /// due to clang-format's lack of complete semantic information. As such,
4576 /// extra care should be taken to review code changes made by this option.
4577 /// \endwarning
4578 /// \code
4579 /// false: true:
4580 ///
4581 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4582 /// handleFunctionDecl(D); handleFunctionDecl(D);
4583 /// } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
4584 /// handleVarDecl(D); handleVarDecl(D);
4585 /// }
4586 ///
4587 /// if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
4588 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4589 /// if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
4590 /// handleAttr(A); handleAttr(A);
4591 /// } }
4592 /// }
4593 /// }
4594 ///
4595 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4596 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4597 /// handleAttr(A); handleAttr(A);
4598 /// }
4599 /// }
4600 ///
4601 /// if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
4602 /// if (shouldProcess(D)) { if (shouldProcess(D))
4603 /// handleVarDecl(D); handleVarDecl(D);
4604 /// } else { else
4605 /// markAsIgnored(D); markAsIgnored(D);
4606 /// } }
4607 /// }
4608 ///
4609 /// if (a) { vs. if (a)
4610 /// b(); b();
4611 /// } else { else if (c)
4612 /// if (c) { d();
4613 /// d(); else
4614 /// } else { e();
4615 /// e();
4616 /// }
4617 /// }
4618 /// \endcode
4619 /// \version 14
4621
4622 /// Remove empty lines within unwrapped lines.
4623 /// \code
4624 /// false: true:
4625 ///
4626 /// int c vs. int c = a + b;
4627 ///
4628 /// = a + b;
4629 ///
4630 /// enum : unsigned vs. enum : unsigned {
4631 /// AA = 0,
4632 /// { BB
4633 /// AA = 0, } myEnum;
4634 /// BB
4635 /// } myEnum;
4636 ///
4637 /// while ( vs. while (true) {
4638 /// }
4639 /// true) {
4640 /// }
4641 /// \endcode
4642 /// \version 20
4644
4645 /// Types of redundant parentheses to remove.
4647 /// Do not remove parentheses.
4648 /// \code
4649 /// class __declspec((dllimport)) X {};
4650 /// co_return (((0)));
4651 /// return ((a + b) - ((c + d)));
4652 /// \endcode
4654 /// Replace multiple parentheses with single parentheses.
4655 /// \code
4656 /// class __declspec(dllimport) X {};
4657 /// co_return (0);
4658 /// return ((a + b) - (c + d));
4659 /// \endcode
4661 /// Also remove parentheses enclosing the expression in a
4662 /// ``return``/``co_return`` statement.
4663 /// \code
4664 /// class __declspec(dllimport) X {};
4665 /// co_return 0;
4666 /// return (a + b) - (c + d);
4667 /// \endcode
4669 };
4670
4671 /// Remove redundant parentheses.
4672 /// \warning
4673 /// Setting this option to any value other than ``Leave`` could lead to
4674 /// incorrect code formatting due to clang-format's lack of complete semantic
4675 /// information. As such, extra care should be taken to review code changes
4676 /// made by this option.
4677 /// \endwarning
4678 /// \version 17
4680
4681 /// Remove semicolons after the closing braces of functions and
4682 /// constructors/destructors.
4683 /// \warning
4684 /// Setting this option to ``true`` could lead to incorrect code formatting
4685 /// due to clang-format's lack of complete semantic information. As such,
4686 /// extra care should be taken to review code changes made by this option.
4687 /// \endwarning
4688 /// \code
4689 /// false: true:
4690 ///
4691 /// int max(int a, int b) { int max(int a, int b) {
4692 /// return a > b ? a : b; return a > b ? a : b;
4693 /// }; }
4694 ///
4695 /// \endcode
4696 /// \version 16
4698
4699 /// The possible positions for the requires clause. The ``IndentRequires``
4700 /// option is only used if the ``requires`` is put on the start of a line.
4702 /// Always put the ``requires`` clause on its own line (possibly followed by
4703 /// a semicolon).
4704 /// \code
4705 /// template <typename T>
4706 /// requires C<T>
4707 /// struct Foo {...
4708 ///
4709 /// template <typename T>
4710 /// void bar(T t)
4711 /// requires C<T>;
4712 ///
4713 /// template <typename T>
4714 /// requires C<T>
4715 /// void bar(T t) {...
4716 ///
4717 /// template <typename T>
4718 /// void baz(T t)
4719 /// requires C<T>
4720 /// {...
4721 /// \endcode
4723 /// As with ``OwnLine``, except, unless otherwise prohibited, place a
4724 /// following open brace (of a function definition) to follow on the same
4725 /// line.
4726 /// \code
4727 /// void bar(T t)
4728 /// requires C<T> {
4729 /// return;
4730 /// }
4731 ///
4732 /// void bar(T t)
4733 /// requires C<T> {}
4734 ///
4735 /// template <typename T>
4736 /// requires C<T>
4737 /// void baz(T t) {
4738 /// ...
4739 /// \endcode
4741 /// Try to put the clause together with the preceding part of a declaration.
4742 /// For class templates: stick to the template declaration.
4743 /// For function templates: stick to the template declaration.
4744 /// For function declaration followed by a requires clause: stick to the
4745 /// parameter list.
4746 /// \code
4747 /// template <typename T> requires C<T>
4748 /// struct Foo {...
4749 ///
4750 /// template <typename T> requires C<T>
4751 /// void bar(T t) {...
4752 ///
4753 /// template <typename T>
4754 /// void baz(T t) requires C<T>
4755 /// {...
4756 /// \endcode
4758 /// Try to put the ``requires`` clause together with the class or function
4759 /// declaration.
4760 /// \code
4761 /// template <typename T>
4762 /// requires C<T> struct Foo {...
4763 ///
4764 /// template <typename T>
4765 /// requires C<T> void bar(T t) {...
4766 ///
4767 /// template <typename T>
4768 /// void baz(T t)
4769 /// requires C<T> {...
4770 /// \endcode
4772 /// Try to put everything in the same line if possible. Otherwise normal
4773 /// line breaking rules take over.
4774 /// \code
4775 /// // Fitting:
4776 /// template <typename T> requires C<T> struct Foo {...
4777 ///
4778 /// template <typename T> requires C<T> void bar(T t) {...
4779 ///
4780 /// template <typename T> void bar(T t) requires C<T> {...
4781 ///
4782 /// // Not fitting, one possible example:
4783 /// template <typename LongName>
4784 /// requires C<LongName>
4785 /// struct Foo {...
4786 ///
4787 /// template <typename LongName>
4788 /// requires C<LongName>
4789 /// void bar(LongName ln) {
4790 ///
4791 /// template <typename LongName>
4792 /// void bar(LongName ln)
4793 /// requires C<LongName> {
4794 /// \endcode
4796 };
4797
4798 /// The position of the ``requires`` clause.
4799 /// \version 15
4801
4802 /// Indentation logic for requires expression bodies.
4804 /// Align requires expression body relative to the indentation level of the
4805 /// outer scope the requires expression resides in.
4806 /// This is the default.
4807 /// \code
4808 /// template <typename T>
4809 /// concept C = requires(T t) {
4810 /// ...
4811 /// }
4812 /// \endcode
4814 /// Align requires expression body relative to the ``requires`` keyword.
4815 /// \code
4816 /// template <typename T>
4817 /// concept C = requires(T t) {
4818 /// ...
4819 /// }
4820 /// \endcode
4822 };
4823
4824 /// The indentation used for requires expression bodies.
4825 /// \version 16
4827
4828 /// The style if definition blocks should be separated.
4830 /// Leave definition blocks as they are.
4832 /// Insert an empty line between definition blocks.
4834 /// Remove any empty line between definition blocks.
4836 };
4837
4838 /// Specifies the use of empty lines to separate definition blocks, including
4839 /// classes, structs, enums, and functions.
4840 /// \code
4841 /// Never v.s. Always
4842 /// #include <cstring> #include <cstring>
4843 /// struct Foo {
4844 /// int a, b, c; struct Foo {
4845 /// }; int a, b, c;
4846 /// namespace Ns { };
4847 /// class Bar {
4848 /// public: namespace Ns {
4849 /// struct Foobar { class Bar {
4850 /// int a; public:
4851 /// int b; struct Foobar {
4852 /// }; int a;
4853 /// private: int b;
4854 /// int t; };
4855 /// int method1() {
4856 /// // ... private:
4857 /// } int t;
4858 /// enum List {
4859 /// ITEM1, int method1() {
4860 /// ITEM2 // ...
4861 /// }; }
4862 /// template<typename T>
4863 /// int method2(T x) { enum List {
4864 /// // ... ITEM1,
4865 /// } ITEM2
4866 /// int i, j, k; };
4867 /// int method3(int par) {
4868 /// // ... template<typename T>
4869 /// } int method2(T x) {
4870 /// }; // ...
4871 /// class C {}; }
4872 /// }
4873 /// int i, j, k;
4874 ///
4875 /// int method3(int par) {
4876 /// // ...
4877 /// }
4878 /// };
4879 ///
4880 /// class C {};
4881 /// }
4882 /// \endcode
4883 /// \version 14
4885
4886 /// The maximal number of unwrapped lines that a short namespace spans.
4887 /// Defaults to 1.
4888 ///
4889 /// This determines the maximum length of short namespaces by counting
4890 /// unwrapped lines (i.e. containing neither opening nor closing
4891 /// namespace brace) and makes ``FixNamespaceComments`` omit adding
4892 /// end comments for those.
4893 /// \code
4894 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4895 /// namespace a { namespace a {
4896 /// int foo; int foo;
4897 /// } } // namespace a
4898 ///
4899 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4900 /// namespace b { namespace b {
4901 /// int foo; int foo;
4902 /// int bar; int bar;
4903 /// } // namespace b } // namespace b
4904 /// \endcode
4905 /// \version 13
4907
4908 /// Do not format macro definition body.
4909 /// \version 18
4911
4912 /// Includes sorting options.
4914 /// If ``true``, includes are sorted based on the other suboptions below.
4915 /// (``Never`` is deprecated by ``Enabled: false``.)
4917 /// Whether or not includes are sorted in a case-insensitive fashion.
4918 /// (``CaseSensitive`` and ``CaseInsensitive`` are deprecated by
4919 /// ``IgnoreCase: false`` and ``IgnoreCase: true``, respectively.)
4920 /// \code
4921 /// true: false:
4922 /// #include "A/B.h" vs. #include "A/B.h"
4923 /// #include "A/b.h" #include "A/b.h"
4924 /// #include "a/b.h" #include "B/A.h"
4925 /// #include "B/A.h" #include "B/a.h"
4926 /// #include "B/a.h" #include "a/b.h"
4927 /// \endcode
4929 /// When sorting includes in each block, only take file extensions into
4930 /// account if two includes compare equal otherwise.
4931 /// \code
4932 /// true: false:
4933 /// # include "A.h" vs. # include "A-util.h"
4934 /// # include "A.inc" # include "A.h"
4935 /// # include "A-util.h" # include "A.inc"
4936 /// \endcode
4938 bool operator==(const SortIncludesOptions &R) const {
4939 return Enabled == R.Enabled && IgnoreCase == R.IgnoreCase &&
4940 IgnoreExtension == R.IgnoreExtension;
4941 }
4942 bool operator!=(const SortIncludesOptions &R) const {
4943 return !(*this == R);
4944 }
4945 };
4946
4947 /// Controls if and how clang-format will sort ``#includes``.
4948 /// \version 3.8
4950
4951 /// Position for Java Static imports.
4953 /// Static imports are placed before non-static imports.
4954 /// \code{.java}
4955 /// import static org.example.function1;
4956 ///
4957 /// import org.example.ClassA;
4958 /// \endcode
4960 /// Static imports are placed after non-static imports.
4961 /// \code{.java}
4962 /// import org.example.ClassA;
4963 ///
4964 /// import static org.example.function1;
4965 /// \endcode
4967 };
4968
4969 /// When sorting Java imports, by default static imports are placed before
4970 /// non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
4971 /// static imports are placed after non-static imports.
4972 /// \version 12
4974
4975 /// Using declaration sorting options.
4977 /// Using declarations are never sorted.
4978 /// \code
4979 /// using std::chrono::duration_cast;
4980 /// using std::move;
4981 /// using boost::regex;
4982 /// using boost::regex_constants::icase;
4983 /// using std::string;
4984 /// \endcode
4986 /// Using declarations are sorted in the order defined as follows:
4987 /// Split the strings by ``::`` and discard any initial empty strings. Sort
4988 /// the lists of names lexicographically, and within those groups, names are
4989 /// in case-insensitive lexicographic order.
4990 /// \code
4991 /// using boost::regex;
4992 /// using boost::regex_constants::icase;
4993 /// using std::chrono::duration_cast;
4994 /// using std::move;
4995 /// using std::string;
4996 /// \endcode
4998 /// Using declarations are sorted in the order defined as follows:
4999 /// Split the strings by ``::`` and discard any initial empty strings. The
5000 /// last element of each list is a non-namespace name; all others are
5001 /// namespace names. Sort the lists of names lexicographically, where the
5002 /// sort order of individual names is that all non-namespace names come
5003 /// before all namespace names, and within those groups, names are in
5004 /// case-insensitive lexicographic order.
5005 /// \code
5006 /// using boost::regex;
5007 /// using boost::regex_constants::icase;
5008 /// using std::move;
5009 /// using std::string;
5010 /// using std::chrono::duration_cast;
5011 /// \endcode
5013 };
5014
5015 /// Controls if and how clang-format will sort using declarations.
5016 /// \version 5
5018
5019 /// If ``true``, a space is inserted after C style casts.
5020 /// \code
5021 /// true: false:
5022 /// (int) i; vs. (int)i;
5023 /// \endcode
5024 /// \version 3.5
5026
5027 /// If ``true``, a space is inserted after the logical not operator (``!``).
5028 /// \code
5029 /// true: false:
5030 /// ! someExpression(); vs. !someExpression();
5031 /// \endcode
5032 /// \version 9
5034
5035 /// If ``true``, a space will be inserted after the ``operator`` keyword.
5036 /// \code
5037 /// true: false:
5038 /// bool operator ==(int a); vs. bool operator==(int a);
5039 /// \endcode
5040 /// \version 21
5042
5043 /// If \c true, a space will be inserted after the ``template`` keyword.
5044 /// \code
5045 /// true: false:
5046 /// template <int> void foo(); vs. template<int> void foo();
5047 /// \endcode
5048 /// \version 4
5050
5051 /// Different ways to put a space before opening parentheses.
5053 /// Don't ensure spaces around pointer qualifiers and use PointerAlignment
5054 /// instead.
5055 /// \code
5056 /// PointerAlignment: Left PointerAlignment: Right
5057 /// void* const* x = NULL; vs. void *const *x = NULL;
5058 /// \endcode
5060 /// Ensure that there is a space before pointer qualifiers.
5061 /// \code
5062 /// PointerAlignment: Left PointerAlignment: Right
5063 /// void* const* x = NULL; vs. void * const *x = NULL;
5064 /// \endcode
5066 /// Ensure that there is a space after pointer qualifiers.
5067 /// \code
5068 /// PointerAlignment: Left PointerAlignment: Right
5069 /// void* const * x = NULL; vs. void *const *x = NULL;
5070 /// \endcode
5072 /// Ensure that there is a space both before and after pointer qualifiers.
5073 /// \code
5074 /// PointerAlignment: Left PointerAlignment: Right
5075 /// void* const * x = NULL; vs. void * const *x = NULL;
5076 /// \endcode
5078 };
5079
5080 /// Defines in which cases to put a space before or after pointer qualifiers
5081 /// \version 12
5083
5084 /// If ``false``, spaces will be removed before assignment operators.
5085 /// \code
5086 /// true: false:
5087 /// int a = 5; vs. int a= 5;
5088 /// a += 42; a+= 42;
5089 /// \endcode
5090 /// \version 3.7
5092
5093 /// If ``false``, spaces will be removed before case colon.
5094 /// \code
5095 /// true: false
5096 /// switch (x) { vs. switch (x) {
5097 /// case 1 : break; case 1: break;
5098 /// } }
5099 /// \endcode
5100 /// \version 12
5102
5103 /// If ``true``, a space will be inserted before a C++11 braced list
5104 /// used to initialize an object (after the preceding identifier or type).
5105 /// \code
5106 /// true: false:
5107 /// Foo foo { bar }; vs. Foo foo{ bar };
5108 /// Foo {}; Foo{};
5109 /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
5110 /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
5111 /// \endcode
5112 /// \version 7
5114
5115 /// If ``false``, spaces will be removed before constructor initializer
5116 /// colon.
5117 /// \code
5118 /// true: false:
5119 /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
5120 /// \endcode
5121 /// \version 7
5123
5124 /// If ``false``, spaces will be removed before enum underlying type colon.
5125 /// \code
5126 /// true: false:
5127 /// enum E : int {} enum E: int {}
5128 /// \endcode
5129 /// \version 23
5131
5132 /// If ``false``, spaces will be removed before inheritance colon.
5133 /// \code
5134 /// true: false:
5135 /// class Foo : Bar {} vs. class Foo: Bar {}
5136 /// \endcode
5137 /// \version 7
5139
5140 /// If ``true``, a space will be added before a JSON colon. For other
5141 /// languages, e.g. JavaScript, use ``SpacesInContainerLiterals`` instead.
5142 /// \code
5143 /// true: false:
5144 /// { {
5145 /// "key" : "value" vs. "key": "value"
5146 /// } }
5147 /// \endcode
5148 /// \version 17
5150
5151 /// Different ways to put a space before opening parentheses.
5153 /// This is **deprecated** and replaced by ``Custom`` below, with all
5154 /// ``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
5155 /// ``false``.
5157 /// Put a space before opening parentheses only after control statement
5158 /// keywords (``for/if/while...``).
5159 /// \code
5160 /// void f() {
5161 /// if (true) {
5162 /// f();
5163 /// }
5164 /// }
5165 /// \endcode
5167 /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
5168 /// ForEach and If macros. This is useful in projects where ForEach/If
5169 /// macros are treated as function calls instead of control statements.
5170 /// ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
5171 /// backward compatibility.
5172 /// \code
5173 /// void f() {
5174 /// Q_FOREACH(...) {
5175 /// f();
5176 /// }
5177 /// }
5178 /// \endcode
5180 /// Put a space before opening parentheses only if the parentheses are not
5181 /// empty.
5182 /// \code
5183 /// void() {
5184 /// if (true) {
5185 /// f();
5186 /// g (x, y, z);
5187 /// }
5188 /// }
5189 /// \endcode
5191 /// Always put a space before opening parentheses, except when it's
5192 /// prohibited by the syntax rules (in function-like macro definitions) or
5193 /// when determined by other style rules (after unary operators, opening
5194 /// parentheses, etc.)
5195 /// \code
5196 /// void f () {
5197 /// if (true) {
5198 /// f ();
5199 /// }
5200 /// }
5201 /// \endcode
5203 /// Configure each individual space before parentheses in
5204 /// ``SpaceBeforeParensOptions``.
5206 };
5207
5208 /// Defines in which cases to put a space before opening parentheses.
5209 /// \version 3.5
5211
5212 /// Precise control over the spacing before parentheses.
5213 /// \code
5214 /// # Should be declared this way:
5215 /// SpaceBeforeParens: Custom
5216 /// SpaceBeforeParensOptions:
5217 /// AfterControlStatements: true
5218 /// AfterFunctionDefinitionName: true
5219 /// \endcode
5221 /// If ``true``, put space between control statement keywords
5222 /// (for/if/while...) and opening parentheses.
5223 /// \code
5224 /// true: false:
5225 /// if (...) {} vs. if(...) {}
5226 /// \endcode
5228 /// If ``true``, put space between foreach macros and opening parentheses.
5229 /// \code
5230 /// true: false:
5231 /// FOREACH (...) vs. FOREACH(...)
5232 /// <loop-body> <loop-body>
5233 /// \endcode
5235 /// If ``true``, put a space between function declaration name and opening
5236 /// parentheses.
5237 /// \code
5238 /// true: false:
5239 /// void f (); vs. void f();
5240 /// \endcode
5242 /// If ``true``, put a space between function definition name and opening
5243 /// parentheses.
5244 /// \code
5245 /// true: false:
5246 /// void f () {} vs. void f() {}
5247 /// \endcode
5249 /// If ``true``, put space between if macros and opening parentheses.
5250 /// \code
5251 /// true: false:
5252 /// IF (...) vs. IF(...)
5253 /// <conditional-body> <conditional-body>
5254 /// \endcode
5256 /// If ``true``, put a space between alternative operator ``not`` and the
5257 /// opening parenthesis.
5258 /// \code
5259 /// true: false:
5260 /// return not (a || b); vs. return not(a || b);
5261 /// \endcode
5263 /// If ``true``, put a space between operator overloading and opening
5264 /// parentheses.
5265 /// \code
5266 /// true: false:
5267 /// void operator++ (int a); vs. void operator++(int a);
5268 /// object.operator++ (10); object.operator++(10);
5269 /// \endcode
5271 /// If ``true``, put a space between operator ``new``/``delete`` and opening
5272 /// parenthesis.
5273 /// \code
5274 /// true: false:
5275 /// new (buf) T; vs. new(buf) T;
5276 /// delete (buf) T; delete(buf) T;
5277 /// \endcode
5279 /// If ``true``, put space between requires keyword in a requires clause and
5280 /// opening parentheses, if there is one.
5281 /// \code
5282 /// true: false:
5283 /// template<typename T> vs. template<typename T>
5284 /// requires (A<T> && B<T>) requires(A<T> && B<T>)
5285 /// ... ...
5286 /// \endcode
5288 /// If ``true``, put space between requires keyword in a requires expression
5289 /// and opening parentheses.
5290 /// \code
5291 /// true: false:
5292 /// template<typename T> vs. template<typename T>
5293 /// concept C = requires (T t) { concept C = requires(T t) {
5294 /// ... ...
5295 /// } }
5296 /// \endcode
5298 /// If ``true``, put a space before opening parentheses only if the
5299 /// parentheses are not empty.
5300 /// \code
5301 /// true: false:
5302 /// void f (int a); vs. void f();
5303 /// f (a); f();
5304 /// \endcode
5306
5314
5316 return AfterControlStatements == Other.AfterControlStatements &&
5317 AfterForeachMacros == Other.AfterForeachMacros &&
5319 Other.AfterFunctionDeclarationName &&
5320 AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
5321 AfterIfMacros == Other.AfterIfMacros &&
5322 AfterNot == Other.AfterNot &&
5323 AfterOverloadedOperator == Other.AfterOverloadedOperator &&
5324 AfterPlacementOperator == Other.AfterPlacementOperator &&
5325 AfterRequiresInClause == Other.AfterRequiresInClause &&
5326 AfterRequiresInExpression == Other.AfterRequiresInExpression &&
5327 BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
5328 }
5329 };
5330
5331 /// Control of individual space before parentheses.
5332 ///
5333 /// If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify
5334 /// how each individual space before parentheses case should be handled.
5335 /// Otherwise, this is ignored.
5336 /// \code{.yaml}
5337 /// # Example of usage:
5338 /// SpaceBeforeParens: Custom
5339 /// SpaceBeforeParensOptions:
5340 /// AfterControlStatements: true
5341 /// AfterFunctionDefinitionName: true
5342 /// \endcode
5343 /// \version 14
5345
5346 /// If ``true``, spaces will be before ``[``.
5347 /// Lambdas will not be affected. Only the first ``[`` will get a space added.
5348 /// \code
5349 /// true: false:
5350 /// int a [5]; vs. int a[5];
5351 /// int a [5][5]; vs. int a[5][5];
5352 /// \endcode
5353 /// \version 10
5355
5356 /// If ``false``, spaces will be removed before range-based for loop
5357 /// colon.
5358 /// \code
5359 /// true: false:
5360 /// for (auto v : values) {} vs. for(auto v: values) {}
5361 /// \endcode
5362 /// \version 7
5364
5365 /// This option is **deprecated**. See ``Block`` of ``SpaceInEmptyBraces``.
5366 /// \version 10
5367 // bool SpaceInEmptyBlock;
5368
5369 /// Style of when to insert a space in empty braces.
5371 /// Always insert a space in empty braces.
5372 /// \code
5373 /// void f() { }
5374 /// class Unit { };
5375 /// auto a = [] { };
5376 /// int x{ };
5377 /// \endcode
5379 /// Only insert a space in empty blocks.
5380 /// \code
5381 /// void f() { }
5382 /// class Unit { };
5383 /// auto a = [] { };
5384 /// int x{};
5385 /// \endcode
5387 /// Never insert a space in empty braces.
5388 /// \code
5389 /// void f() {}
5390 /// class Unit {};
5391 /// auto a = [] {};
5392 /// int x{};
5393 /// \endcode
5395 };
5396
5397 /// Specifies when to insert a space in empty braces.
5398 /// \note
5399 /// This option doesn't apply to initializer braces if
5400 /// ``Cpp11BracedListStyle`` is not ``Block``.
5401 /// \endnote
5402 /// \version 22
5404
5405 /// If ``true``, spaces may be inserted into ``()``.
5406 /// This option is **deprecated**. See ``InEmptyParentheses`` of
5407 /// ``SpacesInParensOptions``.
5408 /// \version 3.7
5409 // bool SpaceInEmptyParentheses;
5410
5411 /// The number of spaces before trailing line comments
5412 /// (``//`` - comments).
5413 ///
5414 /// This does not affect trailing block comments (``/*`` - comments) as those
5415 /// commonly have different usage patterns and a number of special cases. In
5416 /// the case of Verilog, it doesn't affect a comment right after the opening
5417 /// parenthesis in the port or parameter list in a module header, because it
5418 /// is probably for the port on the following line instead of the parenthesis
5419 /// it follows.
5420 /// \code
5421 /// SpacesBeforeTrailingComments: 3
5422 /// void f() {
5423 /// if (true) { // foo1
5424 /// f(); // bar
5425 /// } // foo
5426 /// }
5427 /// \endcode
5428 /// \version 3.7
5430
5431 /// Styles for adding spacing after ``<`` and before ``>``
5432 /// in template argument lists.
5433 enum SpacesInAnglesStyle : int8_t {
5434 /// Remove spaces after ``<`` and before ``>``.
5435 /// \code
5436 /// static_cast<int>(arg);
5437 /// std::function<void(int)> fct;
5438 /// \endcode
5440 /// Add spaces after ``<`` and before ``>``.
5441 /// \code
5442 /// static_cast< int >(arg);
5443 /// std::function< void(int) > fct;
5444 /// \endcode
5446 /// Keep a single space after ``<`` and before ``>`` if any spaces were
5447 /// present. Option ``Standard: Cpp03`` takes precedence.
5449 };
5450 /// The SpacesInAnglesStyle to use for template argument lists.
5451 /// \version 3.4
5453
5454 /// If ``true``, spaces will be inserted around if/for/switch/while
5455 /// conditions.
5456 /// This option is **deprecated**. See ``InConditionalStatements`` of
5457 /// ``SpacesInParensOptions``.
5458 /// \version 10
5459 // bool SpacesInConditionalStatement;
5460
5461 /// If ``true``, spaces are inserted inside container literals (e.g. ObjC and
5462 /// Javascript array and dict literals). For JSON, use
5463 /// ``SpaceBeforeJsonColon`` instead.
5464 /// \code{.js}
5465 /// true: false:
5466 /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
5467 /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
5468 /// \endcode
5469 /// \version 3.7
5471
5472 /// If ``true``, spaces may be inserted into C style casts.
5473 /// This option is **deprecated**. See ``InCStyleCasts`` of
5474 /// ``SpacesInParensOptions``.
5475 /// \version 3.7
5476 // bool SpacesInCStyleCastParentheses;
5477
5478 /// Control of spaces within a single line comment.
5480 /// The minimum number of spaces at the start of the comment.
5481 unsigned Minimum;
5482 /// The maximum number of spaces at the start of the comment.
5483 unsigned Maximum;
5484 };
5485
5486 /// How many spaces are allowed at the start of a line comment. To disable the
5487 /// maximum set it to ``-1``, apart from that the maximum takes precedence
5488 /// over the minimum.
5489 /// \code
5490 /// Minimum = 1
5491 /// Maximum = -1
5492 /// // One space is forced
5493 ///
5494 /// // but more spaces are possible
5495 ///
5496 /// Minimum = 0
5497 /// Maximum = 0
5498 /// //Forces to start every comment directly after the slashes
5499 /// \endcode
5500 ///
5501 /// Note that in line comment sections the relative indent of the subsequent
5502 /// lines is kept, that means the following:
5503 /// \code
5504 /// before: after:
5505 /// Minimum: 1
5506 /// //if (b) { // if (b) {
5507 /// // return true; // return true;
5508 /// //} // }
5509 ///
5510 /// Maximum: 0
5511 /// /// List: ///List:
5512 /// /// - Foo /// - Foo
5513 /// /// - Bar /// - Bar
5514 /// \endcode
5515 ///
5516 /// This option has only effect if ``ReflowComments`` is set to ``true``.
5517 /// \version 13
5519
5520 /// Different ways to put a space before opening and closing parentheses.
5521 enum SpacesInParensStyle : int8_t {
5522 /// Never put a space in parentheses.
5523 /// \code
5524 /// void f() {
5525 /// if(true) {
5526 /// f();
5527 /// }
5528 /// }
5529 /// \endcode
5531 /// Configure each individual space in parentheses in
5532 /// `SpacesInParensOptions`.
5534 };
5535
5536 /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
5537 /// This option is **deprecated**. The previous behavior is preserved by using
5538 /// ``SpacesInParens`` with ``Custom`` and by setting all
5539 /// ``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and
5540 /// ``InEmptyParentheses``.
5541 /// \version 3.7
5542 // bool SpacesInParentheses;
5543
5544 /// Defines in which cases spaces will be inserted after ``(`` and before
5545 /// ``)``.
5546 /// \version 17
5548
5549 /// Precise control over the spacing in parentheses.
5550 /// \code
5551 /// # Should be declared this way:
5552 /// SpacesInParens: Custom
5553 /// SpacesInParensOptions:
5554 /// ExceptDoubleParentheses: false
5555 /// InConditionalStatements: true
5556 /// Other: true
5557 /// \endcode
5559 /// Override any of the following options to prevent addition of space
5560 /// when both opening and closing parentheses use multiple parentheses.
5561 /// \code
5562 /// true:
5563 /// __attribute__(( noreturn ))
5564 /// __decltype__(( x ))
5565 /// if (( a = b ))
5566 /// \endcode
5567 /// false:
5568 /// Uses the applicable option.
5570 /// Put a space in parentheses only inside conditional statements
5571 /// (``for/if/while/switch...``).
5572 /// \code
5573 /// true: false:
5574 /// if ( a ) { ... } vs. if (a) { ... }
5575 /// while ( i < 5 ) { ... } while (i < 5) { ... }
5576 /// \endcode
5578 /// Put a space in C style casts.
5579 /// \code
5580 /// true: false:
5581 /// x = ( int32 )y vs. x = (int32)y
5582 /// y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x);
5583 /// \endcode
5585 /// Insert a space in empty parentheses, i.e. ``()``.
5586 /// \code
5587 /// true: false:
5588 /// void f( ) { vs. void f() {
5589 /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
5590 /// if (true) { if (true) {
5591 /// f( ); f();
5592 /// } }
5593 /// } }
5594 /// \endcode
5596 /// Put a space in parentheses not covered by preceding options.
5597 /// \code
5598 /// true: false:
5599 /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
5600 /// \endcode
5601 bool Other;
5602
5606
5614
5615 bool operator==(const SpacesInParensCustom &R) const {
5616 return ExceptDoubleParentheses == R.ExceptDoubleParentheses &&
5617 InConditionalStatements == R.InConditionalStatements &&
5618 InCStyleCasts == R.InCStyleCasts &&
5619 InEmptyParentheses == R.InEmptyParentheses && Other == R.Other;
5620 }
5621 bool operator!=(const SpacesInParensCustom &R) const {
5622 return !(*this == R);
5623 }
5624 };
5625
5626 /// Control of individual spaces in parentheses.
5627 ///
5628 /// If ``SpacesInParens`` is set to ``Custom``, use this to specify
5629 /// how each individual space in parentheses case should be handled.
5630 /// Otherwise, this is ignored.
5631 /// \code{.yaml}
5632 /// # Example of usage:
5633 /// SpacesInParens: Custom
5634 /// SpacesInParensOptions:
5635 /// ExceptDoubleParentheses: false
5636 /// InConditionalStatements: true
5637 /// InEmptyParentheses: true
5638 /// \endcode
5639 /// \version 17
5641
5642 /// If ``true``, spaces will be inserted after ``[`` and before ``]``.
5643 /// Lambdas without arguments or unspecified size array declarations will not
5644 /// be affected.
5645 /// \code
5646 /// true: false:
5647 /// int a[ 5 ]; vs. int a[5];
5648 /// std::unique_ptr<int[]> foo() {} // Won't be affected
5649 /// \endcode
5650 /// \version 3.7
5652
5653 /// Supported language standards for parsing and formatting C++ constructs.
5654 /// \code
5655 /// Latest: vector<set<int>>
5656 /// c++03 vs. vector<set<int> >
5657 /// \endcode
5658 ///
5659 /// The correct way to spell a specific language version is e.g. ``c++11``.
5660 /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
5661 enum LanguageStandard : int8_t {
5662 /// Parse and format as C++03.
5663 /// ``Cpp03`` is a deprecated alias for ``c++03``
5664 LS_Cpp03, // c++03
5665 /// Parse and format as C++11.
5666 LS_Cpp11, // c++11
5667 /// Parse and format as C++14.
5668 LS_Cpp14, // c++14
5669 /// Parse and format as C++17.
5670 LS_Cpp17, // c++17
5671 /// Parse and format as C++20.
5672 LS_Cpp20, // c++20
5673 /// Parse and format using the latest supported language version.
5674 /// ``Cpp11`` is a deprecated alias for ``Latest``
5676 /// Automatic detection based on the input.
5678 };
5679
5680 /// Parse and format C++ constructs compatible with this standard.
5681 /// \code
5682 /// c++03: latest:
5683 /// vector<set<int> > x; vs. vector<set<int>> x;
5684 /// \endcode
5685 /// \version 3.7
5687
5688 /// Macros which are ignored in front of a statement, as if they were an
5689 /// attribute. So that they are not parsed as identifier, for example for Qts
5690 /// emit.
5691 /// \code
5692 /// AlignConsecutiveDeclarations: true
5693 /// StatementAttributeLikeMacros: []
5694 /// unsigned char data = 'x';
5695 /// emit signal(data); // This is parsed as variable declaration.
5696 ///
5697 /// AlignConsecutiveDeclarations: true
5698 /// StatementAttributeLikeMacros: [emit]
5699 /// unsigned char data = 'x';
5700 /// emit signal(data); // Now it's fine again.
5701 /// \endcode
5702 /// \version 12
5703 std::vector<std::string> StatementAttributeLikeMacros;
5704
5705 /// A vector of macros that should be interpreted as complete statements.
5706 ///
5707 /// Typical macros are expressions and require a semicolon to be added.
5708 /// Sometimes this is not the case, and this allows to make clang-format aware
5709 /// of such cases.
5710 ///
5711 /// For example: Q_UNUSED
5712 /// \version 8
5713 std::vector<std::string> StatementMacros;
5714
5715 /// Works only when TableGenBreakInsideDAGArg is not DontBreak.
5716 /// The string list needs to consist of identifiers in TableGen.
5717 /// If any identifier is specified, this limits the line breaks by
5718 /// TableGenBreakInsideDAGArg option only on DAGArg values beginning with
5719 /// the specified identifiers.
5720 ///
5721 /// For example the configuration,
5722 /// \code{.yaml}
5723 /// TableGenBreakInsideDAGArg: BreakAll
5724 /// TableGenBreakingDAGArgOperators: [ins, outs]
5725 /// \endcode
5726 ///
5727 /// makes the line break only occurs inside DAGArgs beginning with the
5728 /// specified identifiers ``ins`` and ``outs``.
5729 ///
5730 /// \code
5731 /// let DAGArgIns = (ins
5732 /// i32:$src1,
5733 /// i32:$src2
5734 /// );
5735 /// let DAGArgOtherID = (other i32:$other1, i32:$other2);
5736 /// let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)
5737 /// \endcode
5738 /// \version 19
5739 std::vector<std::string> TableGenBreakingDAGArgOperators;
5740
5741 /// Different ways to control the format inside TableGen DAGArg.
5742 enum DAGArgStyle : int8_t {
5743 /// Never break inside DAGArg.
5744 /// \code
5745 /// let DAGArgIns = (ins i32:$src1, i32:$src2);
5746 /// \endcode
5748 /// Break inside DAGArg after each list element but for the last.
5749 /// This aligns to the first element.
5750 /// \code
5751 /// let DAGArgIns = (ins i32:$src1,
5752 /// i32:$src2);
5753 /// \endcode
5755 /// Break inside DAGArg after the operator and the all elements.
5756 /// \code
5757 /// let DAGArgIns = (ins
5758 /// i32:$src1,
5759 /// i32:$src2
5760 /// );
5761 /// \endcode
5763 };
5764
5765 /// The styles of the line break inside the DAGArg in TableGen.
5766 /// \version 19
5768
5769 /// The number of columns used for tab stops.
5770 /// \version 3.7
5771 unsigned TabWidth;
5772
5773 /// A vector of non-keyword identifiers that should be interpreted as template
5774 /// names.
5775 ///
5776 /// A ``<`` after a template name is annotated as a template opener instead of
5777 /// a binary operator.
5778 ///
5779 /// \version 20
5780 std::vector<std::string> TemplateNames;
5781
5782 /// A vector of non-keyword identifiers that should be interpreted as type
5783 /// names.
5784 ///
5785 /// A ``*``, ``&``, or ``&&`` between a type name and another non-keyword
5786 /// identifier is annotated as a pointer or reference token instead of a
5787 /// binary operator.
5788 ///
5789 /// \version 17
5790 std::vector<std::string> TypeNames;
5791
5792 /// A vector of macros that should be interpreted as type declarations instead
5793 /// of as function calls.
5794 ///
5795 /// These are expected to be macros of the form:
5796 /// \code
5797 /// STACK_OF(...)
5798 /// \endcode
5799 ///
5800 /// In the .clang-format configuration file, this can be configured like:
5801 /// \code{.yaml}
5802 /// TypenameMacros: [STACK_OF, LIST]
5803 /// \endcode
5804 ///
5805 /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
5806 /// \version 9
5807 std::vector<std::string> TypenameMacros;
5808
5809 /// This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``.
5810 /// \version 10
5811 // bool UseCRLF;
5812
5813 /// Different ways to use tab in formatting.
5814 enum UseTabStyle : int8_t {
5815 /// Never use tab.
5817 /// Use tabs only for indentation.
5819 /// Fill all leading whitespace with tabs, and use spaces for alignment that
5820 /// appears within a line (e.g. consecutive assignments and declarations).
5822 /// Use tabs for line continuation and indentation, and spaces for
5823 /// alignment.
5825 /// Use tabs whenever we need to fill whitespace that spans at least from
5826 /// one tab stop to the next one.
5828 };
5829
5830 /// The way to use tab characters in the resulting file.
5831 /// \version 3.7
5833
5834 /// A vector of non-keyword identifiers that should be interpreted as variable
5835 /// template names.
5836 ///
5837 /// A ``)`` after a variable template instantiation is **not** annotated as
5838 /// the closing parenthesis of C-style cast operator.
5839 ///
5840 /// \version 20
5841 std::vector<std::string> VariableTemplates;
5842
5843 /// For Verilog, put each port on its own line in module instantiations.
5844 /// \code
5845 /// true:
5846 /// ffnand ff1(.q(),
5847 /// .qbar(out1),
5848 /// .clear(in1),
5849 /// .preset(in2));
5850 ///
5851 /// false:
5852 /// ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
5853 /// \endcode
5854 /// \version 17
5856
5857 /// A vector of macros which are whitespace-sensitive and should not
5858 /// be touched.
5859 ///
5860 /// These are expected to be macros of the form:
5861 /// \code
5862 /// STRINGIZE(...)
5863 /// \endcode
5864 ///
5865 /// In the .clang-format configuration file, this can be configured like:
5866 /// \code{.yaml}
5867 /// WhitespaceSensitiveMacros: [STRINGIZE, PP_STRINGIZE]
5868 /// \endcode
5869 ///
5870 /// For example: BOOST_PP_STRINGIZE
5871 /// \version 11
5872 std::vector<std::string> WhitespaceSensitiveMacros;
5873
5874 /// Different styles for wrapping namespace body with empty lines.
5876 /// Remove all empty lines at the beginning and the end of namespace body.
5877 /// \code
5878 /// namespace N1 {
5879 /// namespace N2 {
5880 /// function();
5881 /// }
5882 /// }
5883 /// \endcode
5885 /// Always have at least one empty line at the beginning and the end of
5886 /// namespace body except that the number of empty lines between consecutive
5887 /// nested namespace definitions is not increased.
5888 /// \code
5889 /// namespace N1 {
5890 /// namespace N2 {
5891 ///
5892 /// function();
5893 ///
5894 /// }
5895 /// }
5896 /// \endcode
5898 /// Keep existing newlines at the beginning and the end of namespace body.
5899 /// ``MaxEmptyLinesToKeep`` still applies.
5901 };
5902
5903 /// Wrap namespace body with empty lines.
5904 /// \version 20
5906
5907 bool operator==(const FormatStyle &R) const {
5908 return AccessModifierOffset == R.AccessModifierOffset &&
5909 AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
5910 AlignArrayOfStructures == R.AlignArrayOfStructures &&
5911 AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
5912 AlignConsecutiveBitFields == R.AlignConsecutiveBitFields &&
5913 AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
5914 AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
5915 AlignConsecutiveShortCaseStatements ==
5916 R.AlignConsecutiveShortCaseStatements &&
5917 AlignConsecutiveTableGenBreakingDAGArgColons ==
5918 R.AlignConsecutiveTableGenBreakingDAGArgColons &&
5919 AlignConsecutiveTableGenCondOperatorColons ==
5920 R.AlignConsecutiveTableGenCondOperatorColons &&
5921 AlignConsecutiveTableGenDefinitionColons ==
5922 R.AlignConsecutiveTableGenDefinitionColons &&
5923 AlignEscapedNewlines == R.AlignEscapedNewlines &&
5924 AlignOperands == R.AlignOperands &&
5925 AlignTrailingComments == R.AlignTrailingComments &&
5926 AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
5927 AllowAllParametersOfDeclarationOnNextLine ==
5928 R.AllowAllParametersOfDeclarationOnNextLine &&
5929 AllowBreakBeforeNoexceptSpecifier ==
5930 R.AllowBreakBeforeNoexceptSpecifier &&
5931 AllowBreakBeforeQtProperty == R.AllowBreakBeforeQtProperty &&
5932 AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
5933 AllowShortCaseExpressionOnASingleLine ==
5934 R.AllowShortCaseExpressionOnASingleLine &&
5935 AllowShortCaseLabelsOnASingleLine ==
5936 R.AllowShortCaseLabelsOnASingleLine &&
5937 AllowShortCompoundRequirementOnASingleLine ==
5938 R.AllowShortCompoundRequirementOnASingleLine &&
5939 AllowShortEnumsOnASingleLine == R.AllowShortEnumsOnASingleLine &&
5940 AllowShortFunctionsOnASingleLine ==
5941 R.AllowShortFunctionsOnASingleLine &&
5942 AllowShortIfStatementsOnASingleLine ==
5943 R.AllowShortIfStatementsOnASingleLine &&
5944 AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
5945 AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
5946 AllowShortNamespacesOnASingleLine ==
5947 R.AllowShortNamespacesOnASingleLine &&
5948 AllowShortRecordOnASingleLine == R.AllowShortRecordOnASingleLine &&
5949 AlwaysBreakBeforeMultilineStrings ==
5950 R.AlwaysBreakBeforeMultilineStrings &&
5951 AttributeMacros == R.AttributeMacros &&
5952 BinPackArguments == R.BinPackArguments &&
5953 BinPackLongBracedList == R.BinPackLongBracedList &&
5954 BinPackParameters == R.BinPackParameters &&
5955 BitFieldColonSpacing == R.BitFieldColonSpacing &&
5956 BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
5957 BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
5958 BreakAfterAttributes == R.BreakAfterAttributes &&
5959 BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
5960 BreakAfterOpenBracketBracedList ==
5961 R.BreakAfterOpenBracketBracedList &&
5962 BreakAfterOpenBracketFunction == R.BreakAfterOpenBracketFunction &&
5963 BreakAfterOpenBracketIf == R.BreakAfterOpenBracketIf &&
5964 BreakAfterOpenBracketLoop == R.BreakAfterOpenBracketLoop &&
5965 BreakAfterOpenBracketSwitch == R.BreakAfterOpenBracketSwitch &&
5966 BreakAfterReturnType == R.BreakAfterReturnType &&
5967 BreakArrays == R.BreakArrays &&
5968 BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
5969 BreakBeforeBraces == R.BreakBeforeBraces &&
5970 BreakBeforeCloseBracketBracedList ==
5971 R.BreakBeforeCloseBracketBracedList &&
5972 BreakBeforeCloseBracketFunction ==
5973 R.BreakBeforeCloseBracketFunction &&
5974 BreakBeforeCloseBracketIf == R.BreakBeforeCloseBracketIf &&
5975 BreakBeforeCloseBracketLoop == R.BreakBeforeCloseBracketLoop &&
5976 BreakBeforeCloseBracketSwitch == R.BreakBeforeCloseBracketSwitch &&
5977 BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations &&
5978 BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
5979 BreakBeforeTemplateCloser == R.BreakBeforeTemplateCloser &&
5980 BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
5981 BreakBinaryOperations == R.BreakBinaryOperations &&
5982 BreakConstructorInitializers == R.BreakConstructorInitializers &&
5983 BreakFunctionDefinitionParameters ==
5984 R.BreakFunctionDefinitionParameters &&
5985 BreakInheritanceList == R.BreakInheritanceList &&
5986 BreakStringLiterals == R.BreakStringLiterals &&
5987 BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
5988 ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
5989 CompactNamespaces == R.CompactNamespaces &&
5990 ConstructorInitializerIndentWidth ==
5991 R.ConstructorInitializerIndentWidth &&
5992 ContinuationIndentWidth == R.ContinuationIndentWidth &&
5993 Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
5994 DerivePointerAlignment == R.DerivePointerAlignment &&
5995 DisableFormat == R.DisableFormat &&
5996 EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
5997 EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
5998 EnumTrailingComma == R.EnumTrailingComma &&
5999 ExperimentalAutoDetectBinPacking ==
6000 R.ExperimentalAutoDetectBinPacking &&
6001 FixNamespaceComments == R.FixNamespaceComments &&
6002 ForEachMacros == R.ForEachMacros &&
6003 IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
6004 IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories &&
6005 IncludeStyle.IncludeIsMainRegex ==
6006 R.IncludeStyle.IncludeIsMainRegex &&
6007 IncludeStyle.IncludeIsMainSourceRegex ==
6008 R.IncludeStyle.IncludeIsMainSourceRegex &&
6009 IncludeStyle.MainIncludeChar == R.IncludeStyle.MainIncludeChar &&
6010 IndentAccessModifiers == R.IndentAccessModifiers &&
6011 IndentCaseBlocks == R.IndentCaseBlocks &&
6012 IndentCaseLabels == R.IndentCaseLabels &&
6013 IndentExportBlock == R.IndentExportBlock &&
6014 IndentExternBlock == R.IndentExternBlock &&
6015 IndentGotoLabels == R.IndentGotoLabels &&
6016 IndentPPDirectives == R.IndentPPDirectives &&
6017 IndentRequiresClause == R.IndentRequiresClause &&
6018 IndentWidth == R.IndentWidth &&
6019 IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
6020 InsertBraces == R.InsertBraces &&
6021 InsertNewlineAtEOF == R.InsertNewlineAtEOF &&
6022 IntegerLiteralSeparator == R.IntegerLiteralSeparator &&
6023 JavaImportGroups == R.JavaImportGroups &&
6024 JavaScriptQuotes == R.JavaScriptQuotes &&
6025 JavaScriptWrapImports == R.JavaScriptWrapImports &&
6026 KeepEmptyLines == R.KeepEmptyLines &&
6027 KeepFormFeed == R.KeepFormFeed && Language == R.Language &&
6028 LambdaBodyIndentation == R.LambdaBodyIndentation &&
6029 LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin &&
6030 MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&
6032 R.MacrosSkippedByRemoveParentheses &&
6033 MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
6034 NamespaceIndentation == R.NamespaceIndentation &&
6035 NamespaceMacros == R.NamespaceMacros &&
6036 NumericLiteralCase == R.NumericLiteralCase &&
6037 ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
6038 ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
6040 R.ObjCBreakBeforeNestedBlockParam &&
6041 ObjCPropertyAttributeOrder == R.ObjCPropertyAttributeOrder &&
6043 R.ObjCSpaceAfterMethodDeclarationPrefix &&
6044 ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
6045 ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
6046 OneLineFormatOffRegex == R.OneLineFormatOffRegex &&
6047 PackConstructorInitializers == R.PackConstructorInitializers &&
6048 PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
6050 R.PenaltyBreakBeforeFirstCallParameter &&
6051 PenaltyBreakBeforeMemberAccess == R.PenaltyBreakBeforeMemberAccess &&
6052 PenaltyBreakComment == R.PenaltyBreakComment &&
6053 PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
6054 PenaltyBreakOpenParenthesis == R.PenaltyBreakOpenParenthesis &&
6055 PenaltyBreakScopeResolution == R.PenaltyBreakScopeResolution &&
6056 PenaltyBreakString == R.PenaltyBreakString &&
6058 R.PenaltyBreakTemplateDeclaration &&
6059 PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
6060 PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
6061 PointerAlignment == R.PointerAlignment &&
6062 QualifierAlignment == R.QualifierAlignment &&
6063 QualifierOrder == R.QualifierOrder &&
6064 RawStringFormats == R.RawStringFormats &&
6065 ReferenceAlignment == R.ReferenceAlignment &&
6066 RemoveBracesLLVM == R.RemoveBracesLLVM &&
6068 R.RemoveEmptyLinesInUnwrappedLines &&
6069 RemoveParentheses == R.RemoveParentheses &&
6070 RemoveSemicolon == R.RemoveSemicolon &&
6071 RequiresClausePosition == R.RequiresClausePosition &&
6072 RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
6073 SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
6074 ShortNamespaceLines == R.ShortNamespaceLines &&
6075 SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
6076 SortIncludes == R.SortIncludes &&
6077 SortJavaStaticImport == R.SortJavaStaticImport &&
6078 SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
6079 SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
6080 SpaceAfterOperatorKeyword == R.SpaceAfterOperatorKeyword &&
6081 SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
6082 SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
6083 SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&
6084 SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
6086 R.SpaceBeforeCtorInitializerColon &&
6087 SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
6088 SpaceBeforeJsonColon == R.SpaceBeforeJsonColon &&
6089 SpaceBeforeParens == R.SpaceBeforeParens &&
6090 SpaceBeforeParensOptions == R.SpaceBeforeParensOptions &&
6091 SpaceAroundPointerQualifiers == R.SpaceAroundPointerQualifiers &&
6093 R.SpaceBeforeRangeBasedForLoopColon &&
6094 SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
6095 SpaceInEmptyBraces == R.SpaceInEmptyBraces &&
6096 SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
6097 SpacesInAngles == R.SpacesInAngles &&
6098 SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
6099 SpacesInLineCommentPrefix.Minimum ==
6100 R.SpacesInLineCommentPrefix.Minimum &&
6101 SpacesInLineCommentPrefix.Maximum ==
6102 R.SpacesInLineCommentPrefix.Maximum &&
6103 SpacesInParens == R.SpacesInParens &&
6104 SpacesInParensOptions == R.SpacesInParensOptions &&
6105 SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
6106 Standard == R.Standard &&
6107 StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
6108 StatementMacros == R.StatementMacros &&
6110 R.TableGenBreakingDAGArgOperators &&
6111 TableGenBreakInsideDAGArg == R.TableGenBreakInsideDAGArg &&
6112 TabWidth == R.TabWidth && TemplateNames == R.TemplateNames &&
6113 TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
6114 UseTab == R.UseTab && VariableTemplates == R.VariableTemplates &&
6116 R.VerilogBreakBetweenInstancePorts &&
6117 WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
6118 WrapNamespaceBodyWithEmptyLines == R.WrapNamespaceBodyWithEmptyLines;
6119 }
6120
6121 std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
6122
6123 // Stores per-language styles. A FormatStyle instance inside has an empty
6124 // StyleSet. A FormatStyle instance returned by the Get method has its
6125 // StyleSet set to a copy of the originating StyleSet, effectively keeping the
6126 // internal representation of that StyleSet alive.
6127 //
6128 // The memory management and ownership reminds of a birds nest: chicks
6129 // leaving the nest take photos of the nest with them.
6131 typedef std::map<LanguageKind, FormatStyle> MapType;
6132
6133 std::optional<FormatStyle> Get(LanguageKind Language) const;
6134
6135 // Adds \p Style to this FormatStyleSet. Style must not have an associated
6136 // FormatStyleSet.
6137 // Style.Language should be different than LK_None. If this FormatStyleSet
6138 // already contains an entry for Style.Language, that gets replaced with the
6139 // passed Style.
6140 void Add(FormatStyle Style);
6141
6142 // Clears this FormatStyleSet.
6143 void Clear();
6144
6145 private:
6146 std::shared_ptr<MapType> Styles;
6147 };
6148
6150 const FormatStyle &MainStyle,
6151 const std::vector<FormatStyle> &ConfigurationStyles);
6152
6153private:
6154 FormatStyleSet StyleSet;
6155
6156 friend std::error_code
6157 parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
6158 bool AllowUnknownOptions,
6159 llvm::SourceMgr::DiagHandlerTy DiagHandler,
6160 void *DiagHandlerCtxt, bool IsDotHFile);
6161};
6162
6163/// Returns a format style complying with the LLVM coding standards:
6164/// http://llvm.org/docs/CodingStandards.html.
6165FormatStyle
6166getLLVMStyle(FormatStyle::LanguageKind Language = FormatStyle::LK_Cpp);
6167
6168/// Returns a format style complying with one of Google's style guides:
6169/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
6170/// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
6171/// https://developers.google.com/protocol-buffers/docs/style.
6172FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
6173
6174/// Returns a format style complying with Chromium's style guide:
6175/// http://www.chromium.org/developers/coding-style.
6176FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
6177
6178/// Returns a format style complying with Mozilla's style guide:
6179/// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html.
6180FormatStyle getMozillaStyle();
6181
6182/// Returns a format style complying with Webkit's style guide:
6183/// http://www.webkit.org/coding/coding-style.html
6184FormatStyle getWebKitStyle();
6185
6186/// Returns a format style complying with GNU Coding Standards:
6187/// http://www.gnu.org/prep/standards/standards.html
6188FormatStyle getGNUStyle();
6189
6190/// Returns a format style complying with Microsoft style guide:
6191/// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
6192FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language);
6193
6195
6196/// Returns style indicating formatting should be not applied at all.
6197FormatStyle getNoStyle();
6198
6199/// Gets a predefined style for the specified language by name.
6200///
6201/// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
6202/// compared case-insensitively.
6203///
6204/// Returns ``true`` if the Style has been set.
6205bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
6206 FormatStyle *Style);
6207
6208/// Parse configuration from YAML-formatted text.
6209///
6210/// Style->Language is used to get the base style, if the ``BasedOnStyle``
6211/// option is present.
6212///
6213/// The FormatStyleSet of Style is reset.
6214///
6215/// When ``BasedOnStyle`` is not present, options not present in the YAML
6216/// document, are retained in \p Style.
6217///
6218/// If AllowUnknownOptions is true, no errors are emitted if unknown
6219/// format options are occurred.
6220///
6221/// If set all diagnostics are emitted through the DiagHandler.
6222std::error_code
6223parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
6224 bool AllowUnknownOptions = false,
6225 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
6226 void *DiagHandlerCtx = nullptr, bool IsDotHFile = false);
6227
6228/// Like above but accepts an unnamed buffer.
6229inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
6230 bool AllowUnknownOptions = false,
6231 bool IsDotHFile = false) {
6232 return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
6233 AllowUnknownOptions, /*DiagHandler=*/nullptr,
6234 /*DiagHandlerCtx=*/nullptr, IsDotHFile);
6235}
6236
6237/// Gets configuration in a YAML string.
6238std::string configurationAsText(const FormatStyle &Style);
6239
6240/// Returns the replacements necessary to sort all ``#include`` blocks
6241/// that are affected by ``Ranges``.
6242tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
6244 StringRef FileName,
6245 unsigned *Cursor = nullptr);
6246
6247/// Returns the replacements corresponding to applying and formatting
6248/// \p Replaces on success; otheriwse, return an llvm::Error carrying
6249/// llvm::StringError.
6251formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
6252 const FormatStyle &Style);
6253
6254/// Returns the replacements corresponding to applying \p Replaces and
6255/// cleaning up the code after that on success; otherwise, return an llvm::Error
6256/// carrying llvm::StringError.
6257/// This also supports inserting/deleting C++ #include directives:
6258/// * If a replacement has offset UINT_MAX, length 0, and a replacement text
6259/// that is an #include directive, this will insert the #include into the
6260/// correct block in the \p Code.
6261/// * If a replacement has offset UINT_MAX, length 1, and a replacement text
6262/// that is the name of the header to be removed, the header will be removed
6263/// from \p Code if it exists.
6264/// The include manipulation is done via ``tooling::HeaderInclude``, see its
6265/// documentation for more details on how include insertion points are found and
6266/// what edits are produced.
6268cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
6269 const FormatStyle &Style);
6270
6271/// Represents the status of a formatting attempt.
6273 /// A value of ``false`` means that any of the affected ranges were not
6274 /// formatted due to a non-recoverable syntax error.
6275 bool FormatComplete = true;
6276
6277 /// If ``FormatComplete`` is false, ``Line`` records a one-based
6278 /// original line number at which a syntax error might have occurred. This is
6279 /// based on a best-effort analysis and could be imprecise.
6280 unsigned Line = 0;
6281};
6282
6283/// Reformats the given \p Ranges in \p Code.
6284///
6285/// Each range is extended on either end to its next bigger logic unit, i.e.
6286/// everything that might influence its formatting or might be influenced by its
6287/// formatting.
6288///
6289/// Returns the ``Replacements`` necessary to make all \p Ranges comply with
6290/// \p Style.
6291///
6292/// If ``Status`` is non-null, its value will be populated with the status of
6293/// this formatting attempt. See \c FormattingAttemptStatus.
6294tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
6296 StringRef FileName = "<stdin>",
6297 FormattingAttemptStatus *Status = nullptr);
6298
6299/// Same as above, except if ``IncompleteFormat`` is non-null, its value
6300/// will be set to true if any of the affected ranges were not formatted due to
6301/// a non-recoverable syntax error.
6302tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
6304 StringRef FileName, bool *IncompleteFormat);
6305
6306/// Clean up any erroneous/redundant code in the given \p Ranges in \p
6307/// Code.
6308///
6309/// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
6310tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
6312 StringRef FileName = "<stdin>");
6313
6314/// Fix namespace end comments in the given \p Ranges in \p Code.
6315///
6316/// Returns the ``Replacements`` that fix the namespace comments in all
6317/// \p Ranges in \p Code.
6318tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style,
6319 StringRef Code,
6321 StringRef FileName = "<stdin>");
6322
6323/// Inserts or removes empty lines separating definition blocks including
6324/// classes, structs, functions, namespaces, and enums in the given \p Ranges in
6325/// \p Code.
6326///
6327/// Returns the ``Replacements`` that inserts or removes empty lines separating
6328/// definition blocks in all \p Ranges in \p Code.
6329tooling::Replacements separateDefinitionBlocks(const FormatStyle &Style,
6330 StringRef Code,
6332 StringRef FileName = "<stdin>");
6333
6334/// Sort consecutive using declarations in the given \p Ranges in
6335/// \p Code.
6336///
6337/// Returns the ``Replacements`` that sort the using declarations in all
6338/// \p Ranges in \p Code.
6339tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
6340 StringRef Code,
6342 StringRef FileName = "<stdin>");
6343
6344/// Returns the ``LangOpts`` that the formatter expects you to set.
6345///
6346/// \param Style determines specific settings for lexing mode.
6347LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle());
6348
6349/// Description to be used for help text for a ``llvm::cl`` option for
6350/// specifying format style. The description is closely related to the operation
6351/// of ``getStyle()``.
6352extern const char *StyleOptionHelpDescription;
6353
6354/// The suggested format style to use by default. This allows tools using
6355/// ``getStyle`` to have a consistent default style.
6356/// Different builds can modify the value to the preferred styles.
6357extern const char *DefaultFormatStyle;
6358
6359/// The suggested predefined style to use as the fallback style in ``getStyle``.
6360/// Different builds can modify the value to the preferred styles.
6361extern const char *DefaultFallbackStyle;
6362
6363/// Construct a FormatStyle based on ``StyleName``.
6364///
6365/// ``StyleName`` can take several forms:
6366/// * "{<key>: <value>, ...}" - Set specic style parameters.
6367/// * "<style name>" - One of the style names supported by getPredefinedStyle().
6368/// * "file" - Load style configuration from a file called ``.clang-format``
6369/// located in one of the parent directories of ``FileName`` or the current
6370/// directory if ``FileName`` is empty.
6371/// * "file:<format_file_path>" to explicitly specify the configuration file to
6372/// use.
6373///
6374/// \param[in] StyleName Style name to interpret according to the description
6375/// above.
6376/// \param[in] FileName Path to start search for .clang-format if ``StyleName``
6377/// == "file".
6378/// \param[in] FallbackStyle The name of a predefined style used to fallback to
6379/// in case \p StyleName is "file" and no file can be found.
6380/// \param[in] Code The actual code to be formatted. Used to determine the
6381/// language if the filename isn't sufficient.
6382/// \param[in] FS The underlying file system, in which the file resides. By
6383/// default, the file system is the real file system.
6384/// \param[in] AllowUnknownOptions If true, unknown format options only
6385/// emit a warning. If false, errors are emitted on unknown format
6386/// options.
6387///
6388/// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
6389/// "file" and no file is found, returns ``FallbackStyle``. If no style could be
6390/// determined, returns an Error.
6392getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle,
6393 StringRef Code = "", llvm::vfs::FileSystem *FS = nullptr,
6394 bool AllowUnknownOptions = false,
6395 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr);
6396
6397// Guesses the language from the ``FileName`` and ``Code`` to be formatted.
6398// Defaults to FormatStyle::LK_Cpp.
6399FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
6400
6401// Returns a string representation of ``Language``.
6402inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
6403 switch (Language) {
6404 case FormatStyle::LK_C:
6405 return "C";
6406 case FormatStyle::LK_Cpp:
6407 return "C++";
6408 case FormatStyle::LK_CSharp:
6409 return "CSharp";
6410 case FormatStyle::LK_ObjC:
6411 return "Objective-C";
6412 case FormatStyle::LK_Java:
6413 return "Java";
6414 case FormatStyle::LK_JavaScript:
6415 return "JavaScript";
6416 case FormatStyle::LK_Json:
6417 return "Json";
6418 case FormatStyle::LK_Proto:
6419 return "Proto";
6420 case FormatStyle::LK_TableGen:
6421 return "TableGen";
6422 case FormatStyle::LK_TextProto:
6423 return "TextProto";
6424 case FormatStyle::LK_Verilog:
6425 return "Verilog";
6426 default:
6427 return "Unknown";
6428 }
6429}
6430
6431bool isClangFormatOn(StringRef Comment);
6432bool isClangFormatOff(StringRef Comment);
6433
6434} // end namespace format
6435} // end namespace clang
6436
6437template <>
6438struct std::is_error_code_enum<clang::format::ParseError> : std::true_type {};
6439
6440#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:6402
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:1586
std::string message(int EV) const override
Definition Format.cpp:1590
bool operator!=(const CommonEntityInfo &LHS, const CommonEntityInfo &RHS)
Definition Types.h:153
FormatStyle getWebKitStyle()
Definition Format.cpp:2228
tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, FormattingAttemptStatus *Status)
Definition Format.cpp:4318
tooling::Replacements sortUsingDeclarations(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName)
Definition Format.cpp:4361
std::error_code make_error_code(ParseError e)
Definition Format.cpp:1577
FormatStyle getClangFormatStyle()
Definition Format.cpp:2296
static std::string format(StringRef NumericLiteral, const FormatStyle &Style)
FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language)
Definition Format.cpp:1989
std::string configurationAsText(const FormatStyle &Style)
Definition Format.cpp:2479
FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language)
Definition Format.cpp:2267
const std::error_category & getParseCategory()
Definition Format.cpp:1573
FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code)
Definition Format.cpp:4503
tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName)
Definition Format.cpp:4351
tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName)
Definition Format.cpp:4329
FormatStyle getGNUStyle()
Definition Format.cpp:2252
bool isClangFormatOff(StringRef Comment)
Definition Format.cpp:4767
FormatStyle getMozillaStyle()
Definition Format.cpp:2201
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
Definition Format.cpp:2318
Expected< tooling::Replacements > cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
Definition Format.cpp:4096
tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, unsigned *Cursor)
Definition Format.cpp:3943
bool isClangFormatOn(StringRef Comment)
Definition Format.cpp:4763
FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language)
Definition Format.cpp:1744
Expected< FormatStyle > getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyleName, StringRef Code, llvm::vfs::FileSystem *FS, bool AllowUnknownOptions, llvm::SourceMgr::DiagHandlerTy DiagHandler)
Definition Format.cpp:4547
FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language)
Definition Format.cpp:2141
std::error_code parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style, bool AllowUnknownOptions, llvm::SourceMgr::DiagHandlerTy DiagHandler, void *DiagHandlerCtxt, bool IsDotHFile)
Definition Format.cpp:2383
Expected< tooling::Replacements > formatReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
Definition Format.cpp:3984
FormatStyle getNoStyle()
Definition Format.cpp:2310
LangOptions getFormattingLangOpts(const FormatStyle &Style)
Definition Format.cpp:4371
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:5771
unsigned ObjCBlockIndentWidth
The number of characters to use for indentation of ObjC blocks.
Definition Format.h:4130
bool ObjCBreakBeforeNestedBlockParam
Break parameters list into lines when there is nested block parameters in a function call.
Definition Format.h:4154
bool SpaceAfterTemplateKeyword
If true, a space will be inserted after the template keyword.
Definition Format.h:5049
WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines
Wrap namespace body with empty lines.
Definition Format.h:5905
ReferenceAlignmentStyle ReferenceAlignment
Reference alignment style (overrides PointerAlignment for references).
Definition Format.h:4528
ReflowCommentsStyle
Types of comment reflow style.
Definition Format.h:4532
@ RCS_IndentOnly
Only apply indentation rules, moving comments left or right, without changing formatting inside the c...
Definition Format.h:4549
@ RCS_Always
Apply indentation rules and reflow long comments into new lines, trying to obey the ColumnLimit.
Definition Format.h:4560
@ RCS_Never
Leave comments untouched.
Definition Format.h:4540
int PPIndentWidth
The number of columns to use for indentation of preprocessor statements. When set to -1 (default) Ind...
Definition Format.h:4371
SeparateDefinitionStyle
The style if definition blocks should be separated.
Definition Format.h:4829
@ SDS_Never
Remove any empty line between definition blocks.
Definition Format.h:4835
@ SDS_Always
Insert an empty line between definition blocks.
Definition Format.h:4833
@ SDS_Leave
Leave definition blocks as they are.
Definition Format.h:4831
SpacesInParensStyle SpacesInParens
If true, spaces will be inserted after ( and before ). This option is deprecated. The previous behavi...
Definition Format.h:5547
bool isJavaScript() const
Definition Format.h:3847
DAGArgStyle
Different ways to control the format inside TableGen DAGArg.
Definition Format.h:5742
@ DAS_BreakAll
Break inside DAGArg after the operator and the all elements.
Definition Format.h:5762
@ DAS_DontBreak
Never break inside DAGArg.
Definition Format.h:5747
@ DAS_BreakElements
Break inside DAGArg after each list element but for the last. This aligns to the first element.
Definition Format.h:5754
bool VerilogBreakBetweenInstancePorts
For Verilog, put each port on its own line in module instantiations.
Definition Format.h:5855
std::vector< std::string > JavaImportGroups
A vector of prefixes ordered by the desired groups for Java imports.
Definition Format.h:3673
unsigned PenaltyBreakTemplateDeclaration
The penalty for breaking after template declaration.
Definition Format.h:4320
SortJavaStaticImportOptions SortJavaStaticImport
When sorting Java imports, by default static imports are placed before non-static imports....
Definition Format.h:4973
RequiresClausePositionStyle
The possible positions for the requires clause. The IndentRequires option is only used if the require...
Definition Format.h:4701
@ RCPS_WithPreceding
Try to put the clause together with the preceding part of a declaration. For class templates: stick t...
Definition Format.h:4757
@ RCPS_SingleLine
Try to put everything in the same line if possible. Otherwise normal line breaking rules take over.
Definition Format.h:4795
@ RCPS_OwnLineWithBrace
As with OwnLine, except, unless otherwise prohibited, place a following open brace (of a function def...
Definition Format.h:4740
@ RCPS_OwnLine
Always put the requires clause on its own line (possibly followed by a semicolon).
Definition Format.h:4722
@ RCPS_WithFollowing
Try to put the requires clause together with the class or function declaration.
Definition Format.h:4771
std::vector< RawStringFormat > RawStringFormats
Defines hints for detecting supported languages code blocks in raw strings.
Definition Format.h:4503
UseTabStyle
This option is deprecated. See LF and CRLF of LineEnding.
Definition Format.h:5814
@ UT_ForContinuationAndIndentation
Fill all leading whitespace with tabs, and use spaces for alignment that appears within a line (e....
Definition Format.h:5821
@ UT_ForIndentation
Use tabs only for indentation.
Definition Format.h:5818
@ 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:5827
@ UT_AlignWithSpaces
Use tabs for line continuation and indentation, and spaces for alignment.
Definition Format.h:5824
@ UT_Never
Never use tab.
Definition Format.h:5816
bool ObjCSpaceAfterMethodDeclarationPrefix
Add or remove a space between the '-'/'+' and the return type in Objective-C method declarations....
Definition Format.h:4187
LanguageStandard Standard
Parse and format C++ constructs compatible with this standard.
Definition Format.h:5686
bool isTableGen() const
Definition Format.h:3851
bool isProto() const
Definition Format.h:3850
PointerAlignmentStyle
The &, && and * alignment style.
Definition Format.h:4336
@ PAS_Right
Align pointer to the right.
Definition Format.h:4346
@ PAS_Middle
Align pointer in the middle.
Definition Format.h:4351
@ PAS_Left
Align pointer to the left.
Definition Format.h:4341
bool isJava() const
Definition Format.h:3846
bool isTextProto() const
Definition Format.h:3849
SpaceBeforeParensCustom SpaceBeforeParensOptions
Control of individual space before parentheses.
Definition Format.h:5344
std::vector< std::string > Macros
A list of macros of the form <definition>=<expansion> .
Definition Format.h:3949
RequiresExpressionIndentationKind RequiresExpressionIndentation
The indentation used for requires expression bodies.
Definition Format.h:4826
SpaceInEmptyBracesStyle SpaceInEmptyBraces
Specifies when to insert a space in empty braces.
Definition Format.h:5403
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:5518
bool SkipMacroDefinitionBody
Do not format macro definition body.
Definition Format.h:4910
PointerAlignmentStyle PointerAlignment
Pointer and reference alignment style.
Definition Format.h:4356
std::optional< FormatStyle > GetLanguageStyle(LanguageKind Language) const
PackConstructorInitializersStyle
Different ways to try to fit all constructor initializers on a line.
Definition Format.h:4225
@ PCIS_CurrentLine
Put all constructor initializers on the current line if they fit. Otherwise, put each one on its own ...
Definition Format.h:4250
@ PCIS_Never
Always put each constructor initializer on its own line.
Definition Format.h:4232
@ PCIS_BinPack
Bin-pack constructor initializers.
Definition Format.h:4239
@ PCIS_NextLine
Same as PCIS_CurrentLine except that if all constructor initializers do not fit on the current line,...
Definition Format.h:4264
@ PCIS_NextLineOnly
Put all constructor initializers on the next line if they fit. Otherwise, put each one on its own lin...
Definition Format.h:4279
bool SpaceBeforeRangeBasedForLoopColon
If false, spaces will be removed before range-based for loop colon.
Definition Format.h:5363
unsigned PenaltyReturnTypeOnItsOwnLine
Penalty for putting the return type of a function onto its own line.
Definition Format.h:4333
bool SpaceBeforeCaseColon
If false, spaces will be removed before case colon.
Definition Format.h:5101
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:5703
SpacesInParensStyle
Different ways to put a space before opening and closing parentheses.
Definition Format.h:5521
@ SIPO_Never
Never put a space in parentheses.
Definition Format.h:5530
@ SIPO_Custom
Configure each individual space in parentheses in SpacesInParensOptions.
Definition Format.h:5533
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:3700
NumericLiteralComponentStyle
Control over each component in a numeric literal.
Definition Format.h:4022
@ NLCS_Leave
Leave this component of the literal as is.
Definition Format.h:4024
@ NLCS_Upper
Format this component with uppercase characters.
Definition Format.h:4026
@ NLCS_Lower
Format this component with lowercase characters.
Definition Format.h:4028
RequiresExpressionIndentationKind
Indentation logic for requires expression bodies.
Definition Format.h:4803
@ REI_Keyword
Align requires expression body relative to the requires keyword.
Definition Format.h:4821
@ REI_OuterScope
Align requires expression body relative to the indentation level of the outer scope the requires expr...
Definition Format.h:4813
SpaceBeforeParensStyle
Different ways to put a space before opening parentheses.
Definition Format.h:5152
@ SBPO_ControlStatementsExceptControlMacros
Same as SBPO_ControlStatements except this option doesn't apply to ForEach and If macros....
Definition Format.h:5179
@ SBPO_ControlStatements
Put a space before opening parentheses only after control statement keywords (for/if/while....
Definition Format.h:5166
@ SBPO_Always
Always put a space before opening parentheses, except when it's prohibited by the syntax rules (in fu...
Definition Format.h:5202
@ SBPO_Never
This is deprecated and replaced by Custom below, with all SpaceBeforeParensOptions but AfterPlacement...
Definition Format.h:5156
@ SBPO_Custom
Configure each individual space before parentheses in SpaceBeforeParensOptions.
Definition Format.h:5205
@ SBPO_NonEmptyParentheses
Put a space before opening parentheses only if the parentheses are not empty.
Definition Format.h:5190
std::vector< std::string > WhitespaceSensitiveMacros
A vector of macros which are whitespace-sensitive and should not be touched.
Definition Format.h:5872
bool SpaceAfterOperatorKeyword
If true, a space will be inserted after the operator keyword.
Definition Format.h:5041
bool ObjCSpaceAfterProperty
Add a space after @property in Objective-C, i.e. use @property (readonly) instead of @property(readon...
Definition Format.h:4192
ReflowCommentsStyle ReflowComments
Comment reformatting style.
Definition Format.h:4566
std::vector< std::string > TypeNames
A vector of non-keyword identifiers that should be interpreted as type names.
Definition Format.h:5790
LineEndingStyle
Line ending style.
Definition Format.h:3863
@ LE_DeriveCRLF
Use \r\n unless the input has more lines ending in \n.
Definition Format.h:3871
@ LE_CRLF
Use \r\n.
Definition Format.h:3867
@ LE_LF
Use \n.
Definition Format.h:3865
@ LE_DeriveLF
Use \n unless the input has more lines ending in \r\n.
Definition Format.h:3869
SpacesInAnglesStyle
Styles for adding spacing after < and before > in template argument lists.
Definition Format.h:5433
@ SIAS_Always
Add spaces after < and before >.
Definition Format.h:5445
@ SIAS_Never
Remove spaces after < and before >.
Definition Format.h:5439
@ SIAS_Leave
Keep a single space after < and before > if any spaces were present. Option Standard: Cpp03 takes pre...
Definition Format.h:5448
IntegerLiteralSeparatorStyle IntegerLiteralSeparator
Format integer literal separators (' for C/C++ and _ for C#, Java, and JavaScript).
Definition Format.h:3639
std::vector< std::string > TableGenBreakingDAGArgOperators
Works only when TableGenBreakInsideDAGArg is not DontBreak. The string list needs to consist of ident...
Definition Format.h:5739
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:5113
unsigned PenaltyExcessCharacter
The penalty for each character outside of the column limit.
Definition Format.h:4324
SortJavaStaticImportOptions
Position for Java Static imports.
Definition Format.h:4952
@ SJSIO_After
Static imports are placed after non-static imports.
Definition Format.h:4966
@ SJSIO_Before
Static imports are placed before non-static imports.
Definition Format.h:4959
NamespaceIndentationKind NamespaceIndentation
The indentation used for namespaces.
Definition Format.h:4006
bool SpaceBeforeSquareBrackets
If true, spaces will be before [. Lambdas will not be affected. Only the first [ will get a space add...
Definition Format.h:5354
bool RemoveSemicolon
Remove semicolons after the closing braces of functions and constructors/destructors.
Definition Format.h:4697
Language
The language for the input, used to select and validate the language standard and possible actions.
bool isCpp() const
Definition Format.h:3841
bool isCSharp() const
Definition Format.h:3844
bool SpaceBeforeAssignmentOperators
If false, spaces will be removed before assignment operators.
Definition Format.h:5091
unsigned PenaltyBreakComment
The penalty for each line break introduced inside a comment.
Definition Format.h:4300
QualifierAlignmentStyle
Different specifiers and qualifiers alignment styles.
Definition Format.h:4374
@ QAS_Custom
Change specifiers/qualifiers to be aligned based on QualifierOrder. With:
Definition Format.h:4405
@ QAS_Leave
Don't change specifiers/qualifiers to either Left or Right alignment (default).
Definition Format.h:4381
@ QAS_Left
Change specifiers/qualifiers to be left-aligned.
Definition Format.h:4387
@ QAS_Right
Change specifiers/qualifiers to be right-aligned.
Definition Format.h:4393
SpacesInParensCustom SpacesInParensOptions
Control of individual spaces in parentheses.
Definition Format.h:5640
SpacesInAnglesStyle SpacesInAngles
The SpacesInAnglesStyle to use for template argument lists.
Definition Format.h:5452
BinPackStyle ObjCBinPackProtocolList
Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when t...
Definition Format.h:4119
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:4197
bool SpacesInContainerLiterals
If true, spaces will be inserted around if/for/switch/while conditions. This option is deprecated....
Definition Format.h:5470
std::string OneLineFormatOffRegex
A regular expression that describes markers for turning formatting off for one line....
Definition Format.h:4222
RemoveParenthesesStyle RemoveParentheses
Remove redundant parentheses.
Definition Format.h:4679
UseTabStyle UseTab
The way to use tab characters in the resulting file.
Definition Format.h:5832
std::vector< std::string > ObjCPropertyAttributeOrder
The order in which ObjC property attributes should appear.
Definition Format.h:4177
std::string MacroBlockBegin
A regular expression matching macros that start a block.
Definition Format.h:3905
unsigned PenaltyBreakString
The penalty for each line break introduced inside a string literal.
Definition Format.h:4316
unsigned PenaltyBreakOpenParenthesis
The penalty for breaking after (.
Definition Format.h:4308
WrapNamespaceBodyWithEmptyLinesStyle
Different styles for wrapping namespace body with empty lines.
Definition Format.h:5875
@ WNBWELS_Never
Remove all empty lines at the beginning and the end of namespace body.
Definition Format.h:5884
@ 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:5897
@ WNBWELS_Leave
Keep existing newlines at the beginning and the end of namespace body. MaxEmptyLinesToKeep still appl...
Definition Format.h:5900
unsigned PenaltyBreakBeforeFirstCallParameter
The penalty for breaking a function call after call(.
Definition Format.h:4292
LambdaBodyIndentationKind
Indentation logic for lambda bodies.
Definition Format.h:3773
@ LBI_Signature
Align lambda body relative to the lambda signature. This is the default.
Definition Format.h:3781
@ LBI_OuterScope
For statements within block scope, align lambda body relative to the indentation level of the outer s...
Definition Format.h:3795
bool isJson() const
Definition Format.h:3845
unsigned PenaltyBreakFirstLessLess
The penalty for breaking before the first <<.
Definition Format.h:4304
std::vector< std::string > MacrosSkippedByRemoveParentheses
A vector of function-like macros whose invocations should be skipped by RemoveParentheses.
Definition Format.h:3954
RequiresClausePositionStyle RequiresClausePosition
The position of the requires clause.
Definition Format.h:4800
bool SpaceBeforeJsonColon
If true, a space will be added before a JSON colon. For other languages, e.g. JavaScript,...
Definition Format.h:5149
bool JavaScriptWrapImports
Whether to wrap JavaScript import/export statements.
Definition Format.h:3716
bool SpaceBeforeInheritanceColon
If false, spaces will be removed before inheritance colon.
Definition Format.h:5138
SpaceInEmptyBracesStyle
This option is deprecated. See Block of SpaceInEmptyBraces.
Definition Format.h:5370
@ SIEB_Block
Only insert a space in empty blocks.
Definition Format.h:5386
@ SIEB_Always
Always insert a space in empty braces.
Definition Format.h:5378
@ SIEB_Never
Never insert a space in empty braces.
Definition Format.h:5394
std::vector< std::string > TypenameMacros
A vector of macros that should be interpreted as type declarations instead of as function calls.
Definition Format.h:5807
LanguageStandard
Supported language standards for parsing and formatting C++ constructs.
Definition Format.h:5661
@ LS_Cpp03
Parse and format as C++03. Cpp03 is a deprecated alias for c++03
Definition Format.h:5664
@ LS_Cpp14
Parse and format as C++14.
Definition Format.h:5668
@ LS_Cpp17
Parse and format as C++17.
Definition Format.h:5670
@ LS_Cpp11
Parse and format as C++11.
Definition Format.h:5666
@ LS_Auto
Automatic detection based on the input.
Definition Format.h:5677
@ LS_Latest
Parse and format using the latest supported language version. Cpp11 is a deprecated alias for Latest
Definition Format.h:5675
@ LS_Cpp20
Parse and format as C++20.
Definition Format.h:5672
KeepEmptyLinesStyle KeepEmptyLines
Which empty lines are kept. See MaxEmptyLinesToKeep for how many consecutive empty lines are kept.
Definition Format.h:3753
bool SpaceBeforeEnumUnderlyingTypeColon
If false, spaces will be removed before enum underlying type colon.
Definition Format.h:5130
bool isVerilog() const
Definition Format.h:3848
SortUsingDeclarationsOptions
Using declaration sorting options.
Definition Format.h:4976
@ SUD_LexicographicNumeric
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition Format.h:5012
@ SUD_Never
Using declarations are never sorted.
Definition Format.h:4985
@ SUD_Lexicographic
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition Format.h:4997
unsigned PenaltyBreakScopeResolution
The penalty for breaking after ::.
Definition Format.h:4312
DAGArgStyle TableGenBreakInsideDAGArg
The styles of the line break inside the DAGArg in TableGen.
Definition Format.h:5767
LambdaBodyIndentationKind LambdaBodyIndentation
The indentation style of lambda bodies. Signature (the default) causes the lambda body to be indented...
Definition Format.h:3804
NamespaceIndentationKind
Different ways to indent namespace contents.
Definition Format.h:3971
@ NI_None
Don't indent in namespaces.
Definition Format.h:3981
@ NI_All
Indent in all namespaces.
Definition Format.h:4001
@ NI_Inner
Indent only in inner namespaces (nested in other namespaces).
Definition Format.h:3991
SeparateDefinitionStyle SeparateDefinitionBlocks
Specifies the use of empty lines to separate definition blocks, including classes,...
Definition Format.h:4884
bool SpaceAfterCStyleCast
If true, a space is inserted after C style casts.
Definition Format.h:5025
SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers
Defines in which cases to put a space before or after pointer qualifiers.
Definition Format.h:5082
SpaceAroundPointerQualifiersStyle
Different ways to put a space before opening parentheses.
Definition Format.h:5052
@ SAPQ_Both
Ensure that there is a space both before and after pointer qualifiers.
Definition Format.h:5077
@ SAPQ_Default
Don't ensure spaces around pointer qualifiers and use PointerAlignment instead.
Definition Format.h:5059
@ SAPQ_Before
Ensure that there is a space before pointer qualifiers.
Definition Format.h:5065
@ SAPQ_After
Ensure that there is a space after pointer qualifiers.
Definition Format.h:5071
std::vector< std::string > TemplateNames
A vector of non-keyword identifiers that should be interpreted as template names.
Definition Format.h:5780
bool SpacesInSquareBrackets
If true, spaces will be inserted after [ and before ]. Lambdas without arguments or unspecified size ...
Definition Format.h:5651
std::vector< std::string > StatementMacros
A vector of macros that should be interpreted as complete statements.
Definition Format.h:5713
RemoveParenthesesStyle
Types of redundant parentheses to remove.
Definition Format.h:4646
@ RPS_ReturnStatement
Also remove parentheses enclosing the expression in a return/co_return statement.
Definition Format.h:4668
@ RPS_MultipleParentheses
Replace multiple parentheses with single parentheses.
Definition Format.h:4660
@ RPS_Leave
Do not remove parentheses.
Definition Format.h:4653
std::vector< std::string > NamespaceMacros
A vector of macros which are used to open namespace blocks.
Definition Format.h:4019
unsigned PenaltyBreakBeforeMemberAccess
The penalty for breaking before a member access operator (., ->).
Definition Format.h:4296
LineEndingStyle LineEnding
Line ending style (\n or \r\n) to use.
Definition Format.h:3876
unsigned SpacesBeforeTrailingComments
If true, spaces may be inserted into (). This option is deprecated. See InEmptyParentheses of SpacesI...
Definition Format.h:5429
bool RemoveEmptyLinesInUnwrappedLines
Remove empty lines within unwrapped lines.
Definition Format.h:4643
unsigned MaxEmptyLinesToKeep
The maximum number of consecutive empty lines to keep.
Definition Format.h:3968
PackConstructorInitializersStyle PackConstructorInitializers
The pack constructor initializers style to use.
Definition Format.h:4284
SortIncludesOptions SortIncludes
Controls if and how clang-format will sort #includes.
Definition Format.h:4949
bool SpaceAfterLogicalNot
If true, a space is inserted after the logical not operator (!).
Definition Format.h:5033
bool KeepFormFeed
This option is deprecated. See AtEndOfFile of KeepEmptyLines.
Definition Format.h:3770
std::string MacroBlockEnd
A regular expression matching macros that end a block.
Definition Format.h:3909
unsigned ShortNamespaceLines
The maximal number of unwrapped lines that a short namespace spans. Defaults to 1.
Definition Format.h:4906
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:4443
bool RemoveBracesLLVM
Remove optional braces of control statements (if, else, for, and while) in C++ according to the LLVM ...
Definition Format.h:4620
ReferenceAlignmentStyle
The & and && alignment style.
Definition Format.h:4506
@ RAS_Middle
Align reference in the middle.
Definition Format.h:4523
@ RAS_Right
Align reference to the right.
Definition Format.h:4518
@ RAS_Pointer
Align reference like PointerAlignment.
Definition Format.h:4508
@ RAS_Left
Align reference to the left.
Definition Format.h:4513
bool SpaceBeforeCtorInitializerColon
If false, spaces will be removed before constructor initializer colon.
Definition Format.h:5122
unsigned PenaltyBreakAssignment
The penalty for breaking around an assignment operator.
Definition Format.h:4288
QualifierAlignmentStyle QualifierAlignment
Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
Definition Format.h:4417
LanguageKind
Supported languages.
Definition Format.h:3811
@ LK_Java
Should be used for Java.
Definition Format.h:3821
@ LK_Cpp
Should be used for C++.
Definition Format.h:3817
@ LK_TableGen
Should be used for TableGen code.
Definition Format.h:3832
@ LK_ObjC
Should be used for Objective-C, Objective-C++.
Definition Format.h:3827
@ LK_CSharp
Should be used for C#.
Definition Format.h:3819
@ LK_TextProto
Should be used for Protocol Buffer messages in text format (https://developers.google....
Definition Format.h:3835
@ LK_Json
Should be used for JSON.
Definition Format.h:3825
@ LK_JavaScript
Should be used for JavaScript.
Definition Format.h:3823
@ LK_Verilog
Should be used for Verilog and SystemVerilog. https://standards.ieee.org/ieee/1800/6700/ https://sci-...
Definition Format.h:3839
@ LK_C
Should be used for C.
Definition Format.h:3815
@ LK_None
Do not use.
Definition Format.h:3813
@ LK_Proto
Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).
Definition Format.h:3830
@ Other
Other implicit parameter.
Definition Decl.h:1761
std::vector< std::string > VariableTemplates
A vector of non-keyword identifiers that should be interpreted as variable template names.
Definition Format.h:5841
SortUsingDeclarationsOptions SortUsingDeclarations
Controls if and how clang-format will sort using declarations.
Definition Format.h:5017
unsigned PenaltyIndentedWhitespace
Penalty for each character of whitespace indentation (counted relative to leading non-whitespace colu...
Definition Format.h:4329
static FormatStyleSet BuildStyleSetFromConfiguration(const FormatStyle &MainStyle, const std::vector< FormatStyle > &ConfigurationStyles)
NumericLiteralCaseStyle NumericLiteralCase
Capitalization style for numeric literals.
Definition Format.h:4086
JavaScriptQuoteStyle
Quotation styles for JavaScript strings. Does not affect template strings.
Definition Format.h:3677
@ JSQS_Double
Always use double quotes.
Definition Format.h:3695
@ JSQS_Leave
Leave string quotes as they are.
Definition Format.h:3683
@ JSQS_Single
Always use single quotes.
Definition Format.h:3689
SpaceBeforeParensStyle SpaceBeforeParens
Defines in which cases to put a space before opening parentheses.
Definition Format.h:5210
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:6272
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:6275
unsigned Line
If FormatComplete is false, Line records a one-based original line number at which a syntax error mig...
Definition Format.h:6280
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:6131
Options regarding which empty lines are kept.
Definition Format.h:3730
bool AtStartOfBlock
Keep empty lines at start of a block.
Definition Format.h:3741
bool AtStartOfFile
Keep empty lines at start of file.
Definition Format.h:3743
bool AtEndOfFile
Keep empty lines at end of file.
Definition Format.h:3732
bool operator==(const KeepEmptyLinesStyle &R) const
Definition Format.h:3744
Separate control for each numeric literal component.
Definition Format.h:4043
bool operator==(const NumericLiteralCaseStyle &R) const
Definition Format.h:4074
bool operator!=(const NumericLiteralCaseStyle &R) const
Definition Format.h:4079
NumericLiteralComponentStyle ExponentLetter
Format floating point exponent separator letter case.
Definition Format.h:4050
NumericLiteralComponentStyle Suffix
Format suffix case. This option excludes case-sensitive reserved suffixes, such as min in C++.
Definition Format.h:4072
NumericLiteralComponentStyle Prefix
Format integer prefix case.
Definition Format.h:4064
NumericLiteralComponentStyle HexDigit
Format hexadecimal digit case.
Definition Format.h:4057
See documentation of RawStringFormats.
Definition Format.h:4446
std::string CanonicalDelimiter
The canonical delimiter for this language.
Definition Format.h:4454
std::vector< std::string > Delimiters
A list of raw string delimiters that match this language.
Definition Format.h:4450
std::vector< std::string > EnclosingFunctions
A list of enclosing function names that match this language.
Definition Format.h:4452
bool operator==(const RawStringFormat &Other) const
Definition Format.h:4459
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:4458
LanguageKind Language
The language of this raw string.
Definition Format.h:4448
Includes sorting options.
Definition Format.h:4913
bool operator!=(const SortIncludesOptions &R) const
Definition Format.h:4942
bool IgnoreCase
Whether or not includes are sorted in a case-insensitive fashion. (CaseSensitive and CaseInsensitive ...
Definition Format.h:4928
bool IgnoreExtension
When sorting includes in each block, only take file extensions into account if two includes compare e...
Definition Format.h:4937
bool operator==(const SortIncludesOptions &R) const
Definition Format.h:4938
bool Enabled
If true, includes are sorted based on the other suboptions below. (Never is deprecated by Enabled: fa...
Definition Format.h:4916
Precise control over the spacing before parentheses.
Definition Format.h:5220
bool AfterFunctionDefinitionName
If true, put a space between function definition name and opening parentheses.
Definition Format.h:5248
bool AfterIfMacros
If true, put space between if macros and opening parentheses.
Definition Format.h:5255
bool AfterForeachMacros
If true, put space between foreach macros and opening parentheses.
Definition Format.h:5234
bool AfterFunctionDeclarationName
If true, put a space between function declaration name and opening parentheses.
Definition Format.h:5241
bool operator==(const SpaceBeforeParensCustom &Other) const
Definition Format.h:5315
bool AfterControlStatements
If true, put space between control statement keywords (for/if/while...) and opening parentheses.
Definition Format.h:5227
bool BeforeNonEmptyParentheses
If true, put a space before opening parentheses only if the parentheses are not empty.
Definition Format.h:5305
bool AfterPlacementOperator
If true, put a space between operator new/delete and opening parenthesis.
Definition Format.h:5278
bool AfterRequiresInExpression
If true, put space between requires keyword in a requires expression and opening parentheses.
Definition Format.h:5297
bool AfterNot
If true, put a space between alternative operator not and the opening parenthesis.
Definition Format.h:5262
bool AfterRequiresInClause
If true, put space between requires keyword in a requires clause and opening parentheses,...
Definition Format.h:5287
bool AfterOverloadedOperator
If true, put a space between operator overloading and opening parentheses.
Definition Format.h:5270
If true, spaces may be inserted into C style casts. This option is deprecated. See InCStyleCasts of S...
Definition Format.h:5479
unsigned Maximum
The maximum number of spaces at the start of the comment.
Definition Format.h:5483
unsigned Minimum
The minimum number of spaces at the start of the comment.
Definition Format.h:5481
Precise control over the spacing in parentheses.
Definition Format.h:5558
bool Other
Put a space in parentheses not covered by preceding options.
Definition Format.h:5601
bool InCStyleCasts
Put a space in C style casts.
Definition Format.h:5584
bool operator!=(const SpacesInParensCustom &R) const
Definition Format.h:5621
bool InConditionalStatements
Put a space in parentheses only inside conditional statements (for/if/while/switch....
Definition Format.h:5577
bool InEmptyParentheses
Insert a space in empty parentheses, i.e. ().
Definition Format.h:5595
bool ExceptDoubleParentheses
Override any of the following options to prevent addition of space when both opening and closing pare...
Definition Format.h:5569
SpacesInParensCustom(bool ExceptDoubleParentheses, bool InConditionalStatements, bool InCStyleCasts, bool InEmptyParentheses, bool Other)
Definition Format.h:5607
bool operator==(const SpacesInParensCustom &R) const
Definition Format.h:5615