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