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 "llvm/Support/SourceMgr.h" |
23 | #include <optional> |
24 | #include <system_error> |
25 | |
26 | namespace llvm { |
27 | namespace vfs { |
28 | class FileSystem; |
29 | } |
30 | } // namespace llvm |
31 | |
32 | namespace clang { |
33 | namespace format { |
34 | |
35 | enum class ParseError { |
36 | Success = 0, |
37 | Error, |
38 | Unsuitable, |
39 | BinPackTrailingCommaConflict, |
40 | InvalidQualifierSpecified, |
41 | DuplicateQualifierSpecified, |
42 | MissingQualifierType, |
43 | MissingQualifierOrder |
44 | }; |
45 | class ParseErrorCategory final : public std::error_category { |
46 | public: |
47 | const char *name() const noexcept override; |
48 | std::string message(int EV) const override; |
49 | }; |
50 | const std::error_category &getParseCategory(); |
51 | std::error_code make_error_code(ParseError e); |
52 | |
53 | /// The ``FormatStyle`` is used to configure the formatting to follow |
54 | /// specific guidelines. |
55 | struct FormatStyle { |
56 | // If the BasedOn: was InheritParentConfig and this style needs the file from |
57 | // the parent directories. It is not part of the actual style for formatting. |
58 | // Thus the // instead of ///. |
59 | bool InheritsParentConfig; |
60 | |
61 | /// The extra indent or outdent of access modifiers, e.g. ``public:``. |
62 | /// \version 3.3 |
63 | int AccessModifierOffset; |
64 | |
65 | /// Different styles for aligning after open brackets. |
66 | enum BracketAlignmentStyle : int8_t { |
67 | /// Align parameters on the open bracket, e.g.: |
68 | /// \code |
69 | /// someLongFunction(argument1, |
70 | /// argument2); |
71 | /// \endcode |
72 | BAS_Align, |
73 | /// Don't align, instead use ``ContinuationIndentWidth``, e.g.: |
74 | /// \code |
75 | /// someLongFunction(argument1, |
76 | /// argument2); |
77 | /// \endcode |
78 | BAS_DontAlign, |
79 | /// Always break after an open bracket, if the parameters don't fit |
80 | /// on a single line, e.g.: |
81 | /// \code |
82 | /// someLongFunction( |
83 | /// argument1, argument2); |
84 | /// \endcode |
85 | BAS_AlwaysBreak, |
86 | /// Always break after an open bracket, if the parameters don't fit |
87 | /// on a single line. Closing brackets will be placed on a new line. |
88 | /// E.g.: |
89 | /// \code |
90 | /// someLongFunction( |
91 | /// argument1, argument2 |
92 | /// ) |
93 | /// \endcode |
94 | /// |
95 | /// \note |
96 | /// This currently only applies to braced initializer lists (when |
97 | /// ``Cpp11BracedListStyle`` is ``true``) and parentheses. |
98 | /// \endnote |
99 | BAS_BlockIndent, |
100 | }; |
101 | |
102 | /// If ``true``, horizontally aligns arguments after an open bracket. |
103 | /// |
104 | /// This applies to round brackets (parentheses), angle brackets and square |
105 | /// brackets. |
106 | /// \version 3.8 |
107 | BracketAlignmentStyle AlignAfterOpenBracket; |
108 | |
109 | /// Different style for aligning array initializers. |
110 | enum ArrayInitializerAlignmentStyle : int8_t { |
111 | /// Align array column and left justify the columns e.g.: |
112 | /// \code |
113 | /// struct test demo[] = |
114 | /// { |
115 | /// {56, 23, "hello"}, |
116 | /// {-1, 93463, "world"}, |
117 | /// {7, 5, "!!" } |
118 | /// }; |
119 | /// \endcode |
120 | AIAS_Left, |
121 | /// Align array column and right justify the columns e.g.: |
122 | /// \code |
123 | /// struct test demo[] = |
124 | /// { |
125 | /// {56, 23, "hello"}, |
126 | /// {-1, 93463, "world"}, |
127 | /// { 7, 5, "!!"} |
128 | /// }; |
129 | /// \endcode |
130 | AIAS_Right, |
131 | /// Don't align array initializer columns. |
132 | AIAS_None |
133 | }; |
134 | /// if not ``None``, when using initialization for an array of structs |
135 | /// aligns the fields into columns. |
136 | /// |
137 | /// \note |
138 | /// As of clang-format 15 this option only applied to arrays with equal |
139 | /// number of columns per row. |
140 | /// \endnote |
141 | /// |
142 | /// \version 13 |
143 | ArrayInitializerAlignmentStyle AlignArrayOfStructures; |
144 | |
145 | /// Alignment options. |
146 | /// |
147 | /// They can also be read as a whole for compatibility. The choices are: |
148 | /// - None |
149 | /// - Consecutive |
150 | /// - AcrossEmptyLines |
151 | /// - AcrossComments |
152 | /// - AcrossEmptyLinesAndComments |
153 | /// |
154 | /// For example, to align across empty lines and not across comments, either |
155 | /// of these work. |
156 | /// \code |
157 | /// AlignConsecutiveMacros: AcrossEmptyLines |
158 | /// |
159 | /// AlignConsecutiveMacros: |
160 | /// Enabled: true |
161 | /// AcrossEmptyLines: true |
162 | /// AcrossComments: false |
163 | /// \endcode |
164 | struct AlignConsecutiveStyle { |
165 | /// Whether aligning is enabled. |
166 | /// \code |
167 | /// #define SHORT_NAME 42 |
168 | /// #define LONGER_NAME 0x007f |
169 | /// #define EVEN_LONGER_NAME (2) |
170 | /// #define foo(x) (x * x) |
171 | /// #define bar(y, z) (y + z) |
172 | /// |
173 | /// int a = 1; |
174 | /// int somelongname = 2; |
175 | /// double c = 3; |
176 | /// |
177 | /// int aaaa : 1; |
178 | /// int b : 12; |
179 | /// int ccc : 8; |
180 | /// |
181 | /// int aaaa = 12; |
182 | /// float b = 23; |
183 | /// std::string ccc; |
184 | /// \endcode |
185 | bool Enabled; |
186 | /// Whether to align across empty lines. |
187 | /// \code |
188 | /// true: |
189 | /// int a = 1; |
190 | /// int somelongname = 2; |
191 | /// double c = 3; |
192 | /// |
193 | /// int d = 3; |
194 | /// |
195 | /// false: |
196 | /// int a = 1; |
197 | /// int somelongname = 2; |
198 | /// double c = 3; |
199 | /// |
200 | /// int d = 3; |
201 | /// \endcode |
202 | bool AcrossEmptyLines; |
203 | /// Whether to align across comments. |
204 | /// \code |
205 | /// true: |
206 | /// int d = 3; |
207 | /// /* A comment. */ |
208 | /// double e = 4; |
209 | /// |
210 | /// false: |
211 | /// int d = 3; |
212 | /// /* A comment. */ |
213 | /// double e = 4; |
214 | /// \endcode |
215 | bool ; |
216 | /// Only for ``AlignConsecutiveAssignments``. Whether compound assignments |
217 | /// like ``+=`` are aligned along with ``=``. |
218 | /// \code |
219 | /// true: |
220 | /// a &= 2; |
221 | /// bbb = 2; |
222 | /// |
223 | /// false: |
224 | /// a &= 2; |
225 | /// bbb = 2; |
226 | /// \endcode |
227 | bool AlignCompound; |
228 | /// Only for ``AlignConsecutiveDeclarations``. Whether function pointers are |
229 | /// aligned. |
230 | /// \code |
231 | /// true: |
232 | /// unsigned i; |
233 | /// int &r; |
234 | /// int *p; |
235 | /// int (*f)(); |
236 | /// |
237 | /// false: |
238 | /// unsigned i; |
239 | /// int &r; |
240 | /// int *p; |
241 | /// int (*f)(); |
242 | /// \endcode |
243 | bool AlignFunctionPointers; |
244 | /// Only for ``AlignConsecutiveAssignments``. Whether short assignment |
245 | /// operators are left-padded to the same length as long ones in order to |
246 | /// put all assignment operators to the right of the left hand side. |
247 | /// \code |
248 | /// true: |
249 | /// a >>= 2; |
250 | /// bbb = 2; |
251 | /// |
252 | /// a = 2; |
253 | /// bbb >>= 2; |
254 | /// |
255 | /// false: |
256 | /// a >>= 2; |
257 | /// bbb = 2; |
258 | /// |
259 | /// a = 2; |
260 | /// bbb >>= 2; |
261 | /// \endcode |
262 | bool PadOperators; |
263 | bool operator==(const AlignConsecutiveStyle &R) const { |
264 | return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines && |
265 | AcrossComments == R.AcrossComments && |
266 | AlignCompound == R.AlignCompound && |
267 | AlignFunctionPointers == R.AlignFunctionPointers && |
268 | PadOperators == R.PadOperators; |
269 | } |
270 | bool operator!=(const AlignConsecutiveStyle &R) const { |
271 | return !(*this == R); |
272 | } |
273 | }; |
274 | |
275 | /// Style of aligning consecutive macro definitions. |
276 | /// |
277 | /// ``Consecutive`` will result in formattings like: |
278 | /// \code |
279 | /// #define SHORT_NAME 42 |
280 | /// #define LONGER_NAME 0x007f |
281 | /// #define EVEN_LONGER_NAME (2) |
282 | /// #define foo(x) (x * x) |
283 | /// #define bar(y, z) (y + z) |
284 | /// \endcode |
285 | /// \version 9 |
286 | AlignConsecutiveStyle AlignConsecutiveMacros; |
287 | /// Style of aligning consecutive assignments. |
288 | /// |
289 | /// ``Consecutive`` will result in formattings like: |
290 | /// \code |
291 | /// int a = 1; |
292 | /// int somelongname = 2; |
293 | /// double c = 3; |
294 | /// \endcode |
295 | /// \version 3.8 |
296 | AlignConsecutiveStyle AlignConsecutiveAssignments; |
297 | /// Style of aligning consecutive bit fields. |
298 | /// |
299 | /// ``Consecutive`` will align the bitfield separators of consecutive lines. |
300 | /// This will result in formattings like: |
301 | /// \code |
302 | /// int aaaa : 1; |
303 | /// int b : 12; |
304 | /// int ccc : 8; |
305 | /// \endcode |
306 | /// \version 11 |
307 | AlignConsecutiveStyle AlignConsecutiveBitFields; |
308 | /// Style of aligning consecutive declarations. |
309 | /// |
310 | /// ``Consecutive`` will align the declaration names of consecutive lines. |
311 | /// This will result in formattings like: |
312 | /// \code |
313 | /// int aaaa = 12; |
314 | /// float b = 23; |
315 | /// std::string ccc; |
316 | /// \endcode |
317 | /// \version 3.8 |
318 | AlignConsecutiveStyle AlignConsecutiveDeclarations; |
319 | |
320 | /// Alignment options. |
321 | /// |
322 | struct ShortCaseStatementsAlignmentStyle { |
323 | /// Whether aligning is enabled. |
324 | /// \code |
325 | /// true: |
326 | /// switch (level) { |
327 | /// case log::info: return "info:"; |
328 | /// case log::warning: return "warning:"; |
329 | /// default: return ""; |
330 | /// } |
331 | /// |
332 | /// false: |
333 | /// switch (level) { |
334 | /// case log::info: return "info:"; |
335 | /// case log::warning: return "warning:"; |
336 | /// default: return ""; |
337 | /// } |
338 | /// \endcode |
339 | bool Enabled; |
340 | /// Whether to align across empty lines. |
341 | /// \code |
342 | /// true: |
343 | /// switch (level) { |
344 | /// case log::info: return "info:"; |
345 | /// case log::warning: return "warning:"; |
346 | /// |
347 | /// default: return ""; |
348 | /// } |
349 | /// |
350 | /// false: |
351 | /// switch (level) { |
352 | /// case log::info: return "info:"; |
353 | /// case log::warning: return "warning:"; |
354 | /// |
355 | /// default: return ""; |
356 | /// } |
357 | /// \endcode |
358 | bool AcrossEmptyLines; |
359 | /// Whether to align across comments. |
360 | /// \code |
361 | /// true: |
362 | /// switch (level) { |
363 | /// case log::info: return "info:"; |
364 | /// case log::warning: return "warning:"; |
365 | /// /* A comment. */ |
366 | /// default: return ""; |
367 | /// } |
368 | /// |
369 | /// false: |
370 | /// switch (level) { |
371 | /// case log::info: return "info:"; |
372 | /// case log::warning: return "warning:"; |
373 | /// /* A comment. */ |
374 | /// default: return ""; |
375 | /// } |
376 | /// \endcode |
377 | bool ; |
378 | /// Whether aligned case labels are aligned on the colon, or on the |
379 | /// , or on the tokens after the colon. |
380 | /// \code |
381 | /// true: |
382 | /// switch (level) { |
383 | /// case log::info : return "info:"; |
384 | /// case log::warning: return "warning:"; |
385 | /// default : return ""; |
386 | /// } |
387 | /// |
388 | /// false: |
389 | /// switch (level) { |
390 | /// case log::info: return "info:"; |
391 | /// case log::warning: return "warning:"; |
392 | /// default: return ""; |
393 | /// } |
394 | /// \endcode |
395 | bool AlignCaseColons; |
396 | bool operator==(const ShortCaseStatementsAlignmentStyle &R) const { |
397 | return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines && |
398 | AcrossComments == R.AcrossComments && |
399 | AlignCaseColons == R.AlignCaseColons; |
400 | } |
401 | }; |
402 | |
403 | /// Style of aligning consecutive short case labels. |
404 | /// Only applies if ``AllowShortCaseLabelsOnASingleLine`` is ``true``. |
405 | /// |
406 | /// \code{.yaml} |
407 | /// # Example of usage: |
408 | /// AlignConsecutiveShortCaseStatements: |
409 | /// Enabled: true |
410 | /// AcrossEmptyLines: true |
411 | /// AcrossComments: true |
412 | /// AlignCaseColons: false |
413 | /// \endcode |
414 | /// \version 17 |
415 | ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements; |
416 | |
417 | /// Different styles for aligning escaped newlines. |
418 | enum EscapedNewlineAlignmentStyle : int8_t { |
419 | /// Don't align escaped newlines. |
420 | /// \code |
421 | /// #define A \ |
422 | /// int aaaa; \ |
423 | /// int b; \ |
424 | /// int dddddddddd; |
425 | /// \endcode |
426 | ENAS_DontAlign, |
427 | /// Align escaped newlines as far left as possible. |
428 | /// \code |
429 | /// true: |
430 | /// #define A \ |
431 | /// int aaaa; \ |
432 | /// int b; \ |
433 | /// int dddddddddd; |
434 | /// |
435 | /// false: |
436 | /// \endcode |
437 | ENAS_Left, |
438 | /// Align escaped newlines in the right-most column. |
439 | /// \code |
440 | /// #define A \ |
441 | /// int aaaa; \ |
442 | /// int b; \ |
443 | /// int dddddddddd; |
444 | /// \endcode |
445 | ENAS_Right, |
446 | }; |
447 | |
448 | /// Options for aligning backslashes in escaped newlines. |
449 | /// \version 5 |
450 | EscapedNewlineAlignmentStyle AlignEscapedNewlines; |
451 | |
452 | /// Different styles for aligning operands. |
453 | enum OperandAlignmentStyle : int8_t { |
454 | /// Do not align operands of binary and ternary expressions. |
455 | /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from |
456 | /// the start of the line. |
457 | OAS_DontAlign, |
458 | /// Horizontally align operands of binary and ternary expressions. |
459 | /// |
460 | /// Specifically, this aligns operands of a single expression that needs |
461 | /// to be split over multiple lines, e.g.: |
462 | /// \code |
463 | /// int aaa = bbbbbbbbbbbbbbb + |
464 | /// ccccccccccccccc; |
465 | /// \endcode |
466 | /// |
467 | /// When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is |
468 | /// aligned with the operand on the first line. |
469 | /// \code |
470 | /// int aaa = bbbbbbbbbbbbbbb |
471 | /// + ccccccccccccccc; |
472 | /// \endcode |
473 | OAS_Align, |
474 | /// Horizontally align operands of binary and ternary expressions. |
475 | /// |
476 | /// This is similar to ``AO_Align``, except when |
477 | /// ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so |
478 | /// that the wrapped operand is aligned with the operand on the first line. |
479 | /// \code |
480 | /// int aaa = bbbbbbbbbbbbbbb |
481 | /// + ccccccccccccccc; |
482 | /// \endcode |
483 | OAS_AlignAfterOperator, |
484 | }; |
485 | |
486 | /// If ``true``, horizontally align operands of binary and ternary |
487 | /// expressions. |
488 | /// \version 3.5 |
489 | OperandAlignmentStyle AlignOperands; |
490 | |
491 | /// Enums for AlignTrailingComments |
492 | enum : int8_t { |
493 | /// Leave trailing comments as they are. |
494 | /// \code |
495 | /// int a; // comment |
496 | /// int ab; // comment |
497 | /// |
498 | /// int abc; // comment |
499 | /// int abcd; // comment |
500 | /// \endcode |
501 | TCAS_Leave, |
502 | /// Align trailing comments. |
503 | /// \code |
504 | /// int a; // comment |
505 | /// int ab; // comment |
506 | /// |
507 | /// int abc; // comment |
508 | /// int abcd; // comment |
509 | /// \endcode |
510 | TCAS_Always, |
511 | /// Don't align trailing comments but other formatter applies. |
512 | /// \code |
513 | /// int a; // comment |
514 | /// int ab; // comment |
515 | /// |
516 | /// int abc; // comment |
517 | /// int abcd; // comment |
518 | /// \endcode |
519 | TCAS_Never, |
520 | }; |
521 | |
522 | /// Alignment options |
523 | struct { |
524 | /// Specifies the way to align trailing comments. |
525 | TrailingCommentsAlignmentKinds ; |
526 | /// How many empty lines to apply alignment. |
527 | /// When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2, |
528 | /// it formats like below. |
529 | /// \code |
530 | /// int a; // all these |
531 | /// |
532 | /// int ab; // comments are |
533 | /// |
534 | /// |
535 | /// int abcdef; // aligned |
536 | /// \endcode |
537 | /// |
538 | /// When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set |
539 | /// to 1, it formats like below. |
540 | /// \code |
541 | /// int a; // these are |
542 | /// |
543 | /// int ab; // aligned |
544 | /// |
545 | /// |
546 | /// int abcdef; // but this isn't |
547 | /// \endcode |
548 | unsigned ; |
549 | |
550 | bool (const TrailingCommentsAlignmentStyle &R) const { |
551 | return Kind == R.Kind && OverEmptyLines == R.OverEmptyLines; |
552 | } |
553 | bool (const TrailingCommentsAlignmentStyle &R) const { |
554 | return !(*this == R); |
555 | } |
556 | }; |
557 | |
558 | /// Control of trailing comments. |
559 | /// |
560 | /// The alignment stops at closing braces after a line break, and only |
561 | /// followed by other closing braces, a (``do-``) ``while``, a lambda call, or |
562 | /// a semicolon. |
563 | /// |
564 | /// \note |
565 | /// As of clang-format 16 this option is not a bool but can be set |
566 | /// to the options. Conventional bool options still can be parsed as before. |
567 | /// \endnote |
568 | /// |
569 | /// \code{.yaml} |
570 | /// # Example of usage: |
571 | /// AlignTrailingComments: |
572 | /// Kind: Always |
573 | /// OverEmptyLines: 2 |
574 | /// \endcode |
575 | /// \version 3.7 |
576 | TrailingCommentsAlignmentStyle ; |
577 | |
578 | /// \brief If a function call or braced initializer list doesn't fit on a |
579 | /// line, allow putting all arguments onto the next line, even if |
580 | /// ``BinPackArguments`` is ``false``. |
581 | /// \code |
582 | /// true: |
583 | /// callFunction( |
584 | /// a, b, c, d); |
585 | /// |
586 | /// false: |
587 | /// callFunction(a, |
588 | /// b, |
589 | /// c, |
590 | /// d); |
591 | /// \endcode |
592 | /// \version 9 |
593 | bool AllowAllArgumentsOnNextLine; |
594 | |
595 | /// This option is **deprecated**. See ``NextLine`` of |
596 | /// ``PackConstructorInitializers``. |
597 | /// \version 9 |
598 | // bool AllowAllConstructorInitializersOnNextLine; |
599 | |
600 | /// If the function declaration doesn't fit on a line, |
601 | /// allow putting all parameters of a function declaration onto |
602 | /// the next line even if ``BinPackParameters`` is ``false``. |
603 | /// \code |
604 | /// true: |
605 | /// void myFunction( |
606 | /// int a, int b, int c, int d, int e); |
607 | /// |
608 | /// false: |
609 | /// void myFunction(int a, |
610 | /// int b, |
611 | /// int c, |
612 | /// int d, |
613 | /// int e); |
614 | /// \endcode |
615 | /// \version 3.3 |
616 | bool AllowAllParametersOfDeclarationOnNextLine; |
617 | |
618 | /// Different ways to break before a noexcept specifier. |
619 | enum BreakBeforeNoexceptSpecifierStyle : int8_t { |
620 | /// No line break allowed. |
621 | /// \code |
622 | /// void foo(int arg1, |
623 | /// double arg2) noexcept; |
624 | /// |
625 | /// void bar(int arg1, double arg2) noexcept( |
626 | /// noexcept(baz(arg1)) && |
627 | /// noexcept(baz(arg2))); |
628 | /// \endcode |
629 | BBNSS_Never, |
630 | /// For a simple ``noexcept`` there is no line break allowed, but when we |
631 | /// have a condition it is. |
632 | /// \code |
633 | /// void foo(int arg1, |
634 | /// double arg2) noexcept; |
635 | /// |
636 | /// void bar(int arg1, double arg2) |
637 | /// noexcept(noexcept(baz(arg1)) && |
638 | /// noexcept(baz(arg2))); |
639 | /// \endcode |
640 | BBNSS_OnlyWithParen, |
641 | /// Line breaks are allowed. But note that because of the associated |
642 | /// penalties ``clang-format`` often prefers not to break before the |
643 | /// ``noexcept``. |
644 | /// \code |
645 | /// void foo(int arg1, |
646 | /// double arg2) noexcept; |
647 | /// |
648 | /// void bar(int arg1, double arg2) |
649 | /// noexcept(noexcept(baz(arg1)) && |
650 | /// noexcept(baz(arg2))); |
651 | /// \endcode |
652 | BBNSS_Always, |
653 | }; |
654 | |
655 | /// Controls if there could be a line break before a ``noexcept`` specifier. |
656 | /// \version 18 |
657 | BreakBeforeNoexceptSpecifierStyle AllowBreakBeforeNoexceptSpecifier; |
658 | |
659 | /// Different styles for merging short blocks containing at most one |
660 | /// statement. |
661 | enum ShortBlockStyle : int8_t { |
662 | /// Never merge blocks into a single line. |
663 | /// \code |
664 | /// while (true) { |
665 | /// } |
666 | /// while (true) { |
667 | /// continue; |
668 | /// } |
669 | /// \endcode |
670 | SBS_Never, |
671 | /// Only merge empty blocks. |
672 | /// \code |
673 | /// while (true) {} |
674 | /// while (true) { |
675 | /// continue; |
676 | /// } |
677 | /// \endcode |
678 | SBS_Empty, |
679 | /// Always merge short blocks into a single line. |
680 | /// \code |
681 | /// while (true) {} |
682 | /// while (true) { continue; } |
683 | /// \endcode |
684 | SBS_Always, |
685 | }; |
686 | |
687 | /// Dependent on the value, ``while (true) { continue; }`` can be put on a |
688 | /// single line. |
689 | /// \version 3.5 |
690 | ShortBlockStyle AllowShortBlocksOnASingleLine; |
691 | |
692 | /// If ``true``, short case labels will be contracted to a single line. |
693 | /// \code |
694 | /// true: false: |
695 | /// switch (a) { vs. switch (a) { |
696 | /// case 1: x = 1; break; case 1: |
697 | /// case 2: return; x = 1; |
698 | /// } break; |
699 | /// case 2: |
700 | /// return; |
701 | /// } |
702 | /// \endcode |
703 | /// \version 3.6 |
704 | bool AllowShortCaseLabelsOnASingleLine; |
705 | |
706 | /// Allow short compound requirement on a single line. |
707 | /// \code |
708 | /// true: |
709 | /// template <typename T> |
710 | /// concept c = requires(T x) { |
711 | /// { x + 1 } -> std::same_as<int>; |
712 | /// }; |
713 | /// |
714 | /// false: |
715 | /// template <typename T> |
716 | /// concept c = requires(T x) { |
717 | /// { |
718 | /// x + 1 |
719 | /// } -> std::same_as<int>; |
720 | /// }; |
721 | /// \endcode |
722 | /// \version 18 |
723 | bool AllowShortCompoundRequirementOnASingleLine; |
724 | |
725 | /// Allow short enums on a single line. |
726 | /// \code |
727 | /// true: |
728 | /// enum { A, B } myEnum; |
729 | /// |
730 | /// false: |
731 | /// enum { |
732 | /// A, |
733 | /// B |
734 | /// } myEnum; |
735 | /// \endcode |
736 | /// \version 11 |
737 | bool AllowShortEnumsOnASingleLine; |
738 | |
739 | /// Different styles for merging short functions containing at most one |
740 | /// statement. |
741 | enum ShortFunctionStyle : int8_t { |
742 | /// Never merge functions into a single line. |
743 | SFS_None, |
744 | /// Only merge functions defined inside a class. Same as "inline", |
745 | /// except it does not implies "empty": i.e. top level empty functions |
746 | /// are not merged either. |
747 | /// \code |
748 | /// class Foo { |
749 | /// void f() { foo(); } |
750 | /// }; |
751 | /// void f() { |
752 | /// foo(); |
753 | /// } |
754 | /// void f() { |
755 | /// } |
756 | /// \endcode |
757 | SFS_InlineOnly, |
758 | /// Only merge empty functions. |
759 | /// \code |
760 | /// void f() {} |
761 | /// void f2() { |
762 | /// bar2(); |
763 | /// } |
764 | /// \endcode |
765 | SFS_Empty, |
766 | /// Only merge functions defined inside a class. Implies "empty". |
767 | /// \code |
768 | /// class Foo { |
769 | /// void f() { foo(); } |
770 | /// }; |
771 | /// void f() { |
772 | /// foo(); |
773 | /// } |
774 | /// void f() {} |
775 | /// \endcode |
776 | SFS_Inline, |
777 | /// Merge all functions fitting on a single line. |
778 | /// \code |
779 | /// class Foo { |
780 | /// void f() { foo(); } |
781 | /// }; |
782 | /// void f() { bar(); } |
783 | /// \endcode |
784 | SFS_All, |
785 | }; |
786 | |
787 | /// Dependent on the value, ``int f() { return 0; }`` can be put on a |
788 | /// single line. |
789 | /// \version 3.5 |
790 | ShortFunctionStyle AllowShortFunctionsOnASingleLine; |
791 | |
792 | /// Different styles for handling short if statements. |
793 | enum ShortIfStyle : int8_t { |
794 | /// Never put short ifs on the same line. |
795 | /// \code |
796 | /// if (a) |
797 | /// return; |
798 | /// |
799 | /// if (b) |
800 | /// return; |
801 | /// else |
802 | /// return; |
803 | /// |
804 | /// if (c) |
805 | /// return; |
806 | /// else { |
807 | /// return; |
808 | /// } |
809 | /// \endcode |
810 | SIS_Never, |
811 | /// Put short ifs on the same line only if there is no else statement. |
812 | /// \code |
813 | /// if (a) return; |
814 | /// |
815 | /// if (b) |
816 | /// return; |
817 | /// else |
818 | /// return; |
819 | /// |
820 | /// if (c) |
821 | /// return; |
822 | /// else { |
823 | /// return; |
824 | /// } |
825 | /// \endcode |
826 | SIS_WithoutElse, |
827 | /// Put short ifs, but not else ifs nor else statements, on the same line. |
828 | /// \code |
829 | /// if (a) return; |
830 | /// |
831 | /// if (b) return; |
832 | /// else if (b) |
833 | /// return; |
834 | /// else |
835 | /// return; |
836 | /// |
837 | /// if (c) return; |
838 | /// else { |
839 | /// return; |
840 | /// } |
841 | /// \endcode |
842 | SIS_OnlyFirstIf, |
843 | /// Always put short ifs, else ifs and else statements on the same |
844 | /// line. |
845 | /// \code |
846 | /// if (a) return; |
847 | /// |
848 | /// if (b) return; |
849 | /// else return; |
850 | /// |
851 | /// if (c) return; |
852 | /// else { |
853 | /// return; |
854 | /// } |
855 | /// \endcode |
856 | SIS_AllIfsAndElse, |
857 | }; |
858 | |
859 | /// Dependent on the value, ``if (a) return;`` can be put on a single line. |
860 | /// \version 3.3 |
861 | ShortIfStyle AllowShortIfStatementsOnASingleLine; |
862 | |
863 | /// Different styles for merging short lambdas containing at most one |
864 | /// statement. |
865 | enum ShortLambdaStyle : int8_t { |
866 | /// Never merge lambdas into a single line. |
867 | SLS_None, |
868 | /// Only merge empty lambdas. |
869 | /// \code |
870 | /// auto lambda = [](int a) {}; |
871 | /// auto lambda2 = [](int a) { |
872 | /// return a; |
873 | /// }; |
874 | /// \endcode |
875 | SLS_Empty, |
876 | /// Merge lambda into a single line if the lambda is argument of a function. |
877 | /// \code |
878 | /// auto lambda = [](int x, int y) { |
879 | /// return x < y; |
880 | /// }; |
881 | /// sort(a.begin(), a.end(), [](int x, int y) { return x < y; }); |
882 | /// \endcode |
883 | SLS_Inline, |
884 | /// Merge all lambdas fitting on a single line. |
885 | /// \code |
886 | /// auto lambda = [](int a) {}; |
887 | /// auto lambda2 = [](int a) { return a; }; |
888 | /// \endcode |
889 | SLS_All, |
890 | }; |
891 | |
892 | /// Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a |
893 | /// single line. |
894 | /// \version 9 |
895 | ShortLambdaStyle AllowShortLambdasOnASingleLine; |
896 | |
897 | /// If ``true``, ``while (true) continue;`` can be put on a single |
898 | /// line. |
899 | /// \version 3.7 |
900 | bool AllowShortLoopsOnASingleLine; |
901 | |
902 | /// Different ways to break after the function definition return type. |
903 | /// This option is **deprecated** and is retained for backwards compatibility. |
904 | enum DefinitionReturnTypeBreakingStyle : int8_t { |
905 | /// Break after return type automatically. |
906 | /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. |
907 | DRTBS_None, |
908 | /// Always break after the return type. |
909 | DRTBS_All, |
910 | /// Always break after the return types of top-level functions. |
911 | DRTBS_TopLevel, |
912 | }; |
913 | |
914 | /// Different ways to break after the function definition or |
915 | /// declaration return type. |
916 | enum ReturnTypeBreakingStyle : int8_t { |
917 | /// This is **deprecated**. See ``Automatic`` below. |
918 | RTBS_None, |
919 | /// Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``. |
920 | /// \code |
921 | /// class A { |
922 | /// int f() { return 0; }; |
923 | /// }; |
924 | /// int f(); |
925 | /// int f() { return 1; } |
926 | /// int |
927 | /// LongName::AnotherLongName(); |
928 | /// \endcode |
929 | RTBS_Automatic, |
930 | /// Same as ``Automatic`` above, except that there is no break after short |
931 | /// return types. |
932 | /// \code |
933 | /// class A { |
934 | /// int f() { return 0; }; |
935 | /// }; |
936 | /// int f(); |
937 | /// int f() { return 1; } |
938 | /// int LongName:: |
939 | /// AnotherLongName(); |
940 | /// \endcode |
941 | RTBS_ExceptShortType, |
942 | /// Always break after the return type. |
943 | /// \code |
944 | /// class A { |
945 | /// int |
946 | /// f() { |
947 | /// return 0; |
948 | /// }; |
949 | /// }; |
950 | /// int |
951 | /// f(); |
952 | /// int |
953 | /// f() { |
954 | /// return 1; |
955 | /// } |
956 | /// int |
957 | /// LongName::AnotherLongName(); |
958 | /// \endcode |
959 | RTBS_All, |
960 | /// Always break after the return types of top-level functions. |
961 | /// \code |
962 | /// class A { |
963 | /// int f() { return 0; }; |
964 | /// }; |
965 | /// int |
966 | /// f(); |
967 | /// int |
968 | /// f() { |
969 | /// return 1; |
970 | /// } |
971 | /// int |
972 | /// LongName::AnotherLongName(); |
973 | /// \endcode |
974 | RTBS_TopLevel, |
975 | /// Always break after the return type of function definitions. |
976 | /// \code |
977 | /// class A { |
978 | /// int |
979 | /// f() { |
980 | /// return 0; |
981 | /// }; |
982 | /// }; |
983 | /// int f(); |
984 | /// int |
985 | /// f() { |
986 | /// return 1; |
987 | /// } |
988 | /// int |
989 | /// LongName::AnotherLongName(); |
990 | /// \endcode |
991 | RTBS_AllDefinitions, |
992 | /// Always break after the return type of top-level definitions. |
993 | /// \code |
994 | /// class A { |
995 | /// int f() { return 0; }; |
996 | /// }; |
997 | /// int f(); |
998 | /// int |
999 | /// f() { |
1000 | /// return 1; |
1001 | /// } |
1002 | /// int |
1003 | /// LongName::AnotherLongName(); |
1004 | /// \endcode |
1005 | RTBS_TopLevelDefinitions, |
1006 | }; |
1007 | |
1008 | /// The function definition return type breaking style to use. This |
1009 | /// option is **deprecated** and is retained for backwards compatibility. |
1010 | /// \version 3.7 |
1011 | DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType; |
1012 | |
1013 | /// This option is renamed to ``BreakAfterReturnType``. |
1014 | /// \version 3.8 |
1015 | /// @deprecated |
1016 | ReturnTypeBreakingStyle AlwaysBreakAfterReturnType; |
1017 | |
1018 | /// If ``true``, always break before multiline string literals. |
1019 | /// |
1020 | /// This flag is mean to make cases where there are multiple multiline strings |
1021 | /// in a file look more consistent. Thus, it will only take effect if wrapping |
1022 | /// the string at that point leads to it being indented |
1023 | /// ``ContinuationIndentWidth`` spaces from the start of the line. |
1024 | /// \code |
1025 | /// true: false: |
1026 | /// aaaa = vs. aaaa = "bbbb" |
1027 | /// "bbbb" "cccc"; |
1028 | /// "cccc"; |
1029 | /// \endcode |
1030 | /// \version 3.4 |
1031 | bool AlwaysBreakBeforeMultilineStrings; |
1032 | |
1033 | /// Different ways to break after the template declaration. |
1034 | enum BreakTemplateDeclarationsStyle : int8_t { |
1035 | /// Do not change the line breaking before the declaration. |
1036 | /// \code |
1037 | /// template <typename T> |
1038 | /// T foo() { |
1039 | /// } |
1040 | /// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, |
1041 | /// int bbbbbbbbbbbbbbbbbbbbb) { |
1042 | /// } |
1043 | /// \endcode |
1044 | BTDS_Leave, |
1045 | /// Do not force break before declaration. |
1046 | /// ``PenaltyBreakTemplateDeclaration`` is taken into account. |
1047 | /// \code |
1048 | /// template <typename T> T foo() { |
1049 | /// } |
1050 | /// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, |
1051 | /// int bbbbbbbbbbbbbbbbbbbbb) { |
1052 | /// } |
1053 | /// \endcode |
1054 | BTDS_No, |
1055 | /// Force break after template declaration only when the following |
1056 | /// declaration spans multiple lines. |
1057 | /// \code |
1058 | /// template <typename T> T foo() { |
1059 | /// } |
1060 | /// template <typename T> |
1061 | /// T foo(int aaaaaaaaaaaaaaaaaaaaa, |
1062 | /// int bbbbbbbbbbbbbbbbbbbbb) { |
1063 | /// } |
1064 | /// \endcode |
1065 | BTDS_MultiLine, |
1066 | /// Always break after template declaration. |
1067 | /// \code |
1068 | /// template <typename T> |
1069 | /// T foo() { |
1070 | /// } |
1071 | /// template <typename T> |
1072 | /// T foo(int aaaaaaaaaaaaaaaaaaaaa, |
1073 | /// int bbbbbbbbbbbbbbbbbbbbb) { |
1074 | /// } |
1075 | /// \endcode |
1076 | BTDS_Yes |
1077 | }; |
1078 | |
1079 | /// This option is renamed to ``BreakTemplateDeclarations``. |
1080 | /// \version 3.4 |
1081 | /// @deprecated |
1082 | // BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations; |
1083 | |
1084 | /// A vector of strings that should be interpreted as attributes/qualifiers |
1085 | /// instead of identifiers. This can be useful for language extensions or |
1086 | /// static analyzer annotations. |
1087 | /// |
1088 | /// For example: |
1089 | /// \code |
1090 | /// x = (char *__capability)&y; |
1091 | /// int function(void) __unused; |
1092 | /// void only_writes_to_buffer(char *__output buffer); |
1093 | /// \endcode |
1094 | /// |
1095 | /// In the .clang-format configuration file, this can be configured like: |
1096 | /// \code{.yaml} |
1097 | /// AttributeMacros: ['__capability', '__output', '__unused'] |
1098 | /// \endcode |
1099 | /// |
1100 | /// \version 12 |
1101 | std::vector<std::string> AttributeMacros; |
1102 | |
1103 | /// If ``false``, a function call's arguments will either be all on the |
1104 | /// same line or will have one line each. |
1105 | /// \code |
1106 | /// true: |
1107 | /// void f() { |
1108 | /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, |
1109 | /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); |
1110 | /// } |
1111 | /// |
1112 | /// false: |
1113 | /// void f() { |
1114 | /// f(aaaaaaaaaaaaaaaaaaaa, |
1115 | /// aaaaaaaaaaaaaaaaaaaa, |
1116 | /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); |
1117 | /// } |
1118 | /// \endcode |
1119 | /// \version 3.7 |
1120 | bool BinPackArguments; |
1121 | |
1122 | /// If ``false``, a function declaration's or function definition's |
1123 | /// parameters will either all be on the same line or will have one line each. |
1124 | /// \code |
1125 | /// true: |
1126 | /// void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa, |
1127 | /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} |
1128 | /// |
1129 | /// false: |
1130 | /// void f(int aaaaaaaaaaaaaaaaaaaa, |
1131 | /// int aaaaaaaaaaaaaaaaaaaa, |
1132 | /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} |
1133 | /// \endcode |
1134 | /// \version 3.7 |
1135 | bool BinPackParameters; |
1136 | |
1137 | /// Styles for adding spacing around ``:`` in bitfield definitions. |
1138 | enum BitFieldColonSpacingStyle : int8_t { |
1139 | /// Add one space on each side of the ``:`` |
1140 | /// \code |
1141 | /// unsigned bf : 2; |
1142 | /// \endcode |
1143 | BFCS_Both, |
1144 | /// Add no space around the ``:`` (except when needed for |
1145 | /// ``AlignConsecutiveBitFields``). |
1146 | /// \code |
1147 | /// unsigned bf:2; |
1148 | /// \endcode |
1149 | BFCS_None, |
1150 | /// Add space before the ``:`` only |
1151 | /// \code |
1152 | /// unsigned bf :2; |
1153 | /// \endcode |
1154 | BFCS_Before, |
1155 | /// Add space after the ``:`` only (space may be added before if |
1156 | /// needed for ``AlignConsecutiveBitFields``). |
1157 | /// \code |
1158 | /// unsigned bf: 2; |
1159 | /// \endcode |
1160 | BFCS_After |
1161 | }; |
1162 | /// The BitFieldColonSpacingStyle to use for bitfields. |
1163 | /// \version 12 |
1164 | BitFieldColonSpacingStyle BitFieldColonSpacing; |
1165 | |
1166 | /// The number of columns to use to indent the contents of braced init lists. |
1167 | /// If unset, ``ContinuationIndentWidth`` is used. |
1168 | /// \code |
1169 | /// AlignAfterOpenBracket: AlwaysBreak |
1170 | /// BracedInitializerIndentWidth: 2 |
1171 | /// |
1172 | /// void f() { |
1173 | /// SomeClass c{ |
1174 | /// "foo", |
1175 | /// "bar", |
1176 | /// "baz", |
1177 | /// }; |
1178 | /// auto s = SomeStruct{ |
1179 | /// .foo = "foo", |
1180 | /// .bar = "bar", |
1181 | /// .baz = "baz", |
1182 | /// }; |
1183 | /// SomeArrayT a[3] = { |
1184 | /// { |
1185 | /// foo, |
1186 | /// bar, |
1187 | /// }, |
1188 | /// { |
1189 | /// foo, |
1190 | /// bar, |
1191 | /// }, |
1192 | /// SomeArrayT{}, |
1193 | /// }; |
1194 | /// } |
1195 | /// \endcode |
1196 | /// \version 17 |
1197 | std::optional<unsigned> BracedInitializerIndentWidth; |
1198 | |
1199 | /// Different ways to wrap braces after control statements. |
1200 | enum BraceWrappingAfterControlStatementStyle : int8_t { |
1201 | /// Never wrap braces after a control statement. |
1202 | /// \code |
1203 | /// if (foo()) { |
1204 | /// } else { |
1205 | /// } |
1206 | /// for (int i = 0; i < 10; ++i) { |
1207 | /// } |
1208 | /// \endcode |
1209 | BWACS_Never, |
1210 | /// Only wrap braces after a multi-line control statement. |
1211 | /// \code |
1212 | /// if (foo && bar && |
1213 | /// baz) |
1214 | /// { |
1215 | /// quux(); |
1216 | /// } |
1217 | /// while (foo || bar) { |
1218 | /// } |
1219 | /// \endcode |
1220 | BWACS_MultiLine, |
1221 | /// Always wrap braces after a control statement. |
1222 | /// \code |
1223 | /// if (foo()) |
1224 | /// { |
1225 | /// } else |
1226 | /// {} |
1227 | /// for (int i = 0; i < 10; ++i) |
1228 | /// {} |
1229 | /// \endcode |
1230 | BWACS_Always |
1231 | }; |
1232 | |
1233 | /// Precise control over the wrapping of braces. |
1234 | /// \code |
1235 | /// # Should be declared this way: |
1236 | /// BreakBeforeBraces: Custom |
1237 | /// BraceWrapping: |
1238 | /// AfterClass: true |
1239 | /// \endcode |
1240 | struct BraceWrappingFlags { |
1241 | /// Wrap case labels. |
1242 | /// \code |
1243 | /// false: true: |
1244 | /// switch (foo) { vs. switch (foo) { |
1245 | /// case 1: { case 1: |
1246 | /// bar(); { |
1247 | /// break; bar(); |
1248 | /// } break; |
1249 | /// default: { } |
1250 | /// plop(); default: |
1251 | /// } { |
1252 | /// } plop(); |
1253 | /// } |
1254 | /// } |
1255 | /// \endcode |
1256 | bool AfterCaseLabel; |
1257 | /// Wrap class definitions. |
1258 | /// \code |
1259 | /// true: |
1260 | /// class foo |
1261 | /// {}; |
1262 | /// |
1263 | /// false: |
1264 | /// class foo {}; |
1265 | /// \endcode |
1266 | bool AfterClass; |
1267 | |
1268 | /// Wrap control statements (``if``/``for``/``while``/``switch``/..). |
1269 | BraceWrappingAfterControlStatementStyle AfterControlStatement; |
1270 | /// Wrap enum definitions. |
1271 | /// \code |
1272 | /// true: |
1273 | /// enum X : int |
1274 | /// { |
1275 | /// B |
1276 | /// }; |
1277 | /// |
1278 | /// false: |
1279 | /// enum X : int { B }; |
1280 | /// \endcode |
1281 | bool AfterEnum; |
1282 | /// Wrap function definitions. |
1283 | /// \code |
1284 | /// true: |
1285 | /// void foo() |
1286 | /// { |
1287 | /// bar(); |
1288 | /// bar2(); |
1289 | /// } |
1290 | /// |
1291 | /// false: |
1292 | /// void foo() { |
1293 | /// bar(); |
1294 | /// bar2(); |
1295 | /// } |
1296 | /// \endcode |
1297 | bool AfterFunction; |
1298 | /// Wrap namespace definitions. |
1299 | /// \code |
1300 | /// true: |
1301 | /// namespace |
1302 | /// { |
1303 | /// int foo(); |
1304 | /// int bar(); |
1305 | /// } |
1306 | /// |
1307 | /// false: |
1308 | /// namespace { |
1309 | /// int foo(); |
1310 | /// int bar(); |
1311 | /// } |
1312 | /// \endcode |
1313 | bool AfterNamespace; |
1314 | /// Wrap ObjC definitions (interfaces, implementations...). |
1315 | /// \note |
1316 | /// @autoreleasepool and @synchronized blocks are wrapped |
1317 | /// according to ``AfterControlStatement`` flag. |
1318 | /// \endnote |
1319 | bool AfterObjCDeclaration; |
1320 | /// Wrap struct definitions. |
1321 | /// \code |
1322 | /// true: |
1323 | /// struct foo |
1324 | /// { |
1325 | /// int x; |
1326 | /// }; |
1327 | /// |
1328 | /// false: |
1329 | /// struct foo { |
1330 | /// int x; |
1331 | /// }; |
1332 | /// \endcode |
1333 | bool AfterStruct; |
1334 | /// Wrap union definitions. |
1335 | /// \code |
1336 | /// true: |
1337 | /// union foo |
1338 | /// { |
1339 | /// int x; |
1340 | /// } |
1341 | /// |
1342 | /// false: |
1343 | /// union foo { |
1344 | /// int x; |
1345 | /// } |
1346 | /// \endcode |
1347 | bool AfterUnion; |
1348 | /// Wrap extern blocks. |
1349 | /// \code |
1350 | /// true: |
1351 | /// extern "C" |
1352 | /// { |
1353 | /// int foo(); |
1354 | /// } |
1355 | /// |
1356 | /// false: |
1357 | /// extern "C" { |
1358 | /// int foo(); |
1359 | /// } |
1360 | /// \endcode |
1361 | bool AfterExternBlock; // Partially superseded by IndentExternBlock |
1362 | /// Wrap before ``catch``. |
1363 | /// \code |
1364 | /// true: |
1365 | /// try { |
1366 | /// foo(); |
1367 | /// } |
1368 | /// catch () { |
1369 | /// } |
1370 | /// |
1371 | /// false: |
1372 | /// try { |
1373 | /// foo(); |
1374 | /// } catch () { |
1375 | /// } |
1376 | /// \endcode |
1377 | bool BeforeCatch; |
1378 | /// Wrap before ``else``. |
1379 | /// \code |
1380 | /// true: |
1381 | /// if (foo()) { |
1382 | /// } |
1383 | /// else { |
1384 | /// } |
1385 | /// |
1386 | /// false: |
1387 | /// if (foo()) { |
1388 | /// } else { |
1389 | /// } |
1390 | /// \endcode |
1391 | bool BeforeElse; |
1392 | /// Wrap lambda block. |
1393 | /// \code |
1394 | /// true: |
1395 | /// connect( |
1396 | /// []() |
1397 | /// { |
1398 | /// foo(); |
1399 | /// bar(); |
1400 | /// }); |
1401 | /// |
1402 | /// false: |
1403 | /// connect([]() { |
1404 | /// foo(); |
1405 | /// bar(); |
1406 | /// }); |
1407 | /// \endcode |
1408 | bool BeforeLambdaBody; |
1409 | /// Wrap before ``while``. |
1410 | /// \code |
1411 | /// true: |
1412 | /// do { |
1413 | /// foo(); |
1414 | /// } |
1415 | /// while (1); |
1416 | /// |
1417 | /// false: |
1418 | /// do { |
1419 | /// foo(); |
1420 | /// } while (1); |
1421 | /// \endcode |
1422 | bool BeforeWhile; |
1423 | /// Indent the wrapped braces themselves. |
1424 | bool IndentBraces; |
1425 | /// If ``false``, empty function body can be put on a single line. |
1426 | /// This option is used only if the opening brace of the function has |
1427 | /// already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is |
1428 | /// set, and the function could/should not be put on a single line (as per |
1429 | /// ``AllowShortFunctionsOnASingleLine`` and constructor formatting |
1430 | /// options). |
1431 | /// \code |
1432 | /// false: true: |
1433 | /// int f() vs. int f() |
1434 | /// {} { |
1435 | /// } |
1436 | /// \endcode |
1437 | /// |
1438 | bool SplitEmptyFunction; |
1439 | /// If ``false``, empty record (e.g. class, struct or union) body |
1440 | /// can be put on a single line. This option is used only if the opening |
1441 | /// brace of the record has already been wrapped, i.e. the ``AfterClass`` |
1442 | /// (for classes) brace wrapping mode is set. |
1443 | /// \code |
1444 | /// false: true: |
1445 | /// class Foo vs. class Foo |
1446 | /// {} { |
1447 | /// } |
1448 | /// \endcode |
1449 | /// |
1450 | bool SplitEmptyRecord; |
1451 | /// If ``false``, empty namespace body can be put on a single line. |
1452 | /// This option is used only if the opening brace of the namespace has |
1453 | /// already been wrapped, i.e. the ``AfterNamespace`` brace wrapping mode is |
1454 | /// set. |
1455 | /// \code |
1456 | /// false: true: |
1457 | /// namespace Foo vs. namespace Foo |
1458 | /// {} { |
1459 | /// } |
1460 | /// \endcode |
1461 | /// |
1462 | bool SplitEmptyNamespace; |
1463 | }; |
1464 | |
1465 | /// Control of individual brace wrapping cases. |
1466 | /// |
1467 | /// If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how |
1468 | /// each individual brace case should be handled. Otherwise, this is ignored. |
1469 | /// \code{.yaml} |
1470 | /// # Example of usage: |
1471 | /// BreakBeforeBraces: Custom |
1472 | /// BraceWrapping: |
1473 | /// AfterEnum: true |
1474 | /// AfterStruct: false |
1475 | /// SplitEmptyFunction: false |
1476 | /// \endcode |
1477 | /// \version 3.8 |
1478 | BraceWrappingFlags BraceWrapping; |
1479 | |
1480 | /// Break between adjacent string literals. |
1481 | /// \code |
1482 | /// true: |
1483 | /// return "Code" |
1484 | /// "\0\52\26\55\55\0" |
1485 | /// "x013" |
1486 | /// "\02\xBA"; |
1487 | /// false: |
1488 | /// return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA"; |
1489 | /// \endcode |
1490 | /// \version 18 |
1491 | bool BreakAdjacentStringLiterals; |
1492 | |
1493 | /// Different ways to break after attributes. |
1494 | enum AttributeBreakingStyle : int8_t { |
1495 | /// Always break after attributes. |
1496 | /// \code |
1497 | /// [[maybe_unused]] |
1498 | /// const int i; |
1499 | /// [[gnu::const]] [[maybe_unused]] |
1500 | /// int j; |
1501 | /// |
1502 | /// [[nodiscard]] |
1503 | /// inline int f(); |
1504 | /// [[gnu::const]] [[nodiscard]] |
1505 | /// int g(); |
1506 | /// |
1507 | /// [[likely]] |
1508 | /// if (a) |
1509 | /// f(); |
1510 | /// else |
1511 | /// g(); |
1512 | /// |
1513 | /// switch (b) { |
1514 | /// [[unlikely]] |
1515 | /// case 1: |
1516 | /// ++b; |
1517 | /// break; |
1518 | /// [[likely]] |
1519 | /// default: |
1520 | /// return; |
1521 | /// } |
1522 | /// \endcode |
1523 | ABS_Always, |
1524 | /// Leave the line breaking after attributes as is. |
1525 | /// \code |
1526 | /// [[maybe_unused]] const int i; |
1527 | /// [[gnu::const]] [[maybe_unused]] |
1528 | /// int j; |
1529 | /// |
1530 | /// [[nodiscard]] inline int f(); |
1531 | /// [[gnu::const]] [[nodiscard]] |
1532 | /// int g(); |
1533 | /// |
1534 | /// [[likely]] if (a) |
1535 | /// f(); |
1536 | /// else |
1537 | /// g(); |
1538 | /// |
1539 | /// switch (b) { |
1540 | /// [[unlikely]] case 1: |
1541 | /// ++b; |
1542 | /// break; |
1543 | /// [[likely]] |
1544 | /// default: |
1545 | /// return; |
1546 | /// } |
1547 | /// \endcode |
1548 | ABS_Leave, |
1549 | /// Never break after attributes. |
1550 | /// \code |
1551 | /// [[maybe_unused]] const int i; |
1552 | /// [[gnu::const]] [[maybe_unused]] int j; |
1553 | /// |
1554 | /// [[nodiscard]] inline int f(); |
1555 | /// [[gnu::const]] [[nodiscard]] int g(); |
1556 | /// |
1557 | /// [[likely]] if (a) |
1558 | /// f(); |
1559 | /// else |
1560 | /// g(); |
1561 | /// |
1562 | /// switch (b) { |
1563 | /// [[unlikely]] case 1: |
1564 | /// ++b; |
1565 | /// break; |
1566 | /// [[likely]] default: |
1567 | /// return; |
1568 | /// } |
1569 | /// \endcode |
1570 | ABS_Never, |
1571 | }; |
1572 | |
1573 | /// Break after a group of C++11 attributes before variable or function |
1574 | /// (including constructor/destructor) declaration/definition names or before |
1575 | /// control statements, i.e. ``if``, ``switch`` (including ``case`` and |
1576 | /// ``default`` labels), ``for``, and ``while`` statements. |
1577 | /// \version 16 |
1578 | AttributeBreakingStyle BreakAfterAttributes; |
1579 | |
1580 | /// The function declaration return type breaking style to use. |
1581 | /// \version 19 |
1582 | // ReturnTypeBreakingStyle BreakAfterReturnType; |
1583 | |
1584 | /// If ``true``, clang-format will always break after a Json array ``[`` |
1585 | /// otherwise it will scan until the closing ``]`` to determine if it should |
1586 | /// add newlines between elements (prettier compatible). |
1587 | /// |
1588 | /// \note |
1589 | /// This is currently only for formatting JSON. |
1590 | /// \endnote |
1591 | /// \code |
1592 | /// true: false: |
1593 | /// [ vs. [1, 2, 3, 4] |
1594 | /// 1, |
1595 | /// 2, |
1596 | /// 3, |
1597 | /// 4 |
1598 | /// ] |
1599 | /// \endcode |
1600 | /// \version 16 |
1601 | bool BreakArrays; |
1602 | |
1603 | /// The style of wrapping parameters on the same line (bin-packed) or |
1604 | /// on one line each. |
1605 | enum BinPackStyle : int8_t { |
1606 | /// Automatically determine parameter bin-packing behavior. |
1607 | BPS_Auto, |
1608 | /// Always bin-pack parameters. |
1609 | BPS_Always, |
1610 | /// Never bin-pack parameters. |
1611 | BPS_Never, |
1612 | }; |
1613 | |
1614 | /// The style of breaking before or after binary operators. |
1615 | enum BinaryOperatorStyle : int8_t { |
1616 | /// Break after operators. |
1617 | /// \code |
1618 | /// LooooooooooongType loooooooooooooooooooooongVariable = |
1619 | /// someLooooooooooooooooongFunction(); |
1620 | /// |
1621 | /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + |
1622 | /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == |
1623 | /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && |
1624 | /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > |
1625 | /// ccccccccccccccccccccccccccccccccccccccccc; |
1626 | /// \endcode |
1627 | BOS_None, |
1628 | /// Break before operators that aren't assignments. |
1629 | /// \code |
1630 | /// LooooooooooongType loooooooooooooooooooooongVariable = |
1631 | /// someLooooooooooooooooongFunction(); |
1632 | /// |
1633 | /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
1634 | /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
1635 | /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
1636 | /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
1637 | /// > ccccccccccccccccccccccccccccccccccccccccc; |
1638 | /// \endcode |
1639 | BOS_NonAssignment, |
1640 | /// Break before operators. |
1641 | /// \code |
1642 | /// LooooooooooongType loooooooooooooooooooooongVariable |
1643 | /// = someLooooooooooooooooongFunction(); |
1644 | /// |
1645 | /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
1646 | /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
1647 | /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
1648 | /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
1649 | /// > ccccccccccccccccccccccccccccccccccccccccc; |
1650 | /// \endcode |
1651 | BOS_All, |
1652 | }; |
1653 | |
1654 | /// The way to wrap binary operators. |
1655 | /// \version 3.6 |
1656 | BinaryOperatorStyle BreakBeforeBinaryOperators; |
1657 | |
1658 | /// Different ways to attach braces to their surrounding context. |
1659 | enum BraceBreakingStyle : int8_t { |
1660 | /// Always attach braces to surrounding context. |
1661 | /// \code |
1662 | /// namespace N { |
1663 | /// enum E { |
1664 | /// E1, |
1665 | /// E2, |
1666 | /// }; |
1667 | /// |
1668 | /// class C { |
1669 | /// public: |
1670 | /// C(); |
1671 | /// }; |
1672 | /// |
1673 | /// bool baz(int i) { |
1674 | /// try { |
1675 | /// do { |
1676 | /// switch (i) { |
1677 | /// case 1: { |
1678 | /// foobar(); |
1679 | /// break; |
1680 | /// } |
1681 | /// default: { |
1682 | /// break; |
1683 | /// } |
1684 | /// } |
1685 | /// } while (--i); |
1686 | /// return true; |
1687 | /// } catch (...) { |
1688 | /// handleError(); |
1689 | /// return false; |
1690 | /// } |
1691 | /// } |
1692 | /// |
1693 | /// void foo(bool b) { |
1694 | /// if (b) { |
1695 | /// baz(2); |
1696 | /// } else { |
1697 | /// baz(5); |
1698 | /// } |
1699 | /// } |
1700 | /// |
1701 | /// void bar() { foo(true); } |
1702 | /// } // namespace N |
1703 | /// \endcode |
1704 | BS_Attach, |
1705 | /// Like ``Attach``, but break before braces on function, namespace and |
1706 | /// class definitions. |
1707 | /// \code |
1708 | /// namespace N |
1709 | /// { |
1710 | /// enum E { |
1711 | /// E1, |
1712 | /// E2, |
1713 | /// }; |
1714 | /// |
1715 | /// class C |
1716 | /// { |
1717 | /// public: |
1718 | /// C(); |
1719 | /// }; |
1720 | /// |
1721 | /// bool baz(int i) |
1722 | /// { |
1723 | /// try { |
1724 | /// do { |
1725 | /// switch (i) { |
1726 | /// case 1: { |
1727 | /// foobar(); |
1728 | /// break; |
1729 | /// } |
1730 | /// default: { |
1731 | /// break; |
1732 | /// } |
1733 | /// } |
1734 | /// } while (--i); |
1735 | /// return true; |
1736 | /// } catch (...) { |
1737 | /// handleError(); |
1738 | /// return false; |
1739 | /// } |
1740 | /// } |
1741 | /// |
1742 | /// void foo(bool b) |
1743 | /// { |
1744 | /// if (b) { |
1745 | /// baz(2); |
1746 | /// } else { |
1747 | /// baz(5); |
1748 | /// } |
1749 | /// } |
1750 | /// |
1751 | /// void bar() { foo(true); } |
1752 | /// } // namespace N |
1753 | /// \endcode |
1754 | BS_Linux, |
1755 | /// Like ``Attach``, but break before braces on enum, function, and record |
1756 | /// definitions. |
1757 | /// \code |
1758 | /// namespace N { |
1759 | /// enum E |
1760 | /// { |
1761 | /// E1, |
1762 | /// E2, |
1763 | /// }; |
1764 | /// |
1765 | /// class C |
1766 | /// { |
1767 | /// public: |
1768 | /// C(); |
1769 | /// }; |
1770 | /// |
1771 | /// bool baz(int i) |
1772 | /// { |
1773 | /// try { |
1774 | /// do { |
1775 | /// switch (i) { |
1776 | /// case 1: { |
1777 | /// foobar(); |
1778 | /// break; |
1779 | /// } |
1780 | /// default: { |
1781 | /// break; |
1782 | /// } |
1783 | /// } |
1784 | /// } while (--i); |
1785 | /// return true; |
1786 | /// } catch (...) { |
1787 | /// handleError(); |
1788 | /// return false; |
1789 | /// } |
1790 | /// } |
1791 | /// |
1792 | /// void foo(bool b) |
1793 | /// { |
1794 | /// if (b) { |
1795 | /// baz(2); |
1796 | /// } else { |
1797 | /// baz(5); |
1798 | /// } |
1799 | /// } |
1800 | /// |
1801 | /// void bar() { foo(true); } |
1802 | /// } // namespace N |
1803 | /// \endcode |
1804 | BS_Mozilla, |
1805 | /// Like ``Attach``, but break before function definitions, ``catch``, and |
1806 | /// ``else``. |
1807 | /// \code |
1808 | /// namespace N { |
1809 | /// enum E { |
1810 | /// E1, |
1811 | /// E2, |
1812 | /// }; |
1813 | /// |
1814 | /// class C { |
1815 | /// public: |
1816 | /// C(); |
1817 | /// }; |
1818 | /// |
1819 | /// bool baz(int i) |
1820 | /// { |
1821 | /// try { |
1822 | /// do { |
1823 | /// switch (i) { |
1824 | /// case 1: { |
1825 | /// foobar(); |
1826 | /// break; |
1827 | /// } |
1828 | /// default: { |
1829 | /// break; |
1830 | /// } |
1831 | /// } |
1832 | /// } while (--i); |
1833 | /// return true; |
1834 | /// } |
1835 | /// catch (...) { |
1836 | /// handleError(); |
1837 | /// return false; |
1838 | /// } |
1839 | /// } |
1840 | /// |
1841 | /// void foo(bool b) |
1842 | /// { |
1843 | /// if (b) { |
1844 | /// baz(2); |
1845 | /// } |
1846 | /// else { |
1847 | /// baz(5); |
1848 | /// } |
1849 | /// } |
1850 | /// |
1851 | /// void bar() { foo(true); } |
1852 | /// } // namespace N |
1853 | /// \endcode |
1854 | BS_Stroustrup, |
1855 | /// Always break before braces. |
1856 | /// \code |
1857 | /// namespace N |
1858 | /// { |
1859 | /// enum E |
1860 | /// { |
1861 | /// E1, |
1862 | /// E2, |
1863 | /// }; |
1864 | /// |
1865 | /// class C |
1866 | /// { |
1867 | /// public: |
1868 | /// C(); |
1869 | /// }; |
1870 | /// |
1871 | /// bool baz(int i) |
1872 | /// { |
1873 | /// try |
1874 | /// { |
1875 | /// do |
1876 | /// { |
1877 | /// switch (i) |
1878 | /// { |
1879 | /// case 1: |
1880 | /// { |
1881 | /// foobar(); |
1882 | /// break; |
1883 | /// } |
1884 | /// default: |
1885 | /// { |
1886 | /// break; |
1887 | /// } |
1888 | /// } |
1889 | /// } while (--i); |
1890 | /// return true; |
1891 | /// } |
1892 | /// catch (...) |
1893 | /// { |
1894 | /// handleError(); |
1895 | /// return false; |
1896 | /// } |
1897 | /// } |
1898 | /// |
1899 | /// void foo(bool b) |
1900 | /// { |
1901 | /// if (b) |
1902 | /// { |
1903 | /// baz(2); |
1904 | /// } |
1905 | /// else |
1906 | /// { |
1907 | /// baz(5); |
1908 | /// } |
1909 | /// } |
1910 | /// |
1911 | /// void bar() { foo(true); } |
1912 | /// } // namespace N |
1913 | /// \endcode |
1914 | BS_Allman, |
1915 | /// Like ``Allman`` but always indent braces and line up code with braces. |
1916 | /// \code |
1917 | /// namespace N |
1918 | /// { |
1919 | /// enum E |
1920 | /// { |
1921 | /// E1, |
1922 | /// E2, |
1923 | /// }; |
1924 | /// |
1925 | /// class C |
1926 | /// { |
1927 | /// public: |
1928 | /// C(); |
1929 | /// }; |
1930 | /// |
1931 | /// bool baz(int i) |
1932 | /// { |
1933 | /// try |
1934 | /// { |
1935 | /// do |
1936 | /// { |
1937 | /// switch (i) |
1938 | /// { |
1939 | /// case 1: |
1940 | /// { |
1941 | /// foobar(); |
1942 | /// break; |
1943 | /// } |
1944 | /// default: |
1945 | /// { |
1946 | /// break; |
1947 | /// } |
1948 | /// } |
1949 | /// } while (--i); |
1950 | /// return true; |
1951 | /// } |
1952 | /// catch (...) |
1953 | /// { |
1954 | /// handleError(); |
1955 | /// return false; |
1956 | /// } |
1957 | /// } |
1958 | /// |
1959 | /// void foo(bool b) |
1960 | /// { |
1961 | /// if (b) |
1962 | /// { |
1963 | /// baz(2); |
1964 | /// } |
1965 | /// else |
1966 | /// { |
1967 | /// baz(5); |
1968 | /// } |
1969 | /// } |
1970 | /// |
1971 | /// void bar() { foo(true); } |
1972 | /// } // namespace N |
1973 | /// \endcode |
1974 | BS_Whitesmiths, |
1975 | /// Always break before braces and add an extra level of indentation to |
1976 | /// braces of control statements, not to those of class, function |
1977 | /// or other definitions. |
1978 | /// \code |
1979 | /// namespace N |
1980 | /// { |
1981 | /// enum E |
1982 | /// { |
1983 | /// E1, |
1984 | /// E2, |
1985 | /// }; |
1986 | /// |
1987 | /// class C |
1988 | /// { |
1989 | /// public: |
1990 | /// C(); |
1991 | /// }; |
1992 | /// |
1993 | /// bool baz(int i) |
1994 | /// { |
1995 | /// try |
1996 | /// { |
1997 | /// do |
1998 | /// { |
1999 | /// switch (i) |
2000 | /// { |
2001 | /// case 1: |
2002 | /// { |
2003 | /// foobar(); |
2004 | /// break; |
2005 | /// } |
2006 | /// default: |
2007 | /// { |
2008 | /// break; |
2009 | /// } |
2010 | /// } |
2011 | /// } |
2012 | /// while (--i); |
2013 | /// return true; |
2014 | /// } |
2015 | /// catch (...) |
2016 | /// { |
2017 | /// handleError(); |
2018 | /// return false; |
2019 | /// } |
2020 | /// } |
2021 | /// |
2022 | /// void foo(bool b) |
2023 | /// { |
2024 | /// if (b) |
2025 | /// { |
2026 | /// baz(2); |
2027 | /// } |
2028 | /// else |
2029 | /// { |
2030 | /// baz(5); |
2031 | /// } |
2032 | /// } |
2033 | /// |
2034 | /// void bar() { foo(true); } |
2035 | /// } // namespace N |
2036 | /// \endcode |
2037 | BS_GNU, |
2038 | /// Like ``Attach``, but break before functions. |
2039 | /// \code |
2040 | /// namespace N { |
2041 | /// enum E { |
2042 | /// E1, |
2043 | /// E2, |
2044 | /// }; |
2045 | /// |
2046 | /// class C { |
2047 | /// public: |
2048 | /// C(); |
2049 | /// }; |
2050 | /// |
2051 | /// bool baz(int i) |
2052 | /// { |
2053 | /// try { |
2054 | /// do { |
2055 | /// switch (i) { |
2056 | /// case 1: { |
2057 | /// foobar(); |
2058 | /// break; |
2059 | /// } |
2060 | /// default: { |
2061 | /// break; |
2062 | /// } |
2063 | /// } |
2064 | /// } while (--i); |
2065 | /// return true; |
2066 | /// } catch (...) { |
2067 | /// handleError(); |
2068 | /// return false; |
2069 | /// } |
2070 | /// } |
2071 | /// |
2072 | /// void foo(bool b) |
2073 | /// { |
2074 | /// if (b) { |
2075 | /// baz(2); |
2076 | /// } else { |
2077 | /// baz(5); |
2078 | /// } |
2079 | /// } |
2080 | /// |
2081 | /// void bar() { foo(true); } |
2082 | /// } // namespace N |
2083 | /// \endcode |
2084 | BS_WebKit, |
2085 | /// Configure each individual brace in ``BraceWrapping``. |
2086 | BS_Custom |
2087 | }; |
2088 | |
2089 | /// The brace breaking style to use. |
2090 | /// \version 3.7 |
2091 | BraceBreakingStyle BreakBeforeBraces; |
2092 | |
2093 | /// Different ways to break before concept declarations. |
2094 | enum BreakBeforeConceptDeclarationsStyle : int8_t { |
2095 | /// Keep the template declaration line together with ``concept``. |
2096 | /// \code |
2097 | /// template <typename T> concept C = ...; |
2098 | /// \endcode |
2099 | BBCDS_Never, |
2100 | /// Breaking between template declaration and ``concept`` is allowed. The |
2101 | /// actual behavior depends on the content and line breaking rules and |
2102 | /// penalties. |
2103 | BBCDS_Allowed, |
2104 | /// Always break before ``concept``, putting it in the line after the |
2105 | /// template declaration. |
2106 | /// \code |
2107 | /// template <typename T> |
2108 | /// concept C = ...; |
2109 | /// \endcode |
2110 | BBCDS_Always, |
2111 | }; |
2112 | |
2113 | /// The concept declaration style to use. |
2114 | /// \version 12 |
2115 | BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations; |
2116 | |
2117 | /// Different ways to break ASM parameters. |
2118 | enum BreakBeforeInlineASMColonStyle : int8_t { |
2119 | /// No break before inline ASM colon. |
2120 | /// \code |
2121 | /// asm volatile("string", : : val); |
2122 | /// \endcode |
2123 | BBIAS_Never, |
2124 | /// Break before inline ASM colon if the line length is longer than column |
2125 | /// limit. |
2126 | /// \code |
2127 | /// asm volatile("string", : : val); |
2128 | /// asm("cmoveq %1, %2, %[result]" |
2129 | /// : [result] "=r"(result) |
2130 | /// : "r"(test), "r"(new), "[result]"(old)); |
2131 | /// \endcode |
2132 | BBIAS_OnlyMultiline, |
2133 | /// Always break before inline ASM colon. |
2134 | /// \code |
2135 | /// asm volatile("string", |
2136 | /// : |
2137 | /// : val); |
2138 | /// \endcode |
2139 | BBIAS_Always, |
2140 | }; |
2141 | |
2142 | /// The inline ASM colon style to use. |
2143 | /// \version 16 |
2144 | BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon; |
2145 | |
2146 | /// If ``true``, ternary operators will be placed after line breaks. |
2147 | /// \code |
2148 | /// true: |
2149 | /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription |
2150 | /// ? firstValue |
2151 | /// : SecondValueVeryVeryVeryVeryLong; |
2152 | /// |
2153 | /// false: |
2154 | /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ? |
2155 | /// firstValue : |
2156 | /// SecondValueVeryVeryVeryVeryLong; |
2157 | /// \endcode |
2158 | /// \version 3.7 |
2159 | bool BreakBeforeTernaryOperators; |
2160 | |
2161 | /// Different ways to break initializers. |
2162 | enum : int8_t { |
2163 | /// Break constructor initializers before the colon and after the commas. |
2164 | /// \code |
2165 | /// Constructor() |
2166 | /// : initializer1(), |
2167 | /// initializer2() |
2168 | /// \endcode |
2169 | BCIS_BeforeColon, |
2170 | /// Break constructor initializers before the colon and commas, and align |
2171 | /// the commas with the colon. |
2172 | /// \code |
2173 | /// Constructor() |
2174 | /// : initializer1() |
2175 | /// , initializer2() |
2176 | /// \endcode |
2177 | BCIS_BeforeComma, |
2178 | /// Break constructor initializers after the colon and commas. |
2179 | /// \code |
2180 | /// Constructor() : |
2181 | /// initializer1(), |
2182 | /// initializer2() |
2183 | /// \endcode |
2184 | BCIS_AfterColon |
2185 | }; |
2186 | |
2187 | /// The break constructor initializers style to use. |
2188 | /// \version 5 |
2189 | BreakConstructorInitializersStyle BreakConstructorInitializers; |
2190 | |
2191 | /// Break after each annotation on a field in Java files. |
2192 | /// \code{.java} |
2193 | /// true: false: |
2194 | /// @Partial vs. @Partial @Mock DataLoad loader; |
2195 | /// @Mock |
2196 | /// DataLoad loader; |
2197 | /// \endcode |
2198 | /// \version 3.8 |
2199 | bool BreakAfterJavaFieldAnnotations; |
2200 | |
2201 | /// Allow breaking string literals when formatting. |
2202 | /// |
2203 | /// In C, C++, and Objective-C: |
2204 | /// \code |
2205 | /// true: |
2206 | /// const char* x = "veryVeryVeryVeryVeryVe" |
2207 | /// "ryVeryVeryVeryVeryVery" |
2208 | /// "VeryLongString"; |
2209 | /// |
2210 | /// false: |
2211 | /// const char* x = |
2212 | /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; |
2213 | /// \endcode |
2214 | /// |
2215 | /// In C# and Java: |
2216 | /// \code |
2217 | /// true: |
2218 | /// string x = "veryVeryVeryVeryVeryVe" + |
2219 | /// "ryVeryVeryVeryVeryVery" + |
2220 | /// "VeryLongString"; |
2221 | /// |
2222 | /// false: |
2223 | /// string x = |
2224 | /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; |
2225 | /// \endcode |
2226 | /// |
2227 | /// C# interpolated strings are not broken. |
2228 | /// |
2229 | /// In Verilog: |
2230 | /// \code |
2231 | /// true: |
2232 | /// string x = {"veryVeryVeryVeryVeryVe", |
2233 | /// "ryVeryVeryVeryVeryVery", |
2234 | /// "VeryLongString"}; |
2235 | /// |
2236 | /// false: |
2237 | /// string x = |
2238 | /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; |
2239 | /// \endcode |
2240 | /// |
2241 | /// \version 3.9 |
2242 | bool BreakStringLiterals; |
2243 | |
2244 | /// The column limit. |
2245 | /// |
2246 | /// A column limit of ``0`` means that there is no column limit. In this case, |
2247 | /// clang-format will respect the input's line breaking decisions within |
2248 | /// statements unless they contradict other rules. |
2249 | /// \version 3.7 |
2250 | unsigned ColumnLimit; |
2251 | |
2252 | /// A regular expression that describes comments with special meaning, |
2253 | /// which should not be split into lines or otherwise changed. |
2254 | /// \code |
2255 | /// // CommentPragmas: '^ FOOBAR pragma:' |
2256 | /// // Will leave the following line unaffected |
2257 | /// #include <vector> // FOOBAR pragma: keep |
2258 | /// \endcode |
2259 | /// \version 3.7 |
2260 | std::string ; |
2261 | |
2262 | /// Different ways to break inheritance list. |
2263 | enum BreakInheritanceListStyle : int8_t { |
2264 | /// Break inheritance list before the colon and after the commas. |
2265 | /// \code |
2266 | /// class Foo |
2267 | /// : Base1, |
2268 | /// Base2 |
2269 | /// {}; |
2270 | /// \endcode |
2271 | BILS_BeforeColon, |
2272 | /// Break inheritance list before the colon and commas, and align |
2273 | /// the commas with the colon. |
2274 | /// \code |
2275 | /// class Foo |
2276 | /// : Base1 |
2277 | /// , Base2 |
2278 | /// {}; |
2279 | /// \endcode |
2280 | BILS_BeforeComma, |
2281 | /// Break inheritance list after the colon and commas. |
2282 | /// \code |
2283 | /// class Foo : |
2284 | /// Base1, |
2285 | /// Base2 |
2286 | /// {}; |
2287 | /// \endcode |
2288 | BILS_AfterColon, |
2289 | /// Break inheritance list only after the commas. |
2290 | /// \code |
2291 | /// class Foo : Base1, |
2292 | /// Base2 |
2293 | /// {}; |
2294 | /// \endcode |
2295 | BILS_AfterComma, |
2296 | }; |
2297 | |
2298 | /// The inheritance list style to use. |
2299 | /// \version 7 |
2300 | BreakInheritanceListStyle BreakInheritanceList; |
2301 | |
2302 | /// The template declaration breaking style to use. |
2303 | /// \version 19 |
2304 | BreakTemplateDeclarationsStyle BreakTemplateDeclarations; |
2305 | |
2306 | /// If ``true``, consecutive namespace declarations will be on the same |
2307 | /// line. If ``false``, each namespace is declared on a new line. |
2308 | /// \code |
2309 | /// true: |
2310 | /// namespace Foo { namespace Bar { |
2311 | /// }} |
2312 | /// |
2313 | /// false: |
2314 | /// namespace Foo { |
2315 | /// namespace Bar { |
2316 | /// } |
2317 | /// } |
2318 | /// \endcode |
2319 | /// |
2320 | /// If it does not fit on a single line, the overflowing namespaces get |
2321 | /// wrapped: |
2322 | /// \code |
2323 | /// namespace Foo { namespace Bar { |
2324 | /// namespace Extra { |
2325 | /// }}} |
2326 | /// \endcode |
2327 | /// \version 5 |
2328 | bool CompactNamespaces; |
2329 | |
2330 | /// This option is **deprecated**. See ``CurrentLine`` of |
2331 | /// ``PackConstructorInitializers``. |
2332 | /// \version 3.7 |
2333 | // bool ConstructorInitializerAllOnOneLineOrOnePerLine; |
2334 | |
2335 | /// The number of characters to use for indentation of constructor |
2336 | /// initializer lists as well as inheritance lists. |
2337 | /// \version 3.7 |
2338 | unsigned ConstructorInitializerIndentWidth; |
2339 | |
2340 | /// Indent width for line continuations. |
2341 | /// \code |
2342 | /// ContinuationIndentWidth: 2 |
2343 | /// |
2344 | /// int i = // VeryVeryVeryVeryVeryLongComment |
2345 | /// longFunction( // Again a long comment |
2346 | /// arg); |
2347 | /// \endcode |
2348 | /// \version 3.7 |
2349 | unsigned ContinuationIndentWidth; |
2350 | |
2351 | /// If ``true``, format braced lists as best suited for C++11 braced |
2352 | /// lists. |
2353 | /// |
2354 | /// Important differences: |
2355 | /// - No spaces inside the braced list. |
2356 | /// - No line break before the closing brace. |
2357 | /// - Indentation with the continuation indent, not with the block indent. |
2358 | /// |
2359 | /// Fundamentally, C++11 braced lists are formatted exactly like function |
2360 | /// calls would be formatted in their place. If the braced list follows a name |
2361 | /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were |
2362 | /// the parentheses of a function call with that name. If there is no name, |
2363 | /// a zero-length name is assumed. |
2364 | /// \code |
2365 | /// true: false: |
2366 | /// vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 }; |
2367 | /// vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} }; |
2368 | /// f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]); |
2369 | /// new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 }; |
2370 | /// \endcode |
2371 | /// \version 3.4 |
2372 | bool Cpp11BracedListStyle; |
2373 | |
2374 | /// This option is **deprecated**. See ``DeriveLF`` and ``DeriveCRLF`` of |
2375 | /// ``LineEnding``. |
2376 | /// \version 10 |
2377 | // bool DeriveLineEnding; |
2378 | |
2379 | /// If ``true``, analyze the formatted file for the most common |
2380 | /// alignment of ``&`` and ``*``. |
2381 | /// Pointer and reference alignment styles are going to be updated according |
2382 | /// to the preferences found in the file. |
2383 | /// ``PointerAlignment`` is then used only as fallback. |
2384 | /// \version 3.7 |
2385 | bool DerivePointerAlignment; |
2386 | |
2387 | /// Disables formatting completely. |
2388 | /// \version 3.7 |
2389 | bool DisableFormat; |
2390 | |
2391 | /// Different styles for empty line after access modifiers. |
2392 | /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of |
2393 | /// empty lines between two access modifiers. |
2394 | enum EmptyLineAfterAccessModifierStyle : int8_t { |
2395 | /// Remove all empty lines after access modifiers. |
2396 | /// \code |
2397 | /// struct foo { |
2398 | /// private: |
2399 | /// int i; |
2400 | /// protected: |
2401 | /// int j; |
2402 | /// /* comment */ |
2403 | /// public: |
2404 | /// foo() {} |
2405 | /// private: |
2406 | /// protected: |
2407 | /// }; |
2408 | /// \endcode |
2409 | ELAAMS_Never, |
2410 | /// Keep existing empty lines after access modifiers. |
2411 | /// MaxEmptyLinesToKeep is applied instead. |
2412 | ELAAMS_Leave, |
2413 | /// Always add empty line after access modifiers if there are none. |
2414 | /// MaxEmptyLinesToKeep is applied also. |
2415 | /// \code |
2416 | /// struct foo { |
2417 | /// private: |
2418 | /// |
2419 | /// int i; |
2420 | /// protected: |
2421 | /// |
2422 | /// int j; |
2423 | /// /* comment */ |
2424 | /// public: |
2425 | /// |
2426 | /// foo() {} |
2427 | /// private: |
2428 | /// |
2429 | /// protected: |
2430 | /// |
2431 | /// }; |
2432 | /// \endcode |
2433 | ELAAMS_Always, |
2434 | }; |
2435 | |
2436 | /// Defines when to put an empty line after access modifiers. |
2437 | /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of |
2438 | /// empty lines between two access modifiers. |
2439 | /// \version 13 |
2440 | EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier; |
2441 | |
2442 | /// Different styles for empty line before access modifiers. |
2443 | enum EmptyLineBeforeAccessModifierStyle : int8_t { |
2444 | /// Remove all empty lines before access modifiers. |
2445 | /// \code |
2446 | /// struct foo { |
2447 | /// private: |
2448 | /// int i; |
2449 | /// protected: |
2450 | /// int j; |
2451 | /// /* comment */ |
2452 | /// public: |
2453 | /// foo() {} |
2454 | /// private: |
2455 | /// protected: |
2456 | /// }; |
2457 | /// \endcode |
2458 | ELBAMS_Never, |
2459 | /// Keep existing empty lines before access modifiers. |
2460 | ELBAMS_Leave, |
2461 | /// Add empty line only when access modifier starts a new logical block. |
2462 | /// Logical block is a group of one or more member fields or functions. |
2463 | /// \code |
2464 | /// struct foo { |
2465 | /// private: |
2466 | /// int i; |
2467 | /// |
2468 | /// protected: |
2469 | /// int j; |
2470 | /// /* comment */ |
2471 | /// public: |
2472 | /// foo() {} |
2473 | /// |
2474 | /// private: |
2475 | /// protected: |
2476 | /// }; |
2477 | /// \endcode |
2478 | ELBAMS_LogicalBlock, |
2479 | /// Always add empty line before access modifiers unless access modifier |
2480 | /// is at the start of struct or class definition. |
2481 | /// \code |
2482 | /// struct foo { |
2483 | /// private: |
2484 | /// int i; |
2485 | /// |
2486 | /// protected: |
2487 | /// int j; |
2488 | /// /* comment */ |
2489 | /// |
2490 | /// public: |
2491 | /// foo() {} |
2492 | /// |
2493 | /// private: |
2494 | /// |
2495 | /// protected: |
2496 | /// }; |
2497 | /// \endcode |
2498 | ELBAMS_Always, |
2499 | }; |
2500 | |
2501 | /// Defines in which cases to put empty line before access modifiers. |
2502 | /// \version 12 |
2503 | EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier; |
2504 | |
2505 | /// If ``true``, clang-format detects whether function calls and |
2506 | /// definitions are formatted with one parameter per line. |
2507 | /// |
2508 | /// Each call can be bin-packed, one-per-line or inconclusive. If it is |
2509 | /// inconclusive, e.g. completely on one line, but a decision needs to be |
2510 | /// made, clang-format analyzes whether there are other bin-packed cases in |
2511 | /// the input file and act accordingly. |
2512 | /// |
2513 | /// \note |
2514 | /// This is an experimental flag, that might go away or be renamed. Do |
2515 | /// not use this in config files, etc. Use at your own risk. |
2516 | /// \endnote |
2517 | /// \version 3.7 |
2518 | bool ExperimentalAutoDetectBinPacking; |
2519 | |
2520 | /// If ``true``, clang-format adds missing namespace end comments for |
2521 | /// namespaces and fixes invalid existing ones. This doesn't affect short |
2522 | /// namespaces, which are controlled by ``ShortNamespaceLines``. |
2523 | /// \code |
2524 | /// true: false: |
2525 | /// namespace longNamespace { vs. namespace longNamespace { |
2526 | /// void foo(); void foo(); |
2527 | /// void bar(); void bar(); |
2528 | /// } // namespace a } |
2529 | /// namespace shortNamespace { namespace shortNamespace { |
2530 | /// void baz(); void baz(); |
2531 | /// } } |
2532 | /// \endcode |
2533 | /// \version 5 |
2534 | bool ; |
2535 | |
2536 | /// A vector of macros that should be interpreted as foreach loops |
2537 | /// instead of as function calls. |
2538 | /// |
2539 | /// These are expected to be macros of the form: |
2540 | /// \code |
2541 | /// FOREACH(<variable-declaration>, ...) |
2542 | /// <loop-body> |
2543 | /// \endcode |
2544 | /// |
2545 | /// In the .clang-format configuration file, this can be configured like: |
2546 | /// \code{.yaml} |
2547 | /// ForEachMacros: ['RANGES_FOR', 'FOREACH'] |
2548 | /// \endcode |
2549 | /// |
2550 | /// For example: BOOST_FOREACH. |
2551 | /// \version 3.7 |
2552 | std::vector<std::string> ForEachMacros; |
2553 | |
2554 | tooling::IncludeStyle IncludeStyle; |
2555 | |
2556 | /// A vector of macros that should be interpreted as conditionals |
2557 | /// instead of as function calls. |
2558 | /// |
2559 | /// These are expected to be macros of the form: |
2560 | /// \code |
2561 | /// IF(...) |
2562 | /// <conditional-body> |
2563 | /// else IF(...) |
2564 | /// <conditional-body> |
2565 | /// \endcode |
2566 | /// |
2567 | /// In the .clang-format configuration file, this can be configured like: |
2568 | /// \code{.yaml} |
2569 | /// IfMacros: ['IF'] |
2570 | /// \endcode |
2571 | /// |
2572 | /// For example: `KJ_IF_MAYBE |
2573 | /// <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_ |
2574 | /// \version 13 |
2575 | std::vector<std::string> IfMacros; |
2576 | |
2577 | /// Specify whether access modifiers should have their own indentation level. |
2578 | /// |
2579 | /// When ``false``, access modifiers are indented (or outdented) relative to |
2580 | /// the record members, respecting the ``AccessModifierOffset``. Record |
2581 | /// members are indented one level below the record. |
2582 | /// When ``true``, access modifiers get their own indentation level. As a |
2583 | /// consequence, record members are always indented 2 levels below the record, |
2584 | /// regardless of the access modifier presence. Value of the |
2585 | /// ``AccessModifierOffset`` is ignored. |
2586 | /// \code |
2587 | /// false: true: |
2588 | /// class C { vs. class C { |
2589 | /// class D { class D { |
2590 | /// void bar(); void bar(); |
2591 | /// protected: protected: |
2592 | /// D(); D(); |
2593 | /// }; }; |
2594 | /// public: public: |
2595 | /// C(); C(); |
2596 | /// }; }; |
2597 | /// void foo() { void foo() { |
2598 | /// return 1; return 1; |
2599 | /// } } |
2600 | /// \endcode |
2601 | /// \version 13 |
2602 | bool IndentAccessModifiers; |
2603 | |
2604 | /// Indent case label blocks one level from the case label. |
2605 | /// |
2606 | /// When ``false``, the block following the case label uses the same |
2607 | /// indentation level as for the case label, treating the case label the same |
2608 | /// as an if-statement. |
2609 | /// When ``true``, the block gets indented as a scope block. |
2610 | /// \code |
2611 | /// false: true: |
2612 | /// switch (fool) { vs. switch (fool) { |
2613 | /// case 1: { case 1: |
2614 | /// bar(); { |
2615 | /// } break; bar(); |
2616 | /// default: { } |
2617 | /// plop(); break; |
2618 | /// } default: |
2619 | /// } { |
2620 | /// plop(); |
2621 | /// } |
2622 | /// } |
2623 | /// \endcode |
2624 | /// \version 11 |
2625 | bool IndentCaseBlocks; |
2626 | |
2627 | /// Indent case labels one level from the switch statement. |
2628 | /// |
2629 | /// When ``false``, use the same indentation level as for the switch |
2630 | /// statement. Switch statement body is always indented one level more than |
2631 | /// case labels (except the first block following the case label, which |
2632 | /// itself indents the code - unless IndentCaseBlocks is enabled). |
2633 | /// \code |
2634 | /// false: true: |
2635 | /// switch (fool) { vs. switch (fool) { |
2636 | /// case 1: case 1: |
2637 | /// bar(); bar(); |
2638 | /// break; break; |
2639 | /// default: default: |
2640 | /// plop(); plop(); |
2641 | /// } } |
2642 | /// \endcode |
2643 | /// \version 3.3 |
2644 | bool IndentCaseLabels; |
2645 | |
2646 | /// Indent goto labels. |
2647 | /// |
2648 | /// When ``false``, goto labels are flushed left. |
2649 | /// \code |
2650 | /// true: false: |
2651 | /// int f() { vs. int f() { |
2652 | /// if (foo()) { if (foo()) { |
2653 | /// label1: label1: |
2654 | /// bar(); bar(); |
2655 | /// } } |
2656 | /// label2: label2: |
2657 | /// return 1; return 1; |
2658 | /// } } |
2659 | /// \endcode |
2660 | /// \version 10 |
2661 | bool IndentGotoLabels; |
2662 | |
2663 | /// Indents extern blocks |
2664 | enum IndentExternBlockStyle : int8_t { |
2665 | /// Backwards compatible with AfterExternBlock's indenting. |
2666 | /// \code |
2667 | /// IndentExternBlock: AfterExternBlock |
2668 | /// BraceWrapping.AfterExternBlock: true |
2669 | /// extern "C" |
2670 | /// { |
2671 | /// void foo(); |
2672 | /// } |
2673 | /// \endcode |
2674 | /// |
2675 | /// \code |
2676 | /// IndentExternBlock: AfterExternBlock |
2677 | /// BraceWrapping.AfterExternBlock: false |
2678 | /// extern "C" { |
2679 | /// void foo(); |
2680 | /// } |
2681 | /// \endcode |
2682 | IEBS_AfterExternBlock, |
2683 | /// Does not indent extern blocks. |
2684 | /// \code |
2685 | /// extern "C" { |
2686 | /// void foo(); |
2687 | /// } |
2688 | /// \endcode |
2689 | IEBS_NoIndent, |
2690 | /// Indents extern blocks. |
2691 | /// \code |
2692 | /// extern "C" { |
2693 | /// void foo(); |
2694 | /// } |
2695 | /// \endcode |
2696 | IEBS_Indent, |
2697 | }; |
2698 | |
2699 | /// IndentExternBlockStyle is the type of indenting of extern blocks. |
2700 | /// \version 11 |
2701 | IndentExternBlockStyle IndentExternBlock; |
2702 | |
2703 | /// Options for indenting preprocessor directives. |
2704 | enum PPDirectiveIndentStyle : int8_t { |
2705 | /// Does not indent any directives. |
2706 | /// \code |
2707 | /// #if FOO |
2708 | /// #if BAR |
2709 | /// #include <foo> |
2710 | /// #endif |
2711 | /// #endif |
2712 | /// \endcode |
2713 | PPDIS_None, |
2714 | /// Indents directives after the hash. |
2715 | /// \code |
2716 | /// #if FOO |
2717 | /// # if BAR |
2718 | /// # include <foo> |
2719 | /// # endif |
2720 | /// #endif |
2721 | /// \endcode |
2722 | PPDIS_AfterHash, |
2723 | /// Indents directives before the hash. |
2724 | /// \code |
2725 | /// #if FOO |
2726 | /// #if BAR |
2727 | /// #include <foo> |
2728 | /// #endif |
2729 | /// #endif |
2730 | /// \endcode |
2731 | PPDIS_BeforeHash |
2732 | }; |
2733 | |
2734 | /// The preprocessor directive indenting style to use. |
2735 | /// \version 6 |
2736 | PPDirectiveIndentStyle IndentPPDirectives; |
2737 | |
2738 | /// Indent the requires clause in a template. This only applies when |
2739 | /// ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``. |
2740 | /// |
2741 | /// In clang-format 12, 13 and 14 it was named ``IndentRequires``. |
2742 | /// \code |
2743 | /// true: |
2744 | /// template <typename It> |
2745 | /// requires Iterator<It> |
2746 | /// void sort(It begin, It end) { |
2747 | /// //.... |
2748 | /// } |
2749 | /// |
2750 | /// false: |
2751 | /// template <typename It> |
2752 | /// requires Iterator<It> |
2753 | /// void sort(It begin, It end) { |
2754 | /// //.... |
2755 | /// } |
2756 | /// \endcode |
2757 | /// \version 15 |
2758 | bool IndentRequiresClause; |
2759 | |
2760 | /// The number of columns to use for indentation. |
2761 | /// \code |
2762 | /// IndentWidth: 3 |
2763 | /// |
2764 | /// void f() { |
2765 | /// someFunction(); |
2766 | /// if (true, false) { |
2767 | /// f(); |
2768 | /// } |
2769 | /// } |
2770 | /// \endcode |
2771 | /// \version 3.7 |
2772 | unsigned IndentWidth; |
2773 | |
2774 | /// Indent if a function definition or declaration is wrapped after the |
2775 | /// type. |
2776 | /// \code |
2777 | /// true: |
2778 | /// LoooooooooooooooooooooooooooooooooooooooongReturnType |
2779 | /// LoooooooooooooooooooooooooooooooongFunctionDeclaration(); |
2780 | /// |
2781 | /// false: |
2782 | /// LoooooooooooooooooooooooooooooooooooooooongReturnType |
2783 | /// LoooooooooooooooooooooooooooooooongFunctionDeclaration(); |
2784 | /// \endcode |
2785 | /// \version 3.7 |
2786 | bool IndentWrappedFunctionNames; |
2787 | |
2788 | /// Insert braces after control statements (``if``, ``else``, ``for``, ``do``, |
2789 | /// and ``while``) in C++ unless the control statements are inside macro |
2790 | /// definitions or the braces would enclose preprocessor directives. |
2791 | /// \warning |
2792 | /// Setting this option to ``true`` could lead to incorrect code formatting |
2793 | /// due to clang-format's lack of complete semantic information. As such, |
2794 | /// extra care should be taken to review code changes made by this option. |
2795 | /// \endwarning |
2796 | /// \code |
2797 | /// false: true: |
2798 | /// |
2799 | /// if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) { |
2800 | /// handleFunctionDecl(D); handleFunctionDecl(D); |
2801 | /// else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) { |
2802 | /// handleVarDecl(D); handleVarDecl(D); |
2803 | /// else } else { |
2804 | /// return; return; |
2805 | /// } |
2806 | /// |
2807 | /// while (i--) vs. while (i--) { |
2808 | /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) { |
2809 | /// handleAttr(A); handleAttr(A); |
2810 | /// } |
2811 | /// } |
2812 | /// |
2813 | /// do vs. do { |
2814 | /// --i; --i; |
2815 | /// while (i); } while (i); |
2816 | /// \endcode |
2817 | /// \version 15 |
2818 | bool InsertBraces; |
2819 | |
2820 | /// Insert a newline at end of file if missing. |
2821 | /// \version 16 |
2822 | bool InsertNewlineAtEOF; |
2823 | |
2824 | /// The style of inserting trailing commas into container literals. |
2825 | enum TrailingCommaStyle : int8_t { |
2826 | /// Do not insert trailing commas. |
2827 | TCS_None, |
2828 | /// Insert trailing commas in container literals that were wrapped over |
2829 | /// multiple lines. Note that this is conceptually incompatible with |
2830 | /// bin-packing, because the trailing comma is used as an indicator |
2831 | /// that a container should be formatted one-per-line (i.e. not bin-packed). |
2832 | /// So inserting a trailing comma counteracts bin-packing. |
2833 | TCS_Wrapped, |
2834 | }; |
2835 | |
2836 | /// If set to ``TCS_Wrapped`` will insert trailing commas in container |
2837 | /// literals (arrays and objects) that wrap across multiple lines. |
2838 | /// It is currently only available for JavaScript |
2839 | /// and disabled by default ``TCS_None``. |
2840 | /// ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments`` |
2841 | /// as inserting the comma disables bin-packing. |
2842 | /// \code |
2843 | /// TSC_Wrapped: |
2844 | /// const someArray = [ |
2845 | /// aaaaaaaaaaaaaaaaaaaaaaaaaa, |
2846 | /// aaaaaaaaaaaaaaaaaaaaaaaaaa, |
2847 | /// aaaaaaaaaaaaaaaaaaaaaaaaaa, |
2848 | /// // ^ inserted |
2849 | /// ] |
2850 | /// \endcode |
2851 | /// \version 11 |
2852 | TrailingCommaStyle InsertTrailingCommas; |
2853 | |
2854 | /// Separator format of integer literals of different bases. |
2855 | /// |
2856 | /// If negative, remove separators. If ``0``, leave the literal as is. If |
2857 | /// positive, insert separators between digits starting from the rightmost |
2858 | /// digit. |
2859 | /// |
2860 | /// For example, the config below will leave separators in binary literals |
2861 | /// alone, insert separators in decimal literals to separate the digits into |
2862 | /// groups of 3, and remove separators in hexadecimal literals. |
2863 | /// \code |
2864 | /// IntegerLiteralSeparator: |
2865 | /// Binary: 0 |
2866 | /// Decimal: 3 |
2867 | /// Hex: -1 |
2868 | /// \endcode |
2869 | /// |
2870 | /// You can also specify a minimum number of digits (``BinaryMinDigits``, |
2871 | /// ``DecimalMinDigits``, and ``HexMinDigits``) the integer literal must |
2872 | /// have in order for the separators to be inserted. |
2873 | struct IntegerLiteralSeparatorStyle { |
2874 | /// Format separators in binary literals. |
2875 | /// \code{.text} |
2876 | /// /* -1: */ b = 0b100111101101; |
2877 | /// /* 0: */ b = 0b10011'11'0110'1; |
2878 | /// /* 3: */ b = 0b100'111'101'101; |
2879 | /// /* 4: */ b = 0b1001'1110'1101; |
2880 | /// \endcode |
2881 | int8_t Binary; |
2882 | /// Format separators in binary literals with a minimum number of digits. |
2883 | /// \code{.text} |
2884 | /// // Binary: 3 |
2885 | /// // BinaryMinDigits: 7 |
2886 | /// b1 = 0b101101; |
2887 | /// b2 = 0b1'101'101; |
2888 | /// \endcode |
2889 | int8_t BinaryMinDigits; |
2890 | /// Format separators in decimal literals. |
2891 | /// \code{.text} |
2892 | /// /* -1: */ d = 18446744073709550592ull; |
2893 | /// /* 0: */ d = 184467'440737'0'95505'92ull; |
2894 | /// /* 3: */ d = 18'446'744'073'709'550'592ull; |
2895 | /// \endcode |
2896 | int8_t Decimal; |
2897 | /// Format separators in decimal literals with a minimum number of digits. |
2898 | /// \code{.text} |
2899 | /// // Decimal: 3 |
2900 | /// // DecimalMinDigits: 5 |
2901 | /// d1 = 2023; |
2902 | /// d2 = 10'000; |
2903 | /// \endcode |
2904 | int8_t DecimalMinDigits; |
2905 | /// Format separators in hexadecimal literals. |
2906 | /// \code{.text} |
2907 | /// /* -1: */ h = 0xDEADBEEFDEADBEEFuz; |
2908 | /// /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz; |
2909 | /// /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz; |
2910 | /// \endcode |
2911 | int8_t Hex; |
2912 | /// Format separators in hexadecimal literals with a minimum number of |
2913 | /// digits. |
2914 | /// \code{.text} |
2915 | /// // Hex: 2 |
2916 | /// // HexMinDigits: 6 |
2917 | /// h1 = 0xABCDE; |
2918 | /// h2 = 0xAB'CD'EF; |
2919 | /// \endcode |
2920 | int8_t HexMinDigits; |
2921 | bool operator==(const IntegerLiteralSeparatorStyle &R) const { |
2922 | return Binary == R.Binary && BinaryMinDigits == R.BinaryMinDigits && |
2923 | Decimal == R.Decimal && DecimalMinDigits == R.DecimalMinDigits && |
2924 | Hex == R.Hex && HexMinDigits == R.HexMinDigits; |
2925 | } |
2926 | }; |
2927 | |
2928 | /// Format integer literal separators (``'`` for C++ and ``_`` for C#, Java, |
2929 | /// and JavaScript). |
2930 | /// \version 16 |
2931 | IntegerLiteralSeparatorStyle IntegerLiteralSeparator; |
2932 | |
2933 | /// A vector of prefixes ordered by the desired groups for Java imports. |
2934 | /// |
2935 | /// One group's prefix can be a subset of another - the longest prefix is |
2936 | /// always matched. Within a group, the imports are ordered lexicographically. |
2937 | /// Static imports are grouped separately and follow the same group rules. |
2938 | /// By default, static imports are placed before non-static imports, |
2939 | /// but this behavior is changed by another option, |
2940 | /// ``SortJavaStaticImport``. |
2941 | /// |
2942 | /// In the .clang-format configuration file, this can be configured like |
2943 | /// in the following yaml example. This will result in imports being |
2944 | /// formatted as in the Java example below. |
2945 | /// \code{.yaml} |
2946 | /// JavaImportGroups: ['com.example', 'com', 'org'] |
2947 | /// \endcode |
2948 | /// |
2949 | /// \code{.java} |
2950 | /// import static com.example.function1; |
2951 | /// |
2952 | /// import static com.test.function2; |
2953 | /// |
2954 | /// import static org.example.function3; |
2955 | /// |
2956 | /// import com.example.ClassA; |
2957 | /// import com.example.Test; |
2958 | /// import com.example.a.ClassB; |
2959 | /// |
2960 | /// import com.test.ClassC; |
2961 | /// |
2962 | /// import org.example.ClassD; |
2963 | /// \endcode |
2964 | /// \version 8 |
2965 | std::vector<std::string> JavaImportGroups; |
2966 | |
2967 | /// Quotation styles for JavaScript strings. Does not affect template |
2968 | /// strings. |
2969 | enum JavaScriptQuoteStyle : int8_t { |
2970 | /// Leave string quotes as they are. |
2971 | /// \code{.js} |
2972 | /// string1 = "foo"; |
2973 | /// string2 = 'bar'; |
2974 | /// \endcode |
2975 | JSQS_Leave, |
2976 | /// Always use single quotes. |
2977 | /// \code{.js} |
2978 | /// string1 = 'foo'; |
2979 | /// string2 = 'bar'; |
2980 | /// \endcode |
2981 | JSQS_Single, |
2982 | /// Always use double quotes. |
2983 | /// \code{.js} |
2984 | /// string1 = "foo"; |
2985 | /// string2 = "bar"; |
2986 | /// \endcode |
2987 | JSQS_Double |
2988 | }; |
2989 | |
2990 | /// The JavaScriptQuoteStyle to use for JavaScript strings. |
2991 | /// \version 3.9 |
2992 | JavaScriptQuoteStyle JavaScriptQuotes; |
2993 | |
2994 | // clang-format off |
2995 | /// Whether to wrap JavaScript import/export statements. |
2996 | /// \code{.js} |
2997 | /// true: |
2998 | /// import { |
2999 | /// VeryLongImportsAreAnnoying, |
3000 | /// VeryLongImportsAreAnnoying, |
3001 | /// VeryLongImportsAreAnnoying, |
3002 | /// } from 'some/module.js' |
3003 | /// |
3004 | /// false: |
3005 | /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js" |
3006 | /// \endcode |
3007 | /// \version 3.9 |
3008 | bool JavaScriptWrapImports; |
3009 | // clang-format on |
3010 | |
3011 | /// Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file. |
3012 | /// \version 17 |
3013 | bool KeepEmptyLinesAtEOF; |
3014 | |
3015 | /// If true, the empty line at the start of blocks is kept. |
3016 | /// \code |
3017 | /// true: false: |
3018 | /// if (foo) { vs. if (foo) { |
3019 | /// bar(); |
3020 | /// bar(); } |
3021 | /// } |
3022 | /// \endcode |
3023 | /// \version 3.7 |
3024 | bool KeepEmptyLinesAtTheStartOfBlocks; |
3025 | |
3026 | /// Indentation logic for lambda bodies. |
3027 | enum LambdaBodyIndentationKind : int8_t { |
3028 | /// Align lambda body relative to the lambda signature. This is the default. |
3029 | /// \code |
3030 | /// someMethod( |
3031 | /// [](SomeReallyLongLambdaSignatureArgument foo) { |
3032 | /// return; |
3033 | /// }); |
3034 | /// \endcode |
3035 | LBI_Signature, |
3036 | /// For statements within block scope, align lambda body relative to the |
3037 | /// indentation level of the outer scope the lambda signature resides in. |
3038 | /// \code |
3039 | /// someMethod( |
3040 | /// [](SomeReallyLongLambdaSignatureArgument foo) { |
3041 | /// return; |
3042 | /// }); |
3043 | /// |
3044 | /// someMethod(someOtherMethod( |
3045 | /// [](SomeReallyLongLambdaSignatureArgument foo) { |
3046 | /// return; |
3047 | /// })); |
3048 | /// \endcode |
3049 | LBI_OuterScope, |
3050 | }; |
3051 | |
3052 | /// The indentation style of lambda bodies. ``Signature`` (the default) |
3053 | /// causes the lambda body to be indented one additional level relative to |
3054 | /// the indentation level of the signature. ``OuterScope`` forces the lambda |
3055 | /// body to be indented one additional level relative to the parent scope |
3056 | /// containing the lambda signature. |
3057 | /// \version 13 |
3058 | LambdaBodyIndentationKind LambdaBodyIndentation; |
3059 | |
3060 | /// Supported languages. |
3061 | /// |
3062 | /// When stored in a configuration file, specifies the language, that the |
3063 | /// configuration targets. When passed to the ``reformat()`` function, enables |
3064 | /// syntax features specific to the language. |
3065 | enum LanguageKind : int8_t { |
3066 | /// Do not use. |
3067 | LK_None, |
3068 | /// Should be used for C, C++. |
3069 | LK_Cpp, |
3070 | /// Should be used for C#. |
3071 | LK_CSharp, |
3072 | /// Should be used for Java. |
3073 | LK_Java, |
3074 | /// Should be used for JavaScript. |
3075 | LK_JavaScript, |
3076 | /// Should be used for JSON. |
3077 | LK_Json, |
3078 | /// Should be used for Objective-C, Objective-C++. |
3079 | LK_ObjC, |
3080 | /// Should be used for Protocol Buffers |
3081 | /// (https://developers.google.com/protocol-buffers/). |
3082 | LK_Proto, |
3083 | /// Should be used for TableGen code. |
3084 | LK_TableGen, |
3085 | /// Should be used for Protocol Buffer messages in text format |
3086 | /// (https://developers.google.com/protocol-buffers/). |
3087 | LK_TextProto, |
3088 | /// Should be used for Verilog and SystemVerilog. |
3089 | /// https://standards.ieee.org/ieee/1800/6700/ |
3090 | /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595 |
3091 | LK_Verilog |
3092 | }; |
3093 | bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; } |
3094 | bool isCSharp() const { return Language == LK_CSharp; } |
3095 | bool isJson() const { return Language == LK_Json; } |
3096 | bool isJavaScript() const { return Language == LK_JavaScript; } |
3097 | bool isVerilog() const { return Language == LK_Verilog; } |
3098 | bool isProto() const { |
3099 | return Language == LK_Proto || Language == LK_TextProto; |
3100 | } |
3101 | bool isTableGen() const { return Language == LK_TableGen; } |
3102 | |
3103 | /// Language, this format style is targeted at. |
3104 | /// \version 3.5 |
3105 | LanguageKind Language; |
3106 | |
3107 | /// Line ending style. |
3108 | enum LineEndingStyle : int8_t { |
3109 | /// Use ``\n``. |
3110 | LE_LF, |
3111 | /// Use ``\r\n``. |
3112 | LE_CRLF, |
3113 | /// Use ``\n`` unless the input has more lines ending in ``\r\n``. |
3114 | LE_DeriveLF, |
3115 | /// Use ``\r\n`` unless the input has more lines ending in ``\n``. |
3116 | LE_DeriveCRLF, |
3117 | }; |
3118 | |
3119 | /// Line ending style (``\n`` or ``\r\n``) to use. |
3120 | /// \version 16 |
3121 | LineEndingStyle LineEnding; |
3122 | |
3123 | /// A regular expression matching macros that start a block. |
3124 | /// \code |
3125 | /// # With: |
3126 | /// MacroBlockBegin: "^NS_MAP_BEGIN|\ |
3127 | /// NS_TABLE_HEAD$" |
3128 | /// MacroBlockEnd: "^\ |
3129 | /// NS_MAP_END|\ |
3130 | /// NS_TABLE_.*_END$" |
3131 | /// |
3132 | /// NS_MAP_BEGIN |
3133 | /// foo(); |
3134 | /// NS_MAP_END |
3135 | /// |
3136 | /// NS_TABLE_HEAD |
3137 | /// bar(); |
3138 | /// NS_TABLE_FOO_END |
3139 | /// |
3140 | /// # Without: |
3141 | /// NS_MAP_BEGIN |
3142 | /// foo(); |
3143 | /// NS_MAP_END |
3144 | /// |
3145 | /// NS_TABLE_HEAD |
3146 | /// bar(); |
3147 | /// NS_TABLE_FOO_END |
3148 | /// \endcode |
3149 | /// \version 3.7 |
3150 | std::string MacroBlockBegin; |
3151 | |
3152 | /// A regular expression matching macros that end a block. |
3153 | /// \version 3.7 |
3154 | std::string MacroBlockEnd; |
3155 | |
3156 | /// A list of macros of the form \c <definition>=<expansion> . |
3157 | /// |
3158 | /// Code will be parsed with macros expanded, in order to determine how to |
3159 | /// interpret and format the macro arguments. |
3160 | /// |
3161 | /// For example, the code: |
3162 | /// \code |
3163 | /// A(a*b); |
3164 | /// \endcode |
3165 | /// |
3166 | /// will usually be interpreted as a call to a function A, and the |
3167 | /// multiplication expression will be formatted as ``a * b``. |
3168 | /// |
3169 | /// If we specify the macro definition: |
3170 | /// \code{.yaml} |
3171 | /// Macros: |
3172 | /// - A(x)=x |
3173 | /// \endcode |
3174 | /// |
3175 | /// the code will now be parsed as a declaration of the variable b of type a*, |
3176 | /// and formatted as ``a* b`` (depending on pointer-binding rules). |
3177 | /// |
3178 | /// Features and restrictions: |
3179 | /// * Both function-like macros and object-like macros are supported. |
3180 | /// * Macro arguments must be used exactly once in the expansion. |
3181 | /// * No recursive expansion; macros referencing other macros will be |
3182 | /// ignored. |
3183 | /// * Overloading by arity is supported: for example, given the macro |
3184 | /// definitions A=x, A()=y, A(a)=a |
3185 | /// |
3186 | /// \code |
3187 | /// A; -> x; |
3188 | /// A(); -> y; |
3189 | /// A(z); -> z; |
3190 | /// A(a, b); // will not be expanded. |
3191 | /// \endcode |
3192 | /// |
3193 | /// \version 17 |
3194 | std::vector<std::string> Macros; |
3195 | |
3196 | /// The maximum number of consecutive empty lines to keep. |
3197 | /// \code |
3198 | /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0 |
3199 | /// int f() { int f() { |
3200 | /// int = 1; int i = 1; |
3201 | /// i = foo(); |
3202 | /// i = foo(); return i; |
3203 | /// } |
3204 | /// return i; |
3205 | /// } |
3206 | /// \endcode |
3207 | /// \version 3.7 |
3208 | unsigned MaxEmptyLinesToKeep; |
3209 | |
3210 | /// Different ways to indent namespace contents. |
3211 | enum NamespaceIndentationKind : int8_t { |
3212 | /// Don't indent in namespaces. |
3213 | /// \code |
3214 | /// namespace out { |
3215 | /// int i; |
3216 | /// namespace in { |
3217 | /// int i; |
3218 | /// } |
3219 | /// } |
3220 | /// \endcode |
3221 | NI_None, |
3222 | /// Indent only in inner namespaces (nested in other namespaces). |
3223 | /// \code |
3224 | /// namespace out { |
3225 | /// int i; |
3226 | /// namespace in { |
3227 | /// int i; |
3228 | /// } |
3229 | /// } |
3230 | /// \endcode |
3231 | NI_Inner, |
3232 | /// Indent in all namespaces. |
3233 | /// \code |
3234 | /// namespace out { |
3235 | /// int i; |
3236 | /// namespace in { |
3237 | /// int i; |
3238 | /// } |
3239 | /// } |
3240 | /// \endcode |
3241 | NI_All |
3242 | }; |
3243 | |
3244 | /// The indentation used for namespaces. |
3245 | /// \version 3.7 |
3246 | NamespaceIndentationKind NamespaceIndentation; |
3247 | |
3248 | /// A vector of macros which are used to open namespace blocks. |
3249 | /// |
3250 | /// These are expected to be macros of the form: |
3251 | /// \code |
3252 | /// NAMESPACE(<namespace-name>, ...) { |
3253 | /// <namespace-content> |
3254 | /// } |
3255 | /// \endcode |
3256 | /// |
3257 | /// For example: TESTSUITE |
3258 | /// \version 9 |
3259 | std::vector<std::string> NamespaceMacros; |
3260 | |
3261 | /// Controls bin-packing Objective-C protocol conformance list |
3262 | /// items into as few lines as possible when they go over ``ColumnLimit``. |
3263 | /// |
3264 | /// If ``Auto`` (the default), delegates to the value in |
3265 | /// ``BinPackParameters``. If that is ``true``, bin-packs Objective-C |
3266 | /// protocol conformance list items into as few lines as possible |
3267 | /// whenever they go over ``ColumnLimit``. |
3268 | /// |
3269 | /// If ``Always``, always bin-packs Objective-C protocol conformance |
3270 | /// list items into as few lines as possible whenever they go over |
3271 | /// ``ColumnLimit``. |
3272 | /// |
3273 | /// If ``Never``, lays out Objective-C protocol conformance list items |
3274 | /// onto individual lines whenever they go over ``ColumnLimit``. |
3275 | /// |
3276 | /// \code{.objc} |
3277 | /// Always (or Auto, if BinPackParameters=true): |
3278 | /// @interface ccccccccccccc () < |
3279 | /// ccccccccccccc, ccccccccccccc, |
3280 | /// ccccccccccccc, ccccccccccccc> { |
3281 | /// } |
3282 | /// |
3283 | /// Never (or Auto, if BinPackParameters=false): |
3284 | /// @interface ddddddddddddd () < |
3285 | /// ddddddddddddd, |
3286 | /// ddddddddddddd, |
3287 | /// ddddddddddddd, |
3288 | /// ddddddddddddd> { |
3289 | /// } |
3290 | /// \endcode |
3291 | /// \version 7 |
3292 | BinPackStyle ObjCBinPackProtocolList; |
3293 | |
3294 | /// The number of characters to use for indentation of ObjC blocks. |
3295 | /// \code{.objc} |
3296 | /// ObjCBlockIndentWidth: 4 |
3297 | /// |
3298 | /// [operation setCompletionBlock:^{ |
3299 | /// [self onOperationDone]; |
3300 | /// }]; |
3301 | /// \endcode |
3302 | /// \version 3.7 |
3303 | unsigned ObjCBlockIndentWidth; |
3304 | |
3305 | /// Break parameters list into lines when there is nested block |
3306 | /// parameters in a function call. |
3307 | /// \code |
3308 | /// false: |
3309 | /// - (void)_aMethod |
3310 | /// { |
3311 | /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber |
3312 | /// *u, NSNumber *v) { |
3313 | /// u = c; |
3314 | /// }] |
3315 | /// } |
3316 | /// true: |
3317 | /// - (void)_aMethod |
3318 | /// { |
3319 | /// [self.test1 t:self |
3320 | /// w:self |
3321 | /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) { |
3322 | /// u = c; |
3323 | /// }] |
3324 | /// } |
3325 | /// \endcode |
3326 | /// \version 11 |
3327 | bool ObjCBreakBeforeNestedBlockParam; |
3328 | |
3329 | /// The order in which ObjC property attributes should appear. |
3330 | /// |
3331 | /// Attributes in code will be sorted in the order specified. Any attributes |
3332 | /// encountered that are not mentioned in this array will be sorted last, in |
3333 | /// stable order. Comments between attributes will leave the attributes |
3334 | /// untouched. |
3335 | /// \warning |
3336 | /// Using this option could lead to incorrect code formatting due to |
3337 | /// clang-format's lack of complete semantic information. As such, extra |
3338 | /// care should be taken to review code changes made by this option. |
3339 | /// \endwarning |
3340 | /// \code{.yaml} |
3341 | /// ObjCPropertyAttributeOrder: [ |
3342 | /// class, direct, |
3343 | /// atomic, nonatomic, |
3344 | /// assign, retain, strong, copy, weak, unsafe_unretained, |
3345 | /// readonly, readwrite, getter, setter, |
3346 | /// nullable, nonnull, null_resettable, null_unspecified |
3347 | /// ] |
3348 | /// \endcode |
3349 | /// \version 18 |
3350 | std::vector<std::string> ObjCPropertyAttributeOrder; |
3351 | |
3352 | /// Add a space after ``@property`` in Objective-C, i.e. use |
3353 | /// ``@property (readonly)`` instead of ``@property(readonly)``. |
3354 | /// \version 3.7 |
3355 | bool ObjCSpaceAfterProperty; |
3356 | |
3357 | /// Add a space in front of an Objective-C protocol list, i.e. use |
3358 | /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``. |
3359 | /// \version 3.7 |
3360 | bool ObjCSpaceBeforeProtocolList; |
3361 | |
3362 | /// Different ways to try to fit all constructor initializers on a line. |
3363 | enum : int8_t { |
3364 | /// Always put each constructor initializer on its own line. |
3365 | /// \code |
3366 | /// Constructor() |
3367 | /// : a(), |
3368 | /// b() |
3369 | /// \endcode |
3370 | PCIS_Never, |
3371 | /// Bin-pack constructor initializers. |
3372 | /// \code |
3373 | /// Constructor() |
3374 | /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), |
3375 | /// cccccccccccccccccccc() |
3376 | /// \endcode |
3377 | PCIS_BinPack, |
3378 | /// Put all constructor initializers on the current line if they fit. |
3379 | /// Otherwise, put each one on its own line. |
3380 | /// \code |
3381 | /// Constructor() : a(), b() |
3382 | /// |
3383 | /// Constructor() |
3384 | /// : aaaaaaaaaaaaaaaaaaaa(), |
3385 | /// bbbbbbbbbbbbbbbbbbbb(), |
3386 | /// ddddddddddddd() |
3387 | /// \endcode |
3388 | PCIS_CurrentLine, |
3389 | /// Same as ``PCIS_CurrentLine`` except that if all constructor initializers |
3390 | /// do not fit on the current line, try to fit them on the next line. |
3391 | /// \code |
3392 | /// Constructor() : a(), b() |
3393 | /// |
3394 | /// Constructor() |
3395 | /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd() |
3396 | /// |
3397 | /// Constructor() |
3398 | /// : aaaaaaaaaaaaaaaaaaaa(), |
3399 | /// bbbbbbbbbbbbbbbbbbbb(), |
3400 | /// cccccccccccccccccccc() |
3401 | /// \endcode |
3402 | PCIS_NextLine, |
3403 | /// Put all constructor initializers on the next line if they fit. |
3404 | /// Otherwise, put each one on its own line. |
3405 | /// \code |
3406 | /// Constructor() |
3407 | /// : a(), b() |
3408 | /// |
3409 | /// Constructor() |
3410 | /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd() |
3411 | /// |
3412 | /// Constructor() |
3413 | /// : aaaaaaaaaaaaaaaaaaaa(), |
3414 | /// bbbbbbbbbbbbbbbbbbbb(), |
3415 | /// cccccccccccccccccccc() |
3416 | /// \endcode |
3417 | PCIS_NextLineOnly, |
3418 | }; |
3419 | |
3420 | /// The pack constructor initializers style to use. |
3421 | /// \version 14 |
3422 | PackConstructorInitializersStyle PackConstructorInitializers; |
3423 | |
3424 | /// The penalty for breaking around an assignment operator. |
3425 | /// \version 5 |
3426 | unsigned PenaltyBreakAssignment; |
3427 | |
3428 | /// The penalty for breaking a function call after ``call(``. |
3429 | /// \version 3.7 |
3430 | unsigned PenaltyBreakBeforeFirstCallParameter; |
3431 | |
3432 | /// The penalty for each line break introduced inside a comment. |
3433 | /// \version 3.7 |
3434 | unsigned ; |
3435 | |
3436 | /// The penalty for breaking before the first ``<<``. |
3437 | /// \version 3.7 |
3438 | unsigned PenaltyBreakFirstLessLess; |
3439 | |
3440 | /// The penalty for breaking after ``(``. |
3441 | /// \version 14 |
3442 | unsigned PenaltyBreakOpenParenthesis; |
3443 | |
3444 | /// The penalty for breaking after ``::``. |
3445 | /// \version 18 |
3446 | unsigned PenaltyBreakScopeResolution; |
3447 | |
3448 | /// The penalty for each line break introduced inside a string literal. |
3449 | /// \version 3.7 |
3450 | unsigned PenaltyBreakString; |
3451 | |
3452 | /// The penalty for breaking after template declaration. |
3453 | /// \version 7 |
3454 | unsigned PenaltyBreakTemplateDeclaration; |
3455 | |
3456 | /// The penalty for each character outside of the column limit. |
3457 | /// \version 3.7 |
3458 | unsigned PenaltyExcessCharacter; |
3459 | |
3460 | /// Penalty for each character of whitespace indentation |
3461 | /// (counted relative to leading non-whitespace column). |
3462 | /// \version 12 |
3463 | unsigned PenaltyIndentedWhitespace; |
3464 | |
3465 | /// Penalty for putting the return type of a function onto its own line. |
3466 | /// \version 3.7 |
3467 | unsigned PenaltyReturnTypeOnItsOwnLine; |
3468 | |
3469 | /// The ``&``, ``&&`` and ``*`` alignment style. |
3470 | enum PointerAlignmentStyle : int8_t { |
3471 | /// Align pointer to the left. |
3472 | /// \code |
3473 | /// int* a; |
3474 | /// \endcode |
3475 | PAS_Left, |
3476 | /// Align pointer to the right. |
3477 | /// \code |
3478 | /// int *a; |
3479 | /// \endcode |
3480 | PAS_Right, |
3481 | /// Align pointer in the middle. |
3482 | /// \code |
3483 | /// int * a; |
3484 | /// \endcode |
3485 | PAS_Middle |
3486 | }; |
3487 | |
3488 | /// Pointer and reference alignment style. |
3489 | /// \version 3.7 |
3490 | PointerAlignmentStyle PointerAlignment; |
3491 | |
3492 | /// The number of columns to use for indentation of preprocessor statements. |
3493 | /// When set to -1 (default) ``IndentWidth`` is used also for preprocessor |
3494 | /// statements. |
3495 | /// \code |
3496 | /// PPIndentWidth: 1 |
3497 | /// |
3498 | /// #ifdef __linux__ |
3499 | /// # define FOO |
3500 | /// #else |
3501 | /// # define BAR |
3502 | /// #endif |
3503 | /// \endcode |
3504 | /// \version 13 |
3505 | int PPIndentWidth; |
3506 | |
3507 | /// Different specifiers and qualifiers alignment styles. |
3508 | enum QualifierAlignmentStyle : int8_t { |
3509 | /// Don't change specifiers/qualifiers to either Left or Right alignment |
3510 | /// (default). |
3511 | /// \code |
3512 | /// int const a; |
3513 | /// const int *a; |
3514 | /// \endcode |
3515 | QAS_Leave, |
3516 | /// Change specifiers/qualifiers to be left-aligned. |
3517 | /// \code |
3518 | /// const int a; |
3519 | /// const int *a; |
3520 | /// \endcode |
3521 | QAS_Left, |
3522 | /// Change specifiers/qualifiers to be right-aligned. |
3523 | /// \code |
3524 | /// int const a; |
3525 | /// int const *a; |
3526 | /// \endcode |
3527 | QAS_Right, |
3528 | /// Change specifiers/qualifiers to be aligned based on ``QualifierOrder``. |
3529 | /// With: |
3530 | /// \code{.yaml} |
3531 | /// QualifierOrder: ['inline', 'static', 'type', 'const'] |
3532 | /// \endcode |
3533 | /// |
3534 | /// \code |
3535 | /// |
3536 | /// int const a; |
3537 | /// int const *a; |
3538 | /// \endcode |
3539 | QAS_Custom |
3540 | }; |
3541 | |
3542 | /// Different ways to arrange specifiers and qualifiers (e.g. const/volatile). |
3543 | /// \warning |
3544 | /// Setting ``QualifierAlignment`` to something other than ``Leave``, COULD |
3545 | /// lead to incorrect code formatting due to incorrect decisions made due to |
3546 | /// clang-formats lack of complete semantic information. |
3547 | /// As such extra care should be taken to review code changes made by the use |
3548 | /// of this option. |
3549 | /// \endwarning |
3550 | /// \version 14 |
3551 | QualifierAlignmentStyle QualifierAlignment; |
3552 | |
3553 | /// The order in which the qualifiers appear. |
3554 | /// Order is an array that can contain any of the following: |
3555 | /// |
3556 | /// * const |
3557 | /// * inline |
3558 | /// * static |
3559 | /// * friend |
3560 | /// * constexpr |
3561 | /// * volatile |
3562 | /// * restrict |
3563 | /// * type |
3564 | /// |
3565 | /// \note |
3566 | /// it MUST contain 'type'. |
3567 | /// \endnote |
3568 | /// |
3569 | /// Items to the left of 'type' will be placed to the left of the type and |
3570 | /// aligned in the order supplied. Items to the right of 'type' will be |
3571 | /// placed to the right of the type and aligned in the order supplied. |
3572 | /// |
3573 | /// \code{.yaml} |
3574 | /// QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ] |
3575 | /// \endcode |
3576 | /// \version 14 |
3577 | std::vector<std::string> QualifierOrder; |
3578 | |
3579 | /// See documentation of ``RawStringFormats``. |
3580 | struct RawStringFormat { |
3581 | /// The language of this raw string. |
3582 | LanguageKind Language; |
3583 | /// A list of raw string delimiters that match this language. |
3584 | std::vector<std::string> Delimiters; |
3585 | /// A list of enclosing function names that match this language. |
3586 | std::vector<std::string> EnclosingFunctions; |
3587 | /// The canonical delimiter for this language. |
3588 | std::string CanonicalDelimiter; |
3589 | /// The style name on which this raw string format is based on. |
3590 | /// If not specified, the raw string format is based on the style that this |
3591 | /// format is based on. |
3592 | std::string BasedOnStyle; |
3593 | bool operator==(const RawStringFormat &Other) const { |
3594 | return Language == Other.Language && Delimiters == Other.Delimiters && |
3595 | EnclosingFunctions == Other.EnclosingFunctions && |
3596 | CanonicalDelimiter == Other.CanonicalDelimiter && |
3597 | BasedOnStyle == Other.BasedOnStyle; |
3598 | } |
3599 | }; |
3600 | |
3601 | /// Defines hints for detecting supported languages code blocks in raw |
3602 | /// strings. |
3603 | /// |
3604 | /// A raw string with a matching delimiter or a matching enclosing function |
3605 | /// name will be reformatted assuming the specified language based on the |
3606 | /// style for that language defined in the .clang-format file. If no style has |
3607 | /// been defined in the .clang-format file for the specific language, a |
3608 | /// predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not |
3609 | /// found, the formatting is based on llvm style. A matching delimiter takes |
3610 | /// precedence over a matching enclosing function name for determining the |
3611 | /// language of the raw string contents. |
3612 | /// |
3613 | /// If a canonical delimiter is specified, occurrences of other delimiters for |
3614 | /// the same language will be updated to the canonical if possible. |
3615 | /// |
3616 | /// There should be at most one specification per language and each delimiter |
3617 | /// and enclosing function should not occur in multiple specifications. |
3618 | /// |
3619 | /// To configure this in the .clang-format file, use: |
3620 | /// \code{.yaml} |
3621 | /// RawStringFormats: |
3622 | /// - Language: TextProto |
3623 | /// Delimiters: |
3624 | /// - 'pb' |
3625 | /// - 'proto' |
3626 | /// EnclosingFunctions: |
3627 | /// - 'PARSE_TEXT_PROTO' |
3628 | /// BasedOnStyle: google |
3629 | /// - Language: Cpp |
3630 | /// Delimiters: |
3631 | /// - 'cc' |
3632 | /// - 'cpp' |
3633 | /// BasedOnStyle: llvm |
3634 | /// CanonicalDelimiter: 'cc' |
3635 | /// \endcode |
3636 | /// \version 6 |
3637 | std::vector<RawStringFormat> RawStringFormats; |
3638 | |
3639 | /// \brief The ``&`` and ``&&`` alignment style. |
3640 | enum ReferenceAlignmentStyle : int8_t { |
3641 | /// Align reference like ``PointerAlignment``. |
3642 | RAS_Pointer, |
3643 | /// Align reference to the left. |
3644 | /// \code |
3645 | /// int& a; |
3646 | /// \endcode |
3647 | RAS_Left, |
3648 | /// Align reference to the right. |
3649 | /// \code |
3650 | /// int &a; |
3651 | /// \endcode |
3652 | RAS_Right, |
3653 | /// Align reference in the middle. |
3654 | /// \code |
3655 | /// int & a; |
3656 | /// \endcode |
3657 | RAS_Middle |
3658 | }; |
3659 | |
3660 | /// \brief Reference alignment style (overrides ``PointerAlignment`` for |
3661 | /// references). |
3662 | /// \version 13 |
3663 | ReferenceAlignmentStyle ReferenceAlignment; |
3664 | |
3665 | // clang-format off |
3666 | /// If ``true``, clang-format will attempt to re-flow comments. That is it |
3667 | /// will touch a comment and *reflow* long comments into new lines, trying to |
3668 | /// obey the ``ColumnLimit``. |
3669 | /// \code |
3670 | /// false: |
3671 | /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information |
3672 | /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */ |
3673 | /// |
3674 | /// true: |
3675 | /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of |
3676 | /// // information |
3677 | /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of |
3678 | /// * information */ |
3679 | /// \endcode |
3680 | /// \version 3.8 |
3681 | bool ; |
3682 | // clang-format on |
3683 | |
3684 | /// Remove optional braces of control statements (``if``, ``else``, ``for``, |
3685 | /// and ``while``) in C++ according to the LLVM coding style. |
3686 | /// \warning |
3687 | /// This option will be renamed and expanded to support other styles. |
3688 | /// \endwarning |
3689 | /// \warning |
3690 | /// Setting this option to ``true`` could lead to incorrect code formatting |
3691 | /// due to clang-format's lack of complete semantic information. As such, |
3692 | /// extra care should be taken to review code changes made by this option. |
3693 | /// \endwarning |
3694 | /// \code |
3695 | /// false: true: |
3696 | /// |
3697 | /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D)) |
3698 | /// handleFunctionDecl(D); handleFunctionDecl(D); |
3699 | /// } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D)) |
3700 | /// handleVarDecl(D); handleVarDecl(D); |
3701 | /// } |
3702 | /// |
3703 | /// if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) { |
3704 | /// for (auto *A : D.attrs()) { for (auto *A : D.attrs()) |
3705 | /// if (shouldProcessAttr(A)) { if (shouldProcessAttr(A)) |
3706 | /// handleAttr(A); handleAttr(A); |
3707 | /// } } |
3708 | /// } |
3709 | /// } |
3710 | /// |
3711 | /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D)) |
3712 | /// for (auto *A : D.attrs()) { for (auto *A : D.attrs()) |
3713 | /// handleAttr(A); handleAttr(A); |
3714 | /// } |
3715 | /// } |
3716 | /// |
3717 | /// if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) { |
3718 | /// if (shouldProcess(D)) { if (shouldProcess(D)) |
3719 | /// handleVarDecl(D); handleVarDecl(D); |
3720 | /// } else { else |
3721 | /// markAsIgnored(D); markAsIgnored(D); |
3722 | /// } } |
3723 | /// } |
3724 | /// |
3725 | /// if (a) { vs. if (a) |
3726 | /// b(); b(); |
3727 | /// } else { else if (c) |
3728 | /// if (c) { d(); |
3729 | /// d(); else |
3730 | /// } else { e(); |
3731 | /// e(); |
3732 | /// } |
3733 | /// } |
3734 | /// \endcode |
3735 | /// \version 14 |
3736 | bool RemoveBracesLLVM; |
3737 | |
3738 | /// Types of redundant parentheses to remove. |
3739 | enum RemoveParenthesesStyle : int8_t { |
3740 | /// Do not remove parentheses. |
3741 | /// \code |
3742 | /// class __declspec((dllimport)) X {}; |
3743 | /// co_return (((0))); |
3744 | /// return ((a + b) - ((c + d))); |
3745 | /// \endcode |
3746 | RPS_Leave, |
3747 | /// Replace multiple parentheses with single parentheses. |
3748 | /// \code |
3749 | /// class __declspec(dllimport) X {}; |
3750 | /// co_return (0); |
3751 | /// return ((a + b) - (c + d)); |
3752 | /// \endcode |
3753 | RPS_MultipleParentheses, |
3754 | /// Also remove parentheses enclosing the expression in a |
3755 | /// ``return``/``co_return`` statement. |
3756 | /// \code |
3757 | /// class __declspec(dllimport) X {}; |
3758 | /// co_return 0; |
3759 | /// return (a + b) - (c + d); |
3760 | /// \endcode |
3761 | RPS_ReturnStatement, |
3762 | }; |
3763 | |
3764 | /// Remove redundant parentheses. |
3765 | /// \warning |
3766 | /// Setting this option to any value other than ``Leave`` could lead to |
3767 | /// incorrect code formatting due to clang-format's lack of complete semantic |
3768 | /// information. As such, extra care should be taken to review code changes |
3769 | /// made by this option. |
3770 | /// \endwarning |
3771 | /// \version 17 |
3772 | RemoveParenthesesStyle RemoveParentheses; |
3773 | |
3774 | /// Remove semicolons after the closing brace of a non-empty function. |
3775 | /// \warning |
3776 | /// Setting this option to ``true`` could lead to incorrect code formatting |
3777 | /// due to clang-format's lack of complete semantic information. As such, |
3778 | /// extra care should be taken to review code changes made by this option. |
3779 | /// \endwarning |
3780 | /// \code |
3781 | /// false: true: |
3782 | /// |
3783 | /// int max(int a, int b) { int max(int a, int b) { |
3784 | /// return a > b ? a : b; return a > b ? a : b; |
3785 | /// }; } |
3786 | /// |
3787 | /// \endcode |
3788 | /// \version 16 |
3789 | bool RemoveSemicolon; |
3790 | |
3791 | /// \brief The possible positions for the requires clause. The |
3792 | /// ``IndentRequires`` option is only used if the ``requires`` is put on the |
3793 | /// start of a line. |
3794 | enum RequiresClausePositionStyle : int8_t { |
3795 | /// Always put the ``requires`` clause on its own line. |
3796 | /// \code |
3797 | /// template <typename T> |
3798 | /// requires C<T> |
3799 | /// struct Foo {... |
3800 | /// |
3801 | /// template <typename T> |
3802 | /// requires C<T> |
3803 | /// void bar(T t) {... |
3804 | /// |
3805 | /// template <typename T> |
3806 | /// void baz(T t) |
3807 | /// requires C<T> |
3808 | /// {... |
3809 | /// \endcode |
3810 | RCPS_OwnLine, |
3811 | /// Try to put the clause together with the preceding part of a declaration. |
3812 | /// For class templates: stick to the template declaration. |
3813 | /// For function templates: stick to the template declaration. |
3814 | /// For function declaration followed by a requires clause: stick to the |
3815 | /// parameter list. |
3816 | /// \code |
3817 | /// template <typename T> requires C<T> |
3818 | /// struct Foo {... |
3819 | /// |
3820 | /// template <typename T> requires C<T> |
3821 | /// void bar(T t) {... |
3822 | /// |
3823 | /// template <typename T> |
3824 | /// void baz(T t) requires C<T> |
3825 | /// {... |
3826 | /// \endcode |
3827 | RCPS_WithPreceding, |
3828 | /// Try to put the ``requires`` clause together with the class or function |
3829 | /// declaration. |
3830 | /// \code |
3831 | /// template <typename T> |
3832 | /// requires C<T> struct Foo {... |
3833 | /// |
3834 | /// template <typename T> |
3835 | /// requires C<T> void bar(T t) {... |
3836 | /// |
3837 | /// template <typename T> |
3838 | /// void baz(T t) |
3839 | /// requires C<T> {... |
3840 | /// \endcode |
3841 | RCPS_WithFollowing, |
3842 | /// Try to put everything in the same line if possible. Otherwise normal |
3843 | /// line breaking rules take over. |
3844 | /// \code |
3845 | /// // Fitting: |
3846 | /// template <typename T> requires C<T> struct Foo {... |
3847 | /// |
3848 | /// template <typename T> requires C<T> void bar(T t) {... |
3849 | /// |
3850 | /// template <typename T> void bar(T t) requires C<T> {... |
3851 | /// |
3852 | /// // Not fitting, one possible example: |
3853 | /// template <typename LongName> |
3854 | /// requires C<LongName> |
3855 | /// struct Foo {... |
3856 | /// |
3857 | /// template <typename LongName> |
3858 | /// requires C<LongName> |
3859 | /// void bar(LongName ln) { |
3860 | /// |
3861 | /// template <typename LongName> |
3862 | /// void bar(LongName ln) |
3863 | /// requires C<LongName> { |
3864 | /// \endcode |
3865 | RCPS_SingleLine, |
3866 | }; |
3867 | |
3868 | /// \brief The position of the ``requires`` clause. |
3869 | /// \version 15 |
3870 | RequiresClausePositionStyle RequiresClausePosition; |
3871 | |
3872 | /// Indentation logic for requires expression bodies. |
3873 | enum RequiresExpressionIndentationKind : int8_t { |
3874 | /// Align requires expression body relative to the indentation level of the |
3875 | /// outer scope the requires expression resides in. |
3876 | /// This is the default. |
3877 | /// \code |
3878 | /// template <typename T> |
3879 | /// concept C = requires(T t) { |
3880 | /// ... |
3881 | /// } |
3882 | /// \endcode |
3883 | REI_OuterScope, |
3884 | /// Align requires expression body relative to the ``requires`` keyword. |
3885 | /// \code |
3886 | /// template <typename T> |
3887 | /// concept C = requires(T t) { |
3888 | /// ... |
3889 | /// } |
3890 | /// \endcode |
3891 | REI_Keyword, |
3892 | }; |
3893 | |
3894 | /// The indentation used for requires expression bodies. |
3895 | /// \version 16 |
3896 | RequiresExpressionIndentationKind RequiresExpressionIndentation; |
3897 | |
3898 | /// \brief The style if definition blocks should be separated. |
3899 | enum SeparateDefinitionStyle : int8_t { |
3900 | /// Leave definition blocks as they are. |
3901 | SDS_Leave, |
3902 | /// Insert an empty line between definition blocks. |
3903 | SDS_Always, |
3904 | /// Remove any empty line between definition blocks. |
3905 | SDS_Never |
3906 | }; |
3907 | |
3908 | /// Specifies the use of empty lines to separate definition blocks, including |
3909 | /// classes, structs, enums, and functions. |
3910 | /// \code |
3911 | /// Never v.s. Always |
3912 | /// #include <cstring> #include <cstring> |
3913 | /// struct Foo { |
3914 | /// int a, b, c; struct Foo { |
3915 | /// }; int a, b, c; |
3916 | /// namespace Ns { }; |
3917 | /// class Bar { |
3918 | /// public: namespace Ns { |
3919 | /// struct Foobar { class Bar { |
3920 | /// int a; public: |
3921 | /// int b; struct Foobar { |
3922 | /// }; int a; |
3923 | /// private: int b; |
3924 | /// int t; }; |
3925 | /// int method1() { |
3926 | /// // ... private: |
3927 | /// } int t; |
3928 | /// enum List { |
3929 | /// ITEM1, int method1() { |
3930 | /// ITEM2 // ... |
3931 | /// }; } |
3932 | /// template<typename T> |
3933 | /// int method2(T x) { enum List { |
3934 | /// // ... ITEM1, |
3935 | /// } ITEM2 |
3936 | /// int i, j, k; }; |
3937 | /// int method3(int par) { |
3938 | /// // ... template<typename T> |
3939 | /// } int method2(T x) { |
3940 | /// }; // ... |
3941 | /// class C {}; } |
3942 | /// } |
3943 | /// int i, j, k; |
3944 | /// |
3945 | /// int method3(int par) { |
3946 | /// // ... |
3947 | /// } |
3948 | /// }; |
3949 | /// |
3950 | /// class C {}; |
3951 | /// } |
3952 | /// \endcode |
3953 | /// \version 14 |
3954 | SeparateDefinitionStyle SeparateDefinitionBlocks; |
3955 | |
3956 | /// The maximal number of unwrapped lines that a short namespace spans. |
3957 | /// Defaults to 1. |
3958 | /// |
3959 | /// This determines the maximum length of short namespaces by counting |
3960 | /// unwrapped lines (i.e. containing neither opening nor closing |
3961 | /// namespace brace) and makes "FixNamespaceComments" omit adding |
3962 | /// end comments for those. |
3963 | /// \code |
3964 | /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0 |
3965 | /// namespace a { namespace a { |
3966 | /// int foo; int foo; |
3967 | /// } } // namespace a |
3968 | /// |
3969 | /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0 |
3970 | /// namespace b { namespace b { |
3971 | /// int foo; int foo; |
3972 | /// int bar; int bar; |
3973 | /// } // namespace b } // namespace b |
3974 | /// \endcode |
3975 | /// \version 13 |
3976 | unsigned ShortNamespaceLines; |
3977 | |
3978 | /// Do not format macro definition body. |
3979 | /// \version 18 |
3980 | bool SkipMacroDefinitionBody; |
3981 | |
3982 | /// Include sorting options. |
3983 | enum SortIncludesOptions : int8_t { |
3984 | /// Includes are never sorted. |
3985 | /// \code |
3986 | /// #include "B/A.h" |
3987 | /// #include "A/B.h" |
3988 | /// #include "a/b.h" |
3989 | /// #include "A/b.h" |
3990 | /// #include "B/a.h" |
3991 | /// \endcode |
3992 | SI_Never, |
3993 | /// Includes are sorted in an ASCIIbetical or case sensitive fashion. |
3994 | /// \code |
3995 | /// #include "A/B.h" |
3996 | /// #include "A/b.h" |
3997 | /// #include "B/A.h" |
3998 | /// #include "B/a.h" |
3999 | /// #include "a/b.h" |
4000 | /// \endcode |
4001 | SI_CaseSensitive, |
4002 | /// Includes are sorted in an alphabetical or case insensitive fashion. |
4003 | /// \code |
4004 | /// #include "A/B.h" |
4005 | /// #include "A/b.h" |
4006 | /// #include "a/b.h" |
4007 | /// #include "B/A.h" |
4008 | /// #include "B/a.h" |
4009 | /// \endcode |
4010 | SI_CaseInsensitive, |
4011 | }; |
4012 | |
4013 | /// Controls if and how clang-format will sort ``#includes``. |
4014 | /// \version 3.8 |
4015 | SortIncludesOptions SortIncludes; |
4016 | |
4017 | /// Position for Java Static imports. |
4018 | enum SortJavaStaticImportOptions : int8_t { |
4019 | /// Static imports are placed before non-static imports. |
4020 | /// \code{.java} |
4021 | /// import static org.example.function1; |
4022 | /// |
4023 | /// import org.example.ClassA; |
4024 | /// \endcode |
4025 | SJSIO_Before, |
4026 | /// Static imports are placed after non-static imports. |
4027 | /// \code{.java} |
4028 | /// import org.example.ClassA; |
4029 | /// |
4030 | /// import static org.example.function1; |
4031 | /// \endcode |
4032 | SJSIO_After, |
4033 | }; |
4034 | |
4035 | /// When sorting Java imports, by default static imports are placed before |
4036 | /// non-static imports. If ``JavaStaticImportAfterImport`` is ``After``, |
4037 | /// static imports are placed after non-static imports. |
4038 | /// \version 12 |
4039 | SortJavaStaticImportOptions SortJavaStaticImport; |
4040 | |
4041 | /// Using declaration sorting options. |
4042 | enum SortUsingDeclarationsOptions : int8_t { |
4043 | /// Using declarations are never sorted. |
4044 | /// \code |
4045 | /// using std::chrono::duration_cast; |
4046 | /// using std::move; |
4047 | /// using boost::regex; |
4048 | /// using boost::regex_constants::icase; |
4049 | /// using std::string; |
4050 | /// \endcode |
4051 | SUD_Never, |
4052 | /// Using declarations are sorted in the order defined as follows: |
4053 | /// Split the strings by "::" and discard any initial empty strings. Sort |
4054 | /// the lists of names lexicographically, and within those groups, names are |
4055 | /// in case-insensitive lexicographic order. |
4056 | /// \code |
4057 | /// using boost::regex; |
4058 | /// using boost::regex_constants::icase; |
4059 | /// using std::chrono::duration_cast; |
4060 | /// using std::move; |
4061 | /// using std::string; |
4062 | /// \endcode |
4063 | SUD_Lexicographic, |
4064 | /// Using declarations are sorted in the order defined as follows: |
4065 | /// Split the strings by "::" and discard any initial empty strings. The |
4066 | /// last element of each list is a non-namespace name; all others are |
4067 | /// namespace names. Sort the lists of names lexicographically, where the |
4068 | /// sort order of individual names is that all non-namespace names come |
4069 | /// before all namespace names, and within those groups, names are in |
4070 | /// case-insensitive lexicographic order. |
4071 | /// \code |
4072 | /// using boost::regex; |
4073 | /// using boost::regex_constants::icase; |
4074 | /// using std::move; |
4075 | /// using std::string; |
4076 | /// using std::chrono::duration_cast; |
4077 | /// \endcode |
4078 | SUD_LexicographicNumeric, |
4079 | }; |
4080 | |
4081 | /// Controls if and how clang-format will sort using declarations. |
4082 | /// \version 5 |
4083 | SortUsingDeclarationsOptions SortUsingDeclarations; |
4084 | |
4085 | /// If ``true``, a space is inserted after C style casts. |
4086 | /// \code |
4087 | /// true: false: |
4088 | /// (int) i; vs. (int)i; |
4089 | /// \endcode |
4090 | /// \version 3.5 |
4091 | bool SpaceAfterCStyleCast; |
4092 | |
4093 | /// If ``true``, a space is inserted after the logical not operator (``!``). |
4094 | /// \code |
4095 | /// true: false: |
4096 | /// ! someExpression(); vs. !someExpression(); |
4097 | /// \endcode |
4098 | /// \version 9 |
4099 | bool SpaceAfterLogicalNot; |
4100 | |
4101 | /// If \c true, a space will be inserted after the 'template' keyword. |
4102 | /// \code |
4103 | /// true: false: |
4104 | /// template <int> void foo(); vs. template<int> void foo(); |
4105 | /// \endcode |
4106 | /// \version 4 |
4107 | bool SpaceAfterTemplateKeyword; |
4108 | |
4109 | /// Different ways to put a space before opening parentheses. |
4110 | enum : int8_t { |
4111 | /// Don't ensure spaces around pointer qualifiers and use PointerAlignment |
4112 | /// instead. |
4113 | /// \code |
4114 | /// PointerAlignment: Left PointerAlignment: Right |
4115 | /// void* const* x = NULL; vs. void *const *x = NULL; |
4116 | /// \endcode |
4117 | SAPQ_Default, |
4118 | /// Ensure that there is a space before pointer qualifiers. |
4119 | /// \code |
4120 | /// PointerAlignment: Left PointerAlignment: Right |
4121 | /// void* const* x = NULL; vs. void * const *x = NULL; |
4122 | /// \endcode |
4123 | SAPQ_Before, |
4124 | /// Ensure that there is a space after pointer qualifiers. |
4125 | /// \code |
4126 | /// PointerAlignment: Left PointerAlignment: Right |
4127 | /// void* const * x = NULL; vs. void *const *x = NULL; |
4128 | /// \endcode |
4129 | SAPQ_After, |
4130 | /// Ensure that there is a space both before and after pointer qualifiers. |
4131 | /// \code |
4132 | /// PointerAlignment: Left PointerAlignment: Right |
4133 | /// void* const * x = NULL; vs. void * const *x = NULL; |
4134 | /// \endcode |
4135 | SAPQ_Both, |
4136 | }; |
4137 | |
4138 | /// Defines in which cases to put a space before or after pointer qualifiers |
4139 | /// \version 12 |
4140 | SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers; |
4141 | |
4142 | /// If ``false``, spaces will be removed before assignment operators. |
4143 | /// \code |
4144 | /// true: false: |
4145 | /// int a = 5; vs. int a= 5; |
4146 | /// a += 42; a+= 42; |
4147 | /// \endcode |
4148 | /// \version 3.7 |
4149 | bool SpaceBeforeAssignmentOperators; |
4150 | |
4151 | /// If ``false``, spaces will be removed before case colon. |
4152 | /// \code |
4153 | /// true: false |
4154 | /// switch (x) { vs. switch (x) { |
4155 | /// case 1 : break; case 1: break; |
4156 | /// } } |
4157 | /// \endcode |
4158 | /// \version 12 |
4159 | bool SpaceBeforeCaseColon; |
4160 | |
4161 | /// If ``true``, a space will be inserted before a C++11 braced list |
4162 | /// used to initialize an object (after the preceding identifier or type). |
4163 | /// \code |
4164 | /// true: false: |
4165 | /// Foo foo { bar }; vs. Foo foo{ bar }; |
4166 | /// Foo {}; Foo{}; |
4167 | /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 }; |
4168 | /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 }; |
4169 | /// \endcode |
4170 | /// \version 7 |
4171 | bool SpaceBeforeCpp11BracedList; |
4172 | |
4173 | /// If ``false``, spaces will be removed before constructor initializer |
4174 | /// colon. |
4175 | /// \code |
4176 | /// true: false: |
4177 | /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {} |
4178 | /// \endcode |
4179 | /// \version 7 |
4180 | bool SpaceBeforeCtorInitializerColon; |
4181 | |
4182 | /// If ``false``, spaces will be removed before inheritance colon. |
4183 | /// \code |
4184 | /// true: false: |
4185 | /// class Foo : Bar {} vs. class Foo: Bar {} |
4186 | /// \endcode |
4187 | /// \version 7 |
4188 | bool SpaceBeforeInheritanceColon; |
4189 | |
4190 | /// If ``true``, a space will be added before a JSON colon. For other |
4191 | /// languages, e.g. JavaScript, use ``SpacesInContainerLiterals`` instead. |
4192 | /// \code |
4193 | /// true: false: |
4194 | /// { { |
4195 | /// "key" : "value" vs. "key": "value" |
4196 | /// } } |
4197 | /// \endcode |
4198 | /// \version 17 |
4199 | bool SpaceBeforeJsonColon; |
4200 | |
4201 | /// Different ways to put a space before opening parentheses. |
4202 | enum SpaceBeforeParensStyle : int8_t { |
4203 | /// This is **deprecated** and replaced by ``Custom`` below, with all |
4204 | /// ``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to |
4205 | /// ``false``. |
4206 | SBPO_Never, |
4207 | /// Put a space before opening parentheses only after control statement |
4208 | /// keywords (``for/if/while...``). |
4209 | /// \code |
4210 | /// void f() { |
4211 | /// if (true) { |
4212 | /// f(); |
4213 | /// } |
4214 | /// } |
4215 | /// \endcode |
4216 | SBPO_ControlStatements, |
4217 | /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to |
4218 | /// ForEach and If macros. This is useful in projects where ForEach/If |
4219 | /// macros are treated as function calls instead of control statements. |
4220 | /// ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for |
4221 | /// backward compatibility. |
4222 | /// \code |
4223 | /// void f() { |
4224 | /// Q_FOREACH(...) { |
4225 | /// f(); |
4226 | /// } |
4227 | /// } |
4228 | /// \endcode |
4229 | SBPO_ControlStatementsExceptControlMacros, |
4230 | /// Put a space before opening parentheses only if the parentheses are not |
4231 | /// empty i.e. '()' |
4232 | /// \code |
4233 | /// void() { |
4234 | /// if (true) { |
4235 | /// f(); |
4236 | /// g (x, y, z); |
4237 | /// } |
4238 | /// } |
4239 | /// \endcode |
4240 | SBPO_NonEmptyParentheses, |
4241 | /// Always put a space before opening parentheses, except when it's |
4242 | /// prohibited by the syntax rules (in function-like macro definitions) or |
4243 | /// when determined by other style rules (after unary operators, opening |
4244 | /// parentheses, etc.) |
4245 | /// \code |
4246 | /// void f () { |
4247 | /// if (true) { |
4248 | /// f (); |
4249 | /// } |
4250 | /// } |
4251 | /// \endcode |
4252 | SBPO_Always, |
4253 | /// Configure each individual space before parentheses in |
4254 | /// ``SpaceBeforeParensOptions``. |
4255 | SBPO_Custom, |
4256 | }; |
4257 | |
4258 | /// Defines in which cases to put a space before opening parentheses. |
4259 | /// \version 3.5 |
4260 | SpaceBeforeParensStyle SpaceBeforeParens; |
4261 | |
4262 | /// Precise control over the spacing before parentheses. |
4263 | /// \code |
4264 | /// # Should be declared this way: |
4265 | /// SpaceBeforeParens: Custom |
4266 | /// SpaceBeforeParensOptions: |
4267 | /// AfterControlStatements: true |
4268 | /// AfterFunctionDefinitionName: true |
4269 | /// \endcode |
4270 | struct SpaceBeforeParensCustom { |
4271 | /// If ``true``, put space between control statement keywords |
4272 | /// (for/if/while...) and opening parentheses. |
4273 | /// \code |
4274 | /// true: false: |
4275 | /// if (...) {} vs. if(...) {} |
4276 | /// \endcode |
4277 | bool AfterControlStatements; |
4278 | /// If ``true``, put space between foreach macros and opening parentheses. |
4279 | /// \code |
4280 | /// true: false: |
4281 | /// FOREACH (...) vs. FOREACH(...) |
4282 | /// <loop-body> <loop-body> |
4283 | /// \endcode |
4284 | bool AfterForeachMacros; |
4285 | /// If ``true``, put a space between function declaration name and opening |
4286 | /// parentheses. |
4287 | /// \code |
4288 | /// true: false: |
4289 | /// void f (); vs. void f(); |
4290 | /// \endcode |
4291 | bool AfterFunctionDeclarationName; |
4292 | /// If ``true``, put a space between function definition name and opening |
4293 | /// parentheses. |
4294 | /// \code |
4295 | /// true: false: |
4296 | /// void f () {} vs. void f() {} |
4297 | /// \endcode |
4298 | bool AfterFunctionDefinitionName; |
4299 | /// If ``true``, put space between if macros and opening parentheses. |
4300 | /// \code |
4301 | /// true: false: |
4302 | /// IF (...) vs. IF(...) |
4303 | /// <conditional-body> <conditional-body> |
4304 | /// \endcode |
4305 | bool AfterIfMacros; |
4306 | /// If ``true``, put a space between operator overloading and opening |
4307 | /// parentheses. |
4308 | /// \code |
4309 | /// true: false: |
4310 | /// void operator++ (int a); vs. void operator++(int a); |
4311 | /// object.operator++ (10); object.operator++(10); |
4312 | /// \endcode |
4313 | bool AfterOverloadedOperator; |
4314 | /// If ``true``, put a space between operator ``new``/``delete`` and opening |
4315 | /// parenthesis. |
4316 | /// \code |
4317 | /// true: false: |
4318 | /// new (buf) T; vs. new(buf) T; |
4319 | /// delete (buf) T; delete(buf) T; |
4320 | /// \endcode |
4321 | bool AfterPlacementOperator; |
4322 | /// If ``true``, put space between requires keyword in a requires clause and |
4323 | /// opening parentheses, if there is one. |
4324 | /// \code |
4325 | /// true: false: |
4326 | /// template<typename T> vs. template<typename T> |
4327 | /// requires (A<T> && B<T>) requires(A<T> && B<T>) |
4328 | /// ... ... |
4329 | /// \endcode |
4330 | bool AfterRequiresInClause; |
4331 | /// If ``true``, put space between requires keyword in a requires expression |
4332 | /// and opening parentheses. |
4333 | /// \code |
4334 | /// true: false: |
4335 | /// template<typename T> vs. template<typename T> |
4336 | /// concept C = requires (T t) { concept C = requires(T t) { |
4337 | /// ... ... |
4338 | /// } } |
4339 | /// \endcode |
4340 | bool AfterRequiresInExpression; |
4341 | /// If ``true``, put a space before opening parentheses only if the |
4342 | /// parentheses are not empty. |
4343 | /// \code |
4344 | /// true: false: |
4345 | /// void f (int a); vs. void f(); |
4346 | /// f (a); f(); |
4347 | /// \endcode |
4348 | bool BeforeNonEmptyParentheses; |
4349 | |
4350 | SpaceBeforeParensCustom() |
4351 | : AfterControlStatements(false), AfterForeachMacros(false), |
4352 | AfterFunctionDeclarationName(false), |
4353 | AfterFunctionDefinitionName(false), AfterIfMacros(false), |
4354 | AfterOverloadedOperator(false), AfterPlacementOperator(true), |
4355 | AfterRequiresInClause(false), AfterRequiresInExpression(false), |
4356 | BeforeNonEmptyParentheses(false) {} |
4357 | |
4358 | bool operator==(const SpaceBeforeParensCustom &Other) const { |
4359 | return AfterControlStatements == Other.AfterControlStatements && |
4360 | AfterForeachMacros == Other.AfterForeachMacros && |
4361 | AfterFunctionDeclarationName == |
4362 | Other.AfterFunctionDeclarationName && |
4363 | AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName && |
4364 | AfterIfMacros == Other.AfterIfMacros && |
4365 | AfterOverloadedOperator == Other.AfterOverloadedOperator && |
4366 | AfterPlacementOperator == Other.AfterPlacementOperator && |
4367 | AfterRequiresInClause == Other.AfterRequiresInClause && |
4368 | AfterRequiresInExpression == Other.AfterRequiresInExpression && |
4369 | BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses; |
4370 | } |
4371 | }; |
4372 | |
4373 | /// Control of individual space before parentheses. |
4374 | /// |
4375 | /// If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify |
4376 | /// how each individual space before parentheses case should be handled. |
4377 | /// Otherwise, this is ignored. |
4378 | /// \code{.yaml} |
4379 | /// # Example of usage: |
4380 | /// SpaceBeforeParens: Custom |
4381 | /// SpaceBeforeParensOptions: |
4382 | /// AfterControlStatements: true |
4383 | /// AfterFunctionDefinitionName: true |
4384 | /// \endcode |
4385 | /// \version 14 |
4386 | SpaceBeforeParensCustom SpaceBeforeParensOptions; |
4387 | |
4388 | /// If ``true``, spaces will be before ``[``. |
4389 | /// Lambdas will not be affected. Only the first ``[`` will get a space added. |
4390 | /// \code |
4391 | /// true: false: |
4392 | /// int a [5]; vs. int a[5]; |
4393 | /// int a [5][5]; vs. int a[5][5]; |
4394 | /// \endcode |
4395 | /// \version 10 |
4396 | bool SpaceBeforeSquareBrackets; |
4397 | |
4398 | /// If ``false``, spaces will be removed before range-based for loop |
4399 | /// colon. |
4400 | /// \code |
4401 | /// true: false: |
4402 | /// for (auto v : values) {} vs. for(auto v: values) {} |
4403 | /// \endcode |
4404 | /// \version 7 |
4405 | bool SpaceBeforeRangeBasedForLoopColon; |
4406 | |
4407 | /// If ``true``, spaces will be inserted into ``{}``. |
4408 | /// \code |
4409 | /// true: false: |
4410 | /// void f() { } vs. void f() {} |
4411 | /// while (true) { } while (true) {} |
4412 | /// \endcode |
4413 | /// \version 10 |
4414 | bool SpaceInEmptyBlock; |
4415 | |
4416 | /// If ``true``, spaces may be inserted into ``()``. |
4417 | /// This option is **deprecated**. See ``InEmptyParentheses`` of |
4418 | /// ``SpacesInParensOptions``. |
4419 | /// \version 3.7 |
4420 | // bool SpaceInEmptyParentheses; |
4421 | |
4422 | /// The number of spaces before trailing line comments |
4423 | /// (``//`` - comments). |
4424 | /// |
4425 | /// This does not affect trailing block comments (``/*`` - comments) as those |
4426 | /// commonly have different usage patterns and a number of special cases. In |
4427 | /// the case of Verilog, it doesn't affect a comment right after the opening |
4428 | /// parenthesis in the port or parameter list in a module header, because it |
4429 | /// is probably for the port on the following line instead of the parenthesis |
4430 | /// it follows. |
4431 | /// \code |
4432 | /// SpacesBeforeTrailingComments: 3 |
4433 | /// void f() { |
4434 | /// if (true) { // foo1 |
4435 | /// f(); // bar |
4436 | /// } // foo |
4437 | /// } |
4438 | /// \endcode |
4439 | /// \version 3.7 |
4440 | unsigned ; |
4441 | |
4442 | /// Styles for adding spacing after ``<`` and before ``>`` |
4443 | /// in template argument lists. |
4444 | enum SpacesInAnglesStyle : int8_t { |
4445 | /// Remove spaces after ``<`` and before ``>``. |
4446 | /// \code |
4447 | /// static_cast<int>(arg); |
4448 | /// std::function<void(int)> fct; |
4449 | /// \endcode |
4450 | SIAS_Never, |
4451 | /// Add spaces after ``<`` and before ``>``. |
4452 | /// \code |
4453 | /// static_cast< int >(arg); |
4454 | /// std::function< void(int) > fct; |
4455 | /// \endcode |
4456 | SIAS_Always, |
4457 | /// Keep a single space after ``<`` and before ``>`` if any spaces were |
4458 | /// present. Option ``Standard: Cpp03`` takes precedence. |
4459 | SIAS_Leave |
4460 | }; |
4461 | /// The SpacesInAnglesStyle to use for template argument lists. |
4462 | /// \version 3.4 |
4463 | SpacesInAnglesStyle SpacesInAngles; |
4464 | |
4465 | /// If ``true``, spaces will be inserted around if/for/switch/while |
4466 | /// conditions. |
4467 | /// This option is **deprecated**. See ``InConditionalStatements`` of |
4468 | /// ``SpacesInParensOptions``. |
4469 | /// \version 10 |
4470 | // bool SpacesInConditionalStatement; |
4471 | |
4472 | /// If ``true``, spaces are inserted inside container literals (e.g. ObjC and |
4473 | /// Javascript array and dict literals). For JSON, use |
4474 | /// ``SpaceBeforeJsonColon`` instead. |
4475 | /// \code{.js} |
4476 | /// true: false: |
4477 | /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3]; |
4478 | /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3}); |
4479 | /// \endcode |
4480 | /// \version 3.7 |
4481 | bool SpacesInContainerLiterals; |
4482 | |
4483 | /// If ``true``, spaces may be inserted into C style casts. |
4484 | /// This option is **deprecated**. See ``InCStyleCasts`` of |
4485 | /// ``SpacesInParensOptions``. |
4486 | /// \version 3.7 |
4487 | // bool SpacesInCStyleCastParentheses; |
4488 | |
4489 | /// Control of spaces within a single line comment. |
4490 | struct { |
4491 | /// The minimum number of spaces at the start of the comment. |
4492 | unsigned ; |
4493 | /// The maximum number of spaces at the start of the comment. |
4494 | unsigned ; |
4495 | }; |
4496 | |
4497 | /// How many spaces are allowed at the start of a line comment. To disable the |
4498 | /// maximum set it to ``-1``, apart from that the maximum takes precedence |
4499 | /// over the minimum. |
4500 | /// \code |
4501 | /// Minimum = 1 |
4502 | /// Maximum = -1 |
4503 | /// // One space is forced |
4504 | /// |
4505 | /// // but more spaces are possible |
4506 | /// |
4507 | /// Minimum = 0 |
4508 | /// Maximum = 0 |
4509 | /// //Forces to start every comment directly after the slashes |
4510 | /// \endcode |
4511 | /// |
4512 | /// Note that in line comment sections the relative indent of the subsequent |
4513 | /// lines is kept, that means the following: |
4514 | /// \code |
4515 | /// before: after: |
4516 | /// Minimum: 1 |
4517 | /// //if (b) { // if (b) { |
4518 | /// // return true; // return true; |
4519 | /// //} // } |
4520 | /// |
4521 | /// Maximum: 0 |
4522 | /// /// List: ///List: |
4523 | /// /// - Foo /// - Foo |
4524 | /// /// - Bar /// - Bar |
4525 | /// \endcode |
4526 | /// |
4527 | /// This option has only effect if ``ReflowComments`` is set to ``true``. |
4528 | /// \version 13 |
4529 | SpacesInLineComment ; |
4530 | |
4531 | /// Different ways to put a space before opening and closing parentheses. |
4532 | enum SpacesInParensStyle : int8_t { |
4533 | /// Never put a space in parentheses. |
4534 | /// \code |
4535 | /// void f() { |
4536 | /// if(true) { |
4537 | /// f(); |
4538 | /// } |
4539 | /// } |
4540 | /// \endcode |
4541 | SIPO_Never, |
4542 | /// Configure each individual space in parentheses in |
4543 | /// `SpacesInParensOptions`. |
4544 | SIPO_Custom, |
4545 | }; |
4546 | |
4547 | /// If ``true``, spaces will be inserted after ``(`` and before ``)``. |
4548 | /// This option is **deprecated**. The previous behavior is preserved by using |
4549 | /// ``SpacesInParens`` with ``Custom`` and by setting all |
4550 | /// ``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and |
4551 | /// ``InEmptyParentheses``. |
4552 | /// \version 3.7 |
4553 | // bool SpacesInParentheses; |
4554 | |
4555 | /// Defines in which cases spaces will be inserted after ``(`` and before |
4556 | /// ``)``. |
4557 | /// \version 17 |
4558 | SpacesInParensStyle SpacesInParens; |
4559 | |
4560 | /// Precise control over the spacing in parentheses. |
4561 | /// \code |
4562 | /// # Should be declared this way: |
4563 | /// SpacesInParens: Custom |
4564 | /// SpacesInParensOptions: |
4565 | /// InConditionalStatements: true |
4566 | /// Other: true |
4567 | /// \endcode |
4568 | struct SpacesInParensCustom { |
4569 | /// Put a space in parentheses only inside conditional statements |
4570 | /// (``for/if/while/switch...``). |
4571 | /// \code |
4572 | /// true: false: |
4573 | /// if ( a ) { ... } vs. if (a) { ... } |
4574 | /// while ( i < 5 ) { ... } while (i < 5) { ... } |
4575 | /// \endcode |
4576 | bool InConditionalStatements; |
4577 | /// Put a space in C style casts. |
4578 | /// \code |
4579 | /// true: false: |
4580 | /// x = ( int32 )y vs. x = (int32)y |
4581 | /// \endcode |
4582 | bool InCStyleCasts; |
4583 | /// Put a space in parentheses only if the parentheses are empty i.e. '()' |
4584 | /// \code |
4585 | /// true: false: |
4586 | /// void f( ) { vs. void f() { |
4587 | /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()}; |
4588 | /// if (true) { if (true) { |
4589 | /// f( ); f(); |
4590 | /// } } |
4591 | /// } } |
4592 | /// \endcode |
4593 | bool InEmptyParentheses; |
4594 | /// Put a space in parentheses not covered by preceding options. |
4595 | /// \code |
4596 | /// true: false: |
4597 | /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; |
4598 | /// \endcode |
4599 | bool Other; |
4600 | |
4601 | SpacesInParensCustom() |
4602 | : InConditionalStatements(false), InCStyleCasts(false), |
4603 | InEmptyParentheses(false), Other(false) {} |
4604 | |
4605 | SpacesInParensCustom(bool InConditionalStatements, bool InCStyleCasts, |
4606 | bool InEmptyParentheses, bool Other) |
4607 | : InConditionalStatements(InConditionalStatements), |
4608 | InCStyleCasts(InCStyleCasts), InEmptyParentheses(InEmptyParentheses), |
4609 | Other(Other) {} |
4610 | |
4611 | bool operator==(const SpacesInParensCustom &R) const { |
4612 | return InConditionalStatements == R.InConditionalStatements && |
4613 | InCStyleCasts == R.InCStyleCasts && |
4614 | InEmptyParentheses == R.InEmptyParentheses && Other == R.Other; |
4615 | } |
4616 | bool operator!=(const SpacesInParensCustom &R) const { |
4617 | return !(*this == R); |
4618 | } |
4619 | }; |
4620 | |
4621 | /// Control of individual spaces in parentheses. |
4622 | /// |
4623 | /// If ``SpacesInParens`` is set to ``Custom``, use this to specify |
4624 | /// how each individual space in parentheses case should be handled. |
4625 | /// Otherwise, this is ignored. |
4626 | /// \code{.yaml} |
4627 | /// # Example of usage: |
4628 | /// SpacesInParens: Custom |
4629 | /// SpacesInParensOptions: |
4630 | /// InConditionalStatements: true |
4631 | /// InEmptyParentheses: true |
4632 | /// \endcode |
4633 | /// \version 17 |
4634 | SpacesInParensCustom SpacesInParensOptions; |
4635 | |
4636 | /// If ``true``, spaces will be inserted after ``[`` and before ``]``. |
4637 | /// Lambdas without arguments or unspecified size array declarations will not |
4638 | /// be affected. |
4639 | /// \code |
4640 | /// true: false: |
4641 | /// int a[ 5 ]; vs. int a[5]; |
4642 | /// std::unique_ptr<int[]> foo() {} // Won't be affected |
4643 | /// \endcode |
4644 | /// \version 3.7 |
4645 | bool SpacesInSquareBrackets; |
4646 | |
4647 | /// Supported language standards for parsing and formatting C++ constructs. |
4648 | /// \code |
4649 | /// Latest: vector<set<int>> |
4650 | /// c++03 vs. vector<set<int> > |
4651 | /// \endcode |
4652 | /// |
4653 | /// The correct way to spell a specific language version is e.g. ``c++11``. |
4654 | /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated. |
4655 | enum LanguageStandard : int8_t { |
4656 | /// Parse and format as C++03. |
4657 | /// ``Cpp03`` is a deprecated alias for ``c++03`` |
4658 | LS_Cpp03, // c++03 |
4659 | /// Parse and format as C++11. |
4660 | LS_Cpp11, // c++11 |
4661 | /// Parse and format as C++14. |
4662 | LS_Cpp14, // c++14 |
4663 | /// Parse and format as C++17. |
4664 | LS_Cpp17, // c++17 |
4665 | /// Parse and format as C++20. |
4666 | LS_Cpp20, // c++20 |
4667 | /// Parse and format using the latest supported language version. |
4668 | /// ``Cpp11`` is a deprecated alias for ``Latest`` |
4669 | LS_Latest, |
4670 | /// Automatic detection based on the input. |
4671 | LS_Auto, |
4672 | }; |
4673 | |
4674 | /// Parse and format C++ constructs compatible with this standard. |
4675 | /// \code |
4676 | /// c++03: latest: |
4677 | /// vector<set<int> > x; vs. vector<set<int>> x; |
4678 | /// \endcode |
4679 | /// \version 3.7 |
4680 | LanguageStandard Standard; |
4681 | |
4682 | /// Macros which are ignored in front of a statement, as if they were an |
4683 | /// attribute. So that they are not parsed as identifier, for example for Qts |
4684 | /// emit. |
4685 | /// \code |
4686 | /// AlignConsecutiveDeclarations: true |
4687 | /// StatementAttributeLikeMacros: [] |
4688 | /// unsigned char data = 'x'; |
4689 | /// emit signal(data); // This is parsed as variable declaration. |
4690 | /// |
4691 | /// AlignConsecutiveDeclarations: true |
4692 | /// StatementAttributeLikeMacros: [emit] |
4693 | /// unsigned char data = 'x'; |
4694 | /// emit signal(data); // Now it's fine again. |
4695 | /// \endcode |
4696 | /// \version 12 |
4697 | std::vector<std::string> StatementAttributeLikeMacros; |
4698 | |
4699 | /// A vector of macros that should be interpreted as complete |
4700 | /// statements. |
4701 | /// |
4702 | /// Typical macros are expressions, and require a semi-colon to be |
4703 | /// added; sometimes this is not the case, and this allows to make |
4704 | /// clang-format aware of such cases. |
4705 | /// |
4706 | /// For example: Q_UNUSED |
4707 | /// \version 8 |
4708 | std::vector<std::string> StatementMacros; |
4709 | |
4710 | /// The number of columns used for tab stops. |
4711 | /// \version 3.7 |
4712 | unsigned TabWidth; |
4713 | |
4714 | /// A vector of non-keyword identifiers that should be interpreted as type |
4715 | /// names. |
4716 | /// |
4717 | /// A ``*``, ``&``, or ``&&`` between a type name and another non-keyword |
4718 | /// identifier is annotated as a pointer or reference token instead of a |
4719 | /// binary operator. |
4720 | /// |
4721 | /// \version 17 |
4722 | std::vector<std::string> TypeNames; |
4723 | |
4724 | /// \brief A vector of macros that should be interpreted as type declarations |
4725 | /// instead of as function calls. |
4726 | /// |
4727 | /// These are expected to be macros of the form: |
4728 | /// \code |
4729 | /// STACK_OF(...) |
4730 | /// \endcode |
4731 | /// |
4732 | /// In the .clang-format configuration file, this can be configured like: |
4733 | /// \code{.yaml} |
4734 | /// TypenameMacros: ['STACK_OF', 'LIST'] |
4735 | /// \endcode |
4736 | /// |
4737 | /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY. |
4738 | /// \version 9 |
4739 | std::vector<std::string> TypenameMacros; |
4740 | |
4741 | /// This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``. |
4742 | /// \version 10 |
4743 | // bool UseCRLF; |
4744 | |
4745 | /// Different ways to use tab in formatting. |
4746 | enum UseTabStyle : int8_t { |
4747 | /// Never use tab. |
4748 | UT_Never, |
4749 | /// Use tabs only for indentation. |
4750 | UT_ForIndentation, |
4751 | /// Fill all leading whitespace with tabs, and use spaces for alignment that |
4752 | /// appears within a line (e.g. consecutive assignments and declarations). |
4753 | UT_ForContinuationAndIndentation, |
4754 | /// Use tabs for line continuation and indentation, and spaces for |
4755 | /// alignment. |
4756 | UT_AlignWithSpaces, |
4757 | /// Use tabs whenever we need to fill whitespace that spans at least from |
4758 | /// one tab stop to the next one. |
4759 | UT_Always |
4760 | }; |
4761 | |
4762 | /// The way to use tab characters in the resulting file. |
4763 | /// \version 3.7 |
4764 | UseTabStyle UseTab; |
4765 | |
4766 | /// For Verilog, put each port on its own line in module instantiations. |
4767 | /// \code |
4768 | /// true: |
4769 | /// ffnand ff1(.q(), |
4770 | /// .qbar(out1), |
4771 | /// .clear(in1), |
4772 | /// .preset(in2)); |
4773 | /// |
4774 | /// false: |
4775 | /// ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2)); |
4776 | /// \endcode |
4777 | /// \version 17 |
4778 | bool VerilogBreakBetweenInstancePorts; |
4779 | |
4780 | /// A vector of macros which are whitespace-sensitive and should not |
4781 | /// be touched. |
4782 | /// |
4783 | /// These are expected to be macros of the form: |
4784 | /// \code |
4785 | /// STRINGIZE(...) |
4786 | /// \endcode |
4787 | /// |
4788 | /// In the .clang-format configuration file, this can be configured like: |
4789 | /// \code{.yaml} |
4790 | /// WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE'] |
4791 | /// \endcode |
4792 | /// |
4793 | /// For example: BOOST_PP_STRINGIZE |
4794 | /// \version 11 |
4795 | std::vector<std::string> WhitespaceSensitiveMacros; |
4796 | |
4797 | bool operator==(const FormatStyle &R) const { |
4798 | return AccessModifierOffset == R.AccessModifierOffset && |
4799 | AlignAfterOpenBracket == R.AlignAfterOpenBracket && |
4800 | AlignArrayOfStructures == R.AlignArrayOfStructures && |
4801 | AlignConsecutiveAssignments == R.AlignConsecutiveAssignments && |
4802 | AlignConsecutiveBitFields == R.AlignConsecutiveBitFields && |
4803 | AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations && |
4804 | AlignConsecutiveMacros == R.AlignConsecutiveMacros && |
4805 | AlignConsecutiveShortCaseStatements == |
4806 | R.AlignConsecutiveShortCaseStatements && |
4807 | AlignEscapedNewlines == R.AlignEscapedNewlines && |
4808 | AlignOperands == R.AlignOperands && |
4809 | AlignTrailingComments == R.AlignTrailingComments && |
4810 | AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine && |
4811 | AllowAllParametersOfDeclarationOnNextLine == |
4812 | R.AllowAllParametersOfDeclarationOnNextLine && |
4813 | AllowBreakBeforeNoexceptSpecifier == |
4814 | R.AllowBreakBeforeNoexceptSpecifier && |
4815 | AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine && |
4816 | AllowShortCaseLabelsOnASingleLine == |
4817 | R.AllowShortCaseLabelsOnASingleLine && |
4818 | AllowShortCompoundRequirementOnASingleLine == |
4819 | R.AllowShortCompoundRequirementOnASingleLine && |
4820 | AllowShortEnumsOnASingleLine == R.AllowShortEnumsOnASingleLine && |
4821 | AllowShortFunctionsOnASingleLine == |
4822 | R.AllowShortFunctionsOnASingleLine && |
4823 | AllowShortIfStatementsOnASingleLine == |
4824 | R.AllowShortIfStatementsOnASingleLine && |
4825 | AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine && |
4826 | AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine && |
4827 | AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType && |
4828 | AlwaysBreakBeforeMultilineStrings == |
4829 | R.AlwaysBreakBeforeMultilineStrings && |
4830 | AttributeMacros == R.AttributeMacros && |
4831 | BinPackArguments == R.BinPackArguments && |
4832 | BinPackParameters == R.BinPackParameters && |
4833 | BitFieldColonSpacing == R.BitFieldColonSpacing && |
4834 | BracedInitializerIndentWidth == R.BracedInitializerIndentWidth && |
4835 | BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals && |
4836 | BreakAfterAttributes == R.BreakAfterAttributes && |
4837 | BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations && |
4838 | BreakArrays == R.BreakArrays && |
4839 | BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators && |
4840 | BreakBeforeBraces == R.BreakBeforeBraces && |
4841 | BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations && |
4842 | BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon && |
4843 | BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators && |
4844 | BreakConstructorInitializers == R.BreakConstructorInitializers && |
4845 | BreakInheritanceList == R.BreakInheritanceList && |
4846 | BreakStringLiterals == R.BreakStringLiterals && |
4847 | BreakTemplateDeclarations == R.BreakTemplateDeclarations && |
4848 | ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas && |
4849 | CompactNamespaces == R.CompactNamespaces && |
4850 | ConstructorInitializerIndentWidth == |
4851 | R.ConstructorInitializerIndentWidth && |
4852 | ContinuationIndentWidth == R.ContinuationIndentWidth && |
4853 | Cpp11BracedListStyle == R.Cpp11BracedListStyle && |
4854 | DerivePointerAlignment == R.DerivePointerAlignment && |
4855 | DisableFormat == R.DisableFormat && |
4856 | EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier && |
4857 | EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier && |
4858 | ExperimentalAutoDetectBinPacking == |
4859 | R.ExperimentalAutoDetectBinPacking && |
4860 | FixNamespaceComments == R.FixNamespaceComments && |
4861 | ForEachMacros == R.ForEachMacros && |
4862 | IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks && |
4863 | IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories && |
4864 | IncludeStyle.IncludeIsMainRegex == |
4865 | R.IncludeStyle.IncludeIsMainRegex && |
4866 | IncludeStyle.IncludeIsMainSourceRegex == |
4867 | R.IncludeStyle.IncludeIsMainSourceRegex && |
4868 | IncludeStyle.MainIncludeChar == R.IncludeStyle.MainIncludeChar && |
4869 | IndentAccessModifiers == R.IndentAccessModifiers && |
4870 | IndentCaseBlocks == R.IndentCaseBlocks && |
4871 | IndentCaseLabels == R.IndentCaseLabels && |
4872 | IndentExternBlock == R.IndentExternBlock && |
4873 | IndentGotoLabels == R.IndentGotoLabels && |
4874 | IndentPPDirectives == R.IndentPPDirectives && |
4875 | IndentRequiresClause == R.IndentRequiresClause && |
4876 | IndentWidth == R.IndentWidth && |
4877 | IndentWrappedFunctionNames == R.IndentWrappedFunctionNames && |
4878 | InsertBraces == R.InsertBraces && |
4879 | InsertNewlineAtEOF == R.InsertNewlineAtEOF && |
4880 | IntegerLiteralSeparator == R.IntegerLiteralSeparator && |
4881 | JavaImportGroups == R.JavaImportGroups && |
4882 | JavaScriptQuotes == R.JavaScriptQuotes && |
4883 | JavaScriptWrapImports == R.JavaScriptWrapImports && |
4884 | KeepEmptyLinesAtEOF == R.KeepEmptyLinesAtEOF && |
4885 | KeepEmptyLinesAtTheStartOfBlocks == |
4886 | R.KeepEmptyLinesAtTheStartOfBlocks && |
4887 | Language == R.Language && |
4888 | LambdaBodyIndentation == R.LambdaBodyIndentation && |
4889 | LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin && |
4890 | MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros && |
4891 | MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep && |
4892 | NamespaceIndentation == R.NamespaceIndentation && |
4893 | NamespaceMacros == R.NamespaceMacros && |
4894 | ObjCBinPackProtocolList == R.ObjCBinPackProtocolList && |
4895 | ObjCBlockIndentWidth == R.ObjCBlockIndentWidth && |
4896 | ObjCBreakBeforeNestedBlockParam == |
4897 | R.ObjCBreakBeforeNestedBlockParam && |
4898 | ObjCPropertyAttributeOrder == R.ObjCPropertyAttributeOrder && |
4899 | ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty && |
4900 | ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList && |
4901 | PackConstructorInitializers == R.PackConstructorInitializers && |
4902 | PenaltyBreakAssignment == R.PenaltyBreakAssignment && |
4903 | PenaltyBreakBeforeFirstCallParameter == |
4904 | R.PenaltyBreakBeforeFirstCallParameter && |
4905 | PenaltyBreakComment == R.PenaltyBreakComment && |
4906 | PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess && |
4907 | PenaltyBreakOpenParenthesis == R.PenaltyBreakOpenParenthesis && |
4908 | PenaltyBreakScopeResolution == R.PenaltyBreakScopeResolution && |
4909 | PenaltyBreakString == R.PenaltyBreakString && |
4910 | PenaltyBreakTemplateDeclaration == |
4911 | R.PenaltyBreakTemplateDeclaration && |
4912 | PenaltyExcessCharacter == R.PenaltyExcessCharacter && |
4913 | PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine && |
4914 | PointerAlignment == R.PointerAlignment && |
4915 | QualifierAlignment == R.QualifierAlignment && |
4916 | QualifierOrder == R.QualifierOrder && |
4917 | RawStringFormats == R.RawStringFormats && |
4918 | ReferenceAlignment == R.ReferenceAlignment && |
4919 | RemoveBracesLLVM == R.RemoveBracesLLVM && |
4920 | RemoveParentheses == R.RemoveParentheses && |
4921 | RemoveSemicolon == R.RemoveSemicolon && |
4922 | RequiresClausePosition == R.RequiresClausePosition && |
4923 | RequiresExpressionIndentation == R.RequiresExpressionIndentation && |
4924 | SeparateDefinitionBlocks == R.SeparateDefinitionBlocks && |
4925 | ShortNamespaceLines == R.ShortNamespaceLines && |
4926 | SkipMacroDefinitionBody == R.SkipMacroDefinitionBody && |
4927 | SortIncludes == R.SortIncludes && |
4928 | SortJavaStaticImport == R.SortJavaStaticImport && |
4929 | SpaceAfterCStyleCast == R.SpaceAfterCStyleCast && |
4930 | SpaceAfterLogicalNot == R.SpaceAfterLogicalNot && |
4931 | SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword && |
4932 | SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators && |
4933 | SpaceBeforeCaseColon == R.SpaceBeforeCaseColon && |
4934 | SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList && |
4935 | SpaceBeforeCtorInitializerColon == |
4936 | R.SpaceBeforeCtorInitializerColon && |
4937 | SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon && |
4938 | SpaceBeforeJsonColon == R.SpaceBeforeJsonColon && |
4939 | SpaceBeforeParens == R.SpaceBeforeParens && |
4940 | SpaceBeforeParensOptions == R.SpaceBeforeParensOptions && |
4941 | SpaceAroundPointerQualifiers == R.SpaceAroundPointerQualifiers && |
4942 | SpaceBeforeRangeBasedForLoopColon == |
4943 | R.SpaceBeforeRangeBasedForLoopColon && |
4944 | SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets && |
4945 | SpaceInEmptyBlock == R.SpaceInEmptyBlock && |
4946 | SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments && |
4947 | SpacesInAngles == R.SpacesInAngles && |
4948 | SpacesInContainerLiterals == R.SpacesInContainerLiterals && |
4949 | SpacesInLineCommentPrefix.Minimum == |
4950 | R.SpacesInLineCommentPrefix.Minimum && |
4951 | SpacesInLineCommentPrefix.Maximum == |
4952 | R.SpacesInLineCommentPrefix.Maximum && |
4953 | SpacesInParens == R.SpacesInParens && |
4954 | SpacesInParensOptions == R.SpacesInParensOptions && |
4955 | SpacesInSquareBrackets == R.SpacesInSquareBrackets && |
4956 | Standard == R.Standard && |
4957 | StatementAttributeLikeMacros == R.StatementAttributeLikeMacros && |
4958 | StatementMacros == R.StatementMacros && TabWidth == R.TabWidth && |
4959 | TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros && |
4960 | UseTab == R.UseTab && |
4961 | VerilogBreakBetweenInstancePorts == |
4962 | R.VerilogBreakBetweenInstancePorts && |
4963 | WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros; |
4964 | } |
4965 | |
4966 | std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const; |
4967 | |
4968 | // Stores per-language styles. A FormatStyle instance inside has an empty |
4969 | // StyleSet. A FormatStyle instance returned by the Get method has its |
4970 | // StyleSet set to a copy of the originating StyleSet, effectively keeping the |
4971 | // internal representation of that StyleSet alive. |
4972 | // |
4973 | // The memory management and ownership reminds of a birds nest: chicks |
4974 | // leaving the nest take photos of the nest with them. |
4975 | struct FormatStyleSet { |
4976 | typedef std::map<FormatStyle::LanguageKind, FormatStyle> MapType; |
4977 | |
4978 | std::optional<FormatStyle> Get(FormatStyle::LanguageKind Language) const; |
4979 | |
4980 | // Adds \p Style to this FormatStyleSet. Style must not have an associated |
4981 | // FormatStyleSet. |
4982 | // Style.Language should be different than LK_None. If this FormatStyleSet |
4983 | // already contains an entry for Style.Language, that gets replaced with the |
4984 | // passed Style. |
4985 | void Add(FormatStyle Style); |
4986 | |
4987 | // Clears this FormatStyleSet. |
4988 | void Clear(); |
4989 | |
4990 | private: |
4991 | std::shared_ptr<MapType> Styles; |
4992 | }; |
4993 | |
4994 | static FormatStyleSet BuildStyleSetFromConfiguration( |
4995 | const FormatStyle &MainStyle, |
4996 | const std::vector<FormatStyle> &ConfigurationStyles); |
4997 | |
4998 | private: |
4999 | FormatStyleSet StyleSet; |
5000 | |
5001 | friend std::error_code |
5002 | parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style, |
5003 | bool AllowUnknownOptions, |
5004 | llvm::SourceMgr::DiagHandlerTy DiagHandler, |
5005 | void *DiagHandlerCtxt); |
5006 | }; |
5007 | |
5008 | /// Returns a format style complying with the LLVM coding standards: |
5009 | /// http://llvm.org/docs/CodingStandards.html. |
5010 | FormatStyle getLLVMStyle( |
5011 | FormatStyle::LanguageKind Language = FormatStyle::LanguageKind::LK_Cpp); |
5012 | |
5013 | /// Returns a format style complying with one of Google's style guides: |
5014 | /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml. |
5015 | /// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml. |
5016 | /// https://developers.google.com/protocol-buffers/docs/style. |
5017 | FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language); |
5018 | |
5019 | /// Returns a format style complying with Chromium's style guide: |
5020 | /// http://www.chromium.org/developers/coding-style. |
5021 | FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language); |
5022 | |
5023 | /// Returns a format style complying with Mozilla's style guide: |
5024 | /// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html. |
5025 | FormatStyle getMozillaStyle(); |
5026 | |
5027 | /// Returns a format style complying with Webkit's style guide: |
5028 | /// http://www.webkit.org/coding/coding-style.html |
5029 | FormatStyle getWebKitStyle(); |
5030 | |
5031 | /// Returns a format style complying with GNU Coding Standards: |
5032 | /// http://www.gnu.org/prep/standards/standards.html |
5033 | FormatStyle getGNUStyle(); |
5034 | |
5035 | /// Returns a format style complying with Microsoft style guide: |
5036 | /// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017 |
5037 | FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language); |
5038 | |
5039 | FormatStyle getClangFormatStyle(); |
5040 | |
5041 | /// Returns style indicating formatting should be not applied at all. |
5042 | FormatStyle getNoStyle(); |
5043 | |
5044 | /// Gets a predefined style for the specified language by name. |
5045 | /// |
5046 | /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are |
5047 | /// compared case-insensitively. |
5048 | /// |
5049 | /// Returns ``true`` if the Style has been set. |
5050 | bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, |
5051 | FormatStyle *Style); |
5052 | |
5053 | /// Parse configuration from YAML-formatted text. |
5054 | /// |
5055 | /// Style->Language is used to get the base style, if the ``BasedOnStyle`` |
5056 | /// option is present. |
5057 | /// |
5058 | /// The FormatStyleSet of Style is reset. |
5059 | /// |
5060 | /// When ``BasedOnStyle`` is not present, options not present in the YAML |
5061 | /// document, are retained in \p Style. |
5062 | /// |
5063 | /// If AllowUnknownOptions is true, no errors are emitted if unknown |
5064 | /// format options are occurred. |
5065 | /// |
5066 | /// If set all diagnostics are emitted through the DiagHandler. |
5067 | std::error_code |
5068 | parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style, |
5069 | bool AllowUnknownOptions = false, |
5070 | llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr, |
5071 | void *DiagHandlerCtx = nullptr); |
5072 | |
5073 | /// Like above but accepts an unnamed buffer. |
5074 | inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style, |
5075 | bool AllowUnknownOptions = false) { |
5076 | return parseConfiguration(Config: llvm::MemoryBufferRef(Config, "YAML" ), Style, |
5077 | AllowUnknownOptions); |
5078 | } |
5079 | |
5080 | /// Gets configuration in a YAML string. |
5081 | std::string configurationAsText(const FormatStyle &Style); |
5082 | |
5083 | /// Returns the replacements necessary to sort all ``#include`` blocks |
5084 | /// that are affected by ``Ranges``. |
5085 | tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, |
5086 | ArrayRef<tooling::Range> Ranges, |
5087 | StringRef FileName, |
5088 | unsigned *Cursor = nullptr); |
5089 | |
5090 | /// Returns the replacements corresponding to applying and formatting |
5091 | /// \p Replaces on success; otheriwse, return an llvm::Error carrying |
5092 | /// llvm::StringError. |
5093 | llvm::Expected<tooling::Replacements> |
5094 | formatReplacements(StringRef Code, const tooling::Replacements &Replaces, |
5095 | const FormatStyle &Style); |
5096 | |
5097 | /// Returns the replacements corresponding to applying \p Replaces and |
5098 | /// cleaning up the code after that on success; otherwise, return an llvm::Error |
5099 | /// carrying llvm::StringError. |
5100 | /// This also supports inserting/deleting C++ #include directives: |
5101 | /// - If a replacement has offset UINT_MAX, length 0, and a replacement text |
5102 | /// that is an #include directive, this will insert the #include into the |
5103 | /// correct block in the \p Code. |
5104 | /// - If a replacement has offset UINT_MAX, length 1, and a replacement text |
5105 | /// that is the name of the header to be removed, the header will be removed |
5106 | /// from \p Code if it exists. |
5107 | /// The include manipulation is done via ``tooling::HeaderInclude``, see its |
5108 | /// documentation for more details on how include insertion points are found and |
5109 | /// what edits are produced. |
5110 | llvm::Expected<tooling::Replacements> |
5111 | cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, |
5112 | const FormatStyle &Style); |
5113 | |
5114 | /// Represents the status of a formatting attempt. |
5115 | struct FormattingAttemptStatus { |
5116 | /// A value of ``false`` means that any of the affected ranges were not |
5117 | /// formatted due to a non-recoverable syntax error. |
5118 | bool FormatComplete = true; |
5119 | |
5120 | /// If ``FormatComplete`` is false, ``Line`` records a one-based |
5121 | /// original line number at which a syntax error might have occurred. This is |
5122 | /// based on a best-effort analysis and could be imprecise. |
5123 | unsigned Line = 0; |
5124 | }; |
5125 | |
5126 | /// Reformats the given \p Ranges in \p Code. |
5127 | /// |
5128 | /// Each range is extended on either end to its next bigger logic unit, i.e. |
5129 | /// everything that might influence its formatting or might be influenced by its |
5130 | /// formatting. |
5131 | /// |
5132 | /// Returns the ``Replacements`` necessary to make all \p Ranges comply with |
5133 | /// \p Style. |
5134 | /// |
5135 | /// If ``Status`` is non-null, its value will be populated with the status of |
5136 | /// this formatting attempt. See \c FormattingAttemptStatus. |
5137 | tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, |
5138 | ArrayRef<tooling::Range> Ranges, |
5139 | StringRef FileName = "<stdin>" , |
5140 | FormattingAttemptStatus *Status = nullptr); |
5141 | |
5142 | /// Same as above, except if ``IncompleteFormat`` is non-null, its value |
5143 | /// will be set to true if any of the affected ranges were not formatted due to |
5144 | /// a non-recoverable syntax error. |
5145 | tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, |
5146 | ArrayRef<tooling::Range> Ranges, |
5147 | StringRef FileName, bool *IncompleteFormat); |
5148 | |
5149 | /// Clean up any erroneous/redundant code in the given \p Ranges in \p |
5150 | /// Code. |
5151 | /// |
5152 | /// Returns the ``Replacements`` that clean up all \p Ranges in \p Code. |
5153 | tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, |
5154 | ArrayRef<tooling::Range> Ranges, |
5155 | StringRef FileName = "<stdin>" ); |
5156 | |
5157 | /// Fix namespace end comments in the given \p Ranges in \p Code. |
5158 | /// |
5159 | /// Returns the ``Replacements`` that fix the namespace comments in all |
5160 | /// \p Ranges in \p Code. |
5161 | tooling::Replacements (const FormatStyle &Style, |
5162 | StringRef Code, |
5163 | ArrayRef<tooling::Range> Ranges, |
5164 | StringRef FileName = "<stdin>" ); |
5165 | |
5166 | /// Inserts or removes empty lines separating definition blocks including |
5167 | /// classes, structs, functions, namespaces, and enums in the given \p Ranges in |
5168 | /// \p Code. |
5169 | /// |
5170 | /// Returns the ``Replacements`` that inserts or removes empty lines separating |
5171 | /// definition blocks in all \p Ranges in \p Code. |
5172 | tooling::Replacements separateDefinitionBlocks(const FormatStyle &Style, |
5173 | StringRef Code, |
5174 | ArrayRef<tooling::Range> Ranges, |
5175 | StringRef FileName = "<stdin>" ); |
5176 | |
5177 | /// Sort consecutive using declarations in the given \p Ranges in |
5178 | /// \p Code. |
5179 | /// |
5180 | /// Returns the ``Replacements`` that sort the using declarations in all |
5181 | /// \p Ranges in \p Code. |
5182 | tooling::Replacements sortUsingDeclarations(const FormatStyle &Style, |
5183 | StringRef Code, |
5184 | ArrayRef<tooling::Range> Ranges, |
5185 | StringRef FileName = "<stdin>" ); |
5186 | |
5187 | /// Returns the ``LangOpts`` that the formatter expects you to set. |
5188 | /// |
5189 | /// \param Style determines specific settings for lexing mode. |
5190 | LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle()); |
5191 | |
5192 | /// Description to be used for help text for a ``llvm::cl`` option for |
5193 | /// specifying format style. The description is closely related to the operation |
5194 | /// of ``getStyle()``. |
5195 | extern const char *StyleOptionHelpDescription; |
5196 | |
5197 | /// The suggested format style to use by default. This allows tools using |
5198 | /// ``getStyle`` to have a consistent default style. |
5199 | /// Different builds can modify the value to the preferred styles. |
5200 | extern const char *DefaultFormatStyle; |
5201 | |
5202 | /// The suggested predefined style to use as the fallback style in ``getStyle``. |
5203 | /// Different builds can modify the value to the preferred styles. |
5204 | extern const char *DefaultFallbackStyle; |
5205 | |
5206 | /// Construct a FormatStyle based on ``StyleName``. |
5207 | /// |
5208 | /// ``StyleName`` can take several forms: |
5209 | /// * "{<key>: <value>, ...}" - Set specic style parameters. |
5210 | /// * "<style name>" - One of the style names supported by |
5211 | /// getPredefinedStyle(). |
5212 | /// * "file" - Load style configuration from a file called ``.clang-format`` |
5213 | /// located in one of the parent directories of ``FileName`` or the current |
5214 | /// directory if ``FileName`` is empty. |
5215 | /// * "file:<format_file_path>" to explicitly specify the configuration file to |
5216 | /// use. |
5217 | /// |
5218 | /// \param[in] StyleName Style name to interpret according to the description |
5219 | /// above. |
5220 | /// \param[in] FileName Path to start search for .clang-format if ``StyleName`` |
5221 | /// == "file". |
5222 | /// \param[in] FallbackStyle The name of a predefined style used to fallback to |
5223 | /// in case \p StyleName is "file" and no file can be found. |
5224 | /// \param[in] Code The actual code to be formatted. Used to determine the |
5225 | /// language if the filename isn't sufficient. |
5226 | /// \param[in] FS The underlying file system, in which the file resides. By |
5227 | /// default, the file system is the real file system. |
5228 | /// \param[in] AllowUnknownOptions If true, unknown format options only |
5229 | /// emit a warning. If false, errors are emitted on unknown format |
5230 | /// options. |
5231 | /// |
5232 | /// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is |
5233 | /// "file" and no file is found, returns ``FallbackStyle``. If no style could be |
5234 | /// determined, returns an Error. |
5235 | llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName, |
5236 | StringRef FallbackStyle, |
5237 | StringRef Code = "" , |
5238 | llvm::vfs::FileSystem *FS = nullptr, |
5239 | bool AllowUnknownOptions = false); |
5240 | |
5241 | // Guesses the language from the ``FileName`` and ``Code`` to be formatted. |
5242 | // Defaults to FormatStyle::LK_Cpp. |
5243 | FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code); |
5244 | |
5245 | // Returns a string representation of ``Language``. |
5246 | inline StringRef getLanguageName(FormatStyle::LanguageKind Language) { |
5247 | switch (Language) { |
5248 | case FormatStyle::LK_Cpp: |
5249 | return "C++" ; |
5250 | case FormatStyle::LK_CSharp: |
5251 | return "CSharp" ; |
5252 | case FormatStyle::LK_ObjC: |
5253 | return "Objective-C" ; |
5254 | case FormatStyle::LK_Java: |
5255 | return "Java" ; |
5256 | case FormatStyle::LK_JavaScript: |
5257 | return "JavaScript" ; |
5258 | case FormatStyle::LK_Json: |
5259 | return "Json" ; |
5260 | case FormatStyle::LK_Proto: |
5261 | return "Proto" ; |
5262 | case FormatStyle::LK_TableGen: |
5263 | return "TableGen" ; |
5264 | case FormatStyle::LK_TextProto: |
5265 | return "TextProto" ; |
5266 | case FormatStyle::LK_Verilog: |
5267 | return "Verilog" ; |
5268 | default: |
5269 | return "Unknown" ; |
5270 | } |
5271 | } |
5272 | |
5273 | bool isClangFormatOn(StringRef ); |
5274 | bool isClangFormatOff(StringRef ); |
5275 | |
5276 | } // end namespace format |
5277 | } // end namespace clang |
5278 | |
5279 | namespace std { |
5280 | template <> |
5281 | struct is_error_code_enum<clang::format::ParseError> : std::true_type {}; |
5282 | } // namespace std |
5283 | |
5284 | #endif // LLVM_CLANG_FORMAT_FORMAT_H |
5285 | |