clang  10.0.0svn
Format.h
Go to the documentation of this file.
1 //===--- Format.h - Format C++ code -----------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Various functions to configurably format source code.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_FORMAT_FORMAT_H
15 #define LLVM_CLANG_FORMAT_FORMAT_H
16 
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/Support/Regex.h"
22 #include <system_error>
23 
24 namespace llvm {
25 namespace vfs {
26 class FileSystem;
27 }
28 } // namespace llvm
29 
30 namespace clang {
31 
32 class Lexer;
33 class SourceManager;
34 class DiagnosticConsumer;
35 
36 namespace format {
37 
38 enum class ParseError { Success = 0, Error, Unsuitable };
39 class ParseErrorCategory final : public std::error_category {
40 public:
41  const char *name() const noexcept override;
42  std::string message(int EV) const override;
43 };
44 const std::error_category &getParseCategory();
45 std::error_code make_error_code(ParseError e);
46 
47 /// The ``FormatStyle`` is used to configure the formatting to follow
48 /// specific guidelines.
49 struct FormatStyle {
50  /// The extra indent or outdent of access modifiers, e.g. ``public:``.
52 
53  /// Different styles for aligning after open brackets.
55  /// Align parameters on the open bracket, e.g.:
56  /// \code
57  /// someLongFunction(argument1,
58  /// argument2);
59  /// \endcode
61  /// Don't align, instead use ``ContinuationIndentWidth``, e.g.:
62  /// \code
63  /// someLongFunction(argument1,
64  /// argument2);
65  /// \endcode
67  /// Always break after an open bracket, if the parameters don't fit
68  /// on a single line, e.g.:
69  /// \code
70  /// someLongFunction(
71  /// argument1, argument2);
72  /// \endcode
74  };
75 
76  /// If ``true``, horizontally aligns arguments after an open bracket.
77  ///
78  /// This applies to round brackets (parentheses), angle brackets and square
79  /// brackets.
81 
82  /// \brief If ``true``, aligns consecutive C/C++ preprocessor macros.
83  ///
84  /// This will align C/C++ preprocessor macros of consecutive lines.
85  /// Will result in formattings like
86  /// \code
87  /// #define SHORT_NAME 42
88  /// #define LONGER_NAME 0x007f
89  /// #define EVEN_LONGER_NAME (2)
90  /// #define foo(x) (x * x)
91  /// #define bar(y, z) (y + z)
92  /// \endcode
94 
95  /// If ``true``, aligns consecutive assignments.
96  ///
97  /// This will align the assignment operators of consecutive lines. This
98  /// will result in formattings like
99  /// \code
100  /// int aaaa = 12;
101  /// int b = 23;
102  /// int ccc = 23;
103  /// \endcode
105 
106  /// If ``true``, aligns consecutive declarations.
107  ///
108  /// This will align the declaration names of consecutive lines. This
109  /// will result in formattings like
110  /// \code
111  /// int aaaa = 12;
112  /// float b = 23;
113  /// std::string ccc = 23;
114  /// \endcode
116 
117  /// Different styles for aligning escaped newlines.
119  /// Don't align escaped newlines.
120  /// \code
121  /// #define A \
122  /// int aaaa; \
123  /// int b; \
124  /// int dddddddddd;
125  /// \endcode
127  /// Align escaped newlines as far left as possible.
128  /// \code
129  /// true:
130  /// #define A \
131  /// int aaaa; \
132  /// int b; \
133  /// int dddddddddd;
134  ///
135  /// false:
136  /// \endcode
138  /// Align escaped newlines in the right-most column.
139  /// \code
140  /// #define A \
141  /// int aaaa; \
142  /// int b; \
143  /// int dddddddddd;
144  /// \endcode
146  };
147 
148  /// Options for aligning backslashes in escaped newlines.
150 
151  /// If ``true``, horizontally align operands of binary and ternary
152  /// expressions.
153  ///
154  /// Specifically, this aligns operands of a single expression that needs to be
155  /// split over multiple lines, e.g.:
156  /// \code
157  /// int aaa = bbbbbbbbbbbbbbb +
158  /// ccccccccccccccc;
159  /// \endcode
161 
162  /// If ``true``, aligns trailing comments.
163  /// \code
164  /// true: false:
165  /// int a; // My comment a vs. int a; // My comment a
166  /// int b = 2; // comment b int b = 2; // comment about b
167  /// \endcode
169 
170  /// \brief If a function call or braced initializer list doesn't fit on a
171  /// line, allow putting all arguments onto the next line, even if
172  /// ``BinPackArguments`` is ``false``.
173  /// \code
174  /// true:
175  /// callFunction(
176  /// a, b, c, d);
177  ///
178  /// false:
179  /// callFunction(a,
180  /// b,
181  /// c,
182  /// d);
183  /// \endcode
185 
186  /// \brief If a constructor definition with a member initializer list doesn't
187  /// fit on a single line, allow putting all member initializers onto the next
188  /// line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true.
189  /// Note that this parameter has no effect if
190  /// ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is false.
191  /// \code
192  /// true:
193  /// MyClass::MyClass() :
194  /// member0(0), member1(2) {}
195  ///
196  /// false:
197  /// MyClass::MyClass() :
198  /// member0(0),
199  /// member1(2) {}
200  bool AllowAllConstructorInitializersOnNextLine;
201 
202  /// If the function declaration doesn't fit on a line,
203  /// allow putting all parameters of a function declaration onto
204  /// the next line even if ``BinPackParameters`` is ``false``.
205  /// \code
206  /// true:
207  /// void myFunction(
208  /// int a, int b, int c, int d, int e);
209  ///
210  /// false:
211  /// void myFunction(int a,
212  /// int b,
213  /// int c,
214  /// int d,
215  /// int e);
216  /// \endcode
217  bool AllowAllParametersOfDeclarationOnNextLine;
218 
219  /// Different styles for merging short blocks containing at most one
220  /// statement.
221  enum ShortBlockStyle {
222  /// Never merge blocks into a single line.
223  /// \code
224  /// while (true) {
225  /// }
226  /// while (true) {
227  /// continue;
228  /// }
229  /// \endcode
230  SBS_Never,
231  /// Only merge empty blocks.
232  /// \code
233  /// while (true) {}
234  /// while (true) {
235  /// continue;
236  /// }
237  /// \endcode
238  SBS_Empty,
239  /// Always merge short blocks into a single line.
240  /// \code
241  /// while (true) {}
242  /// while (true) { continue; }
243  /// \endcode
244  SBS_Always,
245  };
246 
247  /// Dependent on the value, ``while (true) { continue; }`` can be put on a
248  /// single line.
249  ShortBlockStyle AllowShortBlocksOnASingleLine;
250 
251  /// If ``true``, short case labels will be contracted to a single line.
252  /// \code
253  /// true: false:
254  /// switch (a) { vs. switch (a) {
255  /// case 1: x = 1; break; case 1:
256  /// case 2: return; x = 1;
257  /// } break;
258  /// case 2:
259  /// return;
260  /// }
261  /// \endcode
262  bool AllowShortCaseLabelsOnASingleLine;
263 
264  /// Different styles for merging short functions containing at most one
265  /// statement.
266  enum ShortFunctionStyle {
267  /// Never merge functions into a single line.
268  SFS_None,
269  /// Only merge functions defined inside a class. Same as "inline",
270  /// except it does not implies "empty": i.e. top level empty functions
271  /// are not merged either.
272  /// \code
273  /// class Foo {
274  /// void f() { foo(); }
275  /// };
276  /// void f() {
277  /// foo();
278  /// }
279  /// void f() {
280  /// }
281  /// \endcode
282  SFS_InlineOnly,
283  /// Only merge empty functions.
284  /// \code
285  /// void f() {}
286  /// void f2() {
287  /// bar2();
288  /// }
289  /// \endcode
290  SFS_Empty,
291  /// Only merge functions defined inside a class. Implies "empty".
292  /// \code
293  /// class Foo {
294  /// void f() { foo(); }
295  /// };
296  /// void f() {
297  /// foo();
298  /// }
299  /// void f() {}
300  /// \endcode
301  SFS_Inline,
302  /// Merge all functions fitting on a single line.
303  /// \code
304  /// class Foo {
305  /// void f() { foo(); }
306  /// };
307  /// void f() { bar(); }
308  /// \endcode
309  SFS_All,
310  };
311 
312  /// Dependent on the value, ``int f() { return 0; }`` can be put on a
313  /// single line.
314  ShortFunctionStyle AllowShortFunctionsOnASingleLine;
315 
316  /// Different styles for handling short if lines
317  enum ShortIfStyle {
318  /// Never put short ifs on the same line.
319  /// \code
320  /// if (a)
321  /// return ;
322  /// else {
323  /// return;
324  /// }
325  /// \endcode
326  SIS_Never,
327  /// Without else put short ifs on the same line only if
328  /// the else is not a compound statement.
329  /// \code
330  /// if (a) return;
331  /// else
332  /// return;
333  /// \endcode
334  SIS_WithoutElse,
335  /// Always put short ifs on the same line if
336  /// the else is not a compound statement or not.
337  /// \code
338  /// if (a) return;
339  /// else {
340  /// return;
341  /// }
342  /// \endcode
343  SIS_Always,
344  };
345 
346  /// If ``true``, ``if (a) return;`` can be put on a single line.
347  ShortIfStyle AllowShortIfStatementsOnASingleLine;
348 
349  /// Different styles for merging short lambdas containing at most one
350  /// statement.
351  enum ShortLambdaStyle {
352  /// Never merge lambdas into a single line.
353  SLS_None,
354  /// Only merge empty lambdas.
355  /// \code
356  /// auto lambda = [](int a) {}
357  /// auto lambda2 = [](int a) {
358  /// return a;
359  /// };
360  /// \endcode
361  SLS_Empty,
362  /// Merge lambda into a single line if argument of a function.
363  /// \code
364  /// auto lambda = [](int a) {
365  /// return a;
366  /// };
367  /// sort(a.begin(), a.end(), ()[] { return x < y; })
368  /// \endcode
369  SLS_Inline,
370  /// Merge all lambdas fitting on a single line.
371  /// \code
372  /// auto lambda = [](int a) {}
373  /// auto lambda2 = [](int a) { return a; };
374  /// \endcode
375  SLS_All,
376  };
377 
378  /// Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
379  /// single line.
380  ShortLambdaStyle AllowShortLambdasOnASingleLine;
381 
382  /// If ``true``, ``while (true) continue;`` can be put on a single
383  /// line.
384  bool AllowShortLoopsOnASingleLine;
385 
386  /// Different ways to break after the function definition return type.
387  /// This option is **deprecated** and is retained for backwards compatibility.
388  enum DefinitionReturnTypeBreakingStyle {
389  /// Break after return type automatically.
390  /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
391  DRTBS_None,
392  /// Always break after the return type.
393  DRTBS_All,
394  /// Always break after the return types of top-level functions.
395  DRTBS_TopLevel,
396  };
397 
398  /// Different ways to break after the function definition or
399  /// declaration return type.
400  enum ReturnTypeBreakingStyle {
401  /// Break after return type automatically.
402  /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
403  /// \code
404  /// class A {
405  /// int f() { return 0; };
406  /// };
407  /// int f();
408  /// int f() { return 1; }
409  /// \endcode
410  RTBS_None,
411  /// Always break after the return type.
412  /// \code
413  /// class A {
414  /// int
415  /// f() {
416  /// return 0;
417  /// };
418  /// };
419  /// int
420  /// f();
421  /// int
422  /// f() {
423  /// return 1;
424  /// }
425  /// \endcode
426  RTBS_All,
427  /// Always break after the return types of top-level functions.
428  /// \code
429  /// class A {
430  /// int f() { return 0; };
431  /// };
432  /// int
433  /// f();
434  /// int
435  /// f() {
436  /// return 1;
437  /// }
438  /// \endcode
439  RTBS_TopLevel,
440  /// Always break after the return type of function definitions.
441  /// \code
442  /// class A {
443  /// int
444  /// f() {
445  /// return 0;
446  /// };
447  /// };
448  /// int f();
449  /// int
450  /// f() {
451  /// return 1;
452  /// }
453  /// \endcode
454  RTBS_AllDefinitions,
455  /// Always break after the return type of top-level definitions.
456  /// \code
457  /// class A {
458  /// int f() { return 0; };
459  /// };
460  /// int f();
461  /// int
462  /// f() {
463  /// return 1;
464  /// }
465  /// \endcode
466  RTBS_TopLevelDefinitions,
467  };
468 
469  /// The function definition return type breaking style to use. This
470  /// option is **deprecated** and is retained for backwards compatibility.
471  DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
472 
473  /// The function declaration return type breaking style to use.
474  ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
475 
476  /// If ``true``, always break before multiline string literals.
477  ///
478  /// This flag is mean to make cases where there are multiple multiline strings
479  /// in a file look more consistent. Thus, it will only take effect if wrapping
480  /// the string at that point leads to it being indented
481  /// ``ContinuationIndentWidth`` spaces from the start of the line.
482  /// \code
483  /// true: false:
484  /// aaaa = vs. aaaa = "bbbb"
485  /// "bbbb" "cccc";
486  /// "cccc";
487  /// \endcode
488  bool AlwaysBreakBeforeMultilineStrings;
489 
490  /// Different ways to break after the template declaration.
491  enum BreakTemplateDeclarationsStyle {
492  /// Do not force break before declaration.
493  /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
494  /// \code
495  /// template <typename T> T foo() {
496  /// }
497  /// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
498  /// int bbbbbbbbbbbbbbbbbbbbb) {
499  /// }
500  /// \endcode
501  BTDS_No,
502  /// Force break after template declaration only when the following
503  /// declaration spans multiple lines.
504  /// \code
505  /// template <typename T> T foo() {
506  /// }
507  /// template <typename T>
508  /// T foo(int aaaaaaaaaaaaaaaaaaaaa,
509  /// int bbbbbbbbbbbbbbbbbbbbb) {
510  /// }
511  /// \endcode
512  BTDS_MultiLine,
513  /// Always break after template declaration.
514  /// \code
515  /// template <typename T>
516  /// T foo() {
517  /// }
518  /// template <typename T>
519  /// T foo(int aaaaaaaaaaaaaaaaaaaaa,
520  /// int bbbbbbbbbbbbbbbbbbbbb) {
521  /// }
522  /// \endcode
523  BTDS_Yes
524  };
525 
526  /// The template declaration breaking style to use.
527  BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
528 
529  /// If ``false``, a function call's arguments will either be all on the
530  /// same line or will have one line each.
531  /// \code
532  /// true:
533  /// void f() {
534  /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
535  /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
536  /// }
537  ///
538  /// false:
539  /// void f() {
540  /// f(aaaaaaaaaaaaaaaaaaaa,
541  /// aaaaaaaaaaaaaaaaaaaa,
542  /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
543  /// }
544  /// \endcode
545  bool BinPackArguments;
546 
547  /// If ``false``, a function declaration's or function definition's
548  /// parameters will either all be on the same line or will have one line each.
549  /// \code
550  /// true:
551  /// void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
552  /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
553  ///
554  /// false:
555  /// void f(int aaaaaaaaaaaaaaaaaaaa,
556  /// int aaaaaaaaaaaaaaaaaaaa,
557  /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
558  /// \endcode
559  bool BinPackParameters;
560 
561  /// The style of wrapping parameters on the same line (bin-packed) or
562  /// on one line each.
563  enum BinPackStyle {
564  /// Automatically determine parameter bin-packing behavior.
565  BPS_Auto,
566  /// Always bin-pack parameters.
567  BPS_Always,
568  /// Never bin-pack parameters.
569  BPS_Never,
570  };
571 
572  /// The style of breaking before or after binary operators.
573  enum BinaryOperatorStyle {
574  /// Break after operators.
575  /// \code
576  /// LooooooooooongType loooooooooooooooooooooongVariable =
577  /// someLooooooooooooooooongFunction();
578  ///
579  /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
580  /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
581  /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
582  /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
583  /// ccccccccccccccccccccccccccccccccccccccccc;
584  /// \endcode
585  BOS_None,
586  /// Break before operators that aren't assignments.
587  /// \code
588  /// LooooooooooongType loooooooooooooooooooooongVariable =
589  /// someLooooooooooooooooongFunction();
590  ///
591  /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
592  /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
593  /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
594  /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
595  /// > ccccccccccccccccccccccccccccccccccccccccc;
596  /// \endcode
597  BOS_NonAssignment,
598  /// Break before operators.
599  /// \code
600  /// LooooooooooongType loooooooooooooooooooooongVariable
601  /// = someLooooooooooooooooongFunction();
602  ///
603  /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
604  /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
605  /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
606  /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
607  /// > ccccccccccccccccccccccccccccccccccccccccc;
608  /// \endcode
609  BOS_All,
610  };
611 
612  /// The way to wrap binary operators.
613  BinaryOperatorStyle BreakBeforeBinaryOperators;
614 
615  /// Different ways to attach braces to their surrounding context.
616  enum BraceBreakingStyle {
617  /// Always attach braces to surrounding context.
618  /// \code
619  /// try {
620  /// foo();
621  /// } catch () {
622  /// }
623  /// void foo() { bar(); }
624  /// class foo {};
625  /// if (foo()) {
626  /// } else {
627  /// }
628  /// enum X : int { A, B };
629  /// \endcode
630  BS_Attach,
631  /// Like ``Attach``, but break before braces on function, namespace and
632  /// class definitions.
633  /// \code
634  /// try {
635  /// foo();
636  /// } catch () {
637  /// }
638  /// void foo() { bar(); }
639  /// class foo
640  /// {
641  /// };
642  /// if (foo()) {
643  /// } else {
644  /// }
645  /// enum X : int { A, B };
646  /// \endcode
647  BS_Linux,
648  /// Like ``Attach``, but break before braces on enum, function, and record
649  /// definitions.
650  /// \code
651  /// try {
652  /// foo();
653  /// } catch () {
654  /// }
655  /// void foo() { bar(); }
656  /// class foo
657  /// {
658  /// };
659  /// if (foo()) {
660  /// } else {
661  /// }
662  /// enum X : int { A, B };
663  /// \endcode
664  BS_Mozilla,
665  /// Like ``Attach``, but break before function definitions, ``catch``, and
666  /// ``else``.
667  /// \code
668  /// try {
669  /// foo();
670  /// }
671  /// catch () {
672  /// }
673  /// void foo() { bar(); }
674  /// class foo {
675  /// };
676  /// if (foo()) {
677  /// }
678  /// else {
679  /// }
680  /// enum X : int { A, B };
681  /// \endcode
682  BS_Stroustrup,
683  /// Always break before braces.
684  /// \code
685  /// try
686  /// {
687  /// foo();
688  /// }
689  /// catch ()
690  /// {
691  /// }
692  /// void foo() { bar(); }
693  /// class foo
694  /// {
695  /// };
696  /// if (foo())
697  /// {
698  /// }
699  /// else
700  /// {
701  /// }
702  /// enum X : int
703  /// {
704  /// A,
705  /// B
706  /// };
707  /// \endcode
708  BS_Allman,
709  /// Always break before braces and add an extra level of indentation to
710  /// braces of control statements, not to those of class, function
711  /// or other definitions.
712  /// \code
713  /// try
714  /// {
715  /// foo();
716  /// }
717  /// catch ()
718  /// {
719  /// }
720  /// void foo() { bar(); }
721  /// class foo
722  /// {
723  /// };
724  /// if (foo())
725  /// {
726  /// }
727  /// else
728  /// {
729  /// }
730  /// enum X : int
731  /// {
732  /// A,
733  /// B
734  /// };
735  /// \endcode
736  BS_Whitesmiths,
737  /// Like ``Allman`` but always indent braces and line up code with braces.
738  /// \code
739  /// try
740  /// {
741  /// foo();
742  /// }
743  /// catch ()
744  /// {
745  /// }
746  /// void foo() { bar(); }
747  /// class foo
748  /// {
749  /// };
750  /// if (foo())
751  /// {
752  /// }
753  /// else
754  /// {
755  /// }
756  /// enum X : int
757  /// {
758  /// A,
759  /// B
760  /// };
761  /// \endcode
762  BS_GNU,
763  /// Like ``Attach``, but break before functions.
764  /// \code
765  /// try {
766  /// foo();
767  /// } catch () {
768  /// }
769  /// void foo() { bar(); }
770  /// class foo {
771  /// };
772  /// if (foo()) {
773  /// } else {
774  /// }
775  /// enum X : int { A, B };
776  /// \endcode
777  BS_WebKit,
778  /// Configure each individual brace in `BraceWrapping`.
779  BS_Custom
780  };
781 
782  /// The brace breaking style to use.
783  BraceBreakingStyle BreakBeforeBraces;
784 
785  // Different ways to wrap braces after control statements.
786  enum BraceWrappingAfterControlStatementStyle {
787  /// Never wrap braces after a control statement.
788  /// \code
789  /// if (foo()) {
790  /// } else {
791  /// }
792  /// for (int i = 0; i < 10; ++i) {
793  /// }
794  /// \endcode
795  BWACS_Never,
796  /// Only wrap braces after a multi-line control statement.
797  /// \code
798  /// if (foo && bar &&
799  /// baz)
800  /// {
801  /// quux();
802  /// }
803  /// while (foo || bar) {
804  /// }
805  /// \endcode
806  BWACS_MultiLine,
807  /// Always wrap braces after a control statement.
808  /// \code
809  /// if (foo())
810  /// {
811  /// } else
812  /// {}
813  /// for (int i = 0; i < 10; ++i)
814  /// {}
815  /// \endcode
816  BWACS_Always
817  };
818 
819  /// Precise control over the wrapping of braces.
820  /// \code
821  /// # Should be declared this way:
822  /// BreakBeforeBraces: Custom
823  /// BraceWrapping:
824  /// AfterClass: true
825  /// \endcode
826  struct BraceWrappingFlags {
827  /// Wrap case labels.
828  /// \code
829  /// false: true:
830  /// switch (foo) { vs. switch (foo) {
831  /// case 1: { case 1:
832  /// bar(); {
833  /// break; bar();
834  /// } break;
835  /// default: { }
836  /// plop(); default:
837  /// } {
838  /// } plop();
839  /// }
840  /// }
841  /// \endcode
842  bool AfterCaseLabel;
843  /// Wrap class definitions.
844  /// \code
845  /// true:
846  /// class foo {};
847  ///
848  /// false:
849  /// class foo
850  /// {};
851  /// \endcode
852  bool AfterClass;
853  /// Wrap control statements (``if``/``for``/``while``/``switch``/..).
854  BraceWrappingAfterControlStatementStyle AfterControlStatement;
855  /// Wrap enum definitions.
856  /// \code
857  /// true:
858  /// enum X : int
859  /// {
860  /// B
861  /// };
862  ///
863  /// false:
864  /// enum X : int { B };
865  /// \endcode
866  bool AfterEnum;
867  /// Wrap function definitions.
868  /// \code
869  /// true:
870  /// void foo()
871  /// {
872  /// bar();
873  /// bar2();
874  /// }
875  ///
876  /// false:
877  /// void foo() {
878  /// bar();
879  /// bar2();
880  /// }
881  /// \endcode
882  bool AfterFunction;
883  /// Wrap namespace definitions.
884  /// \code
885  /// true:
886  /// namespace
887  /// {
888  /// int foo();
889  /// int bar();
890  /// }
891  ///
892  /// false:
893  /// namespace {
894  /// int foo();
895  /// int bar();
896  /// }
897  /// \endcode
898  bool AfterNamespace;
899  /// Wrap ObjC definitions (interfaces, implementations...).
900  /// \note @autoreleasepool and @synchronized blocks are wrapped
901  /// according to `AfterControlStatement` flag.
902  bool AfterObjCDeclaration;
903  /// Wrap struct definitions.
904  /// \code
905  /// true:
906  /// struct foo
907  /// {
908  /// int x;
909  /// };
910  ///
911  /// false:
912  /// struct foo {
913  /// int x;
914  /// };
915  /// \endcode
916  bool AfterStruct;
917  /// Wrap union definitions.
918  /// \code
919  /// true:
920  /// union foo
921  /// {
922  /// int x;
923  /// }
924  ///
925  /// false:
926  /// union foo {
927  /// int x;
928  /// }
929  /// \endcode
930  bool AfterUnion;
931  /// Wrap extern blocks.
932  /// \code
933  /// true:
934  /// extern "C"
935  /// {
936  /// int foo();
937  /// }
938  ///
939  /// false:
940  /// extern "C" {
941  /// int foo();
942  /// }
943  /// \endcode
944  bool AfterExternBlock;
945  /// Wrap before ``catch``.
946  /// \code
947  /// true:
948  /// try {
949  /// foo();
950  /// }
951  /// catch () {
952  /// }
953  ///
954  /// false:
955  /// try {
956  /// foo();
957  /// } catch () {
958  /// }
959  /// \endcode
960  bool BeforeCatch;
961  /// Wrap before ``else``.
962  /// \code
963  /// true:
964  /// if (foo()) {
965  /// }
966  /// else {
967  /// }
968  ///
969  /// false:
970  /// if (foo()) {
971  /// } else {
972  /// }
973  /// \endcode
974  bool BeforeElse;
975  /// Indent the wrapped braces themselves.
976  bool IndentBraces;
977  /// If ``false``, empty function body can be put on a single line.
978  /// This option is used only if the opening brace of the function has
979  /// already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
980  /// set, and the function could/should not be put on a single line (as per
981  /// `AllowShortFunctionsOnASingleLine` and constructor formatting options).
982  /// \code
983  /// int f() vs. inf f()
984  /// {} {
985  /// }
986  /// \endcode
987  ///
988  bool SplitEmptyFunction;
989  /// If ``false``, empty record (e.g. class, struct or union) body
990  /// can be put on a single line. This option is used only if the opening
991  /// brace of the record has already been wrapped, i.e. the `AfterClass`
992  /// (for classes) brace wrapping mode is set.
993  /// \code
994  /// class Foo vs. class Foo
995  /// {} {
996  /// }
997  /// \endcode
998  ///
999  bool SplitEmptyRecord;
1000  /// If ``false``, empty namespace body can be put on a single line.
1001  /// This option is used only if the opening brace of the namespace has
1002  /// already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
1003  /// set.
1004  /// \code
1005  /// namespace Foo vs. namespace Foo
1006  /// {} {
1007  /// }
1008  /// \endcode
1009  ///
1010  bool SplitEmptyNamespace;
1011  };
1012 
1013  /// Control of individual brace wrapping cases.
1014  ///
1015  /// If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
1016  /// each individual brace case should be handled. Otherwise, this is ignored.
1017  /// \code{.yaml}
1018  /// # Example of usage:
1019  /// BreakBeforeBraces: Custom
1020  /// BraceWrapping:
1021  /// AfterEnum: true
1022  /// AfterStruct: false
1023  /// SplitEmptyFunction: false
1024  /// \endcode
1025  BraceWrappingFlags BraceWrapping;
1026 
1027  /// If ``true``, ternary operators will be placed after line breaks.
1028  /// \code
1029  /// true:
1030  /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
1031  /// ? firstValue
1032  /// : SecondValueVeryVeryVeryVeryLong;
1033  ///
1034  /// false:
1035  /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
1036  /// firstValue :
1037  /// SecondValueVeryVeryVeryVeryLong;
1038  /// \endcode
1039  bool BreakBeforeTernaryOperators;
1040 
1041  /// Different ways to break initializers.
1042  enum BreakConstructorInitializersStyle {
1043  /// Break constructor initializers before the colon and after the commas.
1044  /// \code
1045  /// Constructor()
1046  /// : initializer1(),
1047  /// initializer2()
1048  /// \endcode
1049  BCIS_BeforeColon,
1050  /// Break constructor initializers before the colon and commas, and align
1051  /// the commas with the colon.
1052  /// \code
1053  /// Constructor()
1054  /// : initializer1()
1055  /// , initializer2()
1056  /// \endcode
1057  BCIS_BeforeComma,
1058  /// Break constructor initializers after the colon and commas.
1059  /// \code
1060  /// Constructor() :
1061  /// initializer1(),
1062  /// initializer2()
1063  /// \endcode
1064  BCIS_AfterColon
1065  };
1066 
1067  /// The constructor initializers style to use.
1068  BreakConstructorInitializersStyle BreakConstructorInitializers;
1069 
1070  /// Break after each annotation on a field in Java files.
1071  /// \code{.java}
1072  /// true: false:
1073  /// @Partial vs. @Partial @Mock DataLoad loader;
1074  /// @Mock
1075  /// DataLoad loader;
1076  /// \endcode
1077  bool BreakAfterJavaFieldAnnotations;
1078 
1079  /// Allow breaking string literals when formatting.
1080  bool BreakStringLiterals;
1081 
1082  /// The column limit.
1083  ///
1084  /// A column limit of ``0`` means that there is no column limit. In this case,
1085  /// clang-format will respect the input's line breaking decisions within
1086  /// statements unless they contradict other rules.
1087  unsigned ColumnLimit;
1088 
1089  /// A regular expression that describes comments with special meaning,
1090  /// which should not be split into lines or otherwise changed.
1091  /// \code
1092  /// // CommentPragmas: '^ FOOBAR pragma:'
1093  /// // Will leave the following line unaffected
1094  /// #include <vector> // FOOBAR pragma: keep
1095  /// \endcode
1096  std::string CommentPragmas;
1097 
1098  /// Different ways to break inheritance list.
1099  enum BreakInheritanceListStyle {
1100  /// Break inheritance list before the colon and after the commas.
1101  /// \code
1102  /// class Foo
1103  /// : Base1,
1104  /// Base2
1105  /// {};
1106  /// \endcode
1107  BILS_BeforeColon,
1108  /// Break inheritance list before the colon and commas, and align
1109  /// the commas with the colon.
1110  /// \code
1111  /// class Foo
1112  /// : Base1
1113  /// , Base2
1114  /// {};
1115  /// \endcode
1116  BILS_BeforeComma,
1117  /// Break inheritance list after the colon and commas.
1118  /// \code
1119  /// class Foo :
1120  /// Base1,
1121  /// Base2
1122  /// {};
1123  /// \endcode
1124  BILS_AfterColon
1125  };
1126 
1127  /// The inheritance list style to use.
1128  BreakInheritanceListStyle BreakInheritanceList;
1129 
1130  /// If ``true``, consecutive namespace declarations will be on the same
1131  /// line. If ``false``, each namespace is declared on a new line.
1132  /// \code
1133  /// true:
1134  /// namespace Foo { namespace Bar {
1135  /// }}
1136  ///
1137  /// false:
1138  /// namespace Foo {
1139  /// namespace Bar {
1140  /// }
1141  /// }
1142  /// \endcode
1143  ///
1144  /// If it does not fit on a single line, the overflowing namespaces get
1145  /// wrapped:
1146  /// \code
1147  /// namespace Foo { namespace Bar {
1148  /// namespace Extra {
1149  /// }}}
1150  /// \endcode
1151  bool CompactNamespaces;
1152 
1153  /// If the constructor initializers don't fit on a line, put each
1154  /// initializer on its own line.
1155  /// \code
1156  /// true:
1157  /// SomeClass::Constructor()
1158  /// : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1159  /// return 0;
1160  /// }
1161  ///
1162  /// false:
1163  /// SomeClass::Constructor()
1164  /// : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1165  /// aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1166  /// return 0;
1167  /// }
1168  /// \endcode
1169  bool ConstructorInitializerAllOnOneLineOrOnePerLine;
1170 
1171  /// The number of characters to use for indentation of constructor
1172  /// initializer lists as well as inheritance lists.
1173  unsigned ConstructorInitializerIndentWidth;
1174 
1175  /// Indent width for line continuations.
1176  /// \code
1177  /// ContinuationIndentWidth: 2
1178  ///
1179  /// int i = // VeryVeryVeryVeryVeryLongComment
1180  /// longFunction( // Again a long comment
1181  /// arg);
1182  /// \endcode
1183  unsigned ContinuationIndentWidth;
1184 
1185  /// If ``true``, format braced lists as best suited for C++11 braced
1186  /// lists.
1187  ///
1188  /// Important differences:
1189  /// - No spaces inside the braced list.
1190  /// - No line break before the closing brace.
1191  /// - Indentation with the continuation indent, not with the block indent.
1192  ///
1193  /// Fundamentally, C++11 braced lists are formatted exactly like function
1194  /// calls would be formatted in their place. If the braced list follows a name
1195  /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1196  /// the parentheses of a function call with that name. If there is no name,
1197  /// a zero-length name is assumed.
1198  /// \code
1199  /// true: false:
1200  /// vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
1201  /// vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
1202  /// f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
1203  /// new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
1204  /// \endcode
1205  bool Cpp11BracedListStyle;
1206 
1207  /// If ``true``, analyze the formatted file for the most common
1208  /// alignment of ``&`` and ``*``.
1209  /// Pointer and reference alignment styles are going to be updated according
1210  /// to the preferences found in the file.
1211  /// ``PointerAlignment`` is then used only as fallback.
1212  bool DerivePointerAlignment;
1213 
1214  /// Disables formatting completely.
1215  bool DisableFormat;
1216 
1217  /// If ``true``, clang-format detects whether function calls and
1218  /// definitions are formatted with one parameter per line.
1219  ///
1220  /// Each call can be bin-packed, one-per-line or inconclusive. If it is
1221  /// inconclusive, e.g. completely on one line, but a decision needs to be
1222  /// made, clang-format analyzes whether there are other bin-packed cases in
1223  /// the input file and act accordingly.
1224  ///
1225  /// NOTE: This is an experimental flag, that might go away or be renamed. Do
1226  /// not use this in config files, etc. Use at your own risk.
1227  bool ExperimentalAutoDetectBinPacking;
1228 
1229  /// If ``true``, clang-format adds missing namespace end comments and
1230  /// fixes invalid existing ones.
1231  /// \code
1232  /// true: false:
1233  /// namespace a { vs. namespace a {
1234  /// foo(); foo();
1235  /// } // namespace a }
1236  /// \endcode
1237  bool FixNamespaceComments;
1238 
1239  /// A vector of macros that should be interpreted as foreach loops
1240  /// instead of as function calls.
1241  ///
1242  /// These are expected to be macros of the form:
1243  /// \code
1244  /// FOREACH(<variable-declaration>, ...)
1245  /// <loop-body>
1246  /// \endcode
1247  ///
1248  /// In the .clang-format configuration file, this can be configured like:
1249  /// \code{.yaml}
1250  /// ForEachMacros: ['RANGES_FOR', 'FOREACH']
1251  /// \endcode
1252  ///
1253  /// For example: BOOST_FOREACH.
1254  std::vector<std::string> ForEachMacros;
1255 
1256  /// \brief A vector of macros that should be interpreted as type declarations
1257  /// instead of as function calls.
1258  ///
1259  /// These are expected to be macros of the form:
1260  /// \code
1261  /// STACK_OF(...)
1262  /// \endcode
1263  ///
1264  /// In the .clang-format configuration file, this can be configured like:
1265  /// \code{.yaml}
1266  /// TypenameMacros: ['STACK_OF', 'LIST']
1267  /// \endcode
1268  ///
1269  /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
1270  std::vector<std::string> TypenameMacros;
1271 
1272  /// A vector of macros that should be interpreted as complete
1273  /// statements.
1274  ///
1275  /// Typical macros are expressions, and require a semi-colon to be
1276  /// added; sometimes this is not the case, and this allows to make
1277  /// clang-format aware of such cases.
1278  ///
1279  /// For example: Q_UNUSED
1280  std::vector<std::string> StatementMacros;
1281 
1282  /// A vector of macros which are used to open namespace blocks.
1283  ///
1284  /// These are expected to be macros of the form:
1285  /// \code
1286  /// NAMESPACE(<namespace-name>, ...) {
1287  /// <namespace-content>
1288  /// }
1289  /// \endcode
1290  ///
1291  /// For example: TESTSUITE
1292  std::vector<std::string> NamespaceMacros;
1293 
1294  tooling::IncludeStyle IncludeStyle;
1295 
1296  /// Indent case labels one level from the switch statement.
1297  ///
1298  /// When ``false``, use the same indentation level as for the switch statement.
1299  /// Switch statement body is always indented one level more than case labels.
1300  /// \code
1301  /// false: true:
1302  /// switch (fool) { vs. switch (fool) {
1303  /// case 1: case 1:
1304  /// bar(); bar();
1305  /// break; break;
1306  /// default: default:
1307  /// plop(); plop();
1308  /// } }
1309  /// \endcode
1310  bool IndentCaseLabels;
1311 
1312  /// Indent goto labels.
1313  ///
1314  /// When ``false``, goto labels are flushed left.
1315  /// \code
1316  /// true: false:
1317  /// int f() { vs. int f() {
1318  /// if (foo()) { if (foo()) {
1319  /// label1: label1:
1320  /// bar(); bar();
1321  /// } }
1322  /// label2: label2:
1323  /// return 1; return 1;
1324  /// } }
1325  /// \endcode
1326  bool IndentGotoLabels;
1327 
1328  /// Options for indenting preprocessor directives.
1329  enum PPDirectiveIndentStyle {
1330  /// Does not indent any directives.
1331  /// \code
1332  /// #if FOO
1333  /// #if BAR
1334  /// #include <foo>
1335  /// #endif
1336  /// #endif
1337  /// \endcode
1338  PPDIS_None,
1339  /// Indents directives after the hash.
1340  /// \code
1341  /// #if FOO
1342  /// # if BAR
1343  /// # include <foo>
1344  /// # endif
1345  /// #endif
1346  /// \endcode
1347  PPDIS_AfterHash,
1348  /// Indents directives before the hash.
1349  /// \code
1350  /// #if FOO
1351  /// #if BAR
1352  /// #include <foo>
1353  /// #endif
1354  /// #endif
1355  /// \endcode
1356  PPDIS_BeforeHash
1357  };
1358 
1359  /// The preprocessor directive indenting style to use.
1360  PPDirectiveIndentStyle IndentPPDirectives;
1361 
1362  /// The number of columns to use for indentation.
1363  /// \code
1364  /// IndentWidth: 3
1365  ///
1366  /// void f() {
1367  /// someFunction();
1368  /// if (true, false) {
1369  /// f();
1370  /// }
1371  /// }
1372  /// \endcode
1373  unsigned IndentWidth;
1374 
1375  /// Indent if a function definition or declaration is wrapped after the
1376  /// type.
1377  /// \code
1378  /// true:
1379  /// LoooooooooooooooooooooooooooooooooooooooongReturnType
1380  /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1381  ///
1382  /// false:
1383  /// LoooooooooooooooooooooooooooooooooooooooongReturnType
1384  /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1385  /// \endcode
1386  bool IndentWrappedFunctionNames;
1387 
1388  /// A vector of prefixes ordered by the desired groups for Java imports.
1389  ///
1390  /// Each group is separated by a newline. Static imports will also follow the
1391  /// same grouping convention above all non-static imports. One group's prefix
1392  /// can be a subset of another - the longest prefix is always matched. Within
1393  /// a group, the imports are ordered lexicographically.
1394  ///
1395  /// In the .clang-format configuration file, this can be configured like
1396  /// in the following yaml example. This will result in imports being
1397  /// formatted as in the Java example below.
1398  /// \code{.yaml}
1399  /// JavaImportGroups: ['com.example', 'com', 'org']
1400  /// \endcode
1401  ///
1402  /// \code{.java}
1403  /// import static com.example.function1;
1404  ///
1405  /// import static com.test.function2;
1406  ///
1407  /// import static org.example.function3;
1408  ///
1409  /// import com.example.ClassA;
1410  /// import com.example.Test;
1411  /// import com.example.a.ClassB;
1412  ///
1413  /// import com.test.ClassC;
1414  ///
1415  /// import org.example.ClassD;
1416  /// \endcode
1417  std::vector<std::string> JavaImportGroups;
1418 
1419  /// Quotation styles for JavaScript strings. Does not affect template
1420  /// strings.
1421  enum JavaScriptQuoteStyle {
1422  /// Leave string quotes as they are.
1423  /// \code{.js}
1424  /// string1 = "foo";
1425  /// string2 = 'bar';
1426  /// \endcode
1427  JSQS_Leave,
1428  /// Always use single quotes.
1429  /// \code{.js}
1430  /// string1 = 'foo';
1431  /// string2 = 'bar';
1432  /// \endcode
1433  JSQS_Single,
1434  /// Always use double quotes.
1435  /// \code{.js}
1436  /// string1 = "foo";
1437  /// string2 = "bar";
1438  /// \endcode
1439  JSQS_Double
1440  };
1441 
1442  /// The JavaScriptQuoteStyle to use for JavaScript strings.
1443  JavaScriptQuoteStyle JavaScriptQuotes;
1444 
1445  /// Whether to wrap JavaScript import/export statements.
1446  /// \code{.js}
1447  /// true:
1448  /// import {
1449  /// VeryLongImportsAreAnnoying,
1450  /// VeryLongImportsAreAnnoying,
1451  /// VeryLongImportsAreAnnoying,
1452  /// } from 'some/module.js'
1453  ///
1454  /// false:
1455  /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1456  /// \endcode
1457  bool JavaScriptWrapImports;
1458 
1459  /// If true, the empty line at the start of blocks is kept.
1460  /// \code
1461  /// true: false:
1462  /// if (foo) { vs. if (foo) {
1463  /// bar();
1464  /// bar(); }
1465  /// }
1466  /// \endcode
1467  bool KeepEmptyLinesAtTheStartOfBlocks;
1468 
1469  /// Supported languages.
1470  ///
1471  /// When stored in a configuration file, specifies the language, that the
1472  /// configuration targets. When passed to the ``reformat()`` function, enables
1473  /// syntax features specific to the language.
1474  enum LanguageKind {
1475  /// Do not use.
1476  LK_None,
1477  /// Should be used for C, C++.
1478  LK_Cpp,
1479  /// Should be used for C#.
1480  LK_CSharp,
1481  /// Should be used for Java.
1482  LK_Java,
1483  /// Should be used for JavaScript.
1484  LK_JavaScript,
1485  /// Should be used for Objective-C, Objective-C++.
1486  LK_ObjC,
1487  /// Should be used for Protocol Buffers
1488  /// (https://developers.google.com/protocol-buffers/).
1489  LK_Proto,
1490  /// Should be used for TableGen code.
1491  LK_TableGen,
1492  /// Should be used for Protocol Buffer messages in text format
1493  /// (https://developers.google.com/protocol-buffers/).
1494  LK_TextProto
1495  };
1496  bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
1497  bool isCSharp() const { return Language == LK_CSharp; }
1498 
1499  /// Language, this format style is targeted at.
1500  LanguageKind Language;
1501 
1502  /// A regular expression matching macros that start a block.
1503  /// \code
1504  /// # With:
1505  /// MacroBlockBegin: "^NS_MAP_BEGIN|\
1506  /// NS_TABLE_HEAD$"
1507  /// MacroBlockEnd: "^\
1508  /// NS_MAP_END|\
1509  /// NS_TABLE_.*_END$"
1510  ///
1511  /// NS_MAP_BEGIN
1512  /// foo();
1513  /// NS_MAP_END
1514  ///
1515  /// NS_TABLE_HEAD
1516  /// bar();
1517  /// NS_TABLE_FOO_END
1518  ///
1519  /// # Without:
1520  /// NS_MAP_BEGIN
1521  /// foo();
1522  /// NS_MAP_END
1523  ///
1524  /// NS_TABLE_HEAD
1525  /// bar();
1526  /// NS_TABLE_FOO_END
1527  /// \endcode
1528  std::string MacroBlockBegin;
1529 
1530  /// A regular expression matching macros that end a block.
1531  std::string MacroBlockEnd;
1532 
1533  /// The maximum number of consecutive empty lines to keep.
1534  /// \code
1535  /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
1536  /// int f() { int f() {
1537  /// int = 1; int i = 1;
1538  /// i = foo();
1539  /// i = foo(); return i;
1540  /// }
1541  /// return i;
1542  /// }
1543  /// \endcode
1544  unsigned MaxEmptyLinesToKeep;
1545 
1546  /// Different ways to indent namespace contents.
1547  enum NamespaceIndentationKind {
1548  /// Don't indent in namespaces.
1549  /// \code
1550  /// namespace out {
1551  /// int i;
1552  /// namespace in {
1553  /// int i;
1554  /// }
1555  /// }
1556  /// \endcode
1557  NI_None,
1558  /// Indent only in inner namespaces (nested in other namespaces).
1559  /// \code
1560  /// namespace out {
1561  /// int i;
1562  /// namespace in {
1563  /// int i;
1564  /// }
1565  /// }
1566  /// \endcode
1567  NI_Inner,
1568  /// Indent in all namespaces.
1569  /// \code
1570  /// namespace out {
1571  /// int i;
1572  /// namespace in {
1573  /// int i;
1574  /// }
1575  /// }
1576  /// \endcode
1577  NI_All
1578  };
1579 
1580  /// The indentation used for namespaces.
1581  NamespaceIndentationKind NamespaceIndentation;
1582 
1583  /// Controls bin-packing Objective-C protocol conformance list
1584  /// items into as few lines as possible when they go over ``ColumnLimit``.
1585  ///
1586  /// If ``Auto`` (the default), delegates to the value in
1587  /// ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
1588  /// protocol conformance list items into as few lines as possible
1589  /// whenever they go over ``ColumnLimit``.
1590  ///
1591  /// If ``Always``, always bin-packs Objective-C protocol conformance
1592  /// list items into as few lines as possible whenever they go over
1593  /// ``ColumnLimit``.
1594  ///
1595  /// If ``Never``, lays out Objective-C protocol conformance list items
1596  /// onto individual lines whenever they go over ``ColumnLimit``.
1597  ///
1598  /// \code{.objc}
1599  /// Always (or Auto, if BinPackParameters=true):
1600  /// @interface ccccccccccccc () <
1601  /// ccccccccccccc, ccccccccccccc,
1602  /// ccccccccccccc, ccccccccccccc> {
1603  /// }
1604  ///
1605  /// Never (or Auto, if BinPackParameters=false):
1606  /// @interface ddddddddddddd () <
1607  /// ddddddddddddd,
1608  /// ddddddddddddd,
1609  /// ddddddddddddd,
1610  /// ddddddddddddd> {
1611  /// }
1612  /// \endcode
1613  BinPackStyle ObjCBinPackProtocolList;
1614 
1615  /// The number of characters to use for indentation of ObjC blocks.
1616  /// \code{.objc}
1617  /// ObjCBlockIndentWidth: 4
1618  ///
1619  /// [operation setCompletionBlock:^{
1620  /// [self onOperationDone];
1621  /// }];
1622  /// \endcode
1623  unsigned ObjCBlockIndentWidth;
1624 
1625  /// Add a space after ``@property`` in Objective-C, i.e. use
1626  /// ``@property (readonly)`` instead of ``@property(readonly)``.
1627  bool ObjCSpaceAfterProperty;
1628 
1629  /// Add a space in front of an Objective-C protocol list, i.e. use
1630  /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1631  bool ObjCSpaceBeforeProtocolList;
1632 
1633  /// The penalty for breaking around an assignment operator.
1634  unsigned PenaltyBreakAssignment;
1635 
1636  /// The penalty for breaking a function call after ``call(``.
1637  unsigned PenaltyBreakBeforeFirstCallParameter;
1638 
1639  /// The penalty for each line break introduced inside a comment.
1640  unsigned PenaltyBreakComment;
1641 
1642  /// The penalty for breaking before the first ``<<``.
1643  unsigned PenaltyBreakFirstLessLess;
1644 
1645  /// The penalty for each line break introduced inside a string literal.
1646  unsigned PenaltyBreakString;
1647 
1648  /// The penalty for breaking after template declaration.
1649  unsigned PenaltyBreakTemplateDeclaration;
1650 
1651  /// The penalty for each character outside of the column limit.
1652  unsigned PenaltyExcessCharacter;
1653 
1654  /// Penalty for putting the return type of a function onto its own
1655  /// line.
1656  unsigned PenaltyReturnTypeOnItsOwnLine;
1657 
1658  /// The ``&`` and ``*`` alignment style.
1659  enum PointerAlignmentStyle {
1660  /// Align pointer to the left.
1661  /// \code
1662  /// int* a;
1663  /// \endcode
1664  PAS_Left,
1665  /// Align pointer to the right.
1666  /// \code
1667  /// int *a;
1668  /// \endcode
1669  PAS_Right,
1670  /// Align pointer in the middle.
1671  /// \code
1672  /// int * a;
1673  /// \endcode
1674  PAS_Middle
1675  };
1676 
1677  /// Pointer and reference alignment style.
1678  PointerAlignmentStyle PointerAlignment;
1679 
1680  /// See documentation of ``RawStringFormats``.
1681  struct RawStringFormat {
1682  /// The language of this raw string.
1683  LanguageKind Language;
1684  /// A list of raw string delimiters that match this language.
1685  std::vector<std::string> Delimiters;
1686  /// A list of enclosing function names that match this language.
1687  std::vector<std::string> EnclosingFunctions;
1688  /// The canonical delimiter for this language.
1689  std::string CanonicalDelimiter;
1690  /// The style name on which this raw string format is based on.
1691  /// If not specified, the raw string format is based on the style that this
1692  /// format is based on.
1693  std::string BasedOnStyle;
1694  bool operator==(const RawStringFormat &Other) const {
1695  return Language == Other.Language && Delimiters == Other.Delimiters &&
1696  EnclosingFunctions == Other.EnclosingFunctions &&
1697  CanonicalDelimiter == Other.CanonicalDelimiter &&
1698  BasedOnStyle == Other.BasedOnStyle;
1699  }
1700  };
1701 
1702  /// Defines hints for detecting supported languages code blocks in raw
1703  /// strings.
1704  ///
1705  /// A raw string with a matching delimiter or a matching enclosing function
1706  /// name will be reformatted assuming the specified language based on the
1707  /// style for that language defined in the .clang-format file. If no style has
1708  /// been defined in the .clang-format file for the specific language, a
1709  /// predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
1710  /// found, the formatting is based on llvm style. A matching delimiter takes
1711  /// precedence over a matching enclosing function name for determining the
1712  /// language of the raw string contents.
1713  ///
1714  /// If a canonical delimiter is specified, occurrences of other delimiters for
1715  /// the same language will be updated to the canonical if possible.
1716  ///
1717  /// There should be at most one specification per language and each delimiter
1718  /// and enclosing function should not occur in multiple specifications.
1719  ///
1720  /// To configure this in the .clang-format file, use:
1721  /// \code{.yaml}
1722  /// RawStringFormats:
1723  /// - Language: TextProto
1724  /// Delimiters:
1725  /// - 'pb'
1726  /// - 'proto'
1727  /// EnclosingFunctions:
1728  /// - 'PARSE_TEXT_PROTO'
1729  /// BasedOnStyle: google
1730  /// - Language: Cpp
1731  /// Delimiters:
1732  /// - 'cc'
1733  /// - 'cpp'
1734  /// BasedOnStyle: llvm
1735  /// CanonicalDelimiter: 'cc'
1736  /// \endcode
1737  std::vector<RawStringFormat> RawStringFormats;
1738 
1739  /// If ``true``, clang-format will attempt to re-flow comments.
1740  /// \code
1741  /// false:
1742  /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1743  /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1744  ///
1745  /// true:
1746  /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1747  /// // information
1748  /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1749  /// * information */
1750  /// \endcode
1751  bool ReflowComments;
1752 
1753  /// If ``true``, clang-format will sort ``#includes``.
1754  /// \code
1755  /// false: true:
1756  /// #include "b.h" vs. #include "a.h"
1757  /// #include "a.h" #include "b.h"
1758  /// \endcode
1759  bool SortIncludes;
1760 
1761  /// If ``true``, clang-format will sort using declarations.
1762  ///
1763  /// The order of using declarations is defined as follows:
1764  /// Split the strings by "::" and discard any initial empty strings. The last
1765  /// element of each list is a non-namespace name; all others are namespace
1766  /// names. Sort the lists of names lexicographically, where the sort order of
1767  /// individual names is that all non-namespace names come before all namespace
1768  /// names, and within those groups, names are in case-insensitive
1769  /// lexicographic order.
1770  /// \code
1771  /// false: true:
1772  /// using std::cout; vs. using std::cin;
1773  /// using std::cin; using std::cout;
1774  /// \endcode
1775  bool SortUsingDeclarations;
1776 
1777  /// If ``true``, a space is inserted after C style casts.
1778  /// \code
1779  /// true: false:
1780  /// (int) i; vs. (int)i;
1781  /// \endcode
1782  bool SpaceAfterCStyleCast;
1783 
1784  /// If ``true``, a space is inserted after the logical not operator (``!``).
1785  /// \code
1786  /// true: false:
1787  /// ! someExpression(); vs. !someExpression();
1788  /// \endcode
1789  bool SpaceAfterLogicalNot;
1790 
1791  /// If \c true, a space will be inserted after the 'template' keyword.
1792  /// \code
1793  /// true: false:
1794  /// template <int> void foo(); vs. template<int> void foo();
1795  /// \endcode
1796  bool SpaceAfterTemplateKeyword;
1797 
1798  /// If ``false``, spaces will be removed before assignment operators.
1799  /// \code
1800  /// true: false:
1801  /// int a = 5; vs. int a= 5;
1802  /// a += 42; a+= 42;
1803  /// \endcode
1804  bool SpaceBeforeAssignmentOperators;
1805 
1806  /// If ``true``, a space will be inserted before a C++11 braced list
1807  /// used to initialize an object (after the preceding identifier or type).
1808  /// \code
1809  /// true: false:
1810  /// Foo foo { bar }; vs. Foo foo{ bar };
1811  /// Foo {}; Foo{};
1812  /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
1813  /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
1814  /// \endcode
1815  bool SpaceBeforeCpp11BracedList;
1816 
1817  /// If ``false``, spaces will be removed before constructor initializer
1818  /// colon.
1819  /// \code
1820  /// true: false:
1821  /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
1822  /// \endcode
1823  bool SpaceBeforeCtorInitializerColon;
1824 
1825  /// If ``false``, spaces will be removed before inheritance colon.
1826  /// \code
1827  /// true: false:
1828  /// class Foo : Bar {} vs. class Foo: Bar {}
1829  /// \endcode
1830  bool SpaceBeforeInheritanceColon;
1831 
1832  /// Different ways to put a space before opening parentheses.
1833  enum SpaceBeforeParensOptions {
1834  /// Never put a space before opening parentheses.
1835  /// \code
1836  /// void f() {
1837  /// if(true) {
1838  /// f();
1839  /// }
1840  /// }
1841  /// \endcode
1842  SBPO_Never,
1843  /// Put a space before opening parentheses only after control statement
1844  /// keywords (``for/if/while...``).
1845  /// \code
1846  /// void f() {
1847  /// if (true) {
1848  /// f();
1849  /// }
1850  /// }
1851  /// \endcode
1852  SBPO_ControlStatements,
1853  /// Put a space before opening parentheses only if the parentheses are not
1854  /// empty i.e. '()'
1855  /// \code
1856  /// void() {
1857  /// if (true) {
1858  /// f();
1859  /// g (x, y, z);
1860  /// }
1861  /// }
1862  /// \endcode
1863  SBPO_NonEmptyParentheses,
1864  /// Always put a space before opening parentheses, except when it's
1865  /// prohibited by the syntax rules (in function-like macro definitions) or
1866  /// when determined by other style rules (after unary operators, opening
1867  /// parentheses, etc.)
1868  /// \code
1869  /// void f () {
1870  /// if (true) {
1871  /// f ();
1872  /// }
1873  /// }
1874  /// \endcode
1875  SBPO_Always
1876  };
1877 
1878  /// Defines in which cases to put a space before opening parentheses.
1879  SpaceBeforeParensOptions SpaceBeforeParens;
1880 
1881  /// If ``false``, spaces will be removed before range-based for loop
1882  /// colon.
1883  /// \code
1884  /// true: false:
1885  /// for (auto v : values) {} vs. for(auto v: values) {}
1886  /// \endcode
1887  bool SpaceBeforeRangeBasedForLoopColon;
1888 
1889  /// If ``true``, spaces will be inserted into ``{}``.
1890  /// \code
1891  /// true: false:
1892  /// void f() { } vs. void f() {}
1893  /// while (true) { } while (true) {}
1894  /// \endcode
1895  bool SpaceInEmptyBlock;
1896 
1897  /// If ``true``, spaces may be inserted into ``()``.
1898  /// \code
1899  /// true: false:
1900  /// void f( ) { vs. void f() {
1901  /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
1902  /// if (true) { if (true) {
1903  /// f( ); f();
1904  /// } }
1905  /// } }
1906  /// \endcode
1907  bool SpaceInEmptyParentheses;
1908 
1909  /// The number of spaces before trailing line comments
1910  /// (``//`` - comments).
1911  ///
1912  /// This does not affect trailing block comments (``/*`` - comments) as
1913  /// those commonly have different usage patterns and a number of special
1914  /// cases.
1915  /// \code
1916  /// SpacesBeforeTrailingComments: 3
1917  /// void f() {
1918  /// if (true) { // foo1
1919  /// f(); // bar
1920  /// } // foo
1921  /// }
1922  /// \endcode
1923  unsigned SpacesBeforeTrailingComments;
1924 
1925  /// If ``true``, spaces will be inserted after ``<`` and before ``>``
1926  /// in template argument lists.
1927  /// \code
1928  /// true: false:
1929  /// static_cast< int >(arg); vs. static_cast<int>(arg);
1930  /// std::function< void(int) > fct; std::function<void(int)> fct;
1931  /// \endcode
1932  bool SpacesInAngles;
1933 
1934  /// If ``true``, spaces are inserted inside container literals (e.g.
1935  /// ObjC and Javascript array and dict literals).
1936  /// \code{.js}
1937  /// true: false:
1938  /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
1939  /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
1940  /// \endcode
1941  bool SpacesInContainerLiterals;
1942 
1943  /// If ``true``, spaces may be inserted into C style casts.
1944  /// \code
1945  /// true: false:
1946  /// x = ( int32 )y vs. x = (int32)y
1947  /// \endcode
1948  bool SpacesInCStyleCastParentheses;
1949 
1950  /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
1951  /// \code
1952  /// true: false:
1953  /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
1954  /// \endcode
1955  bool SpacesInParentheses;
1956 
1957  /// If ``true``, spaces will be inserted after ``[`` and before ``]``.
1958  /// Lambdas or unspecified size array declarations will not be affected.
1959  /// \code
1960  /// true: false:
1961  /// int a[ 5 ]; vs. int a[5];
1962  /// std::unique_ptr<int[]> foo() {} // Won't be affected
1963  /// \endcode
1964  bool SpacesInSquareBrackets;
1965 
1966  /// Supported language standards for parsing and formatting C++ constructs.
1967  /// \code
1968  /// Latest: vector<set<int>>
1969  /// c++03 vs. vector<set<int> >
1970  /// \endcode
1971  ///
1972  /// The correct way to spell a specific language version is e.g. ``c++11``.
1973  /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
1974  enum LanguageStandard {
1975  /// c++03: Parse and format as C++03.
1976  LS_Cpp03,
1977  /// c++11: Parse and format as C++11.
1978  LS_Cpp11,
1979  /// c++14: Parse and format as C++14.
1980  LS_Cpp14,
1981  /// c++17: Parse and format as C++17.
1982  LS_Cpp17,
1983  /// c++20: Parse and format as C++20.
1984  LS_Cpp20,
1985  /// Latest: Parse and format using the latest supported language version.
1986  /// 'Cpp11' is an alias for LS_Latest for historical reasons.
1987  LS_Latest,
1988 
1989  /// Auto: Automatic detection based on the input.
1990  /// Parse using the latest language version. Format based on detected input.
1991  LS_Auto,
1992  };
1993 
1994  /// Format compatible with this standard, e.g. use ``A<A<int> >``
1995  /// instead of ``A<A<int>>`` for ``LS_Cpp03``.
1996  LanguageStandard Standard;
1997 
1998  /// The number of columns used for tab stops.
1999  unsigned TabWidth;
2000 
2001  /// Different ways to use tab in formatting.
2002  enum UseTabStyle {
2003  /// Never use tab.
2004  UT_Never,
2005  /// Use tabs only for indentation.
2006  UT_ForIndentation,
2007  /// Use tabs only for line continuation and indentation.
2008  UT_ForContinuationAndIndentation,
2009  /// Use tabs whenever we need to fill whitespace that spans at least from
2010  /// one tab stop to the next one.
2011  UT_Always
2012  };
2013 
2014  /// The way to use tab characters in the resulting file.
2015  UseTabStyle UseTab;
2016 
2017  bool operator==(const FormatStyle &R) const {
2018  return AccessModifierOffset == R.AccessModifierOffset &&
2019  AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
2020  AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
2021  AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
2022  AlignEscapedNewlines == R.AlignEscapedNewlines &&
2023  AlignOperands == R.AlignOperands &&
2024  AlignTrailingComments == R.AlignTrailingComments &&
2025  AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
2026  AllowAllConstructorInitializersOnNextLine ==
2027  R.AllowAllConstructorInitializersOnNextLine &&
2028  AllowAllParametersOfDeclarationOnNextLine ==
2029  R.AllowAllParametersOfDeclarationOnNextLine &&
2030  AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
2031  AllowShortCaseLabelsOnASingleLine ==
2032  R.AllowShortCaseLabelsOnASingleLine &&
2033  AllowShortFunctionsOnASingleLine ==
2034  R.AllowShortFunctionsOnASingleLine &&
2035  AllowShortIfStatementsOnASingleLine ==
2036  R.AllowShortIfStatementsOnASingleLine &&
2037  AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
2038  AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
2039  AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
2040  AlwaysBreakBeforeMultilineStrings ==
2041  R.AlwaysBreakBeforeMultilineStrings &&
2042  AlwaysBreakTemplateDeclarations ==
2043  R.AlwaysBreakTemplateDeclarations &&
2044  BinPackArguments == R.BinPackArguments &&
2045  BinPackParameters == R.BinPackParameters &&
2046  BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
2047  BreakBeforeBraces == R.BreakBeforeBraces &&
2048  BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
2049  BreakConstructorInitializers == R.BreakConstructorInitializers &&
2050  CompactNamespaces == R.CompactNamespaces &&
2051  BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
2052  BreakStringLiterals == R.BreakStringLiterals &&
2053  ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
2054  BreakInheritanceList == R.BreakInheritanceList &&
2055  ConstructorInitializerAllOnOneLineOrOnePerLine ==
2056  R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
2057  ConstructorInitializerIndentWidth ==
2058  R.ConstructorInitializerIndentWidth &&
2059  ContinuationIndentWidth == R.ContinuationIndentWidth &&
2060  Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
2061  DerivePointerAlignment == R.DerivePointerAlignment &&
2062  DisableFormat == R.DisableFormat &&
2063  ExperimentalAutoDetectBinPacking ==
2064  R.ExperimentalAutoDetectBinPacking &&
2065  FixNamespaceComments == R.FixNamespaceComments &&
2066  ForEachMacros == R.ForEachMacros &&
2067  IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
2068  IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories &&
2069  IndentCaseLabels == R.IndentCaseLabels &&
2070  IndentGotoLabels == R.IndentGotoLabels &&
2071  IndentPPDirectives == R.IndentPPDirectives &&
2072  IndentWidth == R.IndentWidth && Language == R.Language &&
2073  IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
2074  JavaImportGroups == R.JavaImportGroups &&
2075  JavaScriptQuotes == R.JavaScriptQuotes &&
2076  JavaScriptWrapImports == R.JavaScriptWrapImports &&
2077  KeepEmptyLinesAtTheStartOfBlocks ==
2078  R.KeepEmptyLinesAtTheStartOfBlocks &&
2079  MacroBlockBegin == R.MacroBlockBegin &&
2080  MacroBlockEnd == R.MacroBlockEnd &&
2081  MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
2082  NamespaceIndentation == R.NamespaceIndentation &&
2083  NamespaceMacros == R.NamespaceMacros &&
2084  ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
2085  ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
2086  ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
2087  ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
2088  PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
2089  PenaltyBreakBeforeFirstCallParameter ==
2090  R.PenaltyBreakBeforeFirstCallParameter &&
2091  PenaltyBreakComment == R.PenaltyBreakComment &&
2092  PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
2093  PenaltyBreakString == R.PenaltyBreakString &&
2094  PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
2095  PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
2096  PenaltyBreakTemplateDeclaration ==
2097  R.PenaltyBreakTemplateDeclaration &&
2098  PointerAlignment == R.PointerAlignment &&
2099  RawStringFormats == R.RawStringFormats &&
2100  SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
2101  SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
2102  SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
2103  SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
2104  SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
2105  SpaceBeforeCtorInitializerColon ==
2106  R.SpaceBeforeCtorInitializerColon &&
2107  SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
2108  SpaceBeforeParens == R.SpaceBeforeParens &&
2109  SpaceBeforeRangeBasedForLoopColon ==
2110  R.SpaceBeforeRangeBasedForLoopColon &&
2111  SpaceInEmptyBlock == R.SpaceInEmptyBlock &&
2112  SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
2113  SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
2114  SpacesInAngles == R.SpacesInAngles &&
2115  SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
2116  SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
2117  SpacesInParentheses == R.SpacesInParentheses &&
2118  SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
2119  Standard == R.Standard && TabWidth == R.TabWidth &&
2120  StatementMacros == R.StatementMacros && UseTab == R.UseTab &&
2121  TypenameMacros == R.TypenameMacros;
2122  }
2123 
2124  llvm::Optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
2125 
2126  // Stores per-language styles. A FormatStyle instance inside has an empty
2127  // StyleSet. A FormatStyle instance returned by the Get method has its
2128  // StyleSet set to a copy of the originating StyleSet, effectively keeping the
2129  // internal representation of that StyleSet alive.
2130  //
2131  // The memory management and ownership reminds of a birds nest: chicks
2132  // leaving the nest take photos of the nest with them.
2133  struct FormatStyleSet {
2134  typedef std::map<FormatStyle::LanguageKind, FormatStyle> MapType;
2135 
2136  llvm::Optional<FormatStyle> Get(FormatStyle::LanguageKind Language) const;
2137 
2138  // Adds \p Style to this FormatStyleSet. Style must not have an associated
2139  // FormatStyleSet.
2140  // Style.Language should be different than LK_None. If this FormatStyleSet
2141  // already contains an entry for Style.Language, that gets replaced with the
2142  // passed Style.
2143  void Add(FormatStyle Style);
2144 
2145  // Clears this FormatStyleSet.
2146  void Clear();
2147 
2148  private:
2149  std::shared_ptr<MapType> Styles;
2150  };
2151 
2152  static FormatStyleSet BuildStyleSetFromConfiguration(
2153  const FormatStyle &MainStyle,
2154  const std::vector<FormatStyle> &ConfigurationStyles);
2155 
2156 private:
2157  FormatStyleSet StyleSet;
2158 
2159  friend std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
2160 };
2161 
2162 /// Returns a format style complying with the LLVM coding standards:
2163 /// http://llvm.org/docs/CodingStandards.html.
2165  FormatStyle::LanguageKind Language = FormatStyle::LanguageKind::LK_Cpp);
2166 
2167 /// Returns a format style complying with one of Google's style guides:
2168 /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
2169 /// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
2170 /// https://developers.google.com/protocol-buffers/docs/style.
2171 FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
2172 
2173 /// Returns a format style complying with Chromium's style guide:
2174 /// http://www.chromium.org/developers/coding-style.
2175 FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
2176 
2177 /// Returns a format style complying with Mozilla's style guide:
2178 /// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
2180 
2181 /// Returns a format style complying with Webkit's style guide:
2182 /// http://www.webkit.org/coding/coding-style.html
2184 
2185 /// Returns a format style complying with GNU Coding Standards:
2186 /// http://www.gnu.org/prep/standards/standards.html
2188 
2189 /// Returns a format style complying with Microsoft style guide:
2190 /// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
2191 FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language);
2192 
2193 /// Returns style indicating formatting should be not applied at all.
2195 
2196 /// Gets a predefined style for the specified language by name.
2197 ///
2198 /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
2199 /// compared case-insensitively.
2200 ///
2201 /// Returns ``true`` if the Style has been set.
2202 bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
2203  FormatStyle *Style);
2204 
2205 /// Parse configuration from YAML-formatted text.
2206 ///
2207 /// Style->Language is used to get the base style, if the ``BasedOnStyle``
2208 /// option is present.
2209 ///
2210 /// The FormatStyleSet of Style is reset.
2211 ///
2212 /// When ``BasedOnStyle`` is not present, options not present in the YAML
2213 /// document, are retained in \p Style.
2214 std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
2215 
2216 /// Gets configuration in a YAML string.
2217 std::string configurationAsText(const FormatStyle &Style);
2218 
2219 /// Returns the replacements necessary to sort all ``#include`` blocks
2220 /// that are affected by ``Ranges``.
2221 tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
2222  ArrayRef<tooling::Range> Ranges,
2223  StringRef FileName,
2224  unsigned *Cursor = nullptr);
2225 
2226 /// Returns the replacements corresponding to applying and formatting
2227 /// \p Replaces on success; otheriwse, return an llvm::Error carrying
2228 /// llvm::StringError.
2230 formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
2231  const FormatStyle &Style);
2232 
2233 /// Returns the replacements corresponding to applying \p Replaces and
2234 /// cleaning up the code after that on success; otherwise, return an llvm::Error
2235 /// carrying llvm::StringError.
2236 /// This also supports inserting/deleting C++ #include directives:
2237 /// - If a replacement has offset UINT_MAX, length 0, and a replacement text
2238 /// that is an #include directive, this will insert the #include into the
2239 /// correct block in the \p Code.
2240 /// - If a replacement has offset UINT_MAX, length 1, and a replacement text
2241 /// that is the name of the header to be removed, the header will be removed
2242 /// from \p Code if it exists.
2243 /// The include manipulation is done via `tooling::HeaderInclude`, see its
2244 /// documentation for more details on how include insertion points are found and
2245 /// what edits are produced.
2247 cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
2248  const FormatStyle &Style);
2249 
2250 /// Represents the status of a formatting attempt.
2252  /// A value of ``false`` means that any of the affected ranges were not
2253  /// formatted due to a non-recoverable syntax error.
2254  bool FormatComplete = true;
2255 
2256  /// If ``FormatComplete`` is false, ``Line`` records a one-based
2257  /// original line number at which a syntax error might have occurred. This is
2258  /// based on a best-effort analysis and could be imprecise.
2259  unsigned Line = 0;
2260 };
2261 
2262 /// Reformats the given \p Ranges in \p Code.
2263 ///
2264 /// Each range is extended on either end to its next bigger logic unit, i.e.
2265 /// everything that might influence its formatting or might be influenced by its
2266 /// formatting.
2267 ///
2268 /// Returns the ``Replacements`` necessary to make all \p Ranges comply with
2269 /// \p Style.
2270 ///
2271 /// If ``Status`` is non-null, its value will be populated with the status of
2272 /// this formatting attempt. See \c FormattingAttemptStatus.
2273 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
2274  ArrayRef<tooling::Range> Ranges,
2275  StringRef FileName = "<stdin>",
2276  FormattingAttemptStatus *Status = nullptr);
2277 
2278 /// Same as above, except if ``IncompleteFormat`` is non-null, its value
2279 /// will be set to true if any of the affected ranges were not formatted due to
2280 /// a non-recoverable syntax error.
2281 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
2282  ArrayRef<tooling::Range> Ranges,
2283  StringRef FileName,
2284  bool *IncompleteFormat);
2285 
2286 /// Clean up any erroneous/redundant code in the given \p Ranges in \p
2287 /// Code.
2288 ///
2289 /// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
2290 tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
2291  ArrayRef<tooling::Range> Ranges,
2292  StringRef FileName = "<stdin>");
2293 
2294 /// Fix namespace end comments in the given \p Ranges in \p Code.
2295 ///
2296 /// Returns the ``Replacements`` that fix the namespace comments in all
2297 /// \p Ranges in \p Code.
2299  StringRef Code,
2300  ArrayRef<tooling::Range> Ranges,
2301  StringRef FileName = "<stdin>");
2302 
2303 /// Sort consecutive using declarations in the given \p Ranges in
2304 /// \p Code.
2305 ///
2306 /// Returns the ``Replacements`` that sort the using declarations in all
2307 /// \p Ranges in \p Code.
2309  StringRef Code,
2310  ArrayRef<tooling::Range> Ranges,
2311  StringRef FileName = "<stdin>");
2312 
2313 /// Returns the ``LangOpts`` that the formatter expects you to set.
2314 ///
2315 /// \param Style determines specific settings for lexing mode.
2317 
2318 /// Description to be used for help text for a ``llvm::cl`` option for
2319 /// specifying format style. The description is closely related to the operation
2320 /// of ``getStyle()``.
2321 extern const char *StyleOptionHelpDescription;
2322 
2323 /// The suggested format style to use by default. This allows tools using
2324 /// `getStyle` to have a consistent default style.
2325 /// Different builds can modify the value to the preferred styles.
2326 extern const char *DefaultFormatStyle;
2327 
2328 /// The suggested predefined style to use as the fallback style in `getStyle`.
2329 /// Different builds can modify the value to the preferred styles.
2330 extern const char *DefaultFallbackStyle;
2331 
2332 /// Construct a FormatStyle based on ``StyleName``.
2333 ///
2334 /// ``StyleName`` can take several forms:
2335 /// * "{<key>: <value>, ...}" - Set specic style parameters.
2336 /// * "<style name>" - One of the style names supported by
2337 /// getPredefinedStyle().
2338 /// * "file" - Load style configuration from a file called ``.clang-format``
2339 /// located in one of the parent directories of ``FileName`` or the current
2340 /// directory if ``FileName`` is empty.
2341 ///
2342 /// \param[in] StyleName Style name to interpret according to the description
2343 /// above.
2344 /// \param[in] FileName Path to start search for .clang-format if ``StyleName``
2345 /// == "file".
2346 /// \param[in] FallbackStyle The name of a predefined style used to fallback to
2347 /// in case \p StyleName is "file" and no file can be found.
2348 /// \param[in] Code The actual code to be formatted. Used to determine the
2349 /// language if the filename isn't sufficient.
2350 /// \param[in] FS The underlying file system, in which the file resides. By
2351 /// default, the file system is the real file system.
2352 ///
2353 /// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
2354 /// "file" and no file is found, returns ``FallbackStyle``. If no style could be
2355 /// determined, returns an Error.
2356 llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
2357  StringRef FallbackStyle,
2358  StringRef Code = "",
2359  llvm::vfs::FileSystem *FS = nullptr);
2360 
2361 // Guesses the language from the ``FileName`` and ``Code`` to be formatted.
2362 // Defaults to FormatStyle::LK_Cpp.
2363 FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
2364 
2365 // Returns a string representation of ``Language``.
2366 inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
2367  switch (Language) {
2368  case FormatStyle::LK_Cpp:
2369  return "C++";
2370  case FormatStyle::LK_CSharp:
2371  return "CSharp";
2372  case FormatStyle::LK_ObjC:
2373  return "Objective-C";
2374  case FormatStyle::LK_Java:
2375  return "Java";
2376  case FormatStyle::LK_JavaScript:
2377  return "JavaScript";
2378  case FormatStyle::LK_Proto:
2379  return "Proto";
2380  case FormatStyle::LK_TableGen:
2381  return "TableGen";
2382  case FormatStyle::LK_TextProto:
2383  return "TextProto";
2384  default:
2385  return "Unknown";
2386  }
2387 }
2388 
2389 } // end namespace format
2390 } // end namespace clang
2391 
2392 namespace std {
2393 template <>
2394 struct is_error_code_enum<clang::format::ParseError> : std::true_type {};
2395 }
2396 
2397 #endif // LLVM_CLANG_FORMAT_FORMAT_H
bool operator==(CanQual< T > x, CanQual< U > y)
tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, bool *IncompleteFormat)
Same as above, except if IncompleteFormat is non-null, its value will be set to true if any of the af...
Definition: Format.cpp:2463
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, unsigned *Cursor=nullptr)
Returns the replacements necessary to sort all #include blocks that are affected by Ranges...
Definition: Format.cpp:2210
tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Clean up any erroneous/redundant code in the given Ranges in Code.
Definition: Format.cpp:2454
bool AlignConsecutiveDeclarations
If true, aligns consecutive declarations.
Definition: Format.h:115
FormatStyle getMozillaStyle()
Returns a format style complying with Mozilla&#39;s style guide: https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
Definition: Format.cpp:1022
std::error_code make_error_code(ParseError e)
Definition: Format.cpp:617
std::vector< IncludeCategory > IncludeCategories
Regular expressions denoting the different #include categories used for ordering #includes.
Definition: IncludeStyle.h:100
Maintains a set of replacements that are conflict-free.
Definition: Replacement.h:209
tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Fix namespace end comments in the given Ranges in Code.
Definition: Format.cpp:2473
FormatStyle getWebKitStyle()
Returns a format style complying with Webkit&#39;s style guide: http://www.webkit.org/coding/coding-style...
Definition: Format.cpp:1048
FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language=FormatStyle::LanguageKind::LK_Cpp)
Returns a format style complying with the LLVM coding standards: http://llvm.org/docs/CodingStandards...
Definition: Format.cpp:717
EscapedNewlineAlignmentStyle AlignEscapedNewlines
Options for aligning backslashes in escaped newlines.
Definition: Format.h:149
Definition: Format.h:2392
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
Always break after an open bracket, if the parameters don&#39;t fit on a single line, e...
Definition: Format.h:73
FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code)
Definition: Format.cpp:2549
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr or CxxCtorInitializer) selects the name&#39;s to...
llvm::Error Error
FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Chromium&#39;s style guide: http://www.chromium.org/developers/coding-style.
Definition: Format.cpp:962
FormatStyle getGNUStyle()
Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standar...
Definition: Format.cpp:1071
bool AlignConsecutiveAssignments
If true, aligns consecutive assignments.
Definition: Format.h:104
Language
The language for the input, used to select and validate the language standard and possible actions...
Definition: LangStandard.h:19
llvm::Expected< tooling::Replacements > formatReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
Returns the replacements corresponding to applying and formatting Replaces on success; otheriwse...
Definition: Format.cpp:2250
BracketAlignmentStyle AlignAfterOpenBracket
If true, horizontally aligns arguments after an open bracket.
Definition: Format.h:80
tooling::Replacements sortUsingDeclarations(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Sort consecutive using declarations in the given Ranges in Code.
Definition: Format.cpp:2482
Defines the clang::LangOptions interface.
const AnnotatedLine * Line
LangOptions getFormattingLangOpts(const FormatStyle &Style=getLLVMStyle())
Returns the LangOpts that the formatter expects you to set.
Definition: Format.cpp:2491
Align escaped newlines as far left as possible.
Definition: Format.h:137
Align escaped newlines in the right-most column.
Definition: Format.h:145
bool AlignOperands
If true, horizontally align operands of binary and ternary expressions.
Definition: Format.h:160
Don&#39;t align escaped newlines.
Definition: Format.h:126
int AccessModifierOffset
The extra indent or outdent of access modifiers, e.g. public:.
Definition: Format.h:51
FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with one of Google&#39;s style guides: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
Definition: Format.cpp:835
EscapedNewlineAlignmentStyle
Different styles for aligning escaped newlines.
Definition: Format.h:118
const char * DefaultFallbackStyle
The suggested predefined style to use as the fallback style in getStyle.
Definition: Format.cpp:2569
llvm::Expected< tooling::Replacements > cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
Returns the replacements corresponding to applying Replaces and cleaning up the code after that on su...
Definition: Format.cpp:2360
StringRef getLanguageName(FormatStyle::LanguageKind Language)
Definition: Format.h:2366
Don&#39;t align, instead use ContinuationIndentWidth, e.g.
Definition: Format.h:66
FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Microsoft style guide: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017.
Definition: Format.cpp:1086
const char * DefaultFormatStyle
The suggested format style to use by default.
Definition: Format.cpp:2567
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition: Format.h:49
Style for sorting and grouping C++ #include directives.
Definition: IncludeStyle.h:20
std::string configurationAsText(const FormatStyle &Style)
Gets configuration in a YAML string.
Definition: Format.cpp:1201
const char * StyleOptionHelpDescription
Description to be used for help text for a llvm::cl option for specifying format style.
Definition: Format.cpp:2515
Represents the status of a formatting attempt.
Definition: Format.h:2251
Dataflow Directional Tag Classes.
BracketAlignmentStyle
Different styles for aligning after open brackets.
Definition: Format.h:54
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
Gets a predefined style for the specified language by name.
Definition: Format.cpp:1121
bool AlignConsecutiveMacros
If true, aligns consecutive C/C++ preprocessor macros.
Definition: Format.h:93
FormatStyle getNoStyle()
Returns style indicating formatting should be not applied at all.
Definition: Format.cpp:1113
Align parameters on the open bracket, e.g.
Definition: Format.h:60
const std::error_category & getParseCategory()
Definition: Format.cpp:613
llvm::Expected< FormatStyle > getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle, StringRef Code="", llvm::vfs::FileSystem *FS=nullptr)
Construct a FormatStyle based on StyleName.
Definition: Format.cpp:2571
bool Add(InterpState &S, CodePtr OpPC)
Definition: Interp.h:132
bool AlignTrailingComments
If true, aligns trailing comments.
Definition: Format.h:168
StringRef Text
Definition: Format.cpp:1808
std::error_code parseConfiguration(StringRef Text, FormatStyle *Style)
Parse configuration from YAML-formatted text.
Definition: Format.cpp:1147
IncludeBlocksStyle IncludeBlocks
Dependent on the value, multiple #include blocks can be sorted as one and divided based on category...
Definition: IncludeStyle.h:53
bool AllowAllArgumentsOnNextLine
If a function call or braced initializer list doesn&#39;t fit on a line, allow putting all arguments onto...
Definition: Format.h:184
const FormatStyle & Style