]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Format/Format.h
Upgrade to OpenSSH 7.6p1. This will be followed shortly by 7.7p1.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Format / Format.h
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
18 #include "clang/Basic/LangOptions.h"
19 #include "clang/Tooling/Core/Replacement.h"
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:``.
48   int AccessModifierOffset;
49
50   /// \brief Different styles for aligning after open brackets.
51   enum BracketAlignmentStyle {
52     /// \brief Align parameters on the open bracket, e.g.:
53     /// \code
54     ///   someLongFunction(argument1,
55     ///                    argument2);
56     /// \endcode
57     BAS_Align,
58     /// \brief Don't align, instead use ``ContinuationIndentWidth``, e.g.:
59     /// \code
60     ///   someLongFunction(argument1,
61     ///       argument2);
62     /// \endcode
63     BAS_DontAlign,
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
70     BAS_AlwaysBreak,
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.
77   BracketAlignmentStyle AlignAfterOpenBracket;
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
88   bool AlignConsecutiveAssignments;
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
99   bool AlignConsecutiveDeclarations;
100
101   /// \brief Different styles for aligning escaped newlines.
102   enum EscapedNewlineAlignmentStyle {
103     /// \brief Don't align escaped newlines.
104     /// \code
105     ///   #define A \
106     ///     int aaaa; \
107     ///     int b; \
108     ///     int dddddddddd;
109     /// \endcode
110     ENAS_DontAlign,
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
121     ENAS_Left,
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
129     ENAS_Right,
130   };
131
132   /// \brief Options for aligning backslashes in escaped newlines.
133   EscapedNewlineAlignmentStyle AlignEscapedNewlines;
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
144   bool AlignOperands;
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
152   bool AlignTrailingComments;
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
169   bool AllowAllParametersOfDeclarationOnNextLine;
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.
174   bool AllowShortBlocksOnASingleLine;
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
187   bool AllowShortCaseLabelsOnASingleLine;
188
189   /// \brief Different styles for merging short functions containing at most one
190   /// statement.
191   enum ShortFunctionStyle {
192     /// \brief Never merge functions into a single line.
193     SFS_None,
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
207     SFS_InlineOnly,
208     /// \brief Only merge empty functions.
209     /// \code
210     ///   void f() {}
211     ///   void f2() {
212     ///     bar2();
213     ///   }
214     /// \endcode
215     SFS_Empty,
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
226     SFS_Inline,
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
234     SFS_All,
235   };
236
237   /// \brief Dependent on the value, ``int f() { return 0; }`` can be put on a
238   /// single line.
239   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
240
241   /// \brief If ``true``, ``if (a) return;`` can be put on a single line.
242   bool AllowShortIfStatementsOnASingleLine;
243
244   /// \brief If ``true``, ``while (true) continue;`` can be put on a single
245   /// line.
246   bool AllowShortLoopsOnASingleLine;
247
248   /// \brief Different ways to break after the function definition return type.
249   /// This option is **deprecated** and is retained for backwards compatibility.
250   enum DefinitionReturnTypeBreakingStyle {
251     /// Break after return type automatically.
252     /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
253     DRTBS_None,
254     /// Always break after the return type.
255     DRTBS_All,
256     /// Always break after the return types of top-level functions.
257     DRTBS_TopLevel,
258   };
259
260   /// \brief Different ways to break after the function definition or
261   /// declaration return type.
262   enum ReturnTypeBreakingStyle {
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
272     RTBS_None,
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
288     RTBS_All,
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
301     RTBS_TopLevel,
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
316     RTBS_AllDefinitions,
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
328     RTBS_TopLevelDefinitions,
329   };
330
331   /// \brief The function definition return type breaking style to use.  This
332   /// option is **deprecated** and is retained for backwards compatibility.
333   DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
334
335   /// \brief The function declaration return type breaking style to use.
336   ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
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
350   bool AlwaysBreakBeforeMultilineStrings;
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
359   bool AlwaysBreakTemplateDeclarations;
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
377   bool BinPackArguments;
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
391   bool BinPackParameters;
392
393   /// \brief The style of breaking before or after binary operators.
394   enum BinaryOperatorStyle {
395     /// Break after operators.
396     /// \code
397     ///    LooooooooooongType loooooooooooooooooooooongVariable =
398     ///        someLooooooooooooooooongFunction();
399     ///
400     ///    bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
401     ///                         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
402     ///                     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
403     ///                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
404     ///                     ccccccccccccccccccccccccccccccccccccccccc;
405     /// \endcode
406     BOS_None,
407     /// Break before operators that aren't assignments.
408     /// \code
409     ///    LooooooooooongType loooooooooooooooooooooongVariable =
410     ///        someLooooooooooooooooongFunction();
411     ///
412     ///    bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
413     ///                         + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
414     ///                     == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
415     ///                 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
416     ///                        > ccccccccccccccccccccccccccccccccccccccccc;
417     /// \endcode
418     BOS_NonAssignment,
419     /// Break before operators.
420     /// \code
421     ///    LooooooooooongType loooooooooooooooooooooongVariable
422     ///        = someLooooooooooooooooongFunction();
423     ///
424     ///    bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
425     ///                         + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
426     ///                     == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
427     ///                 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
428     ///                        > ccccccccccccccccccccccccccccccccccccccccc;
429     /// \endcode
430     BOS_All,
431   };
432
433   /// \brief The way to wrap binary operators.
434   BinaryOperatorStyle BreakBeforeBinaryOperators;
435
436   /// \brief Different ways to attach braces to their surrounding context.
437   enum BraceBreakingStyle {
438     /// Always attach braces to surrounding context.
439     /// \code
440     ///   try {
441     ///     foo();
442     ///   } catch () {
443     ///   }
444     ///   void foo() { bar(); }
445     ///   class foo {};
446     ///   if (foo()) {
447     ///   } else {
448     ///   }
449     ///   enum X : int { A, B };
450     /// \endcode
451     BS_Attach,
452     /// Like ``Attach``, but break before braces on function, namespace and
453     /// class definitions.
454     /// \code
455     ///   try {
456     ///     foo();
457     ///   } catch () {
458     ///   }
459     ///   void foo() { bar(); }
460     ///   class foo
461     ///   {
462     ///   };
463     ///   if (foo()) {
464     ///   } else {
465     ///   }
466     ///   enum X : int { A, B };
467     /// \endcode
468     BS_Linux,
469     /// Like ``Attach``, but break before braces on enum, function, and record
470     /// definitions.
471     /// \code
472     ///   try {
473     ///     foo();
474     ///   } catch () {
475     ///   }
476     ///   void foo() { bar(); }
477     ///   class foo
478     ///   {
479     ///   };
480     ///   if (foo()) {
481     ///   } else {
482     ///   }
483     ///   enum X : int { A, B };
484     /// \endcode
485     BS_Mozilla,
486     /// Like ``Attach``, but break before function definitions, ``catch``, and
487     /// ``else``.
488     /// \code
489     ///   try {
490     ///     foo();
491     ///   } catch () {
492     ///   }
493     ///   void foo() { bar(); }
494     ///   class foo
495     ///   {
496     ///   };
497     ///   if (foo()) {
498     ///   } else {
499     ///   }
500     ///   enum X : int
501     ///   {
502     ///     A,
503     ///     B
504     ///   };
505     /// \endcode
506     BS_Stroustrup,
507     /// Always break before braces.
508     /// \code
509     ///   try {
510     ///     foo();
511     ///   }
512     ///   catch () {
513     ///   }
514     ///   void foo() { bar(); }
515     ///   class foo {
516     ///   };
517     ///   if (foo()) {
518     ///   }
519     ///   else {
520     ///   }
521     ///   enum X : int { A, B };
522     /// \endcode
523     BS_Allman,
524     /// Always break before braces and add an extra level of indentation to
525     /// braces of control statements, not to those of class, function
526     /// or other definitions.
527     /// \code
528     ///   try
529     ///     {
530     ///       foo();
531     ///     }
532     ///   catch ()
533     ///     {
534     ///     }
535     ///   void foo() { bar(); }
536     ///   class foo
537     ///   {
538     ///   };
539     ///   if (foo())
540     ///     {
541     ///     }
542     ///   else
543     ///     {
544     ///     }
545     ///   enum X : int
546     ///   {
547     ///     A,
548     ///     B
549     ///   };
550     /// \endcode
551     BS_GNU,
552     /// Like ``Attach``, but break before functions.
553     /// \code
554     ///   try {
555     ///     foo();
556     ///   } catch () {
557     ///   }
558     ///   void foo() { bar(); }
559     ///   class foo {
560     ///   };
561     ///   if (foo()) {
562     ///   } else {
563     ///   }
564     ///   enum X : int { A, B };
565     /// \endcode
566     BS_WebKit,
567     /// Configure each individual brace in `BraceWrapping`.
568     BS_Custom
569   };
570
571   /// \brief The brace breaking style to use.
572   BraceBreakingStyle BreakBeforeBraces;
573
574   /// \brief Precise control over the wrapping of braces.
575   /// \code
576   ///   # Should be declared this way:
577   ///   BreakBeforeBraces: Custom
578   ///   BraceWrapping:
579   ///       AfterClass: true
580   /// \endcode
581   struct BraceWrappingFlags {
582     /// \brief Wrap class definitions.
583     /// \code
584     ///   true:
585     ///   class foo {};
586     ///
587     ///   false:
588     ///   class foo
589     ///   {};
590     /// \endcode
591     bool AfterClass;
592     /// \brief Wrap control statements (``if``/``for``/``while``/``switch``/..).
593     /// \code
594     ///   true:
595     ///   if (foo())
596     ///   {
597     ///   } else
598     ///   {}
599     ///   for (int i = 0; i < 10; ++i)
600     ///   {}
601     ///
602     ///   false:
603     ///   if (foo()) {
604     ///   } else {
605     ///   }
606     ///   for (int i = 0; i < 10; ++i) {
607     ///   }
608     /// \endcode
609     bool AfterControlStatement;
610     /// \brief Wrap enum definitions.
611     /// \code
612     ///   true:
613     ///   enum X : int
614     ///   {
615     ///     B
616     ///   };
617     ///
618     ///   false:
619     ///   enum X : int { B };
620     /// \endcode
621     bool AfterEnum;
622     /// \brief Wrap function definitions.
623     /// \code
624     ///   true:
625     ///   void foo()
626     ///   {
627     ///     bar();
628     ///     bar2();
629     ///   }
630     ///
631     ///   false:
632     ///   void foo() {
633     ///     bar();
634     ///     bar2();
635     ///   }
636     /// \endcode
637     bool AfterFunction;
638     /// \brief Wrap namespace definitions.
639     /// \code
640     ///   true:
641     ///   namespace
642     ///   {
643     ///   int foo();
644     ///   int bar();
645     ///   }
646     ///
647     ///   false:
648     ///   namespace {
649     ///   int foo();
650     ///   int bar();
651     ///   }
652     /// \endcode
653     bool AfterNamespace;
654     /// \brief Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..).
655     bool AfterObjCDeclaration;
656     /// \brief Wrap struct definitions.
657     /// \code
658     ///   true:
659     ///   struct foo
660     ///   {
661     ///     int x;
662     ///   };
663     ///
664     ///   false:
665     ///   struct foo {
666     ///     int x;
667     ///   };
668     /// \endcode
669     bool AfterStruct;
670     /// \brief Wrap union definitions.
671     /// \code
672     ///   true:
673     ///   union foo
674     ///   {
675     ///     int x;
676     ///   }
677     ///
678     ///   false:
679     ///   union foo {
680     ///     int x;
681     ///   }
682     /// \endcode
683     bool AfterUnion;
684     /// \brief Wrap extern blocks.
685     /// \code
686     ///   true:
687     ///   extern "C"
688     ///   {
689     ///     int foo();
690     ///   }
691     ///
692     ///   false:
693     ///   extern "C" {
694     ///   int foo();
695     ///   }
696     /// \endcode
697     bool AfterExternBlock;
698     /// \brief Wrap before ``catch``.
699     /// \code
700     ///   true:
701     ///   try {
702     ///     foo();
703     ///   }
704     ///   catch () {
705     ///   }
706     ///
707     ///   false:
708     ///   try {
709     ///     foo();
710     ///   } catch () {
711     ///   }
712     /// \endcode
713     bool BeforeCatch;
714     /// \brief Wrap before ``else``.
715     /// \code
716     ///   true:
717     ///   if (foo()) {
718     ///   }
719     ///   else {
720     ///   }
721     ///
722     ///   false:
723     ///   if (foo()) {
724     ///   } else {
725     ///   }
726     /// \endcode
727     bool BeforeElse;
728     /// \brief Indent the wrapped braces themselves.
729     bool IndentBraces;
730     /// \brief If ``false``, empty function body can be put on a single line.
731     /// This option is used only if the opening brace of the function has
732     /// already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
733     /// set, and the function could/should not be put on a single line (as per
734     /// `AllowShortFunctionsOnASingleLine` and constructor formatting options).
735     /// \code
736     ///   int f()   vs.   inf f()
737     ///   {}              {
738     ///                   }
739     /// \endcode
740     ///
741     bool SplitEmptyFunction;
742     /// \brief If ``false``, empty record (e.g. class, struct or union) body
743     /// can be put on a single line. This option is used only if the opening
744     /// brace of the record has already been wrapped, i.e. the `AfterClass`
745     /// (for classes) brace wrapping mode is set.
746     /// \code
747     ///   class Foo   vs.  class Foo
748     ///   {}               {
749     ///                    }
750     /// \endcode
751     ///
752     bool SplitEmptyRecord;
753     /// \brief If ``false``, empty namespace body can be put on a single line.
754     /// This option is used only if the opening brace of the namespace has
755     /// already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
756     /// set.
757     /// \code
758     ///   namespace Foo   vs.  namespace Foo
759     ///   {}                   {
760     ///                        }
761     /// \endcode
762     ///
763     bool SplitEmptyNamespace;
764   };
765
766   /// \brief Control of individual brace wrapping cases.
767   ///
768   /// If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
769   /// each individual brace case should be handled. Otherwise, this is ignored.
770   /// \code{.yaml}
771   ///   # Example of usage:
772   ///   BreakBeforeBraces: Custom
773   ///   BraceWrapping:
774   ///     AfterEnum: true
775   ///     AfterStruct: false
776   ///     SplitEmptyFunction: false
777   /// \endcode
778   BraceWrappingFlags BraceWrapping;
779
780   /// \brief If ``true``, ternary operators will be placed after line breaks.
781   /// \code
782   ///    true:
783   ///    veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
784   ///        ? firstValue
785   ///        : SecondValueVeryVeryVeryVeryLong;
786   ///
787   ///    false:
788   ///    veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
789   ///        firstValue :
790   ///        SecondValueVeryVeryVeryVeryLong;
791   /// \endcode
792   bool BreakBeforeTernaryOperators;
793
794   /// \brief Different ways to break initializers.
795   enum BreakConstructorInitializersStyle {
796     /// Break constructor initializers before the colon and after the commas.
797     /// \code
798     /// Constructor()
799     ///     : initializer1(),
800     ///       initializer2()
801     /// \endcode
802     BCIS_BeforeColon,
803     /// Break constructor initializers before the colon and commas, and align
804     /// the commas with the colon.
805     /// \code
806     /// Constructor()
807     ///     : initializer1()
808     ///     , initializer2()
809     /// \endcode
810     BCIS_BeforeComma,
811     /// Break constructor initializers after the colon and commas.
812     /// \code
813     /// Constructor() :
814     ///     initializer1(),
815     ///     initializer2()
816     /// \endcode
817     BCIS_AfterColon
818   };
819
820   /// \brief The constructor initializers style to use.
821   BreakConstructorInitializersStyle BreakConstructorInitializers;
822
823   /// \brief Break after each annotation on a field in Java files.
824   /// \code{.java}
825   ///    true:                                  false:
826   ///    @Partial                       vs.     @Partial @Mock DataLoad loader;
827   ///    @Mock
828   ///    DataLoad loader;
829   /// \endcode
830   bool BreakAfterJavaFieldAnnotations;
831
832   /// \brief Allow breaking string literals when formatting.
833   bool BreakStringLiterals;
834
835   /// \brief The column limit.
836   ///
837   /// A column limit of ``0`` means that there is no column limit. In this case,
838   /// clang-format will respect the input's line breaking decisions within
839   /// statements unless they contradict other rules.
840   unsigned ColumnLimit;
841
842   /// \brief A regular expression that describes comments with special meaning,
843   /// which should not be split into lines or otherwise changed.
844   /// \code
845   ///    // CommentPragmas: '^ FOOBAR pragma:'
846   ///    // Will leave the following line unaffected
847   ///    #include <vector> // FOOBAR pragma: keep
848   /// \endcode
849   std::string CommentPragmas;
850
851   /// \brief If ``true``, in the class inheritance expression clang-format will
852   /// break before ``:`` and ``,`` if there is multiple inheritance.
853   /// \code
854   ///    true:                                  false:
855   ///    class MyClass                  vs.     class MyClass : public X, public Y {
856   ///        : public X                         };
857   ///        , public Y {
858   ///    };
859   /// \endcode
860   bool BreakBeforeInheritanceComma;
861
862   /// \brief If ``true``, consecutive namespace declarations will be on the same
863   /// line. If ``false``, each namespace is declared on a new line.
864   /// \code
865   ///   true:
866   ///   namespace Foo { namespace Bar {
867   ///   }}
868   ///
869   ///   false:
870   ///   namespace Foo {
871   ///   namespace Bar {
872   ///   }
873   ///   }
874   /// \endcode
875   ///
876   /// If it does not fit on a single line, the overflowing namespaces get
877   /// wrapped:
878   /// \code
879   ///   namespace Foo { namespace Bar {
880   ///   namespace Extra {
881   ///   }}}
882   /// \endcode
883   bool CompactNamespaces;
884
885   /// \brief If the constructor initializers don't fit on a line, put each
886   /// initializer on its own line.
887   /// \code
888   ///   true:
889   ///   SomeClass::Constructor()
890   ///       : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
891   ///     return 0;
892   ///   }
893   ///
894   ///   false:
895   ///   SomeClass::Constructor()
896   ///       : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
897   ///         aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
898   ///     return 0;
899   ///   }
900   /// \endcode
901   bool ConstructorInitializerAllOnOneLineOrOnePerLine;
902
903   /// \brief The number of characters to use for indentation of constructor
904   /// initializer lists.
905   unsigned ConstructorInitializerIndentWidth;
906
907   /// \brief Indent width for line continuations.
908   /// \code
909   ///    ContinuationIndentWidth: 2
910   ///
911   ///    int i =         //  VeryVeryVeryVeryVeryLongComment
912   ///      longFunction( // Again a long comment
913   ///        arg);
914   /// \endcode
915   unsigned ContinuationIndentWidth;
916
917   /// \brief If ``true``, format braced lists as best suited for C++11 braced
918   /// lists.
919   ///
920   /// Important differences:
921   /// - No spaces inside the braced list.
922   /// - No line break before the closing brace.
923   /// - Indentation with the continuation indent, not with the block indent.
924   ///
925   /// Fundamentally, C++11 braced lists are formatted exactly like function
926   /// calls would be formatted in their place. If the braced list follows a name
927   /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were
928   /// the parentheses of a function call with that name. If there is no name,
929   /// a zero-length name is assumed.
930   /// \code
931   ///    true:                                  false:
932   ///    vector<int> x{1, 2, 3, 4};     vs.     vector<int> x{ 1, 2, 3, 4 };
933   ///    vector<T> x{{}, {}, {}, {}};           vector<T> x{ {}, {}, {}, {} };
934   ///    f(MyMap[{composite, key}]);            f(MyMap[{ composite, key }]);
935   ///    new int[3]{1, 2, 3};                   new int[3]{ 1, 2, 3 };
936   /// \endcode
937   bool Cpp11BracedListStyle;
938
939   /// \brief If ``true``, analyze the formatted file for the most common
940   /// alignment of ``&`` and ``*``.
941   /// Pointer and reference alignment styles are going to be updated according
942   /// to the preferences found in the file.
943   /// ``PointerAlignment`` is then used only as fallback.
944   bool DerivePointerAlignment;
945
946   /// \brief Disables formatting completely.
947   bool DisableFormat;
948
949   /// \brief If ``true``, clang-format detects whether function calls and
950   /// definitions are formatted with one parameter per line.
951   ///
952   /// Each call can be bin-packed, one-per-line or inconclusive. If it is
953   /// inconclusive, e.g. completely on one line, but a decision needs to be
954   /// made, clang-format analyzes whether there are other bin-packed cases in
955   /// the input file and act accordingly.
956   ///
957   /// NOTE: This is an experimental flag, that might go away or be renamed. Do
958   /// not use this in config files, etc. Use at your own risk.
959   bool ExperimentalAutoDetectBinPacking;
960
961   /// \brief If ``true``, clang-format adds missing namespace end comments and
962   /// fixes invalid existing ones.
963   /// \code
964   ///    true:                                  false:
965   ///    namespace a {                  vs.     namespace a {
966   ///    foo();                                 foo();
967   ///    } // namespace a;                      }
968   /// \endcode
969   bool FixNamespaceComments;
970
971   /// \brief A vector of macros that should be interpreted as foreach loops
972   /// instead of as function calls.
973   ///
974   /// These are expected to be macros of the form:
975   /// \code
976   ///   FOREACH(<variable-declaration>, ...)
977   ///     <loop-body>
978   /// \endcode
979   ///
980   /// In the .clang-format configuration file, this can be configured like:
981   /// \code{.yaml}
982   ///   ForEachMacros: ['RANGES_FOR', 'FOREACH']
983   /// \endcode
984   ///
985   /// For example: BOOST_FOREACH.
986   std::vector<std::string> ForEachMacros;
987
988   /// \brief Styles for sorting multiple ``#include`` blocks.
989   enum IncludeBlocksStyle {
990     /// \brief Sort each ``#include`` block separately.
991     /// \code
992     ///    #include "b.h"               into      #include "b.h"
993     ///
994     ///    #include <lib/main.h>                  #include "a.h"
995     ///    #include "a.h"                         #include <lib/main.h>
996     /// \endcode
997     IBS_Preserve,
998     /// \brief Merge multiple ``#include`` blocks together and sort as one.
999     /// \code
1000     ///    #include "b.h"               into      #include "a.h"
1001     ///                                           #include "b.h"
1002     ///    #include <lib/main.h>                  #include <lib/main.h>
1003     ///    #include "a.h"
1004     /// \endcode
1005     IBS_Merge,
1006     /// \brief Merge multiple ``#include`` blocks together and sort as one.
1007     /// Then split into groups based on category priority. See
1008     /// ``IncludeCategories``.
1009     /// \code
1010     ///    #include "b.h"               into      #include "a.h"
1011     ///                                           #include "b.h"
1012     ///    #include <lib/main.h>
1013     ///    #include "a.h"                         #include <lib/main.h>
1014     /// \endcode
1015     IBS_Regroup,
1016   };
1017
1018   /// \brief Dependent on the value, multiple ``#include`` blocks can be sorted
1019   /// as one and divided based on category.
1020   IncludeBlocksStyle IncludeBlocks;
1021
1022   /// \brief See documentation of ``IncludeCategories``.
1023   struct IncludeCategory {
1024     /// \brief The regular expression that this category matches.
1025     std::string Regex;
1026     /// \brief The priority to assign to this category.
1027     int Priority;
1028     bool operator==(const IncludeCategory &Other) const {
1029       return Regex == Other.Regex && Priority == Other.Priority;
1030     }
1031   };
1032
1033   /// \brief Regular expressions denoting the different ``#include`` categories
1034   /// used for ordering ``#includes``.
1035   ///
1036   /// These regular expressions are matched against the filename of an include
1037   /// (including the <> or "") in order. The value belonging to the first
1038   /// matching regular expression is assigned and ``#includes`` are sorted first
1039   /// according to increasing category number and then alphabetically within
1040   /// each category.
1041   ///
1042   /// If none of the regular expressions match, INT_MAX is assigned as
1043   /// category. The main header for a source file automatically gets category 0.
1044   /// so that it is generally kept at the beginning of the ``#includes``
1045   /// (http://llvm.org/docs/CodingStandards.html#include-style). However, you
1046   /// can also assign negative priorities if you have certain headers that
1047   /// always need to be first.
1048   ///
1049   /// To configure this in the .clang-format file, use:
1050   /// \code{.yaml}
1051   ///   IncludeCategories:
1052   ///     - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
1053   ///       Priority:        2
1054   ///     - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
1055   ///       Priority:        3
1056   ///     - Regex:           '.*'
1057   ///       Priority:        1
1058   /// \endcode
1059   std::vector<IncludeCategory> IncludeCategories;
1060
1061   /// \brief Specify a regular expression of suffixes that are allowed in the
1062   /// file-to-main-include mapping.
1063   ///
1064   /// When guessing whether a #include is the "main" include (to assign
1065   /// category 0, see above), use this regex of allowed suffixes to the header
1066   /// stem. A partial match is done, so that:
1067   /// - "" means "arbitrary suffix"
1068   /// - "$" means "no suffix"
1069   ///
1070   /// For example, if configured to "(_test)?$", then a header a.h would be seen
1071   /// as the "main" include in both a.cc and a_test.cc.
1072   std::string IncludeIsMainRegex;
1073
1074   /// \brief Indent case labels one level from the switch statement.
1075   ///
1076   /// When ``false``, use the same indentation level as for the switch statement.
1077   /// Switch statement body is always indented one level more than case labels.
1078   /// \code
1079   ///    false:                                 true:
1080   ///    switch (fool) {                vs.     switch (fool) {
1081   ///    case 1:                                  case 1:
1082   ///      bar();                                   bar();
1083   ///      break;                                   break;
1084   ///    default:                                 default:
1085   ///      plop();                                  plop();
1086   ///    }                                      }
1087   /// \endcode
1088   bool IndentCaseLabels;
1089
1090   /// \brief Options for indenting preprocessor directives.
1091   enum PPDirectiveIndentStyle {
1092     /// Does not indent any directives.
1093     /// \code
1094     ///    #if FOO
1095     ///    #if BAR
1096     ///    #include <foo>
1097     ///    #endif
1098     ///    #endif
1099     /// \endcode
1100     PPDIS_None,
1101     /// Indents directives after the hash.
1102     /// \code
1103     ///    #if FOO
1104     ///    #  if BAR
1105     ///    #    include <foo>
1106     ///    #  endif
1107     ///    #endif
1108     /// \endcode
1109     PPDIS_AfterHash
1110   };
1111
1112   /// \brief The preprocessor directive indenting style to use.
1113   PPDirectiveIndentStyle IndentPPDirectives;
1114
1115   /// \brief The number of columns to use for indentation.
1116   /// \code
1117   ///    IndentWidth: 3
1118   ///
1119   ///    void f() {
1120   ///       someFunction();
1121   ///       if (true, false) {
1122   ///          f();
1123   ///       }
1124   ///    }
1125   /// \endcode
1126   unsigned IndentWidth;
1127
1128   /// \brief Indent if a function definition or declaration is wrapped after the
1129   /// type.
1130   /// \code
1131   ///    true:
1132   ///    LoooooooooooooooooooooooooooooooooooooooongReturnType
1133   ///        LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1134   ///
1135   ///    false:
1136   ///    LoooooooooooooooooooooooooooooooooooooooongReturnType
1137   ///    LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1138   /// \endcode
1139   bool IndentWrappedFunctionNames;
1140
1141   /// \brief Quotation styles for JavaScript strings. Does not affect template
1142   /// strings.
1143   enum JavaScriptQuoteStyle {
1144     /// Leave string quotes as they are.
1145     /// \code{.js}
1146     ///    string1 = "foo";
1147     ///    string2 = 'bar';
1148     /// \endcode
1149     JSQS_Leave,
1150     /// Always use single quotes.
1151     /// \code{.js}
1152     ///    string1 = 'foo';
1153     ///    string2 = 'bar';
1154     /// \endcode
1155     JSQS_Single,
1156     /// Always use double quotes.
1157     /// \code{.js}
1158     ///    string1 = "foo";
1159     ///    string2 = "bar";
1160     /// \endcode
1161     JSQS_Double
1162   };
1163
1164   /// \brief The JavaScriptQuoteStyle to use for JavaScript strings.
1165   JavaScriptQuoteStyle JavaScriptQuotes;
1166
1167   /// \brief Whether to wrap JavaScript import/export statements.
1168   /// \code{.js}
1169   ///    true:
1170   ///    import {
1171   ///        VeryLongImportsAreAnnoying,
1172   ///        VeryLongImportsAreAnnoying,
1173   ///        VeryLongImportsAreAnnoying,
1174   ///    } from 'some/module.js'
1175   ///
1176   ///    false:
1177   ///    import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1178   /// \endcode
1179   bool JavaScriptWrapImports;
1180
1181   /// \brief If true, the empty line at the start of blocks is kept.
1182   /// \code
1183   ///    true:                                  false:
1184   ///    if (foo) {                     vs.     if (foo) {
1185   ///                                             bar();
1186   ///      bar();                               }
1187   ///    }
1188   /// \endcode
1189   bool KeepEmptyLinesAtTheStartOfBlocks;
1190
1191   /// \brief Supported languages.
1192   ///
1193   /// When stored in a configuration file, specifies the language, that the
1194   /// configuration targets. When passed to the ``reformat()`` function, enables
1195   /// syntax features specific to the language.
1196   enum LanguageKind {
1197     /// Do not use.
1198     LK_None,
1199     /// Should be used for C, C++.
1200     LK_Cpp,
1201     /// Should be used for Java.
1202     LK_Java,
1203     /// Should be used for JavaScript.
1204     LK_JavaScript,
1205     /// Should be used for Objective-C, Objective-C++.
1206     LK_ObjC,
1207     /// Should be used for Protocol Buffers
1208     /// (https://developers.google.com/protocol-buffers/).
1209     LK_Proto,
1210     /// Should be used for TableGen code.
1211     LK_TableGen,
1212     /// Should be used for Protocol Buffer messages in text format
1213     /// (https://developers.google.com/protocol-buffers/).
1214     LK_TextProto
1215   };
1216   bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
1217
1218   /// \brief Language, this format style is targeted at.
1219   LanguageKind Language;
1220
1221   /// \brief A regular expression matching macros that start a block.
1222   /// \code
1223   ///    # With:
1224   ///    MacroBlockBegin: "^NS_MAP_BEGIN|\
1225   ///    NS_TABLE_HEAD$"
1226   ///    MacroBlockEnd: "^\
1227   ///    NS_MAP_END|\
1228   ///    NS_TABLE_.*_END$"
1229   ///
1230   ///    NS_MAP_BEGIN
1231   ///      foo();
1232   ///    NS_MAP_END
1233   ///
1234   ///    NS_TABLE_HEAD
1235   ///      bar();
1236   ///    NS_TABLE_FOO_END
1237   ///
1238   ///    # Without:
1239   ///    NS_MAP_BEGIN
1240   ///    foo();
1241   ///    NS_MAP_END
1242   ///
1243   ///    NS_TABLE_HEAD
1244   ///    bar();
1245   ///    NS_TABLE_FOO_END
1246   /// \endcode
1247   std::string MacroBlockBegin;
1248
1249   /// \brief A regular expression matching macros that end a block.
1250   std::string MacroBlockEnd;
1251
1252   /// \brief The maximum number of consecutive empty lines to keep.
1253   /// \code
1254   ///    MaxEmptyLinesToKeep: 1         vs.     MaxEmptyLinesToKeep: 0
1255   ///    int f() {                              int f() {
1256   ///      int = 1;                                 int i = 1;
1257   ///                                               i = foo();
1258   ///      i = foo();                               return i;
1259   ///                                           }
1260   ///      return i;
1261   ///    }
1262   /// \endcode
1263   unsigned MaxEmptyLinesToKeep;
1264
1265   /// \brief Different ways to indent namespace contents.
1266   enum NamespaceIndentationKind {
1267     /// Don't indent in namespaces.
1268     /// \code
1269     ///    namespace out {
1270     ///    int i;
1271     ///    namespace in {
1272     ///    int i;
1273     ///    }
1274     ///    }
1275     /// \endcode
1276     NI_None,
1277     /// Indent only in inner namespaces (nested in other namespaces).
1278     /// \code
1279     ///    namespace out {
1280     ///    int i;
1281     ///    namespace in {
1282     ///      int i;
1283     ///    }
1284     ///    }
1285     /// \endcode
1286     NI_Inner,
1287     /// Indent in all namespaces.
1288     /// \code
1289     ///    namespace out {
1290     ///      int i;
1291     ///      namespace in {
1292     ///        int i;
1293     ///      }
1294     ///    }
1295     /// \endcode
1296     NI_All
1297   };
1298
1299   /// \brief The indentation used for namespaces.
1300   NamespaceIndentationKind NamespaceIndentation;
1301
1302   /// \brief The number of characters to use for indentation of ObjC blocks.
1303   /// \code{.objc}
1304   ///    ObjCBlockIndentWidth: 4
1305   ///
1306   ///    [operation setCompletionBlock:^{
1307   ///        [self onOperationDone];
1308   ///    }];
1309   /// \endcode
1310   unsigned ObjCBlockIndentWidth;
1311
1312   /// \brief Add a space after ``@property`` in Objective-C, i.e. use
1313   /// ``@property (readonly)`` instead of ``@property(readonly)``.
1314   bool ObjCSpaceAfterProperty;
1315
1316   /// \brief Add a space in front of an Objective-C protocol list, i.e. use
1317   /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1318   bool ObjCSpaceBeforeProtocolList;
1319
1320   /// \brief The penalty for breaking around an assignment operator.
1321   unsigned PenaltyBreakAssignment;
1322
1323   /// \brief The penalty for breaking a function call after ``call(``.
1324   unsigned PenaltyBreakBeforeFirstCallParameter;
1325
1326   /// \brief The penalty for each line break introduced inside a comment.
1327   unsigned PenaltyBreakComment;
1328
1329   /// \brief The penalty for breaking before the first ``<<``.
1330   unsigned PenaltyBreakFirstLessLess;
1331
1332   /// \brief The penalty for each line break introduced inside a string literal.
1333   unsigned PenaltyBreakString;
1334
1335   /// \brief The penalty for each character outside of the column limit.
1336   unsigned PenaltyExcessCharacter;
1337
1338   /// \brief Penalty for putting the return type of a function onto its own
1339   /// line.
1340   unsigned PenaltyReturnTypeOnItsOwnLine;
1341
1342   /// \brief The ``&`` and ``*`` alignment style.
1343   enum PointerAlignmentStyle {
1344     /// Align pointer to the left.
1345     /// \code
1346     ///   int* a;
1347     /// \endcode
1348     PAS_Left,
1349     /// Align pointer to the right.
1350     /// \code
1351     ///   int *a;
1352     /// \endcode
1353     PAS_Right,
1354     /// Align pointer in the middle.
1355     /// \code
1356     ///   int * a;
1357     /// \endcode
1358     PAS_Middle
1359   };
1360
1361   /// \brief Pointer and reference alignment style.
1362   PointerAlignmentStyle PointerAlignment;
1363
1364   /// See documentation of ``RawStringFormats``.
1365   struct RawStringFormat {
1366     /// \brief The delimiter that this raw string format matches.
1367     std::string Delimiter;
1368     /// \brief The language of this raw string.
1369     LanguageKind Language;
1370     /// \brief The style name on which this raw string format is based on.
1371     /// If not specified, the raw string format is based on the style that this
1372     /// format is based on.
1373     std::string BasedOnStyle;
1374     bool operator==(const RawStringFormat &Other) const {
1375       return Delimiter == Other.Delimiter && Language == Other.Language &&
1376              BasedOnStyle == Other.BasedOnStyle;
1377     }
1378   };
1379
1380   /// \brief Raw string delimiters denoting that the raw string contents are
1381   /// code in a particular language and can be reformatted.
1382   ///
1383   /// A raw string with a matching delimiter will be reformatted assuming the
1384   /// specified language based on a predefined style given by 'BasedOnStyle'.
1385   /// If 'BasedOnStyle' is not found, the formatting is based on llvm style.
1386   ///
1387   /// To configure this in the .clang-format file, use:
1388   /// \code{.yaml}
1389   ///   RawStringFormats:
1390   ///     - Delimiter: 'pb'
1391   ///       Language:  TextProto
1392   ///       BasedOnStyle: llvm
1393   ///     - Delimiter: 'proto'
1394   ///       Language:  TextProto
1395   ///       BasedOnStyle: google
1396   /// \endcode
1397   std::vector<RawStringFormat> RawStringFormats;
1398
1399   /// \brief If ``true``, clang-format will attempt to re-flow comments.
1400   /// \code
1401   ///    false:
1402   ///    // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1403   ///    /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1404   ///
1405   ///    true:
1406   ///    // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1407   ///    // information
1408   ///    /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1409   ///     * information */
1410   /// \endcode
1411   bool ReflowComments;
1412
1413   /// \brief If ``true``, clang-format will sort ``#includes``.
1414   /// \code
1415   ///    false:                                 true:
1416   ///    #include "b.h"                 vs.     #include "a.h"
1417   ///    #include "a.h"                         #include "b.h"
1418   /// \endcode
1419   bool SortIncludes;
1420
1421   /// \brief If ``true``, clang-format will sort using declarations.
1422   ///
1423   /// The order of using declarations is defined as follows:
1424   /// Split the strings by "::" and discard any initial empty strings. The last
1425   /// element of each list is a non-namespace name; all others are namespace
1426   /// names. Sort the lists of names lexicographically, where the sort order of
1427   /// individual names is that all non-namespace names come before all namespace
1428   /// names, and within those groups, names are in case-insensitive
1429   /// lexicographic order.
1430   /// \code
1431   ///    false:                                 true:
1432   ///    using std::cout;               vs.     using std::cin;
1433   ///    using std::cin;                        using std::cout;
1434   /// \endcode
1435   bool SortUsingDeclarations;
1436
1437   /// \brief If ``true``, a space is inserted after C style casts.
1438   /// \code
1439   ///    true:                                  false:
1440   ///    (int)i;                        vs.     (int) i;
1441   /// \endcode
1442   bool SpaceAfterCStyleCast;
1443
1444   /// \brief If \c true, a space will be inserted after the 'template' keyword.
1445   /// \code
1446   ///    true:                                  false:
1447   ///    template <int> void foo();     vs.     template<int> void foo();
1448   /// \endcode
1449   bool SpaceAfterTemplateKeyword;
1450
1451   /// \brief If ``false``, spaces will be removed before assignment operators.
1452   /// \code
1453   ///    true:                                  false:
1454   ///    int a = 5;                     vs.     int a=5;
1455   ///    a += 42                                a+=42;
1456   /// \endcode
1457   bool SpaceBeforeAssignmentOperators;
1458
1459   /// \brief Different ways to put a space before opening parentheses.
1460   enum SpaceBeforeParensOptions {
1461     /// Never put a space before opening parentheses.
1462     /// \code
1463     ///    void f() {
1464     ///      if(true) {
1465     ///        f();
1466     ///      }
1467     ///    }
1468     /// \endcode
1469     SBPO_Never,
1470     /// Put a space before opening parentheses only after control statement
1471     /// keywords (``for/if/while...``).
1472     /// \code
1473     ///    void f() {
1474     ///      if (true) {
1475     ///        f();
1476     ///      }
1477     ///    }
1478     /// \endcode
1479     SBPO_ControlStatements,
1480     /// Always put a space before opening parentheses, except when it's
1481     /// prohibited by the syntax rules (in function-like macro definitions) or
1482     /// when determined by other style rules (after unary operators, opening
1483     /// parentheses, etc.)
1484     /// \code
1485     ///    void f () {
1486     ///      if (true) {
1487     ///        f ();
1488     ///      }
1489     ///    }
1490     /// \endcode
1491     SBPO_Always
1492   };
1493
1494   /// \brief Defines in which cases to put a space before opening parentheses.
1495   SpaceBeforeParensOptions SpaceBeforeParens;
1496
1497   /// \brief If ``true``, spaces may be inserted into ``()``.
1498   /// \code
1499   ///    true:                                false:
1500   ///    void f( ) {                    vs.   void f() {
1501   ///      int x[] = {foo( ), bar( )};          int x[] = {foo(), bar()};
1502   ///      if (true) {                          if (true) {
1503   ///        f( );                                f();
1504   ///      }                                    }
1505   ///    }                                    }
1506   /// \endcode
1507   bool SpaceInEmptyParentheses;
1508
1509   /// \brief The number of spaces before trailing line comments
1510   /// (``//`` - comments).
1511   ///
1512   /// This does not affect trailing block comments (``/*`` - comments) as
1513   /// those commonly have different usage patterns and a number of special
1514   /// cases.
1515   /// \code
1516   ///    SpacesBeforeTrailingComments: 3
1517   ///    void f() {
1518   ///      if (true) {   // foo1
1519   ///        f();        // bar
1520   ///      }             // foo
1521   ///    }
1522   /// \endcode
1523   unsigned SpacesBeforeTrailingComments;
1524
1525   /// \brief If ``true``, spaces will be inserted after ``<`` and before ``>``
1526   /// in template argument lists.
1527   /// \code
1528   ///    true:                                  false:
1529   ///    static_cast< int >(arg);       vs.     static_cast<int>(arg);
1530   ///    std::function< void(int) > fct;        std::function<void(int)> fct;
1531   /// \endcode
1532   bool SpacesInAngles;
1533
1534   /// \brief If ``true``, spaces are inserted inside container literals (e.g.
1535   /// ObjC and Javascript array and dict literals).
1536   /// \code{.js}
1537   ///    true:                                  false:
1538   ///    var arr = [ 1, 2, 3 ];         vs.     var arr = [1, 2, 3];
1539   ///    f({a : 1, b : 2, c : 3});              f({a: 1, b: 2, c: 3});
1540   /// \endcode
1541   bool SpacesInContainerLiterals;
1542
1543   /// \brief If ``true``, spaces may be inserted into C style casts.
1544   /// \code
1545   ///    true:                                  false:
1546   ///    x = ( int32 )y                 vs.     x = (int32)y
1547   /// \endcode
1548   bool SpacesInCStyleCastParentheses;
1549
1550   /// \brief If ``true``, spaces will be inserted after ``(`` and before ``)``.
1551   /// \code
1552   ///    true:                                  false:
1553   ///    t f( Deleted & ) & = delete;   vs.     t f(Deleted &) & = delete;
1554   /// \endcode
1555   bool SpacesInParentheses;
1556
1557   /// \brief If ``true``, spaces will be inserted after ``[`` and before ``]``.
1558   /// Lambdas or unspecified size array declarations will not be affected.
1559   /// \code
1560   ///    true:                                  false:
1561   ///    int a[ 5 ];                    vs.     int a[5];
1562   ///    std::unique_ptr<int[]> foo() {} // Won't be affected
1563   /// \endcode
1564   bool SpacesInSquareBrackets;
1565
1566   /// \brief Supported language standards.
1567   enum LanguageStandard {
1568     /// Use C++03-compatible syntax.
1569     LS_Cpp03,
1570     /// Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
1571     /// ``A<A<int> >``).
1572     LS_Cpp11,
1573     /// Automatic detection based on the input.
1574     LS_Auto
1575   };
1576
1577   /// \brief Format compatible with this standard, e.g. use ``A<A<int> >``
1578   /// instead of ``A<A<int>>`` for ``LS_Cpp03``.
1579   LanguageStandard Standard;
1580
1581   /// \brief The number of columns used for tab stops.
1582   unsigned TabWidth;
1583
1584   /// \brief Different ways to use tab in formatting.
1585   enum UseTabStyle {
1586     /// Never use tab.
1587     UT_Never,
1588     /// Use tabs only for indentation.
1589     UT_ForIndentation,
1590     /// Use tabs only for line continuation and indentation.
1591     UT_ForContinuationAndIndentation,
1592     /// Use tabs whenever we need to fill whitespace that spans at least from
1593     /// one tab stop to the next one.
1594     UT_Always
1595   };
1596
1597   /// \brief The way to use tab characters in the resulting file.
1598   UseTabStyle UseTab;
1599
1600   bool operator==(const FormatStyle &R) const {
1601     return AccessModifierOffset == R.AccessModifierOffset &&
1602            AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
1603            AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
1604            AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
1605            AlignEscapedNewlines == R.AlignEscapedNewlines &&
1606            AlignOperands == R.AlignOperands &&
1607            AlignTrailingComments == R.AlignTrailingComments &&
1608            AllowAllParametersOfDeclarationOnNextLine ==
1609                R.AllowAllParametersOfDeclarationOnNextLine &&
1610            AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
1611            AllowShortCaseLabelsOnASingleLine ==
1612                R.AllowShortCaseLabelsOnASingleLine &&
1613            AllowShortFunctionsOnASingleLine ==
1614                R.AllowShortFunctionsOnASingleLine &&
1615            AllowShortIfStatementsOnASingleLine ==
1616                R.AllowShortIfStatementsOnASingleLine &&
1617            AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
1618            AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
1619            AlwaysBreakBeforeMultilineStrings ==
1620                R.AlwaysBreakBeforeMultilineStrings &&
1621            AlwaysBreakTemplateDeclarations ==
1622                R.AlwaysBreakTemplateDeclarations &&
1623            BinPackArguments == R.BinPackArguments &&
1624            BinPackParameters == R.BinPackParameters &&
1625            BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
1626            BreakBeforeBraces == R.BreakBeforeBraces &&
1627            BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
1628            BreakConstructorInitializers == R.BreakConstructorInitializers &&
1629            CompactNamespaces == R.CompactNamespaces &&
1630            BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
1631            BreakStringLiterals == R.BreakStringLiterals &&
1632            ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
1633            BreakBeforeInheritanceComma == R.BreakBeforeInheritanceComma &&
1634            ConstructorInitializerAllOnOneLineOrOnePerLine ==
1635                R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
1636            ConstructorInitializerIndentWidth ==
1637                R.ConstructorInitializerIndentWidth &&
1638            ContinuationIndentWidth == R.ContinuationIndentWidth &&
1639            Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
1640            DerivePointerAlignment == R.DerivePointerAlignment &&
1641            DisableFormat == R.DisableFormat &&
1642            ExperimentalAutoDetectBinPacking ==
1643                R.ExperimentalAutoDetectBinPacking &&
1644            FixNamespaceComments == R.FixNamespaceComments &&
1645            ForEachMacros == R.ForEachMacros &&
1646            IncludeBlocks == R.IncludeBlocks &&
1647            IncludeCategories == R.IncludeCategories &&
1648            IndentCaseLabels == R.IndentCaseLabels &&
1649            IndentPPDirectives == R.IndentPPDirectives &&
1650            IndentWidth == R.IndentWidth && Language == R.Language &&
1651            IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
1652            JavaScriptQuotes == R.JavaScriptQuotes &&
1653            JavaScriptWrapImports == R.JavaScriptWrapImports &&
1654            KeepEmptyLinesAtTheStartOfBlocks ==
1655                R.KeepEmptyLinesAtTheStartOfBlocks &&
1656            MacroBlockBegin == R.MacroBlockBegin &&
1657            MacroBlockEnd == R.MacroBlockEnd &&
1658            MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
1659            NamespaceIndentation == R.NamespaceIndentation &&
1660            ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
1661            ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
1662            ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
1663            PenaltyBreakAssignment ==
1664                R.PenaltyBreakAssignment &&
1665            PenaltyBreakBeforeFirstCallParameter ==
1666                R.PenaltyBreakBeforeFirstCallParameter &&
1667            PenaltyBreakComment == R.PenaltyBreakComment &&
1668            PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
1669            PenaltyBreakString == R.PenaltyBreakString &&
1670            PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
1671            PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
1672            PointerAlignment == R.PointerAlignment &&
1673            RawStringFormats == R.RawStringFormats &&
1674            SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
1675            SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
1676            SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
1677            SpaceBeforeParens == R.SpaceBeforeParens &&
1678            SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
1679            SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
1680            SpacesInAngles == R.SpacesInAngles &&
1681            SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
1682            SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
1683            SpacesInParentheses == R.SpacesInParentheses &&
1684            SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
1685            Standard == R.Standard && TabWidth == R.TabWidth &&
1686            UseTab == R.UseTab;
1687   }
1688 };
1689
1690 /// \brief Returns a format style complying with the LLVM coding standards:
1691 /// http://llvm.org/docs/CodingStandards.html.
1692 FormatStyle getLLVMStyle();
1693
1694 /// \brief Returns a format style complying with one of Google's style guides:
1695 /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
1696 /// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
1697 /// https://developers.google.com/protocol-buffers/docs/style.
1698 FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
1699
1700 /// \brief Returns a format style complying with Chromium's style guide:
1701 /// http://www.chromium.org/developers/coding-style.
1702 FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
1703
1704 /// \brief Returns a format style complying with Mozilla's style guide:
1705 /// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
1706 FormatStyle getMozillaStyle();
1707
1708 /// \brief Returns a format style complying with Webkit's style guide:
1709 /// http://www.webkit.org/coding/coding-style.html
1710 FormatStyle getWebKitStyle();
1711
1712 /// \brief Returns a format style complying with GNU Coding Standards:
1713 /// http://www.gnu.org/prep/standards/standards.html
1714 FormatStyle getGNUStyle();
1715
1716 /// \brief Returns style indicating formatting should be not applied at all.
1717 FormatStyle getNoStyle();
1718
1719 /// \brief Gets a predefined style for the specified language by name.
1720 ///
1721 /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
1722 /// compared case-insensitively.
1723 ///
1724 /// Returns ``true`` if the Style has been set.
1725 bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
1726                         FormatStyle *Style);
1727
1728 /// \brief Parse configuration from YAML-formatted text.
1729 ///
1730 /// Style->Language is used to get the base style, if the ``BasedOnStyle``
1731 /// option is present.
1732 ///
1733 /// When ``BasedOnStyle`` is not present, options not present in the YAML
1734 /// document, are retained in \p Style.
1735 std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
1736
1737 /// \brief Gets configuration in a YAML string.
1738 std::string configurationAsText(const FormatStyle &Style);
1739
1740 /// \brief Returns the replacements necessary to sort all ``#include`` blocks
1741 /// that are affected by ``Ranges``.
1742 tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
1743                                    ArrayRef<tooling::Range> Ranges,
1744                                    StringRef FileName,
1745                                    unsigned *Cursor = nullptr);
1746
1747 /// \brief Returns the replacements corresponding to applying and formatting
1748 /// \p Replaces on success; otheriwse, return an llvm::Error carrying
1749 /// llvm::StringError.
1750 llvm::Expected<tooling::Replacements>
1751 formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
1752                    const FormatStyle &Style);
1753
1754 /// \brief Returns the replacements corresponding to applying \p Replaces and
1755 /// cleaning up the code after that on success; otherwise, return an llvm::Error
1756 /// carrying llvm::StringError.
1757 /// This also supports inserting/deleting C++ #include directives:
1758 /// - If a replacement has offset UINT_MAX, length 0, and a replacement text
1759 ///   that is an #include directive, this will insert the #include into the
1760 ///   correct block in the \p Code. When searching for points to insert new
1761 ///   header, this ignores #include's after the #include block(s) in the
1762 ///   beginning of a file to avoid inserting headers into code sections where
1763 ///   new #include's should not be added by default. These code sections
1764 ///   include:
1765 ///     - raw string literals (containing #include).
1766 ///     - #if blocks.
1767 ///     - Special #include's among declarations (e.g. functions).
1768 /// - If a replacement has offset UINT_MAX, length 1, and a replacement text
1769 ///   that is the name of the header to be removed, the header will be removed
1770 ///   from \p Code if it exists.
1771 llvm::Expected<tooling::Replacements>
1772 cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
1773                           const FormatStyle &Style);
1774
1775 /// \brief Represents the status of a formatting attempt.
1776 struct FormattingAttemptStatus {
1777   /// \brief A value of ``false`` means that any of the affected ranges were not
1778   /// formatted due to a non-recoverable syntax error.
1779   bool FormatComplete = true;
1780
1781   /// \brief If ``FormatComplete`` is false, ``Line`` records a one-based
1782   /// original line number at which a syntax error might have occurred. This is
1783   /// based on a best-effort analysis and could be imprecise.
1784   unsigned Line = 0;
1785 };
1786
1787 /// \brief Reformats the given \p Ranges in \p Code.
1788 ///
1789 /// Each range is extended on either end to its next bigger logic unit, i.e.
1790 /// everything that might influence its formatting or might be influenced by its
1791 /// formatting.
1792 ///
1793 /// Returns the ``Replacements`` necessary to make all \p Ranges comply with
1794 /// \p Style.
1795 ///
1796 /// If ``Status`` is non-null, its value will be populated with the status of
1797 /// this formatting attempt. See \c FormattingAttemptStatus.
1798 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
1799                                ArrayRef<tooling::Range> Ranges,
1800                                StringRef FileName = "<stdin>",
1801                                FormattingAttemptStatus *Status = nullptr);
1802
1803 /// \brief Same as above, except if ``IncompleteFormat`` is non-null, its value
1804 /// will be set to true if any of the affected ranges were not formatted due to
1805 /// a non-recoverable syntax error.
1806 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
1807                                ArrayRef<tooling::Range> Ranges,
1808                                StringRef FileName,
1809                                bool *IncompleteFormat);
1810
1811 /// \brief Clean up any erroneous/redundant code in the given \p Ranges in \p
1812 /// Code.
1813 ///
1814 /// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
1815 tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
1816                               ArrayRef<tooling::Range> Ranges,
1817                               StringRef FileName = "<stdin>");
1818
1819 /// \brief Fix namespace end comments in the given \p Ranges in \p Code.
1820 ///
1821 /// Returns the ``Replacements`` that fix the namespace comments in all
1822 /// \p Ranges in \p Code.
1823 tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style,
1824                                               StringRef Code,
1825                                               ArrayRef<tooling::Range> Ranges,
1826                                               StringRef FileName = "<stdin>");
1827
1828 /// \brief Sort consecutive using declarations in the given \p Ranges in
1829 /// \p Code.
1830 ///
1831 /// Returns the ``Replacements`` that sort the using declarations in all
1832 /// \p Ranges in \p Code.
1833 tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
1834                                             StringRef Code,
1835                                             ArrayRef<tooling::Range> Ranges,
1836                                             StringRef FileName = "<stdin>");
1837
1838 /// \brief Returns the ``LangOpts`` that the formatter expects you to set.
1839 ///
1840 /// \param Style determines specific settings for lexing mode.
1841 LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle());
1842
1843 /// \brief Description to be used for help text for a ``llvm::cl`` option for
1844 /// specifying format style. The description is closely related to the operation
1845 /// of ``getStyle()``.
1846 extern const char *StyleOptionHelpDescription;
1847
1848 /// \brief Construct a FormatStyle based on ``StyleName``.
1849 ///
1850 /// ``StyleName`` can take several forms:
1851 /// * "{<key>: <value>, ...}" - Set specic style parameters.
1852 /// * "<style name>" - One of the style names supported by
1853 /// getPredefinedStyle().
1854 /// * "file" - Load style configuration from a file called ``.clang-format``
1855 /// located in one of the parent directories of ``FileName`` or the current
1856 /// directory if ``FileName`` is empty.
1857 ///
1858 /// \param[in] StyleName Style name to interpret according to the description
1859 /// above.
1860 /// \param[in] FileName Path to start search for .clang-format if ``StyleName``
1861 /// == "file".
1862 /// \param[in] FallbackStyle The name of a predefined style used to fallback to
1863 /// in case \p StyleName is "file" and no file can be found.
1864 /// \param[in] Code The actual code to be formatted. Used to determine the
1865 /// language if the filename isn't sufficient.
1866 /// \param[in] FS The underlying file system, in which the file resides. By
1867 /// default, the file system is the real file system.
1868 ///
1869 /// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
1870 /// "file" and no file is found, returns ``FallbackStyle``. If no style could be
1871 /// determined, returns an Error.
1872 llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
1873                                      StringRef FallbackStyle,
1874                                      StringRef Code = "",
1875                                      vfs::FileSystem *FS = nullptr);
1876
1877 // \brief Returns a string representation of ``Language``.
1878 inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
1879   switch (Language) {
1880   case FormatStyle::LK_Cpp:
1881     return "C++";
1882   case FormatStyle::LK_ObjC:
1883     return "Objective-C";
1884   case FormatStyle::LK_Java:
1885     return "Java";
1886   case FormatStyle::LK_JavaScript:
1887     return "JavaScript";
1888   case FormatStyle::LK_Proto:
1889     return "Proto";
1890   case FormatStyle::LK_TextProto:
1891     return "TextProto";
1892   default:
1893     return "Unknown";
1894   }
1895 }
1896
1897 } // end namespace format
1898 } // end namespace clang
1899
1900 namespace std {
1901 template <>
1902 struct is_error_code_enum<clang::format::ParseError> : std::true_type {};
1903 }
1904
1905 #endif // LLVM_CLANG_FORMAT_FORMAT_H