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