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