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