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