/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Format/Format.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- Format.h - Format C++ code -----------------------------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | /// |
9 | | /// \file |
10 | | /// Various functions to configurably format source code. |
11 | | /// |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #ifndef LLVM_CLANG_FORMAT_FORMAT_H |
15 | | #define LLVM_CLANG_FORMAT_FORMAT_H |
16 | | |
17 | | #include "clang/Basic/LangOptions.h" |
18 | | #include "clang/Tooling/Core/Replacement.h" |
19 | | #include "clang/Tooling/Inclusions/IncludeStyle.h" |
20 | | #include "llvm/ADT/ArrayRef.h" |
21 | | #include "llvm/Support/Regex.h" |
22 | | #include <system_error> |
23 | | |
24 | | namespace llvm { |
25 | | namespace vfs { |
26 | | class FileSystem; |
27 | | } |
28 | | } // namespace llvm |
29 | | |
30 | | namespace clang { |
31 | | |
32 | | class Lexer; |
33 | | class SourceManager; |
34 | | class DiagnosticConsumer; |
35 | | |
36 | | namespace format { |
37 | | |
38 | | enum class ParseError { |
39 | | Success = 0, |
40 | | Error, |
41 | | Unsuitable, |
42 | | BinPackTrailingCommaConflict |
43 | | }; |
44 | | class ParseErrorCategory final : public std::error_category { |
45 | | public: |
46 | | const char *name() const noexcept override; |
47 | | std::string message(int EV) const override; |
48 | | }; |
49 | | const std::error_category &getParseCategory(); |
50 | | std::error_code make_error_code(ParseError e); |
51 | | |
52 | | /// The ``FormatStyle`` is used to configure the formatting to follow |
53 | | /// specific guidelines. |
54 | | struct FormatStyle { |
55 | | /// The extra indent or outdent of access modifiers, e.g. ``public:``. |
56 | | int AccessModifierOffset; |
57 | | |
58 | | /// Different styles for aligning after open brackets. |
59 | | enum BracketAlignmentStyle : unsigned char { |
60 | | /// Align parameters on the open bracket, e.g.: |
61 | | /// \code |
62 | | /// someLongFunction(argument1, |
63 | | /// argument2); |
64 | | /// \endcode |
65 | | BAS_Align, |
66 | | /// Don't align, instead use ``ContinuationIndentWidth``, e.g.: |
67 | | /// \code |
68 | | /// someLongFunction(argument1, |
69 | | /// argument2); |
70 | | /// \endcode |
71 | | BAS_DontAlign, |
72 | | /// Always break after an open bracket, if the parameters don't fit |
73 | | /// on a single line, e.g.: |
74 | | /// \code |
75 | | /// someLongFunction( |
76 | | /// argument1, argument2); |
77 | | /// \endcode |
78 | | BAS_AlwaysBreak, |
79 | | }; |
80 | | |
81 | | /// If ``true``, horizontally aligns arguments after an open bracket. |
82 | | /// |
83 | | /// This applies to round brackets (parentheses), angle brackets and square |
84 | | /// brackets. |
85 | | BracketAlignmentStyle AlignAfterOpenBracket; |
86 | | |
87 | | /// \brief If ``true``, aligns consecutive C/C++ preprocessor macros. |
88 | | /// |
89 | | /// This will align C/C++ preprocessor macros of consecutive lines. |
90 | | /// Will result in formattings like |
91 | | /// \code |
92 | | /// #define SHORT_NAME 42 |
93 | | /// #define LONGER_NAME 0x007f |
94 | | /// #define EVEN_LONGER_NAME (2) |
95 | | /// #define foo(x) (x * x) |
96 | | /// #define bar(y, z) (y + z) |
97 | | /// \endcode |
98 | | bool AlignConsecutiveMacros; |
99 | | |
100 | | /// If ``true``, aligns consecutive assignments. |
101 | | /// |
102 | | /// This will align the assignment operators of consecutive lines. This |
103 | | /// will result in formattings like |
104 | | /// \code |
105 | | /// int aaaa = 12; |
106 | | /// int b = 23; |
107 | | /// int ccc = 23; |
108 | | /// \endcode |
109 | | bool AlignConsecutiveAssignments; |
110 | | |
111 | | /// If ``true``, aligns consecutive bitfield members. |
112 | | /// |
113 | | /// This will align the bitfield separators of consecutive lines. This |
114 | | /// will result in formattings like |
115 | | /// \code |
116 | | /// int aaaa : 1; |
117 | | /// int b : 12; |
118 | | /// int ccc : 8; |
119 | | /// \endcode |
120 | | bool AlignConsecutiveBitFields; |
121 | | |
122 | | /// If ``true``, aligns consecutive declarations. |
123 | | /// |
124 | | /// This will align the declaration names of consecutive lines. This |
125 | | /// will result in formattings like |
126 | | /// \code |
127 | | /// int aaaa = 12; |
128 | | /// float b = 23; |
129 | | /// std::string ccc = 23; |
130 | | /// \endcode |
131 | | bool AlignConsecutiveDeclarations; |
132 | | |
133 | | /// Different styles for aligning escaped newlines. |
134 | | enum EscapedNewlineAlignmentStyle : unsigned char { |
135 | | /// Don't align escaped newlines. |
136 | | /// \code |
137 | | /// #define A \ |
138 | | /// int aaaa; \ |
139 | | /// int b; \ |
140 | | /// int dddddddddd; |
141 | | /// \endcode |
142 | | ENAS_DontAlign, |
143 | | /// Align escaped newlines as far left as possible. |
144 | | /// \code |
145 | | /// true: |
146 | | /// #define A \ |
147 | | /// int aaaa; \ |
148 | | /// int b; \ |
149 | | /// int dddddddddd; |
150 | | /// |
151 | | /// false: |
152 | | /// \endcode |
153 | | ENAS_Left, |
154 | | /// Align escaped newlines in the right-most column. |
155 | | /// \code |
156 | | /// #define A \ |
157 | | /// int aaaa; \ |
158 | | /// int b; \ |
159 | | /// int dddddddddd; |
160 | | /// \endcode |
161 | | ENAS_Right, |
162 | | }; |
163 | | |
164 | | /// Options for aligning backslashes in escaped newlines. |
165 | | EscapedNewlineAlignmentStyle AlignEscapedNewlines; |
166 | | |
167 | | /// Different styles for aligning operands. |
168 | | enum OperandAlignmentStyle : unsigned char { |
169 | | /// Do not align operands of binary and ternary expressions. |
170 | | /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from |
171 | | /// the start of the line. |
172 | | OAS_DontAlign, |
173 | | /// Horizontally align operands of binary and ternary expressions. |
174 | | /// |
175 | | /// Specifically, this aligns operands of a single expression that needs |
176 | | /// to be split over multiple lines, e.g.: |
177 | | /// \code |
178 | | /// int aaa = bbbbbbbbbbbbbbb + |
179 | | /// ccccccccccccccc; |
180 | | /// \endcode |
181 | | /// |
182 | | /// When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is |
183 | | /// aligned with the operand on the first line. |
184 | | /// \code |
185 | | /// int aaa = bbbbbbbbbbbbbbb |
186 | | /// + ccccccccccccccc; |
187 | | /// \endcode |
188 | | OAS_Align, |
189 | | /// Horizontally align operands of binary and ternary expressions. |
190 | | /// |
191 | | /// This is similar to ``AO_Align``, except when |
192 | | /// ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so |
193 | | /// that the wrapped operand is aligned with the operand on the first line. |
194 | | /// \code |
195 | | /// int aaa = bbbbbbbbbbbbbbb |
196 | | /// + ccccccccccccccc; |
197 | | /// \endcode |
198 | | OAS_AlignAfterOperator, |
199 | | }; |
200 | | |
201 | | /// If ``true``, horizontally align operands of binary and ternary |
202 | | /// expressions. |
203 | | OperandAlignmentStyle AlignOperands; |
204 | | |
205 | | /// If ``true``, aligns trailing comments. |
206 | | /// \code |
207 | | /// true: false: |
208 | | /// int a; // My comment a vs. int a; // My comment a |
209 | | /// int b = 2; // comment b int b = 2; // comment about b |
210 | | /// \endcode |
211 | | bool AlignTrailingComments; |
212 | | |
213 | | /// \brief If a function call or braced initializer list doesn't fit on a |
214 | | /// line, allow putting all arguments onto the next line, even if |
215 | | /// ``BinPackArguments`` is ``false``. |
216 | | /// \code |
217 | | /// true: |
218 | | /// callFunction( |
219 | | /// a, b, c, d); |
220 | | /// |
221 | | /// false: |
222 | | /// callFunction(a, |
223 | | /// b, |
224 | | /// c, |
225 | | /// d); |
226 | | /// \endcode |
227 | | bool AllowAllArgumentsOnNextLine; |
228 | | |
229 | | /// \brief If a constructor definition with a member initializer list doesn't |
230 | | /// fit on a single line, allow putting all member initializers onto the next |
231 | | /// line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true. |
232 | | /// Note that this parameter has no effect if |
233 | | /// ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is false. |
234 | | /// \code |
235 | | /// true: |
236 | | /// MyClass::MyClass() : |
237 | | /// member0(0), member1(2) {} |
238 | | /// |
239 | | /// false: |
240 | | /// MyClass::MyClass() : |
241 | | /// member0(0), |
242 | | /// member1(2) {} |
243 | | bool AllowAllConstructorInitializersOnNextLine; |
244 | | |
245 | | /// If the function declaration doesn't fit on a line, |
246 | | /// allow putting all parameters of a function declaration onto |
247 | | /// the next line even if ``BinPackParameters`` is ``false``. |
248 | | /// \code |
249 | | /// true: |
250 | | /// void myFunction( |
251 | | /// int a, int b, int c, int d, int e); |
252 | | /// |
253 | | /// false: |
254 | | /// void myFunction(int a, |
255 | | /// int b, |
256 | | /// int c, |
257 | | /// int d, |
258 | | /// int e); |
259 | | /// \endcode |
260 | | bool AllowAllParametersOfDeclarationOnNextLine; |
261 | | |
262 | | /// Allow short enums on a single line. |
263 | | /// \code |
264 | | /// true: |
265 | | /// enum { A, B } myEnum; |
266 | | /// |
267 | | /// false: |
268 | | /// enum |
269 | | /// { |
270 | | /// A, |
271 | | /// B |
272 | | /// } myEnum; |
273 | | /// \endcode |
274 | | bool AllowShortEnumsOnASingleLine; |
275 | | |
276 | | /// Different styles for merging short blocks containing at most one |
277 | | /// statement. |
278 | | enum ShortBlockStyle : unsigned char { |
279 | | /// Never merge blocks into a single line. |
280 | | /// \code |
281 | | /// while (true) { |
282 | | /// } |
283 | | /// while (true) { |
284 | | /// continue; |
285 | | /// } |
286 | | /// \endcode |
287 | | SBS_Never, |
288 | | /// Only merge empty blocks. |
289 | | /// \code |
290 | | /// while (true) {} |
291 | | /// while (true) { |
292 | | /// continue; |
293 | | /// } |
294 | | /// \endcode |
295 | | SBS_Empty, |
296 | | /// Always merge short blocks into a single line. |
297 | | /// \code |
298 | | /// while (true) {} |
299 | | /// while (true) { continue; } |
300 | | /// \endcode |
301 | | SBS_Always, |
302 | | }; |
303 | | |
304 | | /// Dependent on the value, ``while (true) { continue; }`` can be put on a |
305 | | /// single line. |
306 | | ShortBlockStyle AllowShortBlocksOnASingleLine; |
307 | | |
308 | | /// If ``true``, short case labels will be contracted to a single line. |
309 | | /// \code |
310 | | /// true: false: |
311 | | /// switch (a) { vs. switch (a) { |
312 | | /// case 1: x = 1; break; case 1: |
313 | | /// case 2: return; x = 1; |
314 | | /// } break; |
315 | | /// case 2: |
316 | | /// return; |
317 | | /// } |
318 | | /// \endcode |
319 | | bool AllowShortCaseLabelsOnASingleLine; |
320 | | |
321 | | /// Different styles for merging short functions containing at most one |
322 | | /// statement. |
323 | | enum ShortFunctionStyle : unsigned char { |
324 | | /// Never merge functions into a single line. |
325 | | SFS_None, |
326 | | /// Only merge functions defined inside a class. Same as "inline", |
327 | | /// except it does not implies "empty": i.e. top level empty functions |
328 | | /// are not merged either. |
329 | | /// \code |
330 | | /// class Foo { |
331 | | /// void f() { foo(); } |
332 | | /// }; |
333 | | /// void f() { |
334 | | /// foo(); |
335 | | /// } |
336 | | /// void f() { |
337 | | /// } |
338 | | /// \endcode |
339 | | SFS_InlineOnly, |
340 | | /// Only merge empty functions. |
341 | | /// \code |
342 | | /// void f() {} |
343 | | /// void f2() { |
344 | | /// bar2(); |
345 | | /// } |
346 | | /// \endcode |
347 | | SFS_Empty, |
348 | | /// Only merge functions defined inside a class. Implies "empty". |
349 | | /// \code |
350 | | /// class Foo { |
351 | | /// void f() { foo(); } |
352 | | /// }; |
353 | | /// void f() { |
354 | | /// foo(); |
355 | | /// } |
356 | | /// void f() {} |
357 | | /// \endcode |
358 | | SFS_Inline, |
359 | | /// Merge all functions fitting on a single line. |
360 | | /// \code |
361 | | /// class Foo { |
362 | | /// void f() { foo(); } |
363 | | /// }; |
364 | | /// void f() { bar(); } |
365 | | /// \endcode |
366 | | SFS_All, |
367 | | }; |
368 | | |
369 | | /// Dependent on the value, ``int f() { return 0; }`` can be put on a |
370 | | /// single line. |
371 | | ShortFunctionStyle AllowShortFunctionsOnASingleLine; |
372 | | |
373 | | /// Different styles for handling short if lines |
374 | | enum ShortIfStyle : unsigned char { |
375 | | /// Never put short ifs on the same line. |
376 | | /// \code |
377 | | /// if (a) |
378 | | /// return ; |
379 | | /// else { |
380 | | /// return; |
381 | | /// } |
382 | | /// \endcode |
383 | | SIS_Never, |
384 | | /// Without else put short ifs on the same line only if |
385 | | /// the else is not a compound statement. |
386 | | /// \code |
387 | | /// if (a) return; |
388 | | /// else |
389 | | /// return; |
390 | | /// \endcode |
391 | | SIS_WithoutElse, |
392 | | /// Always put short ifs on the same line if |
393 | | /// the else is not a compound statement or not. |
394 | | /// \code |
395 | | /// if (a) return; |
396 | | /// else { |
397 | | /// return; |
398 | | /// } |
399 | | /// \endcode |
400 | | SIS_Always, |
401 | | }; |
402 | | |
403 | | /// If ``true``, ``if (a) return;`` can be put on a single line. |
404 | | ShortIfStyle AllowShortIfStatementsOnASingleLine; |
405 | | |
406 | | /// Different styles for merging short lambdas containing at most one |
407 | | /// statement. |
408 | | enum ShortLambdaStyle : unsigned char { |
409 | | /// Never merge lambdas into a single line. |
410 | | SLS_None, |
411 | | /// Only merge empty lambdas. |
412 | | /// \code |
413 | | /// auto lambda = [](int a) {} |
414 | | /// auto lambda2 = [](int a) { |
415 | | /// return a; |
416 | | /// }; |
417 | | /// \endcode |
418 | | SLS_Empty, |
419 | | /// Merge lambda into a single line if argument of a function. |
420 | | /// \code |
421 | | /// auto lambda = [](int a) { |
422 | | /// return a; |
423 | | /// }; |
424 | | /// sort(a.begin(), a.end(), ()[] { return x < y; }) |
425 | | /// \endcode |
426 | | SLS_Inline, |
427 | | /// Merge all lambdas fitting on a single line. |
428 | | /// \code |
429 | | /// auto lambda = [](int a) {} |
430 | | /// auto lambda2 = [](int a) { return a; }; |
431 | | /// \endcode |
432 | | SLS_All, |
433 | | }; |
434 | | |
435 | | /// Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a |
436 | | /// single line. |
437 | | ShortLambdaStyle AllowShortLambdasOnASingleLine; |
438 | | |
439 | | /// If ``true``, ``while (true) continue;`` can be put on a single |
440 | | /// line. |
441 | | bool AllowShortLoopsOnASingleLine; |
442 | | |
443 | | /// Different ways to break after the function definition return type. |
444 | | /// This option is **deprecated** and is retained for backwards compatibility. |
445 | | enum DefinitionReturnTypeBreakingStyle : unsigned char { |
446 | | /// Break after return type automatically. |
447 | | /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. |
448 | | DRTBS_None, |
449 | | /// Always break after the return type. |
450 | | DRTBS_All, |
451 | | /// Always break after the return types of top-level functions. |
452 | | DRTBS_TopLevel, |
453 | | }; |
454 | | |
455 | | /// Different ways to break after the function definition or |
456 | | /// declaration return type. |
457 | | enum ReturnTypeBreakingStyle : unsigned char { |
458 | | /// Break after return type automatically. |
459 | | /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. |
460 | | /// \code |
461 | | /// class A { |
462 | | /// int f() { return 0; }; |
463 | | /// }; |
464 | | /// int f(); |
465 | | /// int f() { return 1; } |
466 | | /// \endcode |
467 | | RTBS_None, |
468 | | /// Always break after the return type. |
469 | | /// \code |
470 | | /// class A { |
471 | | /// int |
472 | | /// f() { |
473 | | /// return 0; |
474 | | /// }; |
475 | | /// }; |
476 | | /// int |
477 | | /// f(); |
478 | | /// int |
479 | | /// f() { |
480 | | /// return 1; |
481 | | /// } |
482 | | /// \endcode |
483 | | RTBS_All, |
484 | | /// Always break after the return types of top-level functions. |
485 | | /// \code |
486 | | /// class A { |
487 | | /// int f() { return 0; }; |
488 | | /// }; |
489 | | /// int |
490 | | /// f(); |
491 | | /// int |
492 | | /// f() { |
493 | | /// return 1; |
494 | | /// } |
495 | | /// \endcode |
496 | | RTBS_TopLevel, |
497 | | /// Always break after the return type of function definitions. |
498 | | /// \code |
499 | | /// class A { |
500 | | /// int |
501 | | /// f() { |
502 | | /// return 0; |
503 | | /// }; |
504 | | /// }; |
505 | | /// int f(); |
506 | | /// int |
507 | | /// f() { |
508 | | /// return 1; |
509 | | /// } |
510 | | /// \endcode |
511 | | RTBS_AllDefinitions, |
512 | | /// Always break after the return type of top-level definitions. |
513 | | /// \code |
514 | | /// class A { |
515 | | /// int f() { return 0; }; |
516 | | /// }; |
517 | | /// int f(); |
518 | | /// int |
519 | | /// f() { |
520 | | /// return 1; |
521 | | /// } |
522 | | /// \endcode |
523 | | RTBS_TopLevelDefinitions, |
524 | | }; |
525 | | |
526 | | /// The function definition return type breaking style to use. This |
527 | | /// option is **deprecated** and is retained for backwards compatibility. |
528 | | DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType; |
529 | | |
530 | | /// The function declaration return type breaking style to use. |
531 | | ReturnTypeBreakingStyle AlwaysBreakAfterReturnType; |
532 | | |
533 | | /// If ``true``, always break before multiline string literals. |
534 | | /// |
535 | | /// This flag is mean to make cases where there are multiple multiline strings |
536 | | /// in a file look more consistent. Thus, it will only take effect if wrapping |
537 | | /// the string at that point leads to it being indented |
538 | | /// ``ContinuationIndentWidth`` spaces from the start of the line. |
539 | | /// \code |
540 | | /// true: false: |
541 | | /// aaaa = vs. aaaa = "bbbb" |
542 | | /// "bbbb" "cccc"; |
543 | | /// "cccc"; |
544 | | /// \endcode |
545 | | bool AlwaysBreakBeforeMultilineStrings; |
546 | | |
547 | | /// Different ways to break after the template declaration. |
548 | | enum BreakTemplateDeclarationsStyle : unsigned char { |
549 | | /// Do not force break before declaration. |
550 | | /// ``PenaltyBreakTemplateDeclaration`` is taken into account. |
551 | | /// \code |
552 | | /// template <typename T> T foo() { |
553 | | /// } |
554 | | /// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, |
555 | | /// int bbbbbbbbbbbbbbbbbbbbb) { |
556 | | /// } |
557 | | /// \endcode |
558 | | BTDS_No, |
559 | | /// Force break after template declaration only when the following |
560 | | /// declaration spans multiple lines. |
561 | | /// \code |
562 | | /// template <typename T> T foo() { |
563 | | /// } |
564 | | /// template <typename T> |
565 | | /// T foo(int aaaaaaaaaaaaaaaaaaaaa, |
566 | | /// int bbbbbbbbbbbbbbbbbbbbb) { |
567 | | /// } |
568 | | /// \endcode |
569 | | BTDS_MultiLine, |
570 | | /// Always break after template declaration. |
571 | | /// \code |
572 | | /// template <typename T> |
573 | | /// T foo() { |
574 | | /// } |
575 | | /// template <typename T> |
576 | | /// T foo(int aaaaaaaaaaaaaaaaaaaaa, |
577 | | /// int bbbbbbbbbbbbbbbbbbbbb) { |
578 | | /// } |
579 | | /// \endcode |
580 | | BTDS_Yes |
581 | | }; |
582 | | |
583 | | /// The template declaration breaking style to use. |
584 | | BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations; |
585 | | |
586 | | /// A vector of strings that should be interpreted as attributes/qualifiers |
587 | | /// instead of identifiers. This can be useful for language extensions or |
588 | | /// static analyzer annotations. |
589 | | /// |
590 | | /// For example: |
591 | | /// \code |
592 | | /// x = (char *__capability)&y; |
593 | | /// int function(void) __ununsed; |
594 | | /// void only_writes_to_buffer(char *__output buffer); |
595 | | /// \endcode |
596 | | /// |
597 | | /// In the .clang-format configuration file, this can be configured like: |
598 | | /// \code{.yaml} |
599 | | /// AttributeMacros: ['__capability', '__output', '__ununsed'] |
600 | | /// \endcode |
601 | | /// |
602 | | std::vector<std::string> AttributeMacros; |
603 | | |
604 | | /// If ``false``, a function call's arguments will either be all on the |
605 | | /// same line or will have one line each. |
606 | | /// \code |
607 | | /// true: |
608 | | /// void f() { |
609 | | /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, |
610 | | /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); |
611 | | /// } |
612 | | /// |
613 | | /// false: |
614 | | /// void f() { |
615 | | /// f(aaaaaaaaaaaaaaaaaaaa, |
616 | | /// aaaaaaaaaaaaaaaaaaaa, |
617 | | /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); |
618 | | /// } |
619 | | /// \endcode |
620 | | bool BinPackArguments; |
621 | | |
622 | | /// The style of inserting trailing commas into container literals. |
623 | | enum TrailingCommaStyle : unsigned char { |
624 | | /// Do not insert trailing commas. |
625 | | TCS_None, |
626 | | /// Insert trailing commas in container literals that were wrapped over |
627 | | /// multiple lines. Note that this is conceptually incompatible with |
628 | | /// bin-packing, because the trailing comma is used as an indicator |
629 | | /// that a container should be formatted one-per-line (i.e. not bin-packed). |
630 | | /// So inserting a trailing comma counteracts bin-packing. |
631 | | TCS_Wrapped, |
632 | | }; |
633 | | |
634 | | /// If set to ``TCS_Wrapped`` will insert trailing commas in container |
635 | | /// literals (arrays and objects) that wrap across multiple lines. |
636 | | /// It is currently only available for JavaScript |
637 | | /// and disabled by default ``TCS_None``. |
638 | | /// ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments`` |
639 | | /// as inserting the comma disables bin-packing. |
640 | | /// \code |
641 | | /// TSC_Wrapped: |
642 | | /// const someArray = [ |
643 | | /// aaaaaaaaaaaaaaaaaaaaaaaaaa, |
644 | | /// aaaaaaaaaaaaaaaaaaaaaaaaaa, |
645 | | /// aaaaaaaaaaaaaaaaaaaaaaaaaa, |
646 | | /// // ^ inserted |
647 | | /// ] |
648 | | /// \endcode |
649 | | TrailingCommaStyle InsertTrailingCommas; |
650 | | |
651 | | /// If ``false``, a function declaration's or function definition's |
652 | | /// parameters will either all be on the same line or will have one line each. |
653 | | /// \code |
654 | | /// true: |
655 | | /// void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa, |
656 | | /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} |
657 | | /// |
658 | | /// false: |
659 | | /// void f(int aaaaaaaaaaaaaaaaaaaa, |
660 | | /// int aaaaaaaaaaaaaaaaaaaa, |
661 | | /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} |
662 | | /// \endcode |
663 | | bool BinPackParameters; |
664 | | |
665 | | /// The style of wrapping parameters on the same line (bin-packed) or |
666 | | /// on one line each. |
667 | | enum BinPackStyle : unsigned char { |
668 | | /// Automatically determine parameter bin-packing behavior. |
669 | | BPS_Auto, |
670 | | /// Always bin-pack parameters. |
671 | | BPS_Always, |
672 | | /// Never bin-pack parameters. |
673 | | BPS_Never, |
674 | | }; |
675 | | |
676 | | /// The style of breaking before or after binary operators. |
677 | | enum BinaryOperatorStyle : unsigned char { |
678 | | /// Break after operators. |
679 | | /// \code |
680 | | /// LooooooooooongType loooooooooooooooooooooongVariable = |
681 | | /// someLooooooooooooooooongFunction(); |
682 | | /// |
683 | | /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + |
684 | | /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == |
685 | | /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && |
686 | | /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > |
687 | | /// ccccccccccccccccccccccccccccccccccccccccc; |
688 | | /// \endcode |
689 | | BOS_None, |
690 | | /// Break before operators that aren't assignments. |
691 | | /// \code |
692 | | /// LooooooooooongType loooooooooooooooooooooongVariable = |
693 | | /// someLooooooooooooooooongFunction(); |
694 | | /// |
695 | | /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
696 | | /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
697 | | /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
698 | | /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
699 | | /// > ccccccccccccccccccccccccccccccccccccccccc; |
700 | | /// \endcode |
701 | | BOS_NonAssignment, |
702 | | /// Break before operators. |
703 | | /// \code |
704 | | /// LooooooooooongType loooooooooooooooooooooongVariable |
705 | | /// = someLooooooooooooooooongFunction(); |
706 | | /// |
707 | | /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
708 | | /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
709 | | /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
710 | | /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
711 | | /// > ccccccccccccccccccccccccccccccccccccccccc; |
712 | | /// \endcode |
713 | | BOS_All, |
714 | | }; |
715 | | |
716 | | /// The way to wrap binary operators. |
717 | | BinaryOperatorStyle BreakBeforeBinaryOperators; |
718 | | |
719 | | /// Different ways to attach braces to their surrounding context. |
720 | | enum BraceBreakingStyle : unsigned char { |
721 | | /// Always attach braces to surrounding context. |
722 | | /// \code |
723 | | /// namespace N { |
724 | | /// enum E { |
725 | | /// E1, |
726 | | /// E2, |
727 | | /// }; |
728 | | /// |
729 | | /// class C { |
730 | | /// public: |
731 | | /// C(); |
732 | | /// }; |
733 | | /// |
734 | | /// bool baz(int i) { |
735 | | /// try { |
736 | | /// do { |
737 | | /// switch (i) { |
738 | | /// case 1: { |
739 | | /// foobar(); |
740 | | /// break; |
741 | | /// } |
742 | | /// default: { |
743 | | /// break; |
744 | | /// } |
745 | | /// } |
746 | | /// } while (--i); |
747 | | /// return true; |
748 | | /// } catch (...) { |
749 | | /// handleError(); |
750 | | /// return false; |
751 | | /// } |
752 | | /// } |
753 | | /// |
754 | | /// void foo(bool b) { |
755 | | /// if (b) { |
756 | | /// baz(2); |
757 | | /// } else { |
758 | | /// baz(5); |
759 | | /// } |
760 | | /// } |
761 | | /// |
762 | | /// void bar() { foo(true); } |
763 | | /// } // namespace N |
764 | | /// \endcode |
765 | | BS_Attach, |
766 | | /// Like ``Attach``, but break before braces on function, namespace and |
767 | | /// class definitions. |
768 | | /// \code |
769 | | /// namespace N |
770 | | /// { |
771 | | /// enum E { |
772 | | /// E1, |
773 | | /// E2, |
774 | | /// }; |
775 | | /// |
776 | | /// class C |
777 | | /// { |
778 | | /// public: |
779 | | /// C(); |
780 | | /// }; |
781 | | /// |
782 | | /// bool baz(int i) |
783 | | /// { |
784 | | /// try { |
785 | | /// do { |
786 | | /// switch (i) { |
787 | | /// case 1: { |
788 | | /// foobar(); |
789 | | /// break; |
790 | | /// } |
791 | | /// default: { |
792 | | /// break; |
793 | | /// } |
794 | | /// } |
795 | | /// } while (--i); |
796 | | /// return true; |
797 | | /// } catch (...) { |
798 | | /// handleError(); |
799 | | /// return false; |
800 | | /// } |
801 | | /// } |
802 | | /// |
803 | | /// void foo(bool b) |
804 | | /// { |
805 | | /// if (b) { |
806 | | /// baz(2); |
807 | | /// } else { |
808 | | /// baz(5); |
809 | | /// } |
810 | | /// } |
811 | | /// |
812 | | /// void bar() { foo(true); } |
813 | | /// } // namespace N |
814 | | /// \endcode |
815 | | BS_Linux, |
816 | | /// Like ``Attach``, but break before braces on enum, function, and record |
817 | | /// definitions. |
818 | | /// \code |
819 | | /// namespace N { |
820 | | /// enum E |
821 | | /// { |
822 | | /// E1, |
823 | | /// E2, |
824 | | /// }; |
825 | | /// |
826 | | /// class C |
827 | | /// { |
828 | | /// public: |
829 | | /// C(); |
830 | | /// }; |
831 | | /// |
832 | | /// bool baz(int i) |
833 | | /// { |
834 | | /// try { |
835 | | /// do { |
836 | | /// switch (i) { |
837 | | /// case 1: { |
838 | | /// foobar(); |
839 | | /// break; |
840 | | /// } |
841 | | /// default: { |
842 | | /// break; |
843 | | /// } |
844 | | /// } |
845 | | /// } while (--i); |
846 | | /// return true; |
847 | | /// } catch (...) { |
848 | | /// handleError(); |
849 | | /// return false; |
850 | | /// } |
851 | | /// } |
852 | | /// |
853 | | /// void foo(bool b) |
854 | | /// { |
855 | | /// if (b) { |
856 | | /// baz(2); |
857 | | /// } else { |
858 | | /// baz(5); |
859 | | /// } |
860 | | /// } |
861 | | /// |
862 | | /// void bar() { foo(true); } |
863 | | /// } // namespace N |
864 | | /// \endcode |
865 | | BS_Mozilla, |
866 | | /// Like ``Attach``, but break before function definitions, ``catch``, and |
867 | | /// ``else``. |
868 | | /// \code |
869 | | /// namespace N { |
870 | | /// enum E { |
871 | | /// E1, |
872 | | /// E2, |
873 | | /// }; |
874 | | /// |
875 | | /// class C { |
876 | | /// public: |
877 | | /// C(); |
878 | | /// }; |
879 | | /// |
880 | | /// bool baz(int i) |
881 | | /// { |
882 | | /// try { |
883 | | /// do { |
884 | | /// switch (i) { |
885 | | /// case 1: { |
886 | | /// foobar(); |
887 | | /// break; |
888 | | /// } |
889 | | /// default: { |
890 | | /// break; |
891 | | /// } |
892 | | /// } |
893 | | /// } while (--i); |
894 | | /// return true; |
895 | | /// } |
896 | | /// catch (...) { |
897 | | /// handleError(); |
898 | | /// return false; |
899 | | /// } |
900 | | /// } |
901 | | /// |
902 | | /// void foo(bool b) |
903 | | /// { |
904 | | /// if (b) { |
905 | | /// baz(2); |
906 | | /// } |
907 | | /// else { |
908 | | /// baz(5); |
909 | | /// } |
910 | | /// } |
911 | | /// |
912 | | /// void bar() { foo(true); } |
913 | | /// } // namespace N |
914 | | /// \endcode |
915 | | BS_Stroustrup, |
916 | | /// Always break before braces. |
917 | | /// \code |
918 | | /// namespace N |
919 | | /// { |
920 | | /// enum E |
921 | | /// { |
922 | | /// E1, |
923 | | /// E2, |
924 | | /// }; |
925 | | /// |
926 | | /// class C |
927 | | /// { |
928 | | /// public: |
929 | | /// C(); |
930 | | /// }; |
931 | | /// |
932 | | /// bool baz(int i) |
933 | | /// { |
934 | | /// try |
935 | | /// { |
936 | | /// do |
937 | | /// { |
938 | | /// switch (i) |
939 | | /// { |
940 | | /// case 1: |
941 | | /// { |
942 | | /// foobar(); |
943 | | /// break; |
944 | | /// } |
945 | | /// default: |
946 | | /// { |
947 | | /// break; |
948 | | /// } |
949 | | /// } |
950 | | /// } while (--i); |
951 | | /// return true; |
952 | | /// } |
953 | | /// catch (...) |
954 | | /// { |
955 | | /// handleError(); |
956 | | /// return false; |
957 | | /// } |
958 | | /// } |
959 | | /// |
960 | | /// void foo(bool b) |
961 | | /// { |
962 | | /// if (b) |
963 | | /// { |
964 | | /// baz(2); |
965 | | /// } |
966 | | /// else |
967 | | /// { |
968 | | /// baz(5); |
969 | | /// } |
970 | | /// } |
971 | | /// |
972 | | /// void bar() { foo(true); } |
973 | | /// } // namespace N |
974 | | /// \endcode |
975 | | BS_Allman, |
976 | | /// Like ``Allman`` but always indent braces and line up code with braces. |
977 | | /// \code |
978 | | /// namespace N |
979 | | /// { |
980 | | /// enum E |
981 | | /// { |
982 | | /// E1, |
983 | | /// E2, |
984 | | /// }; |
985 | | /// |
986 | | /// class C |
987 | | /// { |
988 | | /// public: |
989 | | /// C(); |
990 | | /// }; |
991 | | /// |
992 | | /// bool baz(int i) |
993 | | /// { |
994 | | /// try |
995 | | /// { |
996 | | /// do |
997 | | /// { |
998 | | /// switch (i) |
999 | | /// { |
1000 | | /// case 1: |
1001 | | /// { |
1002 | | /// foobar(); |
1003 | | /// break; |
1004 | | /// } |
1005 | | /// default: |
1006 | | /// { |
1007 | | /// break; |
1008 | | /// } |
1009 | | /// } |
1010 | | /// } while (--i); |
1011 | | /// return true; |
1012 | | /// } |
1013 | | /// catch (...) |
1014 | | /// { |
1015 | | /// handleError(); |
1016 | | /// return false; |
1017 | | /// } |
1018 | | /// } |
1019 | | /// |
1020 | | /// void foo(bool b) |
1021 | | /// { |
1022 | | /// if (b) |
1023 | | /// { |
1024 | | /// baz(2); |
1025 | | /// } |
1026 | | /// else |
1027 | | /// { |
1028 | | /// baz(5); |
1029 | | /// } |
1030 | | /// } |
1031 | | /// |
1032 | | /// void bar() { foo(true); } |
1033 | | /// } // namespace N |
1034 | | /// \endcode |
1035 | | BS_Whitesmiths, |
1036 | | /// Always break before braces and add an extra level of indentation to |
1037 | | /// braces of control statements, not to those of class, function |
1038 | | /// or other definitions. |
1039 | | /// \code |
1040 | | /// namespace N |
1041 | | /// { |
1042 | | /// enum E |
1043 | | /// { |
1044 | | /// E1, |
1045 | | /// E2, |
1046 | | /// }; |
1047 | | /// |
1048 | | /// class C |
1049 | | /// { |
1050 | | /// public: |
1051 | | /// C(); |
1052 | | /// }; |
1053 | | /// |
1054 | | /// bool baz(int i) |
1055 | | /// { |
1056 | | /// try |
1057 | | /// { |
1058 | | /// do |
1059 | | /// { |
1060 | | /// switch (i) |
1061 | | /// { |
1062 | | /// case 1: |
1063 | | /// { |
1064 | | /// foobar(); |
1065 | | /// break; |
1066 | | /// } |
1067 | | /// default: |
1068 | | /// { |
1069 | | /// break; |
1070 | | /// } |
1071 | | /// } |
1072 | | /// } |
1073 | | /// while (--i); |
1074 | | /// return true; |
1075 | | /// } |
1076 | | /// catch (...) |
1077 | | /// { |
1078 | | /// handleError(); |
1079 | | /// return false; |
1080 | | /// } |
1081 | | /// } |
1082 | | /// |
1083 | | /// void foo(bool b) |
1084 | | /// { |
1085 | | /// if (b) |
1086 | | /// { |
1087 | | /// baz(2); |
1088 | | /// } |
1089 | | /// else |
1090 | | /// { |
1091 | | /// baz(5); |
1092 | | /// } |
1093 | | /// } |
1094 | | /// |
1095 | | /// void bar() { foo(true); } |
1096 | | /// } // namespace N |
1097 | | /// \endcode |
1098 | | BS_GNU, |
1099 | | /// Like ``Attach``, but break before functions. |
1100 | | /// \code |
1101 | | /// namespace N { |
1102 | | /// enum E { |
1103 | | /// E1, |
1104 | | /// E2, |
1105 | | /// }; |
1106 | | /// |
1107 | | /// class C { |
1108 | | /// public: |
1109 | | /// C(); |
1110 | | /// }; |
1111 | | /// |
1112 | | /// bool baz(int i) |
1113 | | /// { |
1114 | | /// try { |
1115 | | /// do { |
1116 | | /// switch (i) { |
1117 | | /// case 1: { |
1118 | | /// foobar(); |
1119 | | /// break; |
1120 | | /// } |
1121 | | /// default: { |
1122 | | /// break; |
1123 | | /// } |
1124 | | /// } |
1125 | | /// } while (--i); |
1126 | | /// return true; |
1127 | | /// } catch (...) { |
1128 | | /// handleError(); |
1129 | | /// return false; |
1130 | | /// } |
1131 | | /// } |
1132 | | /// |
1133 | | /// void foo(bool b) |
1134 | | /// { |
1135 | | /// if (b) { |
1136 | | /// baz(2); |
1137 | | /// } else { |
1138 | | /// baz(5); |
1139 | | /// } |
1140 | | /// } |
1141 | | /// |
1142 | | /// void bar() { foo(true); } |
1143 | | /// } // namespace N |
1144 | | /// \endcode |
1145 | | BS_WebKit, |
1146 | | /// Configure each individual brace in `BraceWrapping`. |
1147 | | BS_Custom |
1148 | | }; |
1149 | | |
1150 | | /// The brace breaking style to use. |
1151 | | BraceBreakingStyle BreakBeforeBraces; |
1152 | | |
1153 | | /// Different ways to wrap braces after control statements. |
1154 | | enum BraceWrappingAfterControlStatementStyle : unsigned char { |
1155 | | /// Never wrap braces after a control statement. |
1156 | | /// \code |
1157 | | /// if (foo()) { |
1158 | | /// } else { |
1159 | | /// } |
1160 | | /// for (int i = 0; i < 10; ++i) { |
1161 | | /// } |
1162 | | /// \endcode |
1163 | | BWACS_Never, |
1164 | | /// Only wrap braces after a multi-line control statement. |
1165 | | /// \code |
1166 | | /// if (foo && bar && |
1167 | | /// baz) |
1168 | | /// { |
1169 | | /// quux(); |
1170 | | /// } |
1171 | | /// while (foo || bar) { |
1172 | | /// } |
1173 | | /// \endcode |
1174 | | BWACS_MultiLine, |
1175 | | /// Always wrap braces after a control statement. |
1176 | | /// \code |
1177 | | /// if (foo()) |
1178 | | /// { |
1179 | | /// } else |
1180 | | /// {} |
1181 | | /// for (int i = 0; i < 10; ++i) |
1182 | | /// {} |
1183 | | /// \endcode |
1184 | | BWACS_Always |
1185 | | }; |
1186 | | |
1187 | | /// Precise control over the wrapping of braces. |
1188 | | /// \code |
1189 | | /// # Should be declared this way: |
1190 | | /// BreakBeforeBraces: Custom |
1191 | | /// BraceWrapping: |
1192 | | /// AfterClass: true |
1193 | | /// \endcode |
1194 | | struct BraceWrappingFlags { |
1195 | | /// Wrap case labels. |
1196 | | /// \code |
1197 | | /// false: true: |
1198 | | /// switch (foo) { vs. switch (foo) { |
1199 | | /// case 1: { case 1: |
1200 | | /// bar(); { |
1201 | | /// break; bar(); |
1202 | | /// } break; |
1203 | | /// default: { } |
1204 | | /// plop(); default: |
1205 | | /// } { |
1206 | | /// } plop(); |
1207 | | /// } |
1208 | | /// } |
1209 | | /// \endcode |
1210 | | bool AfterCaseLabel; |
1211 | | /// Wrap class definitions. |
1212 | | /// \code |
1213 | | /// true: |
1214 | | /// class foo {}; |
1215 | | /// |
1216 | | /// false: |
1217 | | /// class foo |
1218 | | /// {}; |
1219 | | /// \endcode |
1220 | | bool AfterClass; |
1221 | | |
1222 | | /// Wrap control statements (``if``/``for``/``while``/``switch``/..). |
1223 | | BraceWrappingAfterControlStatementStyle AfterControlStatement; |
1224 | | /// Wrap enum definitions. |
1225 | | /// \code |
1226 | | /// true: |
1227 | | /// enum X : int |
1228 | | /// { |
1229 | | /// B |
1230 | | /// }; |
1231 | | /// |
1232 | | /// false: |
1233 | | /// enum X : int { B }; |
1234 | | /// \endcode |
1235 | | bool AfterEnum; |
1236 | | /// Wrap function definitions. |
1237 | | /// \code |
1238 | | /// true: |
1239 | | /// void foo() |
1240 | | /// { |
1241 | | /// bar(); |
1242 | | /// bar2(); |
1243 | | /// } |
1244 | | /// |
1245 | | /// false: |
1246 | | /// void foo() { |
1247 | | /// bar(); |
1248 | | /// bar2(); |
1249 | | /// } |
1250 | | /// \endcode |
1251 | | bool AfterFunction; |
1252 | | /// Wrap namespace definitions. |
1253 | | /// \code |
1254 | | /// true: |
1255 | | /// namespace |
1256 | | /// { |
1257 | | /// int foo(); |
1258 | | /// int bar(); |
1259 | | /// } |
1260 | | /// |
1261 | | /// false: |
1262 | | /// namespace { |
1263 | | /// int foo(); |
1264 | | /// int bar(); |
1265 | | /// } |
1266 | | /// \endcode |
1267 | | bool AfterNamespace; |
1268 | | /// Wrap ObjC definitions (interfaces, implementations...). |
1269 | | /// \note @autoreleasepool and @synchronized blocks are wrapped |
1270 | | /// according to `AfterControlStatement` flag. |
1271 | | bool AfterObjCDeclaration; |
1272 | | /// Wrap struct definitions. |
1273 | | /// \code |
1274 | | /// true: |
1275 | | /// struct foo |
1276 | | /// { |
1277 | | /// int x; |
1278 | | /// }; |
1279 | | /// |
1280 | | /// false: |
1281 | | /// struct foo { |
1282 | | /// int x; |
1283 | | /// }; |
1284 | | /// \endcode |
1285 | | bool AfterStruct; |
1286 | | /// Wrap union definitions. |
1287 | | /// \code |
1288 | | /// true: |
1289 | | /// union foo |
1290 | | /// { |
1291 | | /// int x; |
1292 | | /// } |
1293 | | /// |
1294 | | /// false: |
1295 | | /// union foo { |
1296 | | /// int x; |
1297 | | /// } |
1298 | | /// \endcode |
1299 | | bool AfterUnion; |
1300 | | /// Wrap extern blocks. |
1301 | | /// \code |
1302 | | /// true: |
1303 | | /// extern "C" |
1304 | | /// { |
1305 | | /// int foo(); |
1306 | | /// } |
1307 | | /// |
1308 | | /// false: |
1309 | | /// extern "C" { |
1310 | | /// int foo(); |
1311 | | /// } |
1312 | | /// \endcode |
1313 | | bool AfterExternBlock; // Partially superseded by IndentExternBlock |
1314 | | /// Wrap before ``catch``. |
1315 | | /// \code |
1316 | | /// true: |
1317 | | /// try { |
1318 | | /// foo(); |
1319 | | /// } |
1320 | | /// catch () { |
1321 | | /// } |
1322 | | /// |
1323 | | /// false: |
1324 | | /// try { |
1325 | | /// foo(); |
1326 | | /// } catch () { |
1327 | | /// } |
1328 | | /// \endcode |
1329 | | bool BeforeCatch; |
1330 | | /// Wrap before ``else``. |
1331 | | /// \code |
1332 | | /// true: |
1333 | | /// if (foo()) { |
1334 | | /// } |
1335 | | /// else { |
1336 | | /// } |
1337 | | /// |
1338 | | /// false: |
1339 | | /// if (foo()) { |
1340 | | /// } else { |
1341 | | /// } |
1342 | | /// \endcode |
1343 | | bool BeforeElse; |
1344 | | /// Wrap lambda block. |
1345 | | /// \code |
1346 | | /// true: |
1347 | | /// connect( |
1348 | | /// []() |
1349 | | /// { |
1350 | | /// foo(); |
1351 | | /// bar(); |
1352 | | /// }); |
1353 | | /// |
1354 | | /// false: |
1355 | | /// connect([]() { |
1356 | | /// foo(); |
1357 | | /// bar(); |
1358 | | /// }); |
1359 | | /// \endcode |
1360 | | bool BeforeLambdaBody; |
1361 | | /// Wrap before ``while``. |
1362 | | /// \code |
1363 | | /// true: |
1364 | | /// do { |
1365 | | /// foo(); |
1366 | | /// } |
1367 | | /// while (1); |
1368 | | /// |
1369 | | /// false: |
1370 | | /// do { |
1371 | | /// foo(); |
1372 | | /// } while (1); |
1373 | | /// \endcode |
1374 | | bool BeforeWhile; |
1375 | | /// Indent the wrapped braces themselves. |
1376 | | bool IndentBraces; |
1377 | | /// If ``false``, empty function body can be put on a single line. |
1378 | | /// This option is used only if the opening brace of the function has |
1379 | | /// already been wrapped, i.e. the `AfterFunction` brace wrapping mode is |
1380 | | /// set, and the function could/should not be put on a single line (as per |
1381 | | /// `AllowShortFunctionsOnASingleLine` and constructor formatting options). |
1382 | | /// \code |
1383 | | /// int f() vs. int f() |
1384 | | /// {} { |
1385 | | /// } |
1386 | | /// \endcode |
1387 | | /// |
1388 | | bool SplitEmptyFunction; |
1389 | | /// If ``false``, empty record (e.g. class, struct or union) body |
1390 | | /// can be put on a single line. This option is used only if the opening |
1391 | | /// brace of the record has already been wrapped, i.e. the `AfterClass` |
1392 | | /// (for classes) brace wrapping mode is set. |
1393 | | /// \code |
1394 | | /// class Foo vs. class Foo |
1395 | | /// {} { |
1396 | | /// } |
1397 | | /// \endcode |
1398 | | /// |
1399 | | bool SplitEmptyRecord; |
1400 | | /// If ``false``, empty namespace body can be put on a single line. |
1401 | | /// This option is used only if the opening brace of the namespace has |
1402 | | /// already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is |
1403 | | /// set. |
1404 | | /// \code |
1405 | | /// namespace Foo vs. namespace Foo |
1406 | | /// {} { |
1407 | | /// } |
1408 | | /// \endcode |
1409 | | /// |
1410 | | bool SplitEmptyNamespace; |
1411 | | }; |
1412 | | |
1413 | | /// Control of individual brace wrapping cases. |
1414 | | /// |
1415 | | /// If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how |
1416 | | /// each individual brace case should be handled. Otherwise, this is ignored. |
1417 | | /// \code{.yaml} |
1418 | | /// # Example of usage: |
1419 | | /// BreakBeforeBraces: Custom |
1420 | | /// BraceWrapping: |
1421 | | /// AfterEnum: true |
1422 | | /// AfterStruct: false |
1423 | | /// SplitEmptyFunction: false |
1424 | | /// \endcode |
1425 | | BraceWrappingFlags BraceWrapping; |
1426 | | |
1427 | | /// If ``true``, concept will be placed on a new line. |
1428 | | /// \code |
1429 | | /// true: |
1430 | | /// template<typename T> |
1431 | | /// concept ... |
1432 | | /// |
1433 | | /// false: |
1434 | | /// template<typename T> concept ... |
1435 | | /// \endcode |
1436 | | bool BreakBeforeConceptDeclarations; |
1437 | | |
1438 | | /// If ``true``, ternary operators will be placed after line breaks. |
1439 | | /// \code |
1440 | | /// true: |
1441 | | /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription |
1442 | | /// ? firstValue |
1443 | | /// : SecondValueVeryVeryVeryVeryLong; |
1444 | | /// |
1445 | | /// false: |
1446 | | /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ? |
1447 | | /// firstValue : |
1448 | | /// SecondValueVeryVeryVeryVeryLong; |
1449 | | /// \endcode |
1450 | | bool BreakBeforeTernaryOperators; |
1451 | | |
1452 | | /// Different ways to break initializers. |
1453 | | enum BreakConstructorInitializersStyle : unsigned char { |
1454 | | /// Break constructor initializers before the colon and after the commas. |
1455 | | /// \code |
1456 | | /// Constructor() |
1457 | | /// : initializer1(), |
1458 | | /// initializer2() |
1459 | | /// \endcode |
1460 | | BCIS_BeforeColon, |
1461 | | /// Break constructor initializers before the colon and commas, and align |
1462 | | /// the commas with the colon. |
1463 | | /// \code |
1464 | | /// Constructor() |
1465 | | /// : initializer1() |
1466 | | /// , initializer2() |
1467 | | /// \endcode |
1468 | | BCIS_BeforeComma, |
1469 | | /// Break constructor initializers after the colon and commas. |
1470 | | /// \code |
1471 | | /// Constructor() : |
1472 | | /// initializer1(), |
1473 | | /// initializer2() |
1474 | | /// \endcode |
1475 | | BCIS_AfterColon |
1476 | | }; |
1477 | | |
1478 | | /// The constructor initializers style to use. |
1479 | | BreakConstructorInitializersStyle BreakConstructorInitializers; |
1480 | | |
1481 | | /// Break after each annotation on a field in Java files. |
1482 | | /// \code{.java} |
1483 | | /// true: false: |
1484 | | /// @Partial vs. @Partial @Mock DataLoad loader; |
1485 | | /// @Mock |
1486 | | /// DataLoad loader; |
1487 | | /// \endcode |
1488 | | bool BreakAfterJavaFieldAnnotations; |
1489 | | |
1490 | | /// Allow breaking string literals when formatting. |
1491 | | /// \code |
1492 | | /// true: |
1493 | | /// const char* x = "veryVeryVeryVeryVeryVe" |
1494 | | /// "ryVeryVeryVeryVeryVery" |
1495 | | /// "VeryLongString"; |
1496 | | /// |
1497 | | /// false: |
1498 | | /// const char* x = |
1499 | | /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; |
1500 | | /// \endcode |
1501 | | bool BreakStringLiterals; |
1502 | | |
1503 | | /// The column limit. |
1504 | | /// |
1505 | | /// A column limit of ``0`` means that there is no column limit. In this case, |
1506 | | /// clang-format will respect the input's line breaking decisions within |
1507 | | /// statements unless they contradict other rules. |
1508 | | unsigned ColumnLimit; |
1509 | | |
1510 | | /// A regular expression that describes comments with special meaning, |
1511 | | /// which should not be split into lines or otherwise changed. |
1512 | | /// \code |
1513 | | /// // CommentPragmas: '^ FOOBAR pragma:' |
1514 | | /// // Will leave the following line unaffected |
1515 | | /// #include <vector> // FOOBAR pragma: keep |
1516 | | /// \endcode |
1517 | | std::string CommentPragmas; |
1518 | | |
1519 | | /// Different ways to break inheritance list. |
1520 | | enum BreakInheritanceListStyle : unsigned char { |
1521 | | /// Break inheritance list before the colon and after the commas. |
1522 | | /// \code |
1523 | | /// class Foo |
1524 | | /// : Base1, |
1525 | | /// Base2 |
1526 | | /// {}; |
1527 | | /// \endcode |
1528 | | BILS_BeforeColon, |
1529 | | /// Break inheritance list before the colon and commas, and align |
1530 | | /// the commas with the colon. |
1531 | | /// \code |
1532 | | /// class Foo |
1533 | | /// : Base1 |
1534 | | /// , Base2 |
1535 | | /// {}; |
1536 | | /// \endcode |
1537 | | BILS_BeforeComma, |
1538 | | /// Break inheritance list after the colon and commas. |
1539 | | /// \code |
1540 | | /// class Foo : |
1541 | | /// Base1, |
1542 | | /// Base2 |
1543 | | /// {}; |
1544 | | /// \endcode |
1545 | | BILS_AfterColon |
1546 | | }; |
1547 | | |
1548 | | /// The inheritance list style to use. |
1549 | | BreakInheritanceListStyle BreakInheritanceList; |
1550 | | |
1551 | | /// If ``true``, consecutive namespace declarations will be on the same |
1552 | | /// line. If ``false``, each namespace is declared on a new line. |
1553 | | /// \code |
1554 | | /// true: |
1555 | | /// namespace Foo { namespace Bar { |
1556 | | /// }} |
1557 | | /// |
1558 | | /// false: |
1559 | | /// namespace Foo { |
1560 | | /// namespace Bar { |
1561 | | /// } |
1562 | | /// } |
1563 | | /// \endcode |
1564 | | /// |
1565 | | /// If it does not fit on a single line, the overflowing namespaces get |
1566 | | /// wrapped: |
1567 | | /// \code |
1568 | | /// namespace Foo { namespace Bar { |
1569 | | /// namespace Extra { |
1570 | | /// }}} |
1571 | | /// \endcode |
1572 | | bool CompactNamespaces; |
1573 | | |
1574 | | // clang-format off |
1575 | | /// If the constructor initializers don't fit on a line, put each |
1576 | | /// initializer on its own line. |
1577 | | /// \code |
1578 | | /// true: |
1579 | | /// SomeClass::Constructor() |
1580 | | /// : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) { |
1581 | | /// return 0; |
1582 | | /// } |
1583 | | /// |
1584 | | /// false: |
1585 | | /// SomeClass::Constructor() |
1586 | | /// : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), |
1587 | | /// aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) { |
1588 | | /// return 0; |
1589 | | /// } |
1590 | | /// \endcode |
1591 | | bool ConstructorInitializerAllOnOneLineOrOnePerLine; |
1592 | | // clang-format on |
1593 | | |
1594 | | /// The number of characters to use for indentation of constructor |
1595 | | /// initializer lists as well as inheritance lists. |
1596 | | unsigned ConstructorInitializerIndentWidth; |
1597 | | |
1598 | | /// Indent width for line continuations. |
1599 | | /// \code |
1600 | | /// ContinuationIndentWidth: 2 |
1601 | | /// |
1602 | | /// int i = // VeryVeryVeryVeryVeryLongComment |
1603 | | /// longFunction( // Again a long comment |
1604 | | /// arg); |
1605 | | /// \endcode |
1606 | | unsigned ContinuationIndentWidth; |
1607 | | |
1608 | | /// If ``true``, format braced lists as best suited for C++11 braced |
1609 | | /// lists. |
1610 | | /// |
1611 | | /// Important differences: |
1612 | | /// - No spaces inside the braced list. |
1613 | | /// - No line break before the closing brace. |
1614 | | /// - Indentation with the continuation indent, not with the block indent. |
1615 | | /// |
1616 | | /// Fundamentally, C++11 braced lists are formatted exactly like function |
1617 | | /// calls would be formatted in their place. If the braced list follows a name |
1618 | | /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were |
1619 | | /// the parentheses of a function call with that name. If there is no name, |
1620 | | /// a zero-length name is assumed. |
1621 | | /// \code |
1622 | | /// true: false: |
1623 | | /// vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 }; |
1624 | | /// vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} }; |
1625 | | /// f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]); |
1626 | | /// new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 }; |
1627 | | /// \endcode |
1628 | | bool Cpp11BracedListStyle; |
1629 | | |
1630 | | /// \brief Analyze the formatted file for the most used line ending (``\r\n`` |
1631 | | /// or ``\n``). ``UseCRLF`` is only used as a fallback if none can be derived. |
1632 | | bool DeriveLineEnding; |
1633 | | |
1634 | | /// If ``true``, analyze the formatted file for the most common |
1635 | | /// alignment of ``&`` and ``*``. |
1636 | | /// Pointer and reference alignment styles are going to be updated according |
1637 | | /// to the preferences found in the file. |
1638 | | /// ``PointerAlignment`` is then used only as fallback. |
1639 | | bool DerivePointerAlignment; |
1640 | | |
1641 | | /// Disables formatting completely. |
1642 | | bool DisableFormat; |
1643 | | |
1644 | | /// If ``true``, clang-format detects whether function calls and |
1645 | | /// definitions are formatted with one parameter per line. |
1646 | | /// |
1647 | | /// Each call can be bin-packed, one-per-line or inconclusive. If it is |
1648 | | /// inconclusive, e.g. completely on one line, but a decision needs to be |
1649 | | /// made, clang-format analyzes whether there are other bin-packed cases in |
1650 | | /// the input file and act accordingly. |
1651 | | /// |
1652 | | /// NOTE: This is an experimental flag, that might go away or be renamed. Do |
1653 | | /// not use this in config files, etc. Use at your own risk. |
1654 | | bool ExperimentalAutoDetectBinPacking; |
1655 | | |
1656 | | /// If ``true``, clang-format adds missing namespace end comments and |
1657 | | /// fixes invalid existing ones. |
1658 | | /// \code |
1659 | | /// true: false: |
1660 | | /// namespace a { vs. namespace a { |
1661 | | /// foo(); foo(); |
1662 | | /// } // namespace a } |
1663 | | /// \endcode |
1664 | | bool FixNamespaceComments; |
1665 | | |
1666 | | /// A vector of macros that should be interpreted as foreach loops |
1667 | | /// instead of as function calls. |
1668 | | /// |
1669 | | /// These are expected to be macros of the form: |
1670 | | /// \code |
1671 | | /// FOREACH(<variable-declaration>, ...) |
1672 | | /// <loop-body> |
1673 | | /// \endcode |
1674 | | /// |
1675 | | /// In the .clang-format configuration file, this can be configured like: |
1676 | | /// \code{.yaml} |
1677 | | /// ForEachMacros: ['RANGES_FOR', 'FOREACH'] |
1678 | | /// \endcode |
1679 | | /// |
1680 | | /// For example: BOOST_FOREACH. |
1681 | | std::vector<std::string> ForEachMacros; |
1682 | | |
1683 | | /// \brief A vector of macros that should be interpreted as type declarations |
1684 | | /// instead of as function calls. |
1685 | | /// |
1686 | | /// These are expected to be macros of the form: |
1687 | | /// \code |
1688 | | /// STACK_OF(...) |
1689 | | /// \endcode |
1690 | | /// |
1691 | | /// In the .clang-format configuration file, this can be configured like: |
1692 | | /// \code{.yaml} |
1693 | | /// TypenameMacros: ['STACK_OF', 'LIST'] |
1694 | | /// \endcode |
1695 | | /// |
1696 | | /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY. |
1697 | | std::vector<std::string> TypenameMacros; |
1698 | | |
1699 | | /// A vector of macros that should be interpreted as complete |
1700 | | /// statements. |
1701 | | /// |
1702 | | /// Typical macros are expressions, and require a semi-colon to be |
1703 | | /// added; sometimes this is not the case, and this allows to make |
1704 | | /// clang-format aware of such cases. |
1705 | | /// |
1706 | | /// For example: Q_UNUSED |
1707 | | std::vector<std::string> StatementMacros; |
1708 | | |
1709 | | /// A vector of macros which are used to open namespace blocks. |
1710 | | /// |
1711 | | /// These are expected to be macros of the form: |
1712 | | /// \code |
1713 | | /// NAMESPACE(<namespace-name>, ...) { |
1714 | | /// <namespace-content> |
1715 | | /// } |
1716 | | /// \endcode |
1717 | | /// |
1718 | | /// For example: TESTSUITE |
1719 | | std::vector<std::string> NamespaceMacros; |
1720 | | |
1721 | | /// A vector of macros which are whitespace-sensitive and should not |
1722 | | /// be touched. |
1723 | | /// |
1724 | | /// These are expected to be macros of the form: |
1725 | | /// \code |
1726 | | /// STRINGIZE(...) |
1727 | | /// \endcode |
1728 | | /// |
1729 | | /// In the .clang-format configuration file, this can be configured like: |
1730 | | /// \code{.yaml} |
1731 | | /// WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE'] |
1732 | | /// \endcode |
1733 | | /// |
1734 | | /// For example: BOOST_PP_STRINGIZE |
1735 | | std::vector<std::string> WhitespaceSensitiveMacros; |
1736 | | |
1737 | | tooling::IncludeStyle IncludeStyle; |
1738 | | |
1739 | | /// Indent case labels one level from the switch statement. |
1740 | | /// |
1741 | | /// When ``false``, use the same indentation level as for the switch |
1742 | | /// statement. Switch statement body is always indented one level more than |
1743 | | /// case labels (except the first block following the case label, which |
1744 | | /// itself indents the code - unless IndentCaseBlocks is enabled). |
1745 | | /// \code |
1746 | | /// false: true: |
1747 | | /// switch (fool) { vs. switch (fool) { |
1748 | | /// case 1: case 1: |
1749 | | /// bar(); bar(); |
1750 | | /// break; break; |
1751 | | /// default: default: |
1752 | | /// plop(); plop(); |
1753 | | /// } } |
1754 | | /// \endcode |
1755 | | bool IndentCaseLabels; |
1756 | | |
1757 | | /// Indent case label blocks one level from the case label. |
1758 | | /// |
1759 | | /// When ``false``, the block following the case label uses the same |
1760 | | /// indentation level as for the case label, treating the case label the same |
1761 | | /// as an if-statement. |
1762 | | /// When ``true``, the block gets indented as a scope block. |
1763 | | /// \code |
1764 | | /// false: true: |
1765 | | /// switch (fool) { vs. switch (fool) { |
1766 | | /// case 1: { case 1: |
1767 | | /// bar(); { |
1768 | | /// } break; bar(); |
1769 | | /// default: { } |
1770 | | /// plop(); break; |
1771 | | /// } default: |
1772 | | /// } { |
1773 | | /// plop(); |
1774 | | /// } |
1775 | | /// } |
1776 | | /// \endcode |
1777 | | bool IndentCaseBlocks; |
1778 | | |
1779 | | /// Indent goto labels. |
1780 | | /// |
1781 | | /// When ``false``, goto labels are flushed left. |
1782 | | /// \code |
1783 | | /// true: false: |
1784 | | /// int f() { vs. int f() { |
1785 | | /// if (foo()) { if (foo()) { |
1786 | | /// label1: label1: |
1787 | | /// bar(); bar(); |
1788 | | /// } } |
1789 | | /// label2: label2: |
1790 | | /// return 1; return 1; |
1791 | | /// } } |
1792 | | /// \endcode |
1793 | | bool IndentGotoLabels; |
1794 | | |
1795 | | /// Options for indenting preprocessor directives. |
1796 | | enum PPDirectiveIndentStyle : unsigned char { |
1797 | | /// Does not indent any directives. |
1798 | | /// \code |
1799 | | /// #if FOO |
1800 | | /// #if BAR |
1801 | | /// #include <foo> |
1802 | | /// #endif |
1803 | | /// #endif |
1804 | | /// \endcode |
1805 | | PPDIS_None, |
1806 | | /// Indents directives after the hash. |
1807 | | /// \code |
1808 | | /// #if FOO |
1809 | | /// # if BAR |
1810 | | /// # include <foo> |
1811 | | /// # endif |
1812 | | /// #endif |
1813 | | /// \endcode |
1814 | | PPDIS_AfterHash, |
1815 | | /// Indents directives before the hash. |
1816 | | /// \code |
1817 | | /// #if FOO |
1818 | | /// #if BAR |
1819 | | /// #include <foo> |
1820 | | /// #endif |
1821 | | /// #endif |
1822 | | /// \endcode |
1823 | | PPDIS_BeforeHash |
1824 | | }; |
1825 | | |
1826 | | /// The preprocessor directive indenting style to use. |
1827 | | PPDirectiveIndentStyle IndentPPDirectives; |
1828 | | |
1829 | | /// Indents extern blocks |
1830 | | enum IndentExternBlockStyle : unsigned char { |
1831 | | /// Backwards compatible with AfterExternBlock's indenting. |
1832 | | /// \code |
1833 | | /// IndentExternBlock: AfterExternBlock |
1834 | | /// BraceWrapping.AfterExternBlock: true |
1835 | | /// extern "C" |
1836 | | /// { |
1837 | | /// void foo(); |
1838 | | /// } |
1839 | | /// \endcode |
1840 | | /// |
1841 | | /// \code |
1842 | | /// IndentExternBlock: AfterExternBlock |
1843 | | /// BraceWrapping.AfterExternBlock: false |
1844 | | /// extern "C" { |
1845 | | /// void foo(); |
1846 | | /// } |
1847 | | /// \endcode |
1848 | | IEBS_AfterExternBlock, |
1849 | | /// Does not indent extern blocks. |
1850 | | /// \code |
1851 | | /// extern "C" { |
1852 | | /// void foo(); |
1853 | | /// } |
1854 | | /// \endcode |
1855 | | IEBS_NoIndent, |
1856 | | /// Indents extern blocks. |
1857 | | /// \code |
1858 | | /// extern "C" { |
1859 | | /// void foo(); |
1860 | | /// } |
1861 | | /// \endcode |
1862 | | IEBS_Indent, |
1863 | | }; |
1864 | | |
1865 | | /// IndentExternBlockStyle is the type of indenting of extern blocks. |
1866 | | IndentExternBlockStyle IndentExternBlock; |
1867 | | |
1868 | | /// Indent the requires clause in a template |
1869 | | /// \code |
1870 | | /// true: |
1871 | | /// template <typename It> |
1872 | | /// requires Iterator<It> |
1873 | | /// void sort(It begin, It end) { |
1874 | | /// //.... |
1875 | | /// } |
1876 | | /// |
1877 | | /// false: |
1878 | | /// template <typename It> |
1879 | | /// requires Iterator<It> |
1880 | | /// void sort(It begin, It end) { |
1881 | | /// //.... |
1882 | | /// } |
1883 | | /// \endcode |
1884 | | bool IndentRequires; |
1885 | | |
1886 | | /// The number of columns to use for indentation. |
1887 | | /// \code |
1888 | | /// IndentWidth: 3 |
1889 | | /// |
1890 | | /// void f() { |
1891 | | /// someFunction(); |
1892 | | /// if (true, false) { |
1893 | | /// f(); |
1894 | | /// } |
1895 | | /// } |
1896 | | /// \endcode |
1897 | | unsigned IndentWidth; |
1898 | | |
1899 | | /// Indent if a function definition or declaration is wrapped after the |
1900 | | /// type. |
1901 | | /// \code |
1902 | | /// true: |
1903 | | /// LoooooooooooooooooooooooooooooooooooooooongReturnType |
1904 | | /// LoooooooooooooooooooooooooooooooongFunctionDeclaration(); |
1905 | | /// |
1906 | | /// false: |
1907 | | /// LoooooooooooooooooooooooooooooooooooooooongReturnType |
1908 | | /// LoooooooooooooooooooooooooooooooongFunctionDeclaration(); |
1909 | | /// \endcode |
1910 | | bool IndentWrappedFunctionNames; |
1911 | | |
1912 | | /// A vector of prefixes ordered by the desired groups for Java imports. |
1913 | | /// |
1914 | | /// One group's prefix can be a subset of another - the longest prefix is |
1915 | | /// always matched. Within a group, the imports are ordered lexicographically. |
1916 | | /// Static imports are grouped separately and follow the same group rules. |
1917 | | /// By default, static imports are placed before non-static imports, |
1918 | | /// but this behavior is changed by another option, |
1919 | | /// ``SortJavaStaticImport``. |
1920 | | /// |
1921 | | /// In the .clang-format configuration file, this can be configured like |
1922 | | /// in the following yaml example. This will result in imports being |
1923 | | /// formatted as in the Java example below. |
1924 | | /// \code{.yaml} |
1925 | | /// JavaImportGroups: ['com.example', 'com', 'org'] |
1926 | | /// \endcode |
1927 | | /// |
1928 | | /// \code{.java} |
1929 | | /// import static com.example.function1; |
1930 | | /// |
1931 | | /// import static com.test.function2; |
1932 | | /// |
1933 | | /// import static org.example.function3; |
1934 | | /// |
1935 | | /// import com.example.ClassA; |
1936 | | /// import com.example.Test; |
1937 | | /// import com.example.a.ClassB; |
1938 | | /// |
1939 | | /// import com.test.ClassC; |
1940 | | /// |
1941 | | /// import org.example.ClassD; |
1942 | | /// \endcode |
1943 | | std::vector<std::string> JavaImportGroups; |
1944 | | |
1945 | | /// Quotation styles for JavaScript strings. Does not affect template |
1946 | | /// strings. |
1947 | | enum JavaScriptQuoteStyle : unsigned char { |
1948 | | /// Leave string quotes as they are. |
1949 | | /// \code{.js} |
1950 | | /// string1 = "foo"; |
1951 | | /// string2 = 'bar'; |
1952 | | /// \endcode |
1953 | | JSQS_Leave, |
1954 | | /// Always use single quotes. |
1955 | | /// \code{.js} |
1956 | | /// string1 = 'foo'; |
1957 | | /// string2 = 'bar'; |
1958 | | /// \endcode |
1959 | | JSQS_Single, |
1960 | | /// Always use double quotes. |
1961 | | /// \code{.js} |
1962 | | /// string1 = "foo"; |
1963 | | /// string2 = "bar"; |
1964 | | /// \endcode |
1965 | | JSQS_Double |
1966 | | }; |
1967 | | |
1968 | | /// The JavaScriptQuoteStyle to use for JavaScript strings. |
1969 | | JavaScriptQuoteStyle JavaScriptQuotes; |
1970 | | |
1971 | | // clang-format off |
1972 | | /// Whether to wrap JavaScript import/export statements. |
1973 | | /// \code{.js} |
1974 | | /// true: |
1975 | | /// import { |
1976 | | /// VeryLongImportsAreAnnoying, |
1977 | | /// VeryLongImportsAreAnnoying, |
1978 | | /// VeryLongImportsAreAnnoying, |
1979 | | /// } from 'some/module.js' |
1980 | | /// |
1981 | | /// false: |
1982 | | /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js" |
1983 | | /// \endcode |
1984 | | bool JavaScriptWrapImports; |
1985 | | // clang-format on |
1986 | | |
1987 | | /// If true, the empty line at the start of blocks is kept. |
1988 | | /// \code |
1989 | | /// true: false: |
1990 | | /// if (foo) { vs. if (foo) { |
1991 | | /// bar(); |
1992 | | /// bar(); } |
1993 | | /// } |
1994 | | /// \endcode |
1995 | | bool KeepEmptyLinesAtTheStartOfBlocks; |
1996 | | |
1997 | | /// Supported languages. |
1998 | | /// |
1999 | | /// When stored in a configuration file, specifies the language, that the |
2000 | | /// configuration targets. When passed to the ``reformat()`` function, enables |
2001 | | /// syntax features specific to the language. |
2002 | | enum LanguageKind : unsigned char { |
2003 | | /// Do not use. |
2004 | | LK_None, |
2005 | | /// Should be used for C, C++. |
2006 | | LK_Cpp, |
2007 | | /// Should be used for C#. |
2008 | | LK_CSharp, |
2009 | | /// Should be used for Java. |
2010 | | LK_Java, |
2011 | | /// Should be used for JavaScript. |
2012 | | LK_JavaScript, |
2013 | | /// Should be used for Objective-C, Objective-C++. |
2014 | | LK_ObjC, |
2015 | | /// Should be used for Protocol Buffers |
2016 | | /// (https://developers.google.com/protocol-buffers/). |
2017 | | LK_Proto, |
2018 | | /// Should be used for TableGen code. |
2019 | | LK_TableGen, |
2020 | | /// Should be used for Protocol Buffer messages in text format |
2021 | | /// (https://developers.google.com/protocol-buffers/). |
2022 | | LK_TextProto |
2023 | | }; |
2024 | 2.00M | bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC473k ; } |
2025 | 2.79M | bool isCSharp() const { return Language == LK_CSharp; } |
2026 | | |
2027 | | /// Language, this format style is targeted at. |
2028 | | LanguageKind Language; |
2029 | | |
2030 | | /// A regular expression matching macros that start a block. |
2031 | | /// \code |
2032 | | /// # With: |
2033 | | /// MacroBlockBegin: "^NS_MAP_BEGIN|\ |
2034 | | /// NS_TABLE_HEAD$" |
2035 | | /// MacroBlockEnd: "^\ |
2036 | | /// NS_MAP_END|\ |
2037 | | /// NS_TABLE_.*_END$" |
2038 | | /// |
2039 | | /// NS_MAP_BEGIN |
2040 | | /// foo(); |
2041 | | /// NS_MAP_END |
2042 | | /// |
2043 | | /// NS_TABLE_HEAD |
2044 | | /// bar(); |
2045 | | /// NS_TABLE_FOO_END |
2046 | | /// |
2047 | | /// # Without: |
2048 | | /// NS_MAP_BEGIN |
2049 | | /// foo(); |
2050 | | /// NS_MAP_END |
2051 | | /// |
2052 | | /// NS_TABLE_HEAD |
2053 | | /// bar(); |
2054 | | /// NS_TABLE_FOO_END |
2055 | | /// \endcode |
2056 | | std::string MacroBlockBegin; |
2057 | | |
2058 | | /// A regular expression matching macros that end a block. |
2059 | | std::string MacroBlockEnd; |
2060 | | |
2061 | | /// The maximum number of consecutive empty lines to keep. |
2062 | | /// \code |
2063 | | /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0 |
2064 | | /// int f() { int f() { |
2065 | | /// int = 1; int i = 1; |
2066 | | /// i = foo(); |
2067 | | /// i = foo(); return i; |
2068 | | /// } |
2069 | | /// return i; |
2070 | | /// } |
2071 | | /// \endcode |
2072 | | unsigned MaxEmptyLinesToKeep; |
2073 | | |
2074 | | /// Different ways to indent namespace contents. |
2075 | | enum NamespaceIndentationKind : unsigned char { |
2076 | | /// Don't indent in namespaces. |
2077 | | /// \code |
2078 | | /// namespace out { |
2079 | | /// int i; |
2080 | | /// namespace in { |
2081 | | /// int i; |
2082 | | /// } |
2083 | | /// } |
2084 | | /// \endcode |
2085 | | NI_None, |
2086 | | /// Indent only in inner namespaces (nested in other namespaces). |
2087 | | /// \code |
2088 | | /// namespace out { |
2089 | | /// int i; |
2090 | | /// namespace in { |
2091 | | /// int i; |
2092 | | /// } |
2093 | | /// } |
2094 | | /// \endcode |
2095 | | NI_Inner, |
2096 | | /// Indent in all namespaces. |
2097 | | /// \code |
2098 | | /// namespace out { |
2099 | | /// int i; |
2100 | | /// namespace in { |
2101 | | /// int i; |
2102 | | /// } |
2103 | | /// } |
2104 | | /// \endcode |
2105 | | NI_All |
2106 | | }; |
2107 | | |
2108 | | /// The indentation used for namespaces. |
2109 | | NamespaceIndentationKind NamespaceIndentation; |
2110 | | |
2111 | | /// Controls bin-packing Objective-C protocol conformance list |
2112 | | /// items into as few lines as possible when they go over ``ColumnLimit``. |
2113 | | /// |
2114 | | /// If ``Auto`` (the default), delegates to the value in |
2115 | | /// ``BinPackParameters``. If that is ``true``, bin-packs Objective-C |
2116 | | /// protocol conformance list items into as few lines as possible |
2117 | | /// whenever they go over ``ColumnLimit``. |
2118 | | /// |
2119 | | /// If ``Always``, always bin-packs Objective-C protocol conformance |
2120 | | /// list items into as few lines as possible whenever they go over |
2121 | | /// ``ColumnLimit``. |
2122 | | /// |
2123 | | /// If ``Never``, lays out Objective-C protocol conformance list items |
2124 | | /// onto individual lines whenever they go over ``ColumnLimit``. |
2125 | | /// |
2126 | | /// \code{.objc} |
2127 | | /// Always (or Auto, if BinPackParameters=true): |
2128 | | /// @interface ccccccccccccc () < |
2129 | | /// ccccccccccccc, ccccccccccccc, |
2130 | | /// ccccccccccccc, ccccccccccccc> { |
2131 | | /// } |
2132 | | /// |
2133 | | /// Never (or Auto, if BinPackParameters=false): |
2134 | | /// @interface ddddddddddddd () < |
2135 | | /// ddddddddddddd, |
2136 | | /// ddddddddddddd, |
2137 | | /// ddddddddddddd, |
2138 | | /// ddddddddddddd> { |
2139 | | /// } |
2140 | | /// \endcode |
2141 | | BinPackStyle ObjCBinPackProtocolList; |
2142 | | |
2143 | | /// The number of characters to use for indentation of ObjC blocks. |
2144 | | /// \code{.objc} |
2145 | | /// ObjCBlockIndentWidth: 4 |
2146 | | /// |
2147 | | /// [operation setCompletionBlock:^{ |
2148 | | /// [self onOperationDone]; |
2149 | | /// }]; |
2150 | | /// \endcode |
2151 | | unsigned ObjCBlockIndentWidth; |
2152 | | |
2153 | | /// Add a space after ``@property`` in Objective-C, i.e. use |
2154 | | /// ``@property (readonly)`` instead of ``@property(readonly)``. |
2155 | | bool ObjCSpaceAfterProperty; |
2156 | | |
2157 | | /// Break parameters list into lines when there is nested block |
2158 | | /// parameters in a function call. |
2159 | | /// \code |
2160 | | /// false: |
2161 | | /// - (void)_aMethod |
2162 | | /// { |
2163 | | /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber |
2164 | | /// *u, NSNumber *v) { |
2165 | | /// u = c; |
2166 | | /// }] |
2167 | | /// } |
2168 | | /// true: |
2169 | | /// - (void)_aMethod |
2170 | | /// { |
2171 | | /// [self.test1 t:self |
2172 | | /// w:self |
2173 | | /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) { |
2174 | | /// u = c; |
2175 | | /// }] |
2176 | | /// } |
2177 | | /// \endcode |
2178 | | bool ObjCBreakBeforeNestedBlockParam; |
2179 | | |
2180 | | /// Add a space in front of an Objective-C protocol list, i.e. use |
2181 | | /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``. |
2182 | | bool ObjCSpaceBeforeProtocolList; |
2183 | | |
2184 | | /// The penalty for breaking around an assignment operator. |
2185 | | unsigned PenaltyBreakAssignment; |
2186 | | |
2187 | | /// The penalty for breaking a function call after ``call(``. |
2188 | | unsigned PenaltyBreakBeforeFirstCallParameter; |
2189 | | |
2190 | | /// The penalty for each line break introduced inside a comment. |
2191 | | unsigned PenaltyBreakComment; |
2192 | | |
2193 | | /// The penalty for breaking before the first ``<<``. |
2194 | | unsigned PenaltyBreakFirstLessLess; |
2195 | | |
2196 | | /// The penalty for each line break introduced inside a string literal. |
2197 | | unsigned PenaltyBreakString; |
2198 | | |
2199 | | /// The penalty for breaking after template declaration. |
2200 | | unsigned PenaltyBreakTemplateDeclaration; |
2201 | | |
2202 | | /// The penalty for each character outside of the column limit. |
2203 | | unsigned PenaltyExcessCharacter; |
2204 | | |
2205 | | /// Penalty for putting the return type of a function onto its own |
2206 | | /// line. |
2207 | | unsigned PenaltyReturnTypeOnItsOwnLine; |
2208 | | |
2209 | | /// Penalty for each character of whitespace indentation |
2210 | | /// (counted relative to leading non-whitespace column). |
2211 | | unsigned PenaltyIndentedWhitespace; |
2212 | | |
2213 | | /// The ``&`` and ``*`` alignment style. |
2214 | | enum PointerAlignmentStyle : unsigned char { |
2215 | | /// Align pointer to the left. |
2216 | | /// \code |
2217 | | /// int* a; |
2218 | | /// \endcode |
2219 | | PAS_Left, |
2220 | | /// Align pointer to the right. |
2221 | | /// \code |
2222 | | /// int *a; |
2223 | | /// \endcode |
2224 | | PAS_Right, |
2225 | | /// Align pointer in the middle. |
2226 | | /// \code |
2227 | | /// int * a; |
2228 | | /// \endcode |
2229 | | PAS_Middle |
2230 | | }; |
2231 | | |
2232 | | /// Pointer and reference alignment style. |
2233 | | PointerAlignmentStyle PointerAlignment; |
2234 | | |
2235 | | /// See documentation of ``RawStringFormats``. |
2236 | | struct RawStringFormat { |
2237 | | /// The language of this raw string. |
2238 | | LanguageKind Language; |
2239 | | /// A list of raw string delimiters that match this language. |
2240 | | std::vector<std::string> Delimiters; |
2241 | | /// A list of enclosing function names that match this language. |
2242 | | std::vector<std::string> EnclosingFunctions; |
2243 | | /// The canonical delimiter for this language. |
2244 | | std::string CanonicalDelimiter; |
2245 | | /// The style name on which this raw string format is based on. |
2246 | | /// If not specified, the raw string format is based on the style that this |
2247 | | /// format is based on. |
2248 | | std::string BasedOnStyle; |
2249 | 28 | bool operator==(const RawStringFormat &Other) const { |
2250 | 28 | return Language == Other.Language && Delimiters == Other.Delimiters && |
2251 | 28 | EnclosingFunctions == Other.EnclosingFunctions && |
2252 | 28 | CanonicalDelimiter == Other.CanonicalDelimiter && |
2253 | 28 | BasedOnStyle == Other.BasedOnStyle; |
2254 | 28 | } |
2255 | | }; |
2256 | | |
2257 | | /// Defines hints for detecting supported languages code blocks in raw |
2258 | | /// strings. |
2259 | | /// |
2260 | | /// A raw string with a matching delimiter or a matching enclosing function |
2261 | | /// name will be reformatted assuming the specified language based on the |
2262 | | /// style for that language defined in the .clang-format file. If no style has |
2263 | | /// been defined in the .clang-format file for the specific language, a |
2264 | | /// predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not |
2265 | | /// found, the formatting is based on llvm style. A matching delimiter takes |
2266 | | /// precedence over a matching enclosing function name for determining the |
2267 | | /// language of the raw string contents. |
2268 | | /// |
2269 | | /// If a canonical delimiter is specified, occurrences of other delimiters for |
2270 | | /// the same language will be updated to the canonical if possible. |
2271 | | /// |
2272 | | /// There should be at most one specification per language and each delimiter |
2273 | | /// and enclosing function should not occur in multiple specifications. |
2274 | | /// |
2275 | | /// To configure this in the .clang-format file, use: |
2276 | | /// \code{.yaml} |
2277 | | /// RawStringFormats: |
2278 | | /// - Language: TextProto |
2279 | | /// Delimiters: |
2280 | | /// - 'pb' |
2281 | | /// - 'proto' |
2282 | | /// EnclosingFunctions: |
2283 | | /// - 'PARSE_TEXT_PROTO' |
2284 | | /// BasedOnStyle: google |
2285 | | /// - Language: Cpp |
2286 | | /// Delimiters: |
2287 | | /// - 'cc' |
2288 | | /// - 'cpp' |
2289 | | /// BasedOnStyle: llvm |
2290 | | /// CanonicalDelimiter: 'cc' |
2291 | | /// \endcode |
2292 | | std::vector<RawStringFormat> RawStringFormats; |
2293 | | |
2294 | | // clang-format off |
2295 | | /// If ``true``, clang-format will attempt to re-flow comments. |
2296 | | /// \code |
2297 | | /// false: |
2298 | | /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information |
2299 | | /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */ |
2300 | | /// |
2301 | | /// true: |
2302 | | /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of |
2303 | | /// // information |
2304 | | /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of |
2305 | | /// * information */ |
2306 | | /// \endcode |
2307 | | bool ReflowComments; |
2308 | | // clang-format on |
2309 | | |
2310 | | /// If ``true``, clang-format will sort ``#includes``. |
2311 | | /// \code |
2312 | | /// false: true: |
2313 | | /// #include "b.h" vs. #include "a.h" |
2314 | | /// #include "a.h" #include "b.h" |
2315 | | /// \endcode |
2316 | | bool SortIncludes; |
2317 | | |
2318 | | /// Position for Java Static imports. |
2319 | | enum SortJavaStaticImportOptions : unsigned char { |
2320 | | /// Static imports are placed before non-static imports. |
2321 | | /// \code{.java} |
2322 | | /// import static org.example.function1; |
2323 | | /// |
2324 | | /// import org.example.ClassA; |
2325 | | /// \endcode |
2326 | | SJSIO_Before, |
2327 | | /// Static imports are placed after non-static imports. |
2328 | | /// \code{.java} |
2329 | | /// import org.example.ClassA; |
2330 | | /// |
2331 | | /// import static org.example.function1; |
2332 | | /// \endcode |
2333 | | SJSIO_After, |
2334 | | }; |
2335 | | |
2336 | | /// When sorting Java imports, by default static imports are placed before |
2337 | | /// non-static imports. If ``JavaStaticImportAfterImport`` is ``After``, |
2338 | | /// static imports are placed after non-static imports. |
2339 | | SortJavaStaticImportOptions SortJavaStaticImport; |
2340 | | |
2341 | | /// If ``true``, clang-format will sort using declarations. |
2342 | | /// |
2343 | | /// The order of using declarations is defined as follows: |
2344 | | /// Split the strings by "::" and discard any initial empty strings. The last |
2345 | | /// element of each list is a non-namespace name; all others are namespace |
2346 | | /// names. Sort the lists of names lexicographically, where the sort order of |
2347 | | /// individual names is that all non-namespace names come before all namespace |
2348 | | /// names, and within those groups, names are in case-insensitive |
2349 | | /// lexicographic order. |
2350 | | /// \code |
2351 | | /// false: true: |
2352 | | /// using std::cout; vs. using std::cin; |
2353 | | /// using std::cin; using std::cout; |
2354 | | /// \endcode |
2355 | | bool SortUsingDeclarations; |
2356 | | |
2357 | | /// If ``true``, a space is inserted after C style casts. |
2358 | | /// \code |
2359 | | /// true: false: |
2360 | | /// (int) i; vs. (int)i; |
2361 | | /// \endcode |
2362 | | bool SpaceAfterCStyleCast; |
2363 | | |
2364 | | /// If ``true``, a space is inserted after the logical not operator (``!``). |
2365 | | /// \code |
2366 | | /// true: false: |
2367 | | /// ! someExpression(); vs. !someExpression(); |
2368 | | /// \endcode |
2369 | | bool SpaceAfterLogicalNot; |
2370 | | |
2371 | | /// If \c true, a space will be inserted after the 'template' keyword. |
2372 | | /// \code |
2373 | | /// true: false: |
2374 | | /// template <int> void foo(); vs. template<int> void foo(); |
2375 | | /// \endcode |
2376 | | bool SpaceAfterTemplateKeyword; |
2377 | | |
2378 | | /// Different ways to put a space before opening parentheses. |
2379 | | enum SpaceAroundPointerQualifiersStyle : unsigned char { |
2380 | | /// Don't ensure spaces around pointer qualifiers and use PointerAlignment |
2381 | | /// instead. |
2382 | | /// \code |
2383 | | /// PointerAlignment: Left PointerAlignment: Right |
2384 | | /// void* const* x = NULL; vs. void *const *x = NULL; |
2385 | | /// \endcode |
2386 | | SAPQ_Default, |
2387 | | /// Ensure that there is a space before pointer qualifiers. |
2388 | | /// \code |
2389 | | /// PointerAlignment: Left PointerAlignment: Right |
2390 | | /// void* const* x = NULL; vs. void * const *x = NULL; |
2391 | | /// \endcode |
2392 | | SAPQ_Before, |
2393 | | /// Ensure that there is a space after pointer qualifiers. |
2394 | | /// \code |
2395 | | /// PointerAlignment: Left PointerAlignment: Right |
2396 | | /// void* const * x = NULL; vs. void *const *x = NULL; |
2397 | | /// \endcode |
2398 | | SAPQ_After, |
2399 | | /// Ensure that there is a space both before and after pointer qualifiers. |
2400 | | /// \code |
2401 | | /// PointerAlignment: Left PointerAlignment: Right |
2402 | | /// void* const * x = NULL; vs. void * const *x = NULL; |
2403 | | /// \endcode |
2404 | | SAPQ_Both, |
2405 | | }; |
2406 | | |
2407 | | /// Defines in which cases to put a space before or after pointer qualifiers |
2408 | | SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers; |
2409 | | |
2410 | | /// If ``false``, spaces will be removed before assignment operators. |
2411 | | /// \code |
2412 | | /// true: false: |
2413 | | /// int a = 5; vs. int a= 5; |
2414 | | /// a += 42; a+= 42; |
2415 | | /// \endcode |
2416 | | bool SpaceBeforeAssignmentOperators; |
2417 | | |
2418 | | /// If ``false``, spaces will be removed before case colon. |
2419 | | /// \code |
2420 | | /// true: false |
2421 | | /// switch (x) { vs. switch (x) { |
2422 | | /// case 1 : break; case 1: break; |
2423 | | /// } } |
2424 | | /// \endcode |
2425 | | bool SpaceBeforeCaseColon; |
2426 | | |
2427 | | /// If ``true``, a space will be inserted before a C++11 braced list |
2428 | | /// used to initialize an object (after the preceding identifier or type). |
2429 | | /// \code |
2430 | | /// true: false: |
2431 | | /// Foo foo { bar }; vs. Foo foo{ bar }; |
2432 | | /// Foo {}; Foo{}; |
2433 | | /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 }; |
2434 | | /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 }; |
2435 | | /// \endcode |
2436 | | bool SpaceBeforeCpp11BracedList; |
2437 | | |
2438 | | /// If ``false``, spaces will be removed before constructor initializer |
2439 | | /// colon. |
2440 | | /// \code |
2441 | | /// true: false: |
2442 | | /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {} |
2443 | | /// \endcode |
2444 | | bool SpaceBeforeCtorInitializerColon; |
2445 | | |
2446 | | /// If ``false``, spaces will be removed before inheritance colon. |
2447 | | /// \code |
2448 | | /// true: false: |
2449 | | /// class Foo : Bar {} vs. class Foo: Bar {} |
2450 | | /// \endcode |
2451 | | bool SpaceBeforeInheritanceColon; |
2452 | | |
2453 | | /// Different ways to put a space before opening parentheses. |
2454 | | enum SpaceBeforeParensOptions : unsigned char { |
2455 | | /// Never put a space before opening parentheses. |
2456 | | /// \code |
2457 | | /// void f() { |
2458 | | /// if(true) { |
2459 | | /// f(); |
2460 | | /// } |
2461 | | /// } |
2462 | | /// \endcode |
2463 | | SBPO_Never, |
2464 | | /// Put a space before opening parentheses only after control statement |
2465 | | /// keywords (``for/if/while...``). |
2466 | | /// \code |
2467 | | /// void f() { |
2468 | | /// if (true) { |
2469 | | /// f(); |
2470 | | /// } |
2471 | | /// } |
2472 | | /// \endcode |
2473 | | SBPO_ControlStatements, |
2474 | | /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to |
2475 | | /// ForEach macros. This is useful in projects where ForEach macros are |
2476 | | /// treated as function calls instead of control statements. |
2477 | | /// \code |
2478 | | /// void f() { |
2479 | | /// Q_FOREACH(...) { |
2480 | | /// f(); |
2481 | | /// } |
2482 | | /// } |
2483 | | /// \endcode |
2484 | | SBPO_ControlStatementsExceptForEachMacros, |
2485 | | /// Put a space before opening parentheses only if the parentheses are not |
2486 | | /// empty i.e. '()' |
2487 | | /// \code |
2488 | | /// void() { |
2489 | | /// if (true) { |
2490 | | /// f(); |
2491 | | /// g (x, y, z); |
2492 | | /// } |
2493 | | /// } |
2494 | | /// \endcode |
2495 | | SBPO_NonEmptyParentheses, |
2496 | | /// Always put a space before opening parentheses, except when it's |
2497 | | /// prohibited by the syntax rules (in function-like macro definitions) or |
2498 | | /// when determined by other style rules (after unary operators, opening |
2499 | | /// parentheses, etc.) |
2500 | | /// \code |
2501 | | /// void f () { |
2502 | | /// if (true) { |
2503 | | /// f (); |
2504 | | /// } |
2505 | | /// } |
2506 | | /// \endcode |
2507 | | SBPO_Always |
2508 | | }; |
2509 | | |
2510 | | /// Defines in which cases to put a space before opening parentheses. |
2511 | | SpaceBeforeParensOptions SpaceBeforeParens; |
2512 | | |
2513 | | /// If ``false``, spaces will be removed before range-based for loop |
2514 | | /// colon. |
2515 | | /// \code |
2516 | | /// true: false: |
2517 | | /// for (auto v : values) {} vs. for(auto v: values) {} |
2518 | | /// \endcode |
2519 | | bool SpaceBeforeRangeBasedForLoopColon; |
2520 | | |
2521 | | /// If ``true``, spaces will be inserted into ``{}``. |
2522 | | /// \code |
2523 | | /// true: false: |
2524 | | /// void f() { } vs. void f() {} |
2525 | | /// while (true) { } while (true) {} |
2526 | | /// \endcode |
2527 | | bool SpaceInEmptyBlock; |
2528 | | |
2529 | | /// If ``true``, spaces may be inserted into ``()``. |
2530 | | /// \code |
2531 | | /// true: false: |
2532 | | /// void f( ) { vs. void f() { |
2533 | | /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()}; |
2534 | | /// if (true) { if (true) { |
2535 | | /// f( ); f(); |
2536 | | /// } } |
2537 | | /// } } |
2538 | | /// \endcode |
2539 | | bool SpaceInEmptyParentheses; |
2540 | | |
2541 | | /// The number of spaces before trailing line comments |
2542 | | /// (``//`` - comments). |
2543 | | /// |
2544 | | /// This does not affect trailing block comments (``/*`` - comments) as |
2545 | | /// those commonly have different usage patterns and a number of special |
2546 | | /// cases. |
2547 | | /// \code |
2548 | | /// SpacesBeforeTrailingComments: 3 |
2549 | | /// void f() { |
2550 | | /// if (true) { // foo1 |
2551 | | /// f(); // bar |
2552 | | /// } // foo |
2553 | | /// } |
2554 | | /// \endcode |
2555 | | unsigned SpacesBeforeTrailingComments; |
2556 | | |
2557 | | /// If ``true``, spaces will be inserted after ``<`` and before ``>`` |
2558 | | /// in template argument lists. |
2559 | | /// \code |
2560 | | /// true: false: |
2561 | | /// static_cast< int >(arg); vs. static_cast<int>(arg); |
2562 | | /// std::function< void(int) > fct; std::function<void(int)> fct; |
2563 | | /// \endcode |
2564 | | bool SpacesInAngles; |
2565 | | |
2566 | | /// If ``true``, spaces will be inserted around if/for/switch/while |
2567 | | /// conditions. |
2568 | | /// \code |
2569 | | /// true: false: |
2570 | | /// if ( a ) { ... } vs. if (a) { ... } |
2571 | | /// while ( i < 5 ) { ... } while (i < 5) { ... } |
2572 | | /// \endcode |
2573 | | bool SpacesInConditionalStatement; |
2574 | | |
2575 | | /// If ``true``, spaces are inserted inside container literals (e.g. |
2576 | | /// ObjC and Javascript array and dict literals). |
2577 | | /// \code{.js} |
2578 | | /// true: false: |
2579 | | /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3]; |
2580 | | /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3}); |
2581 | | /// \endcode |
2582 | | bool SpacesInContainerLiterals; |
2583 | | |
2584 | | /// If ``true``, spaces may be inserted into C style casts. |
2585 | | /// \code |
2586 | | /// true: false: |
2587 | | /// x = ( int32 )y vs. x = (int32)y |
2588 | | /// \endcode |
2589 | | bool SpacesInCStyleCastParentheses; |
2590 | | |
2591 | | /// If ``true``, spaces will be inserted after ``(`` and before ``)``. |
2592 | | /// \code |
2593 | | /// true: false: |
2594 | | /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; |
2595 | | /// \endcode |
2596 | | bool SpacesInParentheses; |
2597 | | |
2598 | | /// If ``true``, spaces will be inserted after ``[`` and before ``]``. |
2599 | | /// Lambdas without arguments or unspecified size array declarations will not |
2600 | | /// be affected. |
2601 | | /// \code |
2602 | | /// true: false: |
2603 | | /// int a[ 5 ]; vs. int a[5]; |
2604 | | /// std::unique_ptr<int[]> foo() {} // Won't be affected |
2605 | | /// \endcode |
2606 | | bool SpacesInSquareBrackets; |
2607 | | |
2608 | | /// If ``true``, spaces will be before ``[``. |
2609 | | /// Lambdas will not be affected. Only the first ``[`` will get a space added. |
2610 | | /// \code |
2611 | | /// true: false: |
2612 | | /// int a [5]; vs. int a[5]; |
2613 | | /// int a [5][5]; vs. int a[5][5]; |
2614 | | /// \endcode |
2615 | | bool SpaceBeforeSquareBrackets; |
2616 | | |
2617 | | /// Styles for adding spacing around ``:`` in bitfield definitions. |
2618 | | enum BitFieldColonSpacingStyle : unsigned char { |
2619 | | /// Add one space on each side of the ``:`` |
2620 | | /// \code |
2621 | | /// unsigned bf : 2; |
2622 | | /// \endcode |
2623 | | BFCS_Both, |
2624 | | /// Add no space around the ``:`` (except when needed for |
2625 | | /// ``AlignConsecutiveBitFields``). |
2626 | | /// \code |
2627 | | /// unsigned bf:2; |
2628 | | /// \endcode |
2629 | | BFCS_None, |
2630 | | /// Add space before the ``:`` only |
2631 | | /// \code |
2632 | | /// unsigned bf :2; |
2633 | | /// \endcode |
2634 | | BFCS_Before, |
2635 | | /// Add space after the ``:`` only (space may be added before if |
2636 | | /// needed for ``AlignConsecutiveBitFields``). |
2637 | | /// \code |
2638 | | /// unsigned bf: 2; |
2639 | | /// \endcode |
2640 | | BFCS_After |
2641 | | }; |
2642 | | /// The BitFieldColonSpacingStyle to use for bitfields. |
2643 | | BitFieldColonSpacingStyle BitFieldColonSpacing; |
2644 | | |
2645 | | /// Supported language standards for parsing and formatting C++ constructs. |
2646 | | /// \code |
2647 | | /// Latest: vector<set<int>> |
2648 | | /// c++03 vs. vector<set<int> > |
2649 | | /// \endcode |
2650 | | /// |
2651 | | /// The correct way to spell a specific language version is e.g. ``c++11``. |
2652 | | /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated. |
2653 | | enum LanguageStandard : unsigned char { |
2654 | | /// Parse and format as C++03. |
2655 | | /// ``Cpp03`` is a deprecated alias for ``c++03`` |
2656 | | LS_Cpp03, // c++03 |
2657 | | /// Parse and format as C++11. |
2658 | | LS_Cpp11, // c++11 |
2659 | | /// Parse and format as C++14. |
2660 | | LS_Cpp14, // c++14 |
2661 | | /// Parse and format as C++17. |
2662 | | LS_Cpp17, // c++17 |
2663 | | /// Parse and format as C++20. |
2664 | | LS_Cpp20, // c++20 |
2665 | | /// Parse and format using the latest supported language version. |
2666 | | /// ``Cpp11`` is a deprecated alias for ``Latest`` |
2667 | | LS_Latest, |
2668 | | /// Automatic detection based on the input. |
2669 | | LS_Auto, |
2670 | | }; |
2671 | | |
2672 | | /// Parse and format C++ constructs compatible with this standard. |
2673 | | /// \code |
2674 | | /// c++03: latest: |
2675 | | /// vector<set<int> > x; vs. vector<set<int>> x; |
2676 | | /// \endcode |
2677 | | LanguageStandard Standard; |
2678 | | |
2679 | | /// Macros which are ignored in front of a statement, as if they were an |
2680 | | /// attribute. So that they are not parsed as identifier, for example for Qts |
2681 | | /// emit. |
2682 | | /// \code |
2683 | | /// AlignConsecutiveDeclarations: true |
2684 | | /// StatementAttributeLikeMacros: [] |
2685 | | /// unsigned char data = 'x'; |
2686 | | /// emit signal(data); // This is parsed as variable declaration. |
2687 | | /// |
2688 | | /// AlignConsecutiveDeclarations: true |
2689 | | /// StatementAttributeLikeMacros: [emit] |
2690 | | /// unsigned char data = 'x'; |
2691 | | /// emit signal(data); // Now it's fine again. |
2692 | | /// \endcode |
2693 | | std::vector<std::string> StatementAttributeLikeMacros; |
2694 | | |
2695 | | /// The number of columns used for tab stops. |
2696 | | unsigned TabWidth; |
2697 | | |
2698 | | /// Different ways to use tab in formatting. |
2699 | | enum UseTabStyle : unsigned char { |
2700 | | /// Never use tab. |
2701 | | UT_Never, |
2702 | | /// Use tabs only for indentation. |
2703 | | UT_ForIndentation, |
2704 | | /// Fill all leading whitespace with tabs, and use spaces for alignment that |
2705 | | /// appears within a line (e.g. consecutive assignments and declarations). |
2706 | | UT_ForContinuationAndIndentation, |
2707 | | /// Use tabs for line continuation and indentation, and spaces for |
2708 | | /// alignment. |
2709 | | UT_AlignWithSpaces, |
2710 | | /// Use tabs whenever we need to fill whitespace that spans at least from |
2711 | | /// one tab stop to the next one. |
2712 | | UT_Always |
2713 | | }; |
2714 | | |
2715 | | /// \brief Use ``\r\n`` instead of ``\n`` for line breaks. |
2716 | | /// Also used as fallback if ``DeriveLineEnding`` is true. |
2717 | | bool UseCRLF; |
2718 | | |
2719 | | /// The way to use tab characters in the resulting file. |
2720 | | UseTabStyle UseTab; |
2721 | | |
2722 | 58 | bool operator==(const FormatStyle &R) const { |
2723 | 58 | return AccessModifierOffset == R.AccessModifierOffset && |
2724 | 46 | AlignAfterOpenBracket == R.AlignAfterOpenBracket && |
2725 | 46 | AlignConsecutiveAssignments == R.AlignConsecutiveAssignments && |
2726 | 46 | AlignConsecutiveBitFields == R.AlignConsecutiveBitFields && |
2727 | 46 | AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations && |
2728 | 46 | AlignEscapedNewlines == R.AlignEscapedNewlines && |
2729 | 46 | AlignOperands == R.AlignOperands && |
2730 | 46 | AlignTrailingComments == R.AlignTrailingComments && |
2731 | 46 | AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine && |
2732 | 46 | AllowAllConstructorInitializersOnNextLine == |
2733 | 46 | R.AllowAllConstructorInitializersOnNextLine && |
2734 | 46 | AllowAllParametersOfDeclarationOnNextLine == |
2735 | 46 | R.AllowAllParametersOfDeclarationOnNextLine && |
2736 | 42 | AllowShortEnumsOnASingleLine == R.AllowShortEnumsOnASingleLine && |
2737 | 38 | AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine && |
2738 | 38 | AllowShortCaseLabelsOnASingleLine == |
2739 | 38 | R.AllowShortCaseLabelsOnASingleLine && |
2740 | 38 | AllowShortFunctionsOnASingleLine == |
2741 | 38 | R.AllowShortFunctionsOnASingleLine && |
2742 | 38 | AllowShortIfStatementsOnASingleLine == |
2743 | 38 | R.AllowShortIfStatementsOnASingleLine && |
2744 | 38 | AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine && |
2745 | 38 | AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine && |
2746 | 38 | AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType && |
2747 | 34 | AlwaysBreakBeforeMultilineStrings == |
2748 | 34 | R.AlwaysBreakBeforeMultilineStrings && |
2749 | 34 | AlwaysBreakTemplateDeclarations == |
2750 | 34 | R.AlwaysBreakTemplateDeclarations && |
2751 | 32 | AttributeMacros == R.AttributeMacros && |
2752 | 32 | BinPackArguments == R.BinPackArguments && |
2753 | 32 | BinPackParameters == R.BinPackParameters && |
2754 | 32 | BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators && |
2755 | 32 | BreakBeforeBraces == R.BreakBeforeBraces && |
2756 | 32 | BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations && |
2757 | 32 | BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators && |
2758 | 32 | BreakConstructorInitializers == R.BreakConstructorInitializers && |
2759 | 32 | CompactNamespaces == R.CompactNamespaces && |
2760 | 32 | BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations && |
2761 | 32 | BreakStringLiterals == R.BreakStringLiterals && |
2762 | 32 | ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas && |
2763 | 32 | BreakInheritanceList == R.BreakInheritanceList && |
2764 | 32 | ConstructorInitializerAllOnOneLineOrOnePerLine == |
2765 | 32 | R.ConstructorInitializerAllOnOneLineOrOnePerLine && |
2766 | 32 | ConstructorInitializerIndentWidth == |
2767 | 32 | R.ConstructorInitializerIndentWidth && |
2768 | 32 | ContinuationIndentWidth == R.ContinuationIndentWidth && |
2769 | 32 | Cpp11BracedListStyle == R.Cpp11BracedListStyle && |
2770 | 32 | DeriveLineEnding == R.DeriveLineEnding && |
2771 | 32 | DerivePointerAlignment == R.DerivePointerAlignment && |
2772 | 32 | DisableFormat == R.DisableFormat && |
2773 | 32 | ExperimentalAutoDetectBinPacking == |
2774 | 32 | R.ExperimentalAutoDetectBinPacking && |
2775 | 32 | FixNamespaceComments == R.FixNamespaceComments && |
2776 | 32 | ForEachMacros == R.ForEachMacros && |
2777 | 30 | IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks && |
2778 | 30 | IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories && |
2779 | 30 | IncludeStyle.IncludeIsMainRegex == |
2780 | 30 | R.IncludeStyle.IncludeIsMainRegex && |
2781 | 30 | IncludeStyle.IncludeIsMainSourceRegex == |
2782 | 30 | R.IncludeStyle.IncludeIsMainSourceRegex && |
2783 | 30 | IndentCaseLabels == R.IndentCaseLabels && |
2784 | 30 | IndentCaseBlocks == R.IndentCaseBlocks && |
2785 | 30 | IndentGotoLabels == R.IndentGotoLabels && |
2786 | 30 | IndentPPDirectives == R.IndentPPDirectives && |
2787 | 30 | IndentExternBlock == R.IndentExternBlock && |
2788 | 30 | IndentRequires == R.IndentRequires && IndentWidth == R.IndentWidth && |
2789 | 30 | Language == R.Language && |
2790 | 30 | IndentWrappedFunctionNames == R.IndentWrappedFunctionNames && |
2791 | 30 | JavaImportGroups == R.JavaImportGroups && |
2792 | 30 | JavaScriptQuotes == R.JavaScriptQuotes && |
2793 | 30 | JavaScriptWrapImports == R.JavaScriptWrapImports && |
2794 | 30 | KeepEmptyLinesAtTheStartOfBlocks == |
2795 | 30 | R.KeepEmptyLinesAtTheStartOfBlocks && |
2796 | 30 | MacroBlockBegin == R.MacroBlockBegin && |
2797 | 30 | MacroBlockEnd == R.MacroBlockEnd && |
2798 | 30 | MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep && |
2799 | 30 | NamespaceIndentation == R.NamespaceIndentation && |
2800 | 30 | NamespaceMacros == R.NamespaceMacros && |
2801 | 30 | ObjCBinPackProtocolList == R.ObjCBinPackProtocolList && |
2802 | 30 | ObjCBlockIndentWidth == R.ObjCBlockIndentWidth && |
2803 | 30 | ObjCBreakBeforeNestedBlockParam == |
2804 | 30 | R.ObjCBreakBeforeNestedBlockParam && |
2805 | 30 | ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty && |
2806 | 30 | ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList && |
2807 | 30 | PenaltyBreakAssignment == R.PenaltyBreakAssignment && |
2808 | 30 | PenaltyBreakBeforeFirstCallParameter == |
2809 | 30 | R.PenaltyBreakBeforeFirstCallParameter && |
2810 | 30 | PenaltyBreakComment == R.PenaltyBreakComment && |
2811 | 30 | PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess && |
2812 | 30 | PenaltyBreakString == R.PenaltyBreakString && |
2813 | 30 | PenaltyExcessCharacter == R.PenaltyExcessCharacter && |
2814 | 30 | PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine && |
2815 | 30 | PenaltyBreakTemplateDeclaration == |
2816 | 30 | R.PenaltyBreakTemplateDeclaration && |
2817 | 30 | PointerAlignment == R.PointerAlignment && |
2818 | 30 | RawStringFormats == R.RawStringFormats && |
2819 | 30 | SortJavaStaticImport == R.SortJavaStaticImport && |
2820 | 30 | SpaceAfterCStyleCast == R.SpaceAfterCStyleCast && |
2821 | 30 | SpaceAfterLogicalNot == R.SpaceAfterLogicalNot && |
2822 | 30 | SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword && |
2823 | 30 | SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators && |
2824 | 30 | SpaceBeforeCaseColon == R.SpaceBeforeCaseColon && |
2825 | 30 | SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList && |
2826 | 30 | SpaceBeforeCtorInitializerColon == |
2827 | 30 | R.SpaceBeforeCtorInitializerColon && |
2828 | 30 | SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon && |
2829 | 30 | SpaceBeforeParens == R.SpaceBeforeParens && |
2830 | 30 | SpaceAroundPointerQualifiers == R.SpaceAroundPointerQualifiers && |
2831 | 30 | SpaceBeforeRangeBasedForLoopColon == |
2832 | 30 | R.SpaceBeforeRangeBasedForLoopColon && |
2833 | 30 | SpaceInEmptyBlock == R.SpaceInEmptyBlock && |
2834 | 30 | SpaceInEmptyParentheses == R.SpaceInEmptyParentheses && |
2835 | 30 | SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments && |
2836 | 30 | SpacesInAngles == R.SpacesInAngles && |
2837 | 30 | SpacesInConditionalStatement == R.SpacesInConditionalStatement && |
2838 | 30 | SpacesInContainerLiterals == R.SpacesInContainerLiterals && |
2839 | 30 | SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses && |
2840 | 30 | SpacesInParentheses == R.SpacesInParentheses && |
2841 | 30 | SpacesInSquareBrackets == R.SpacesInSquareBrackets && |
2842 | 30 | SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets && |
2843 | 30 | BitFieldColonSpacing == R.BitFieldColonSpacing && |
2844 | 30 | Standard == R.Standard && |
2845 | 30 | StatementAttributeLikeMacros == R.StatementAttributeLikeMacros && |
2846 | 30 | StatementMacros == R.StatementMacros && TabWidth == R.TabWidth && |
2847 | 30 | UseTab == R.UseTab && UseCRLF == R.UseCRLF && |
2848 | 30 | TypenameMacros == R.TypenameMacros; |
2849 | 58 | } |
2850 | | |
2851 | | llvm::Optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const; |
2852 | | |
2853 | | // Stores per-language styles. A FormatStyle instance inside has an empty |
2854 | | // StyleSet. A FormatStyle instance returned by the Get method has its |
2855 | | // StyleSet set to a copy of the originating StyleSet, effectively keeping the |
2856 | | // internal representation of that StyleSet alive. |
2857 | | // |
2858 | | // The memory management and ownership reminds of a birds nest: chicks |
2859 | | // leaving the nest take photos of the nest with them. |
2860 | | struct FormatStyleSet { |
2861 | | typedef std::map<FormatStyle::LanguageKind, FormatStyle> MapType; |
2862 | | |
2863 | | llvm::Optional<FormatStyle> Get(FormatStyle::LanguageKind Language) const; |
2864 | | |
2865 | | // Adds \p Style to this FormatStyleSet. Style must not have an associated |
2866 | | // FormatStyleSet. |
2867 | | // Style.Language should be different than LK_None. If this FormatStyleSet |
2868 | | // already contains an entry for Style.Language, that gets replaced with the |
2869 | | // passed Style. |
2870 | | void Add(FormatStyle Style); |
2871 | | |
2872 | | // Clears this FormatStyleSet. |
2873 | | void Clear(); |
2874 | | |
2875 | | private: |
2876 | | std::shared_ptr<MapType> Styles; |
2877 | | }; |
2878 | | |
2879 | | static FormatStyleSet BuildStyleSetFromConfiguration( |
2880 | | const FormatStyle &MainStyle, |
2881 | | const std::vector<FormatStyle> &ConfigurationStyles); |
2882 | | |
2883 | | private: |
2884 | | FormatStyleSet StyleSet; |
2885 | | |
2886 | | friend std::error_code parseConfiguration(llvm::MemoryBufferRef Config, |
2887 | | FormatStyle *Style, |
2888 | | bool AllowUnknownOptions); |
2889 | | }; |
2890 | | |
2891 | | /// Returns a format style complying with the LLVM coding standards: |
2892 | | /// http://llvm.org/docs/CodingStandards.html. |
2893 | | FormatStyle getLLVMStyle( |
2894 | | FormatStyle::LanguageKind Language = FormatStyle::LanguageKind::LK_Cpp); |
2895 | | |
2896 | | /// Returns a format style complying with one of Google's style guides: |
2897 | | /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml. |
2898 | | /// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml. |
2899 | | /// https://developers.google.com/protocol-buffers/docs/style. |
2900 | | FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language); |
2901 | | |
2902 | | /// Returns a format style complying with Chromium's style guide: |
2903 | | /// http://www.chromium.org/developers/coding-style. |
2904 | | FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language); |
2905 | | |
2906 | | /// Returns a format style complying with Mozilla's style guide: |
2907 | | /// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style. |
2908 | | FormatStyle getMozillaStyle(); |
2909 | | |
2910 | | /// Returns a format style complying with Webkit's style guide: |
2911 | | /// http://www.webkit.org/coding/coding-style.html |
2912 | | FormatStyle getWebKitStyle(); |
2913 | | |
2914 | | /// Returns a format style complying with GNU Coding Standards: |
2915 | | /// http://www.gnu.org/prep/standards/standards.html |
2916 | | FormatStyle getGNUStyle(); |
2917 | | |
2918 | | /// Returns a format style complying with Microsoft style guide: |
2919 | | /// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017 |
2920 | | FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language); |
2921 | | |
2922 | | /// Returns style indicating formatting should be not applied at all. |
2923 | | FormatStyle getNoStyle(); |
2924 | | |
2925 | | /// Gets a predefined style for the specified language by name. |
2926 | | /// |
2927 | | /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are |
2928 | | /// compared case-insensitively. |
2929 | | /// |
2930 | | /// Returns ``true`` if the Style has been set. |
2931 | | bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, |
2932 | | FormatStyle *Style); |
2933 | | |
2934 | | /// Parse configuration from YAML-formatted text. |
2935 | | /// |
2936 | | /// Style->Language is used to get the base style, if the ``BasedOnStyle`` |
2937 | | /// option is present. |
2938 | | /// |
2939 | | /// The FormatStyleSet of Style is reset. |
2940 | | /// |
2941 | | /// When ``BasedOnStyle`` is not present, options not present in the YAML |
2942 | | /// document, are retained in \p Style. |
2943 | | /// |
2944 | | /// If AllowUnknownOptions is true, no errors are emitted if unknown |
2945 | | /// format options are occured. |
2946 | | std::error_code parseConfiguration(llvm::MemoryBufferRef Config, |
2947 | | FormatStyle *Style, |
2948 | | bool AllowUnknownOptions = false); |
2949 | | |
2950 | | /// Like above but accepts an unnamed buffer. |
2951 | | inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style, |
2952 | | bool AllowUnknownOptions = false) { |
2953 | | return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style, |
2954 | | AllowUnknownOptions); |
2955 | | } |
2956 | | |
2957 | | /// Gets configuration in a YAML string. |
2958 | | std::string configurationAsText(const FormatStyle &Style); |
2959 | | |
2960 | | /// Returns the replacements necessary to sort all ``#include`` blocks |
2961 | | /// that are affected by ``Ranges``. |
2962 | | tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, |
2963 | | ArrayRef<tooling::Range> Ranges, |
2964 | | StringRef FileName, |
2965 | | unsigned *Cursor = nullptr); |
2966 | | |
2967 | | /// Returns the replacements corresponding to applying and formatting |
2968 | | /// \p Replaces on success; otheriwse, return an llvm::Error carrying |
2969 | | /// llvm::StringError. |
2970 | | llvm::Expected<tooling::Replacements> |
2971 | | formatReplacements(StringRef Code, const tooling::Replacements &Replaces, |
2972 | | const FormatStyle &Style); |
2973 | | |
2974 | | /// Returns the replacements corresponding to applying \p Replaces and |
2975 | | /// cleaning up the code after that on success; otherwise, return an llvm::Error |
2976 | | /// carrying llvm::StringError. |
2977 | | /// This also supports inserting/deleting C++ #include directives: |
2978 | | /// - If a replacement has offset UINT_MAX, length 0, and a replacement text |
2979 | | /// that is an #include directive, this will insert the #include into the |
2980 | | /// correct block in the \p Code. |
2981 | | /// - If a replacement has offset UINT_MAX, length 1, and a replacement text |
2982 | | /// that is the name of the header to be removed, the header will be removed |
2983 | | /// from \p Code if it exists. |
2984 | | /// The include manipulation is done via `tooling::HeaderInclude`, see its |
2985 | | /// documentation for more details on how include insertion points are found and |
2986 | | /// what edits are produced. |
2987 | | llvm::Expected<tooling::Replacements> |
2988 | | cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, |
2989 | | const FormatStyle &Style); |
2990 | | |
2991 | | /// Represents the status of a formatting attempt. |
2992 | | struct FormattingAttemptStatus { |
2993 | | /// A value of ``false`` means that any of the affected ranges were not |
2994 | | /// formatted due to a non-recoverable syntax error. |
2995 | | bool FormatComplete = true; |
2996 | | |
2997 | | /// If ``FormatComplete`` is false, ``Line`` records a one-based |
2998 | | /// original line number at which a syntax error might have occurred. This is |
2999 | | /// based on a best-effort analysis and could be imprecise. |
3000 | | unsigned Line = 0; |
3001 | | }; |
3002 | | |
3003 | | /// Reformats the given \p Ranges in \p Code. |
3004 | | /// |
3005 | | /// Each range is extended on either end to its next bigger logic unit, i.e. |
3006 | | /// everything that might influence its formatting or might be influenced by its |
3007 | | /// formatting. |
3008 | | /// |
3009 | | /// Returns the ``Replacements`` necessary to make all \p Ranges comply with |
3010 | | /// \p Style. |
3011 | | /// |
3012 | | /// If ``Status`` is non-null, its value will be populated with the status of |
3013 | | /// this formatting attempt. See \c FormattingAttemptStatus. |
3014 | | tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, |
3015 | | ArrayRef<tooling::Range> Ranges, |
3016 | | StringRef FileName = "<stdin>", |
3017 | | FormattingAttemptStatus *Status = nullptr); |
3018 | | |
3019 | | /// Same as above, except if ``IncompleteFormat`` is non-null, its value |
3020 | | /// will be set to true if any of the affected ranges were not formatted due to |
3021 | | /// a non-recoverable syntax error. |
3022 | | tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, |
3023 | | ArrayRef<tooling::Range> Ranges, |
3024 | | StringRef FileName, bool *IncompleteFormat); |
3025 | | |
3026 | | /// Clean up any erroneous/redundant code in the given \p Ranges in \p |
3027 | | /// Code. |
3028 | | /// |
3029 | | /// Returns the ``Replacements`` that clean up all \p Ranges in \p Code. |
3030 | | tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, |
3031 | | ArrayRef<tooling::Range> Ranges, |
3032 | | StringRef FileName = "<stdin>"); |
3033 | | |
3034 | | /// Fix namespace end comments in the given \p Ranges in \p Code. |
3035 | | /// |
3036 | | /// Returns the ``Replacements`` that fix the namespace comments in all |
3037 | | /// \p Ranges in \p Code. |
3038 | | tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style, |
3039 | | StringRef Code, |
3040 | | ArrayRef<tooling::Range> Ranges, |
3041 | | StringRef FileName = "<stdin>"); |
3042 | | |
3043 | | /// Sort consecutive using declarations in the given \p Ranges in |
3044 | | /// \p Code. |
3045 | | /// |
3046 | | /// Returns the ``Replacements`` that sort the using declarations in all |
3047 | | /// \p Ranges in \p Code. |
3048 | | tooling::Replacements sortUsingDeclarations(const FormatStyle &Style, |
3049 | | StringRef Code, |
3050 | | ArrayRef<tooling::Range> Ranges, |
3051 | | StringRef FileName = "<stdin>"); |
3052 | | |
3053 | | /// Returns the ``LangOpts`` that the formatter expects you to set. |
3054 | | /// |
3055 | | /// \param Style determines specific settings for lexing mode. |
3056 | | LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle()); |
3057 | | |
3058 | | /// Description to be used for help text for a ``llvm::cl`` option for |
3059 | | /// specifying format style. The description is closely related to the operation |
3060 | | /// of ``getStyle()``. |
3061 | | extern const char *StyleOptionHelpDescription; |
3062 | | |
3063 | | /// The suggested format style to use by default. This allows tools using |
3064 | | /// `getStyle` to have a consistent default style. |
3065 | | /// Different builds can modify the value to the preferred styles. |
3066 | | extern const char *DefaultFormatStyle; |
3067 | | |
3068 | | /// The suggested predefined style to use as the fallback style in `getStyle`. |
3069 | | /// Different builds can modify the value to the preferred styles. |
3070 | | extern const char *DefaultFallbackStyle; |
3071 | | |
3072 | | /// Construct a FormatStyle based on ``StyleName``. |
3073 | | /// |
3074 | | /// ``StyleName`` can take several forms: |
3075 | | /// * "{<key>: <value>, ...}" - Set specic style parameters. |
3076 | | /// * "<style name>" - One of the style names supported by |
3077 | | /// getPredefinedStyle(). |
3078 | | /// * "file" - Load style configuration from a file called ``.clang-format`` |
3079 | | /// located in one of the parent directories of ``FileName`` or the current |
3080 | | /// directory if ``FileName`` is empty. |
3081 | | /// |
3082 | | /// \param[in] StyleName Style name to interpret according to the description |
3083 | | /// above. |
3084 | | /// \param[in] FileName Path to start search for .clang-format if ``StyleName`` |
3085 | | /// == "file". |
3086 | | /// \param[in] FallbackStyle The name of a predefined style used to fallback to |
3087 | | /// in case \p StyleName is "file" and no file can be found. |
3088 | | /// \param[in] Code The actual code to be formatted. Used to determine the |
3089 | | /// language if the filename isn't sufficient. |
3090 | | /// \param[in] FS The underlying file system, in which the file resides. By |
3091 | | /// default, the file system is the real file system. |
3092 | | /// \param[in] AllowUnknownOptions If true, unknown format options only |
3093 | | /// emit a warning. If false, errors are emitted on unknown format |
3094 | | /// options. |
3095 | | /// |
3096 | | /// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is |
3097 | | /// "file" and no file is found, returns ``FallbackStyle``. If no style could be |
3098 | | /// determined, returns an Error. |
3099 | | llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName, |
3100 | | StringRef FallbackStyle, |
3101 | | StringRef Code = "", |
3102 | | llvm::vfs::FileSystem *FS = nullptr, |
3103 | | bool AllowUnknownOptions = false); |
3104 | | |
3105 | | // Guesses the language from the ``FileName`` and ``Code`` to be formatted. |
3106 | | // Defaults to FormatStyle::LK_Cpp. |
3107 | | FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code); |
3108 | | |
3109 | | // Returns a string representation of ``Language``. |
3110 | 0 | inline StringRef getLanguageName(FormatStyle::LanguageKind Language) { |
3111 | 0 | switch (Language) { |
3112 | 0 | case FormatStyle::LK_Cpp: |
3113 | 0 | return "C++"; |
3114 | 0 | case FormatStyle::LK_CSharp: |
3115 | 0 | return "CSharp"; |
3116 | 0 | case FormatStyle::LK_ObjC: |
3117 | 0 | return "Objective-C"; |
3118 | 0 | case FormatStyle::LK_Java: |
3119 | 0 | return "Java"; |
3120 | 0 | case FormatStyle::LK_JavaScript: |
3121 | 0 | return "JavaScript"; |
3122 | 0 | case FormatStyle::LK_Proto: |
3123 | 0 | return "Proto"; |
3124 | 0 | case FormatStyle::LK_TableGen: |
3125 | 0 | return "TableGen"; |
3126 | 0 | case FormatStyle::LK_TextProto: |
3127 | 0 | return "TextProto"; |
3128 | 0 | default: |
3129 | 0 | return "Unknown"; |
3130 | 0 | } |
3131 | 0 | } |
3132 | | |
3133 | | } // end namespace format |
3134 | | } // end namespace clang |
3135 | | |
3136 | | namespace std { |
3137 | | template <> |
3138 | | struct is_error_code_enum<clang::format::ParseError> : std::true_type {}; |
3139 | | } // namespace std |
3140 | | |
3141 | | #endif // LLVM_CLANG_FORMAT_FORMAT_H |