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