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