Bug Summary

File:tools/clang/include/clang/Format/Format.h
Warning:line 46, column 8
Excessive padding in 'struct clang::format::FormatStyle' (35 padding bytes, where 3 is optimal). Optimal fields order: ForEachMacros, IncludeCategories, CommentPragmas, IncludeIsMainRegex, MacroBlockBegin, MacroBlockEnd, AccessModifierOffset, AlignAfterOpenBracket, AllowShortFunctionsOnASingleLine, AlwaysBreakAfterDefinitionReturnType, AlwaysBreakAfterReturnType, BreakBeforeBinaryOperators, BreakBeforeBraces, ColumnLimit, ConstructorInitializerIndentWidth, ContinuationIndentWidth, IndentWidth, JavaScriptQuotes, Language, MaxEmptyLinesToKeep, NamespaceIndentation, ObjCBlockIndentWidth, PenaltyBreakBeforeFirstCallParameter, PenaltyBreakComment, PenaltyBreakFirstLessLess, PenaltyBreakString, PenaltyExcessCharacter, PenaltyReturnTypeOnItsOwnLine, PointerAlignment, SpaceBeforeParens, SpacesBeforeTrailingComments, Standard, TabWidth, UseTab, AlignConsecutiveAssignments, AlignConsecutiveDeclarations, AlignEscapedNewlinesLeft, AlignOperands, AlignTrailingComments, AllowAllParametersOfDeclarationOnNextLine, AllowShortBlocksOnASingleLine, AllowShortCaseLabelsOnASingleLine, AllowShortIfStatementsOnASingleLine, AllowShortLoopsOnASingleLine, AlwaysBreakBeforeMultilineStrings, AlwaysBreakTemplateDeclarations, BinPackArguments, BinPackParameters, BreakBeforeTernaryOperators, BreakConstructorInitializersBeforeComma, BreakAfterJavaFieldAnnotations, BreakStringLiterals, BreakBeforeInheritanceComma, ConstructorInitializerAllOnOneLineOrOnePerLine, Cpp11BracedListStyle, DerivePointerAlignment, DisableFormat, ExperimentalAutoDetectBinPacking, FixNamespaceComments, IndentCaseLabels, IndentWrappedFunctionNames, JavaScriptWrapImports, KeepEmptyLinesAtTheStartOfBlocks, ObjCSpaceAfterProperty, ObjCSpaceBeforeProtocolList, ReflowComments, SortIncludes, SpaceAfterCStyleCast, SpaceAfterTemplateKeyword, SpaceBeforeAssignmentOperators, SpaceInEmptyParentheses, SpacesInAngles, SpacesInContainerLiterals, SpacesInCStyleCastParentheses, SpacesInParentheses, SpacesInSquareBrackets, BraceWrapping, consider reordering the fields or adding explicit padding members

