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