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