Annotated Source Code

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
23namespace clang {
24
25class Lexer;
26class SourceManager;
27class DiagnosticConsumer;
28
29namespace vfs {
30class FileSystem;
31}
32
33namespace format {
34
35enum class ParseError { Success = 0, Error, Unsuitable };
36class ParseErrorCategory final : public std::error_category {
37public:
38 const char *name() const noexcept override;
39 std::string message(int EV) const override;
40};
41const std::error_category &getParseCategory();
42std::error_code make_error_code(ParseError e);
43
44/// \brief The ``FormatStyle`` is used to configure the formatting to follow
45/// specific guidelines.
46struct FormatStyle {
Excessive padding in 'struct clang::format::FormatStyle' (35 padding bytes, where 3 is optimal). Optimal fields order: ForEachMacros, IncludeCategories, CommentPragmas, IncludeIsMainRegex, MacroBlockBegin, MacroBlockEnd, AccessModifierOffset, AlignAfterOpenBracket, AllowShortFunctionsOnASingleLine, AlwaysBreakAfterDefinitionReturnType, AlwaysBreakAfterReturnType, BreakBeforeBinaryOperators, BreakBeforeBraces, ColumnLimit, ConstructorInitializerIndentWidth, ContinuationIndentWidth, IndentWidth, JavaScriptQuotes, Language, MaxEmptyLinesToKeep, NamespaceIndentation, ObjCBlockIndentWidth, PenaltyBreakBeforeFirstCallParameter, PenaltyBreakComment, PenaltyBreakFirstLessLess, PenaltyBreakString, PenaltyExcessCharacter, PenaltyReturnTypeOnItsOwnLine, PointerAlignment, SpaceBeforeParens, SpacesBeforeTrailingComments, Standard, TabWidth, UseTab, AlignConsecutiveAssignments, AlignConsecutiveDeclarations, AlignEscapedNewlinesLeft, AlignOperands, AlignTrailingComments, AllowAllParametersOfDeclarationOnNextLine, AllowShortBlocksOnASingleLine, AllowShortCaseLabelsOnASingleLine, AllowShortIfStatementsOnASingleLine, AllowShortLoopsOnASingleLine, AlwaysBreakBeforeMultilineStrings, AlwaysBreakTemplateDeclarations, BinPackArguments, BinPackParameters, BreakBeforeTernaryOperators, BreakConstructorInitializersBeforeComma, BreakAfterJavaFieldAnnotations, BreakStringLiterals, BreakBeforeInheritanceComma, ConstructorInitializerAllOnOneLineOrOnePerLine, Cpp11BracedListStyle, DerivePointerAlignment, DisableFormat, ExperimentalAutoDetectBinPacking, FixNamespaceComments, IndentCaseLabels, IndentWrappedFunctionNames, JavaScriptWrapImports, KeepEmptyLinesAtTheStartOfBlocks, ObjCSpaceAfterProperty, ObjCSpaceBeforeProtocolList, ReflowComments, SortIncludes, SpaceAfterCStyleCast, SpaceAfterTemplateKeyword, SpaceBeforeAssignmentOperators, SpaceInEmptyParentheses, SpacesInAngles, SpacesInContainerLiterals, SpacesInCStyleCastParentheses, SpacesInParentheses, SpacesInSquareBrackets, BraceWrapping, consider reordering the fields or adding explicit padding members
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 If ``true``, aligns escaped newlines as far left as possible.
102 /// Otherwise puts them into the right-most column.
103 /// \code
104 /// true:
105 /// #define A \
106 /// int aaaa; \
107 /// int b; \
108 /// int dddddddddd;
109 ///
110 /// false:
111 /// #define A \
112 /// int aaaa; \
113 /// int b; \
114 /// int dddddddddd;
115 /// \endcode
116 bool AlignEscapedNewlinesLeft;
117
118 /// \brief If ``true``, horizontally align operands of binary and ternary
119 /// expressions.
120 ///
121 /// Specifically, this aligns operands of a single expression that needs to be
122 /// split over multiple lines, e.g.:
123 /// \code
124 /// int aaa = bbbbbbbbbbbbbbb +
125 /// ccccccccccccccc;
126 /// \endcode
127 bool AlignOperands;
128
129 /// \brief If ``true``, aligns trailing comments.
130 /// \code
131 /// true: false:
132 /// int a; // My comment a vs. int a; // My comment a
133 /// int b = 2; // comment b int b = 2; // comment about b
134 /// \endcode
135 bool AlignTrailingComments;
136
137 /// \brief Allow putting all parameters of a function declaration onto
138 /// the next line even if ``BinPackParameters`` is ``false``.
139 /// \code
140 /// true: false:
141 /// myFunction(foo, vs. myFunction(foo, bar, plop);
142 /// bar,
143 /// plop);
144 /// \endcode
145 bool AllowAllParametersOfDeclarationOnNextLine;
146
147 /// \brief Allows contracting simple braced statements to a single line.
148 ///
149 /// E.g., this allows ``if (a) { return; }`` to be put on a single line.
150 bool AllowShortBlocksOnASingleLine;
151
152 /// \brief If ``true``, short case labels will be contracted to a single line.
153 /// \code
154 /// true: false:
155 /// switch (a) { vs. switch (a) {
156 /// case 1: x = 1; break; case 1:
157 /// case 2: return; x = 1;
158 /// } break;
159 /// case 2:
160 /// return;
161 /// }
162 /// \endcode
163 bool AllowShortCaseLabelsOnASingleLine;
164
165 /// \brief Different styles for merging short functions containing at most one
166 /// statement.
167 enum ShortFunctionStyle {
168 /// \brief Never merge functions into a single line.
169 SFS_None,
170 /// \brief Only merge empty functions.
171 /// \code
172 /// void f() { bar(); }
173 /// void f2() {
174 /// bar2();
175 /// }
176 /// \endcode
177 SFS_Empty,
178 /// \brief Only merge functions defined inside a class. Implies "empty".
179 /// \code
180 /// class {
181 /// void f() { foo(); }
182 /// };
183 /// \endcode
184 SFS_Inline,
185 /// \brief Merge all functions fitting on a single line.
186 /// \code
187 /// class {
188 /// void f() { foo(); }
189 /// };
190 /// void f() { bar(); }
191 /// \endcode
192 SFS_All,
193 };
194
195 /// \brief Dependent on the value, ``int f() { return 0; }`` can be put on a
196 /// single line.
197 ShortFunctionStyle AllowShortFunctionsOnASingleLine;
198
199 /// \brief If ``true``, ``if (a) return;`` can be put on a single line.
200 bool AllowShortIfStatementsOnASingleLine;
201
202 /// \brief If ``true``, ``while (true) continue;`` can be put on a single
203 /// line.
204 bool AllowShortLoopsOnASingleLine;
205
206 /// \brief Different ways to break after the function definition return type.
207 /// This option is **deprecated** and is retained for backwards compatibility.
208 enum DefinitionReturnTypeBreakingStyle {
209 /// Break after return type automatically.
210 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
211 DRTBS_None,
212 /// Always break after the return type.
213 DRTBS_All,
214 /// Always break after the return types of top-level functions.
215 DRTBS_TopLevel,
216 };
217
218 /// \brief Different ways to break after the function definition or
219 /// declaration return type.
220 enum ReturnTypeBreakingStyle {
221 /// Break after return type automatically.
222 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
223 /// \code
224 /// class A {
225 /// int f() { return 0; };
226 /// };
227 /// int f();
228 /// int f() { return 1; }
229 /// \endcode
230 RTBS_None,
231 /// Always break after the return type.
232 /// \code
233 /// class A {
234 /// int
235 /// f() {
236 /// return 0;
237 /// };
238 /// };
239 /// int
240 /// f();
241 /// int
242 /// f() {
243 /// return 1;
244 /// }
245 /// \endcode
246 RTBS_All,
247 /// Always break after the return types of top-level functions.
248 /// \code
249 /// class A {
250 /// int f() { return 0; };
251 /// };
252 /// int
253 /// f();
254 /// int
255 /// f() {
256 /// return 1;
257 /// }
258 /// \endcode
259 RTBS_TopLevel,
260 /// Always break after the return type of function definitions.
261 /// \code
262 /// class A {
263 /// int
264 /// f() {
265 /// return 0;
266 /// };
267 /// };
268 /// int f();
269 /// int
270 /// f() {
271 /// return 1;
272 /// }
273 /// \endcode
274 RTBS_AllDefinitions,
275 /// Always break after the return type of top-level definitions.
276 /// \code
277 /// class A {
278 /// int f() { return 0; };
279 /// };
280 /// int f();
281 /// int
282 /// f() {
283 /// return 1;
284 /// }
285 /// \endcode
286 RTBS_TopLevelDefinitions,
287 };
288
289 /// \brief The function definition return type breaking style to use. This
290 /// option is **deprecated** and is retained for backwards compatibility.
291 DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
292
293 /// \brief The function declaration return type breaking style to use.
294 ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
295
296 /// \brief If ``true``, always break before multiline string literals.
297 ///
298 /// This flag is mean to make cases where there are multiple multiline strings
299 /// in a file look more consistent. Thus, it will only take effect if wrapping
300 /// the string at that point leads to it being indented
301 /// ``ContinuationIndentWidth`` spaces from the start of the line.
302 /// \code
303 /// true: false:
304 /// aaaa = vs. aaaa = "bbbb"
305 /// "bbbb" "cccc";
306 /// "cccc";
307 /// \endcode
308 bool AlwaysBreakBeforeMultilineStrings;
309
310 /// \brief If ``true``, always break after the ``template<...>`` of a template
311 /// declaration.
312 /// \code
313 /// true: false:
314 /// template <typename T> vs. template <typename T> class C {};
315 /// class C {};
316 /// \endcode
317 bool AlwaysBreakTemplateDeclarations;
318
319 /// \brief If ``false``, a function call's arguments will either be all on the
320 /// same line or will have one line each.
321 /// \code
322 /// true:
323 /// void f() {
324 /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
325 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
326 /// }
327 ///
328 /// false:
329 /// void f() {
330 /// f(aaaaaaaaaaaaaaaaaaaa,
331 /// aaaaaaaaaaaaaaaaaaaa,
332 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
333 /// }
334 /// \endcode
335 bool BinPackArguments;
336
337 /// \brief If ``false``, a function declaration's or function definition's
338 /// parameters will either all be on the same line or will have one line each.
339 /// \code
340 /// true:
341 /// void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
342 /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
343 ///
344 /// false:
345 /// void f(int aaaaaaaaaaaaaaaaaaaa,
346 /// int aaaaaaaaaaaaaaaaaaaa,
347 /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
348 /// \endcode
349 bool BinPackParameters;
350
351 /// \brief The style of breaking before or after binary operators.
352 enum BinaryOperatorStyle {
353 /// Break after operators.
354 /// \code
355 /// LooooooooooongType loooooooooooooooooooooongVariable =
356 /// someLooooooooooooooooongFunction();
357 ///
358 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
359 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
360 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
361 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
362 /// ccccccccccccccccccccccccccccccccccccccccc;
363 /// \endcode
364 BOS_None,
365 /// Break before operators that aren't assignments.
366 /// \code
367 /// LooooooooooongType loooooooooooooooooooooongVariable =
368 /// someLooooooooooooooooongFunction();
369 ///
370 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
371 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
372 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
373 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
374 /// > ccccccccccccccccccccccccccccccccccccccccc;
375 /// \endcode
376 BOS_NonAssignment,
377 /// Break before operators.
378 /// \code
379 /// LooooooooooongType loooooooooooooooooooooongVariable
380 /// = someLooooooooooooooooongFunction();
381 ///
382 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
383 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
384 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
385 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
386 /// > ccccccccccccccccccccccccccccccccccccccccc;
387 /// \endcode
388 BOS_All,
389 };
390
391 /// \brief The way to wrap binary operators.
392 BinaryOperatorStyle BreakBeforeBinaryOperators;
393
394 /// \brief Different ways to attach braces to their surrounding context.
395 enum BraceBreakingStyle {
396 /// Always attach braces to surrounding context.
397 /// \code
398 /// try {
399 /// foo();
400 /// } catch () {
401 /// }
402 /// void foo() { bar(); }
403 /// class foo {};
404 /// if (foo()) {
405 /// } else {
406 /// }
407 /// enum X : int { A, B };
408 /// \endcode
409 BS_Attach,
410 /// Like ``Attach``, but break before braces on function, namespace and
411 /// class definitions.
412 /// \code
413 /// try {
414 /// foo();
415 /// } catch () {
416 /// }
417 /// void foo() { bar(); }
418 /// class foo
419 /// {
420 /// };
421 /// if (foo()) {
422 /// } else {
423 /// }
424 /// enum X : int { A, B };
425 /// \endcode
426 BS_Linux,
427 /// Like ``Attach``, but break before braces on enum, function, and record
428 /// definitions.
429 /// \code
430 /// try {
431 /// foo();
432 /// } catch () {
433 /// }
434 /// void foo() { bar(); }
435 /// class foo
436 /// {
437 /// };
438 /// if (foo()) {
439 /// } else {
440 /// }
441 /// enum X : int { A, B };
442 /// \endcode
443 BS_Mozilla,
444 /// Like ``Attach``, but break before function definitions, ``catch``, and
445 /// ``else``.
446 /// \code
447 /// try {
448 /// foo();
449 /// } catch () {
450 /// }
451 /// void foo() { bar(); }
452 /// class foo
453 /// {
454 /// };
455 /// if (foo()) {
456 /// } else {
457 /// }
458 /// enum X : int
459 /// {
460 /// A,
461 /// B
462 /// };
463 /// \endcode
464 BS_Stroustrup,
465 /// Always break before braces.
466 /// \code
467 /// try {
468 /// foo();
469 /// }
470 /// catch () {
471 /// }
472 /// void foo() { bar(); }
473 /// class foo {
474 /// };
475 /// if (foo()) {
476 /// }
477 /// else {
478 /// }
479 /// enum X : int { A, B };
480 /// \endcode
481 BS_Allman,
482 /// Always break before braces and add an extra level of indentation to
483 /// braces of control statements, not to those of class, function
484 /// or other definitions.
485 /// \code
486 /// try
487 /// {
488 /// foo();
489 /// }
490 /// catch ()
491 /// {
492 /// }
493 /// void foo() { bar(); }
494 /// class foo
495 /// {
496 /// };
497 /// if (foo())
498 /// {
499 /// }
500 /// else
501 /// {
502 /// }
503 /// enum X : int
504 /// {
505 /// A,
506 /// B
507 /// };
508 /// \endcode
509 BS_GNU,
510 /// Like ``Attach``, but break before functions.
511 /// \code
512 /// try {
513 /// foo();
514 /// } catch () {
515 /// }
516 /// void foo() { bar(); }
517 /// class foo {
518 /// };
519 /// if (foo()) {
520 /// } else {
521 /// }
522 /// enum X : int { A, B };
523 /// \endcode
524 BS_WebKit,
525 /// Configure each individual brace in `BraceWrapping`.
526 BS_Custom
527 };
528
529 /// \brief The brace breaking style to use.
530 BraceBreakingStyle BreakBeforeBraces;
531
532 /// \brief Precise control over the wrapping of braces.
533 /// \code
534 /// # Should be declared this way:
535 /// BreakBeforeBraces: Custom
536 /// BraceWrapping:
537 /// AfterClass: true
538 /// \endcode
539 struct BraceWrappingFlags {
540 /// \brief Wrap class definitions.
541 /// \code
542 /// true:
543 /// class foo {};
544 ///
545 /// false:
546 /// class foo
547 /// {};
548 /// \endcode
549 bool AfterClass;
550 /// \brief Wrap control statements (``if``/``for``/``while``/``switch``/..).
551 /// \code
552 /// true:
553 /// if (foo())
554 /// {
555 /// } else
556 /// {}
557 /// for (int i = 0; i < 10; ++i)
558 /// {}
559 ///
560 /// false:
561 /// if (foo()) {
562 /// } else {
563 /// }
564 /// for (int i = 0; i < 10; ++i) {
565 /// }
566 /// \endcode
567 bool AfterControlStatement;
568 /// \brief Wrap enum definitions.
569 /// \code
570 /// true:
571 /// enum X : int
572 /// {
573 /// B
574 /// };
575 ///
576 /// false:
577 /// enum X : int { B };
578 /// \endcode
579 bool AfterEnum;
580 /// \brief Wrap function definitions.
581 /// \code
582 /// true:
583 /// void foo()
584 /// {
585 /// bar();
586 /// bar2();
587 /// }
588 ///
589 /// false:
590 /// void foo() {
591 /// bar();
592 /// bar2();
593 /// }
594 /// \endcode
595 bool AfterFunction;
596 /// \brief Wrap namespace definitions.
597 /// \code
598 /// true:
599 /// namespace
600 /// {
601 /// int foo();
602 /// int bar();
603 /// }
604 ///
605 /// false:
606 /// namespace {
607 /// int foo();
608 /// int bar();
609 /// }
610 /// \endcode
611 bool AfterNamespace;
612 /// \brief Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..).
613 bool AfterObjCDeclaration;
614 /// \brief Wrap struct definitions.
615 /// \code
616 /// true:
617 /// struct foo
618 /// {
619 /// int x;
620 /// }
621 ///
622 /// false:
623 /// struct foo {
624 /// int x;
625 /// }
626 /// \endcode
627 bool AfterStruct;
628 /// \brief Wrap union definitions.
629 /// \code
630 /// true:
631 /// union foo
632 /// {
633 /// int x;
634 /// }
635 ///
636 /// false:
637 /// union foo {
638 /// int x;
639 /// }
640 /// \endcode
641 bool AfterUnion;
642 /// \brief Wrap before ``catch``.
643 /// \code
644 /// true:
645 /// try {
646 /// foo();
647 /// }
648 /// catch () {
649 /// }
650 ///
651 /// false:
652 /// try {
653 /// foo();
654 /// } catch () {
655 /// }
656 /// \endcode
657 bool BeforeCatch;
658 /// \brief Wrap before ``else``.
659 /// \code
660 /// true:
661 /// if (foo()) {
662 /// }
663 /// else {
664 /// }
665 ///
666 /// false:
667 /// if (foo()) {
668 /// } else {
669 /// }
670 /// \endcode
671 bool BeforeElse;
672 /// \brief Indent the wrapped braces themselves.
673 bool IndentBraces;
674 };
675
676 /// \brief Control of individual brace wrapping cases.
677 ///
678 /// If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
679 /// each individual brace case should be handled. Otherwise, this is ignored.
680 BraceWrappingFlags BraceWrapping;
681
682 /// \brief If ``true``, ternary operators will be placed after line breaks.
683 /// \code
684 /// true:
685 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
686 /// ? firstValue
687 /// : SecondValueVeryVeryVeryVeryLong;
688 ///
689 /// true:
690 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
691 /// firstValue :
692 /// SecondValueVeryVeryVeryVeryLong;
693 /// \endcode
694 bool BreakBeforeTernaryOperators;
695
696 /// \brief Always break constructor initializers before commas and align
697 /// the commas with the colon.
698 /// \code
699 /// true: false:
700 /// SomeClass::Constructor() vs. SomeClass::Constructor() : a(a),
701 /// : a(a) b(b),
702 /// , b(b) c(c) {}
703 /// , c(c) {}
704 /// \endcode
705 bool BreakConstructorInitializersBeforeComma;
706
707 /// \brief Break after each annotation on a field in Java files.
708 bool BreakAfterJavaFieldAnnotations;
709
710 /// \brief Allow breaking string literals when formatting.
711 bool BreakStringLiterals;
712
713 /// \brief The column limit.
714 ///
715 /// A column limit of ``0`` means that there is no column limit. In this case,
716 /// clang-format will respect the input's line breaking decisions within
717 /// statements unless they contradict other rules.
718 unsigned ColumnLimit;
719
720 /// \brief A regular expression that describes comments with special meaning,
721 /// which should not be split into lines or otherwise changed.
722 /// \code
723 /// CommentPragmas: '^ FOOBAR pragma:'
724 /// // Will leave the following line unaffected
725 /// #include <vector> // FOOBAR pragma: keep
726 /// \endcode
727 std::string CommentPragmas;
728
729 /// \brief If ``true``, in the class inheritance expression clang-format will
730 /// break before ``:`` and ``,`` if there is multiple inheritance.
731 /// \code
732 /// true: false:
733 /// class MyClass vs. class MyClass : public X, public Y {
734 /// : public X };
735 /// , public Y {
736 /// };
737 /// \endcode
738 bool BreakBeforeInheritanceComma;
739
740 /// \brief If the constructor initializers don't fit on a line, put each
741 /// initializer on its own line.
742 /// \code
743 /// true:
744 /// SomeClass::Constructor()
745 /// : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
746 /// return 0;
747 /// }
748 ///
749 /// false:
750 /// SomeClass::Constructor()
751 /// : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
752 /// aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
753 /// return 0;
754 /// }
755 /// \endcode
756 bool ConstructorInitializerAllOnOneLineOrOnePerLine;
757
758 /// \brief The number of characters to use for indentation of constructor
759 /// initializer lists.
760 unsigned ConstructorInitializerIndentWidth;
761
762 /// \brief Indent width for line continuations.
763 unsigned ContinuationIndentWidth;
764
765 /// \brief If ``true``, format braced lists as best suited for C++11 braced
766 /// lists.
767 ///
768 /// Important differences:
769 /// - No spaces inside the braced list.
770 /// - No line break before the closing brace.
771 /// - Indentation with the continuation indent, not with the block indent.
772 ///
773 /// Fundamentally, C++11 braced lists are formatted exactly like function
774 /// calls would be formatted in their place. If the braced list follows a name
775 /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were
776 /// the parentheses of a function call with that name. If there is no name,
777 /// a zero-length name is assumed.
778 bool Cpp11BracedListStyle;
779
780 /// \brief If ``true``, analyze the formatted file for the most common
781 /// alignment of ``&`` and ``*``. ``PointerAlignment`` is then used only as
782 /// fallback.
783 bool DerivePointerAlignment;
784
785 /// \brief Disables formatting completely.
786 bool DisableFormat;
787
788 /// \brief If ``true``, clang-format detects whether function calls and
789 /// definitions are formatted with one parameter per line.
790 ///
791 /// Each call can be bin-packed, one-per-line or inconclusive. If it is
792 /// inconclusive, e.g. completely on one line, but a decision needs to be
793 /// made, clang-format analyzes whether there are other bin-packed cases in
794 /// the input file and act accordingly.
795 ///
796 /// NOTE: This is an experimental flag, that might go away or be renamed. Do
797 /// not use this in config files, etc. Use at your own risk.
798 bool ExperimentalAutoDetectBinPacking;
799
800 /// \brief If ``true``, clang-format adds missing namespace end comments and
801 /// fixes invalid existing ones.
802 /// \code
803 /// true: false:
804 /// namespace a { vs. namespace a {
805 /// foo(); foo();
806 /// } // namespace a; }
807 /// \endcode
808 bool FixNamespaceComments;
809
810 /// \brief A vector of macros that should be interpreted as foreach loops
811 /// instead of as function calls.
812 ///
813 /// These are expected to be macros of the form:
814 /// \code
815 /// FOREACH(<variable-declaration>, ...)
816 /// <loop-body>
817 /// \endcode
818 ///
819 /// In the .clang-format configuration file, this can be configured like:
820 /// \code{.yaml}
821 /// ForEachMacros: ['RANGES_FOR', 'FOREACH']
822 /// \endcode
823 ///
824 /// For example: BOOST_FOREACH.
825 std::vector<std::string> ForEachMacros;
826
827 /// \brief See documentation of ``IncludeCategories``.
828 struct IncludeCategory {
829 /// \brief The regular expression that this category matches.
830 std::string Regex;
831 /// \brief The priority to assign to this category.
832 int Priority;
833 bool operator==(const IncludeCategory &Other) const {
834 return Regex == Other.Regex && Priority == Other.Priority;
835 }
836 };
837
838 /// \brief Regular expressions denoting the different ``#include`` categories
839 /// used for ordering ``#includes``.
840 ///
841 /// These regular expressions are matched against the filename of an include
842 /// (including the <> or "") in order. The value belonging to the first
843 /// matching regular expression is assigned and ``#includes`` are sorted first
844 /// according to increasing category number and then alphabetically within
845 /// each category.
846 ///
847 /// If none of the regular expressions match, INT_MAX is assigned as
848 /// category. The main header for a source file automatically gets category 0.
849 /// so that it is generally kept at the beginning of the ``#includes``
850 /// (http://llvm.org/docs/CodingStandards.html#include-style). However, you
851 /// can also assign negative priorities if you have certain headers that
852 /// always need to be first.
853 ///
854 /// To configure this in the .clang-format file, use:
855 /// \code{.yaml}
856 /// IncludeCategories:
857 /// - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
858 /// Priority: 2
859 /// - Regex: '^(<|"(gtest|isl|json)/)'
860 /// Priority: 3
861 /// - Regex: '.*'
862 /// Priority: 1
863 /// \endcode
864 std::vector<IncludeCategory> IncludeCategories;
865
866 /// \brief Specify a regular expression of suffixes that are allowed in the
867 /// file-to-main-include mapping.
868 ///
869 /// When guessing whether a #include is the "main" include (to assign
870 /// category 0, see above), use this regex of allowed suffixes to the header
871 /// stem. A partial match is done, so that:
872 /// - "" means "arbitrary suffix"
873 /// - "$" means "no suffix"
874 ///
875 /// For example, if configured to "(_test)?$", then a header a.h would be seen
876 /// as the "main" include in both a.cc and a_test.cc.
877 std::string IncludeIsMainRegex;
878
879 /// \brief Indent case labels one level from the switch statement.
880 ///
881 /// When ``false``, use the same indentation level as for the switch statement.
882 /// Switch statement body is always indented one level more than case labels.
883 bool IndentCaseLabels;
884
885 /// \brief The number of columns to use for indentation.
886 /// \code
887 /// IndentWidth: 3
888 /// void f() {
889 /// someFunction();
890 /// if (true, false) {
891 /// f();
892 /// }
893 /// }
894 /// \endcode
895 unsigned IndentWidth;
896
897 /// \brief Indent if a function definition or declaration is wrapped after the
898 /// type.
899 bool IndentWrappedFunctionNames;
900
901 /// \brief Quotation styles for JavaScript strings. Does not affect template
902 /// strings.
903 enum JavaScriptQuoteStyle {
904 /// Leave string quotes as they are.
905 /// \code{.js}
906 /// string1 = "foo";
907 /// string2 = 'bar';
908 /// \endcode
909 JSQS_Leave,
910 /// Always use single quotes.
911 /// \code{.js}
912 /// string1 = 'foo';
913 /// string2 = 'bar';
914 /// \endcode
915 JSQS_Single,
916 /// Always use double quotes.
917 /// \code{.js}
918 /// string1 = "foo";
919 /// string2 = "bar";
920 /// \endcode
921 JSQS_Double
922 };
923
924 /// \brief The JavaScriptQuoteStyle to use for JavaScript strings.
925 JavaScriptQuoteStyle JavaScriptQuotes;
926
927 /// \brief Whether to wrap JavaScript import/export statements.
928 /// \code{.js}
929 /// true:
930 /// import {
931 /// VeryLongImportsAreAnnoying,
932 /// VeryLongImportsAreAnnoying,
933 /// VeryLongImportsAreAnnoying,
934 /// } from 'some/module.js'
935 ///
936 /// false:
937 /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
938 /// \endcode
939 bool JavaScriptWrapImports;
940
941 /// \brief If true, empty lines at the start of blocks are kept.
942 bool KeepEmptyLinesAtTheStartOfBlocks;
943
944 /// \brief Supported languages.
945 ///
946 /// When stored in a configuration file, specifies the language, that the
947 /// configuration targets. When passed to the ``reformat()`` function, enables
948 /// syntax features specific to the language.
949 enum LanguageKind {
950 /// Do not use.
951 LK_None,
952 /// Should be used for C, C++.
953 LK_Cpp,
954 /// Should be used for Java.
955 LK_Java,
956 /// Should be used for JavaScript.
957 LK_JavaScript,
958 /// Should be used for Objective-C, Objective-C++.
959 LK_ObjC,
960 /// Should be used for Protocol Buffers
961 /// (https://developers.google.com/protocol-buffers/).
962 LK_Proto,
963 /// Should be used for TableGen code.
964 LK_TableGen
965 };
966 bool IsCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
967
968 /// \brief Language, this format style is targeted at.
969 LanguageKind Language;
970
971 /// \brief A regular expression matching macros that start a block.
972 /// \code
973 /// # With:
974 /// MacroBlockBegin: "^NS_MAP_BEGIN|\
975 /// NS_TABLE_HEAD$"
976 /// MacroBlockEnd: "^\
977 /// NS_MAP_END|\
978 /// NS_TABLE_.*_END$"
979 ///
980 /// NS_MAP_BEGIN
981 /// foo();
982 /// NS_MAP_END
983 ///
984 /// NS_TABLE_HEAD
985 /// bar();
986 /// NS_TABLE_FOO_END
987 ///
988 /// # Without:
989 /// NS_MAP_BEGIN
990 /// foo();
991 /// NS_MAP_END
992 ///
993 /// NS_TABLE_HEAD
994 /// bar();
995 /// NS_TABLE_FOO_END
996 /// \endcode
997 std::string MacroBlockBegin;
998
999 /// \brief A regular expression matching macros that end a block.
1000 std::string MacroBlockEnd;
1001
1002 /// \brief The maximum number of consecutive empty lines to keep.
1003 /// \code
1004 /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
1005 /// int f() { int f() {
1006 /// int = 1; int i = 1;
1007 /// i = foo();
1008 /// i = foo(); return i;
1009 /// }
1010 /// return i;
1011 /// }
1012 /// \endcode
1013 unsigned MaxEmptyLinesToKeep;
1014
1015 /// \brief Different ways to indent namespace contents.
1016 enum NamespaceIndentationKind {
1017 /// Don't indent in namespaces.
1018 /// \code
1019 /// namespace out {
1020 /// int i;
1021 /// namespace in {
1022 /// int i;
1023 /// }
1024 /// }
1025 /// \endcode
1026 NI_None,
1027 /// Indent only in inner namespaces (nested in other namespaces).
1028 /// \code
1029 /// namespace out {
1030 /// int i;
1031 /// namespace in {
1032 /// int i;
1033 /// }
1034 /// }
1035 /// \endcode
1036 NI_Inner,
1037 /// Indent in all namespaces.
1038 /// \code
1039 /// namespace out {
1040 /// int i;
1041 /// namespace in {
1042 /// int i;
1043 /// }
1044 /// }
1045 /// \endcode
1046 NI_All
1047 };
1048
1049 /// \brief The indentation used for namespaces.
1050 NamespaceIndentationKind NamespaceIndentation;
1051
1052 /// \brief The number of characters to use for indentation of ObjC blocks.
1053 unsigned ObjCBlockIndentWidth;
1054
1055 /// \brief Add a space after ``@property`` in Objective-C, i.e. use
1056 /// ``@property (readonly)`` instead of ``@property(readonly)``.
1057 bool ObjCSpaceAfterProperty;
1058
1059 /// \brief Add a space in front of an Objective-C protocol list, i.e. use
1060 /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1061 bool ObjCSpaceBeforeProtocolList;
1062
1063 /// \brief The penalty for breaking a function call after ``call(``.
1064 unsigned PenaltyBreakBeforeFirstCallParameter;
1065
1066 /// \brief The penalty for each line break introduced inside a comment.
1067 unsigned PenaltyBreakComment;
1068
1069 /// \brief The penalty for breaking before the first ``<<``.
1070 unsigned PenaltyBreakFirstLessLess;
1071
1072 /// \brief The penalty for each line break introduced inside a string literal.
1073 unsigned PenaltyBreakString;
1074
1075 /// \brief The penalty for each character outside of the column limit.
1076 unsigned PenaltyExcessCharacter;
1077
1078 /// \brief Penalty for putting the return type of a function onto its own
1079 /// line.
1080 unsigned PenaltyReturnTypeOnItsOwnLine;
1081
1082 /// \brief The ``&`` and ``*`` alignment style.
1083 enum PointerAlignmentStyle {
1084 /// Align pointer to the left.
1085 /// \code
1086 /// int* a;
1087 /// \endcode
1088 PAS_Left,
1089 /// Align pointer to the right.
1090 /// \code
1091 /// int *a;
1092 /// \endcode
1093 PAS_Right,
1094 /// Align pointer in the middle.
1095 /// \code
1096 /// int * a;
1097 /// \endcode
1098 PAS_Middle
1099 };
1100
1101 /// \brief Pointer and reference alignment style.
1102 PointerAlignmentStyle PointerAlignment;
1103
1104 /// \brief If ``true``, clang-format will attempt to re-flow comments.
1105 /// \code
1106 /// false:
1107 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1108 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1109 ///
1110 /// true:
1111 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1112 /// // information
1113 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1114 /// * information */
1115 /// \endcode
1116 bool ReflowComments;
1117
1118 /// \brief If ``true``, clang-format will sort ``#includes``.
1119 /// \code
1120 /// false: true:
1121 /// #include "b.h" vs. #include "a.h"
1122 /// #include "a.h" #include "b.h"
1123 /// \endcode
1124 bool SortIncludes;
1125
1126 /// \brief If ``true``, a space is inserted after C style casts.
1127 /// \code
1128 /// true: false:
1129 /// (int)i; vs. (int) i;
1130 /// \endcode
1131 bool SpaceAfterCStyleCast;
1132
1133 /// \brief If \c true, a space will be inserted after the 'template' keyword.
1134 /// \code
1135 /// true: false:
1136 /// template <int> void foo(); vs. template<int> void foo();
1137 /// \endcode
1138 bool SpaceAfterTemplateKeyword;
1139
1140 /// \brief If ``false``, spaces will be removed before assignment operators.
1141 /// \code
1142 /// true: false:
1143 /// int a = 5; vs. int a=5;
1144 /// a += 42 a+=42;
1145 /// \endcode
1146 bool SpaceBeforeAssignmentOperators;
1147
1148 /// \brief Different ways to put a space before opening parentheses.
1149 enum SpaceBeforeParensOptions {
1150 /// Never put a space before opening parentheses.
1151 /// \code
1152 /// void f() {
1153 /// if(true) {
1154 /// f();
1155 /// }
1156 /// }
1157 /// \endcode
1158 SBPO_Never,
1159 /// Put a space before opening parentheses only after control statement
1160 /// keywords (``for/if/while...``).
1161 /// \code
1162 /// void f() {
1163 /// if (true) {
1164 /// f();
1165 /// }
1166 /// }
1167 /// \endcode
1168 SBPO_ControlStatements,
1169 /// Always put a space before opening parentheses, except when it's
1170 /// prohibited by the syntax rules (in function-like macro definitions) or
1171 /// when determined by other style rules (after unary operators, opening
1172 /// parentheses, etc.)
1173 /// \code
1174 /// void f () {
1175 /// if (true) {
1176 /// f ();
1177 /// }
1178 /// }
1179 /// \endcode
1180 SBPO_Always
1181 };
1182
1183 /// \brief Defines in which cases to put a space before opening parentheses.
1184 SpaceBeforeParensOptions SpaceBeforeParens;
1185
1186 /// \brief If ``true``, spaces may be inserted into ``()``.
1187 /// \code
1188 /// true: false:
1189 /// void f( ) { vs. void f() {
1190 /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
1191 /// if (true) { if (true) {
1192 /// f( ); f();
1193 /// } }
1194 /// } }
1195 /// \endcode
1196 bool SpaceInEmptyParentheses;
1197
1198 /// \brief The number of spaces before trailing line comments
1199 /// (``//`` - comments).
1200 ///
1201 /// This does not affect trailing block comments (``/*`` - comments) as
1202 /// those commonly have different usage patterns and a number of special
1203 /// cases.
1204 /// \code
1205 /// SpacesBeforeTrailingComments: 3
1206 /// void f() {
1207 /// if (true) { // foo1
1208 /// f(); // bar
1209 /// } // foo
1210 /// }
1211 /// \endcode
1212 unsigned SpacesBeforeTrailingComments;
1213
1214 /// \brief If ``true``, spaces will be inserted after ``<`` and before ``>``
1215 /// in template argument lists.
1216 /// \code
1217 /// true: false:
1218 /// static_cast< int >(arg); vs. static_cast<int>(arg);
1219 /// std::function< void(int) > fct; std::function<void(int)> fct;
1220 /// \endcode
1221 bool SpacesInAngles;
1222
1223 /// \brief If ``true``, spaces are inserted inside container literals (e.g.
1224 /// ObjC and Javascript array and dict literals).
1225 /// \code{.js}
1226 /// true: false:
1227 /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
1228 /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
1229 /// \endcode
1230 bool SpacesInContainerLiterals;
1231
1232 /// \brief If ``true``, spaces may be inserted into C style casts.
1233 /// \code
1234 /// true: false:
1235 /// x = ( int32 )y vs. x = (int32)y
1236 /// \endcode
1237 bool SpacesInCStyleCastParentheses;
1238
1239 /// \brief If ``true``, spaces will be inserted after ``(`` and before ``)``.
1240 /// \code
1241 /// true: false:
1242 /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
1243 /// \endcode
1244 bool SpacesInParentheses;
1245
1246 /// \brief If ``true``, spaces will be inserted after ``[`` and before ``]``.
1247 /// Lambdas or unspecified size array declarations will not be affected.
1248 /// \code
1249 /// true: false:
1250 /// int a[ 5 ]; vs. int a[5];
1251 /// std::unique_ptr<int[]> foo() {} // Won't be affected
1252 /// \endcode
1253 bool SpacesInSquareBrackets;
1254
1255 /// \brief Supported language standards.
1256 enum LanguageStandard {
1257 /// Use C++03-compatible syntax.
1258 LS_Cpp03,
1259 /// Use features of C++11 (e.g. ``A<A<int>>`` instead of ``A<A<int> >``).
1260 LS_Cpp11,
1261 /// Automatic detection based on the input.
1262 LS_Auto
1263 };
1264
1265 /// \brief Format compatible with this standard, e.g. use ``A<A<int> >``
1266 /// instead of ``A<A<int>>`` for ``LS_Cpp03``.
1267 LanguageStandard Standard;
1268
1269 /// \brief The number of columns used for tab stops.
1270 unsigned TabWidth;
1271
1272 /// \brief Different ways to use tab in formatting.
1273 enum UseTabStyle {
1274 /// Never use tab.
1275 UT_Never,
1276 /// Use tabs only for indentation.
1277 UT_ForIndentation,
1278 /// Use tabs only for line continuation and indentation.
1279 UT_ForContinuationAndIndentation,
1280 /// Use tabs whenever we need to fill whitespace that spans at least from
1281 /// one tab stop to the next one.
1282 UT_Always
1283 };
1284
1285 /// \brief The way to use tab characters in the resulting file.
1286 UseTabStyle UseTab;
1287
1288 bool operator==(const FormatStyle &R) const {
1289 return AccessModifierOffset == R.AccessModifierOffset &&
1290 AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
1291 AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
1292 AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
1293 AlignEscapedNewlinesLeft == R.AlignEscapedNewlinesLeft &&
1294 AlignOperands == R.AlignOperands &&
1295 AlignTrailingComments == R.AlignTrailingComments &&
1296 AllowAllParametersOfDeclarationOnNextLine ==
1297 R.AllowAllParametersOfDeclarationOnNextLine &&
1298 AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
1299 AllowShortCaseLabelsOnASingleLine ==
1300 R.AllowShortCaseLabelsOnASingleLine &&
1301 AllowShortFunctionsOnASingleLine ==
1302 R.AllowShortFunctionsOnASingleLine &&
1303 AllowShortIfStatementsOnASingleLine ==
1304 R.AllowShortIfStatementsOnASingleLine &&
1305 AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
1306 AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
1307 AlwaysBreakBeforeMultilineStrings ==
1308 R.AlwaysBreakBeforeMultilineStrings &&
1309 AlwaysBreakTemplateDeclarations ==
1310 R.AlwaysBreakTemplateDeclarations &&
1311 BinPackArguments == R.BinPackArguments &&
1312 BinPackParameters == R.BinPackParameters &&
1313 BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
1314 BreakBeforeBraces == R.BreakBeforeBraces &&
1315 BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
1316 BreakConstructorInitializersBeforeComma ==
1317 R.BreakConstructorInitializersBeforeComma &&
1318 BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
1319 BreakStringLiterals == R.BreakStringLiterals &&
1320 ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
1321 BreakBeforeInheritanceComma == R.BreakBeforeInheritanceComma &&
1322 ConstructorInitializerAllOnOneLineOrOnePerLine ==
1323 R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
1324 ConstructorInitializerIndentWidth ==
1325 R.ConstructorInitializerIndentWidth &&
1326 ContinuationIndentWidth == R.ContinuationIndentWidth &&
1327 Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
1328 DerivePointerAlignment == R.DerivePointerAlignment &&
1329 DisableFormat == R.DisableFormat &&
1330 ExperimentalAutoDetectBinPacking ==
1331 R.ExperimentalAutoDetectBinPacking &&
1332 FixNamespaceComments == R.FixNamespaceComments &&
1333 ForEachMacros == R.ForEachMacros &&
1334 IncludeCategories == R.IncludeCategories &&
1335 IndentCaseLabels == R.IndentCaseLabels &&
1336 IndentWidth == R.IndentWidth && Language == R.Language &&
1337 IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
1338 JavaScriptQuotes == R.JavaScriptQuotes &&
1339 JavaScriptWrapImports == R.JavaScriptWrapImports &&
1340 KeepEmptyLinesAtTheStartOfBlocks ==
1341 R.KeepEmptyLinesAtTheStartOfBlocks &&
1342 MacroBlockBegin == R.MacroBlockBegin &&
1343 MacroBlockEnd == R.MacroBlockEnd &&
1344 MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
1345 NamespaceIndentation == R.NamespaceIndentation &&
1346 ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
1347 ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
1348 ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
1349 PenaltyBreakBeforeFirstCallParameter ==
1350 R.PenaltyBreakBeforeFirstCallParameter &&
1351 PenaltyBreakComment == R.PenaltyBreakComment &&
1352 PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
1353 PenaltyBreakString == R.PenaltyBreakString &&
1354 PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
1355 PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
1356 PointerAlignment == R.PointerAlignment &&
1357 SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
1358 SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
1359 SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
1360 SpaceBeforeParens == R.SpaceBeforeParens &&
1361 SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
1362 SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
1363 SpacesInAngles == R.SpacesInAngles &&
1364 SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
1365 SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
1366 SpacesInParentheses == R.SpacesInParentheses &&
1367 SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
1368 Standard == R.Standard && TabWidth == R.TabWidth &&
1369 UseTab == R.UseTab;
1370 }
1371};
1372
1373/// \brief Returns a format style complying with the LLVM coding standards:
1374/// http://llvm.org/docs/CodingStandards.html.
1375FormatStyle getLLVMStyle();
1376
1377/// \brief Returns a format style complying with one of Google's style guides:
1378/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
1379/// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
1380/// https://developers.google.com/protocol-buffers/docs/style.
1381FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
1382
1383/// \brief Returns a format style complying with Chromium's style guide:
1384/// http://www.chromium.org/developers/coding-style.
1385FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
1386
1387/// \brief Returns a format style complying with Mozilla's style guide:
1388/// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
1389FormatStyle getMozillaStyle();
1390
1391/// \brief Returns a format style complying with Webkit's style guide:
1392/// http://www.webkit.org/coding/coding-style.html
1393FormatStyle getWebKitStyle();
1394
1395/// \brief Returns a format style complying with GNU Coding Standards:
1396/// http://www.gnu.org/prep/standards/standards.html
1397FormatStyle getGNUStyle();
1398
1399/// \brief Returns style indicating formatting should be not applied at all.
1400FormatStyle getNoStyle();
1401
1402/// \brief Gets a predefined style for the specified language by name.
1403///
1404/// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
1405/// compared case-insensitively.
1406///
1407/// Returns ``true`` if the Style has been set.
1408bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
1409 FormatStyle *Style);
1410
1411/// \brief Parse configuration from YAML-formatted text.
1412///
1413/// Style->Language is used to get the base style, if the ``BasedOnStyle``
1414/// option is present.
1415///
1416/// When ``BasedOnStyle`` is not present, options not present in the YAML
1417/// document, are retained in \p Style.
1418std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
1419
1420/// \brief Gets configuration in a YAML string.
1421std::string configurationAsText(const FormatStyle &Style);
1422
1423/// \brief Returns the replacements necessary to sort all ``#include`` blocks
1424/// that are affected by ``Ranges``.
1425tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
1426 ArrayRef<tooling::Range> Ranges,
1427 StringRef FileName,
1428 unsigned *Cursor = nullptr);
1429
1430/// \brief Returns the replacements corresponding to applying and formatting
1431/// \p Replaces on success; otheriwse, return an llvm::Error carrying
1432/// llvm::StringError.
1433llvm::Expected<tooling::Replacements>
1434formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
1435 const FormatStyle &Style);
1436
1437/// \brief Returns the replacements corresponding to applying \p Replaces and
1438/// cleaning up the code after that on success; otherwise, return an llvm::Error
1439/// carrying llvm::StringError.
1440/// This also supports inserting/deleting C++ #include directives:
1441/// - If a replacement has offset UINT_MAX, length 0, and a replacement text
1442/// that is an #include directive, this will insert the #include into the
1443/// correct block in the \p Code. When searching for points to insert new
1444/// header, this ignores #include's after the #include block(s) in the
1445/// beginning of a file to avoid inserting headers into code sections where
1446/// new #include's should not be added by default. These code sections
1447/// include:
1448/// - raw string literals (containing #include).
1449/// - #if blocks.
1450/// - Special #include's among declarations (e.g. functions).
1451/// - If a replacement has offset UINT_MAX, length 1, and a replacement text
1452/// that is the name of the header to be removed, the header will be removed
1453/// from \p Code if it exists.
1454llvm::Expected<tooling::Replacements>
1455cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
1456 const FormatStyle &Style);
1457
1458/// \brief Reformats the given \p Ranges in \p Code.
1459///
1460/// Each range is extended on either end to its next bigger logic unit, i.e.
1461/// everything that might influence its formatting or might be influenced by its
1462/// formatting.
1463///
1464/// Returns the ``Replacements`` necessary to make all \p Ranges comply with
1465/// \p Style.
1466///
1467/// If ``IncompleteFormat`` is non-null, its value will be set to true if any
1468/// of the affected ranges were not formatted due to a non-recoverable syntax
1469/// error.
1470tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
1471 ArrayRef<tooling::Range> Ranges,
1472 StringRef FileName = "<stdin>",
1473 bool *IncompleteFormat = nullptr);
1474
1475/// \brief Clean up any erroneous/redundant code in the given \p Ranges in \p
1476/// Code.
1477///
1478/// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
1479tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
1480 ArrayRef<tooling::Range> Ranges,
1481 StringRef FileName = "<stdin>");
1482
1483/// \brief Fix namespace end comments in the given \p Ranges in \p Code.
1484///
1485/// Returns the ``Replacements`` that fix the namespace comments in all
1486/// \p Ranges in \p Code.
1487tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style,
1488 StringRef Code,
1489 ArrayRef<tooling::Range> Ranges,
1490 StringRef FileName = "<stdin>");
1491
1492/// \brief Returns the ``LangOpts`` that the formatter expects you to set.
1493///
1494/// \param Style determines specific settings for lexing mode.
1495LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle());
1496
1497/// \brief Description to be used for help text for a ``llvm::cl`` option for
1498/// specifying format style. The description is closely related to the operation
1499/// of ``getStyle()``.
1500extern const char *StyleOptionHelpDescription;
1501
1502/// \brief Construct a FormatStyle based on ``StyleName``.
1503///
1504/// ``StyleName`` can take several forms:
1505/// * "{<key>: <value>, ...}" - Set specic style parameters.
1506/// * "<style name>" - One of the style names supported by
1507/// getPredefinedStyle().
1508/// * "file" - Load style configuration from a file called ``.clang-format``
1509/// located in one of the parent directories of ``FileName`` or the current
1510/// directory if ``FileName`` is empty.
1511///
1512/// \param[in] StyleName Style name to interpret according to the description
1513/// above.
1514/// \param[in] FileName Path to start search for .clang-format if ``StyleName``
1515/// == "file".
1516/// \param[in] FallbackStyle The name of a predefined style used to fallback to
1517/// in case \p StyleName is "file" and no file can be found.
1518/// \param[in] Code The actual code to be formatted. Used to determine the
1519/// language if the filename isn't sufficient.
1520/// \param[in] FS The underlying file system, in which the file resides. By
1521/// default, the file system is the real file system.
1522///
1523/// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
1524/// "file" and no file is found, returns ``FallbackStyle``. If no style could be
1525/// determined, returns an Error.
1526llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
1527 StringRef FallbackStyle,
1528 StringRef Code = "",
1529 vfs::FileSystem *FS = nullptr);
1530
1531// \brief Returns a string representation of ``Language``.
1532inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
1533 switch (Language) {
1534 case FormatStyle::LK_Cpp:
1535 return "C++";
1536 case FormatStyle::LK_ObjC:
1537 return "Objective-C";
1538 case FormatStyle::LK_Java:
1539 return "Java";
1540 case FormatStyle::LK_JavaScript:
1541 return "JavaScript";
1542 case FormatStyle::LK_Proto:
1543 return "Proto";
1544 default:
1545 return "Unknown";
1546 }
1547}
1548
1549} // end namespace format
1550} // end namespace clang
1551
1552namespace std {
1553template <>
1554struct is_error_code_enum<clang::format::ParseError> : std::true_type {};
1555}
1556
1557#endif // LLVM_CLANG_FORMAT_FORMAT_H