summaryrefslogtreecommitdiff
path: root/clang/include/clang/Format/Format.h
diff options
context:
space:
mode:
Diffstat (limited to 'clang/include/clang/Format/Format.h')
-rw-r--r--clang/include/clang/Format/Format.h258
1 files changed, 246 insertions, 12 deletions
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index add2937f3b43c..3549ec9eee0e5 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -35,7 +35,12 @@ class DiagnosticConsumer;
namespace format {
-enum class ParseError { Success = 0, Error, Unsuitable };
+enum class ParseError {
+ Success = 0,
+ Error,
+ Unsuitable,
+ BinPackTrailingCommaConflict
+};
class ParseErrorCategory final : public std::error_category {
public:
const char *name() const noexcept override;
@@ -103,6 +108,17 @@ struct FormatStyle {
/// \endcode
bool AlignConsecutiveAssignments;
+ /// If ``true``, aligns consecutive bitfield members.
+ ///
+ /// This will align the bitfield separators of consecutive lines. This
+ /// will result in formattings like
+ /// \code
+ /// int aaaa : 1;
+ /// int b : 12;
+ /// int ccc : 8;
+ /// \endcode
+ bool AlignConsecutiveBitFields;
+
/// If ``true``, aligns consecutive declarations.
///
/// This will align the declaration names of consecutive lines. This
@@ -148,16 +164,43 @@ struct FormatStyle {
/// Options for aligning backslashes in escaped newlines.
EscapedNewlineAlignmentStyle AlignEscapedNewlines;
+ /// Different styles for aligning operands.
+ enum OperandAlignmentStyle {
+ /// Do not align operands of binary and ternary expressions.
+ /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
+ /// the start of the line.
+ OAS_DontAlign,
+ /// Horizontally align operands of binary and ternary expressions.
+ ///
+ /// Specifically, this aligns operands of a single expression that needs
+ /// to be split over multiple lines, e.g.:
+ /// \code
+ /// int aaa = bbbbbbbbbbbbbbb +
+ /// ccccccccccccccc;
+ /// \endcode
+ ///
+ /// When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is
+ /// aligned with the operand on the first line.
+ /// \code
+ /// int aaa = bbbbbbbbbbbbbbb
+ /// + ccccccccccccccc;
+ /// \endcode
+ OAS_Align,
+ /// Horizontally align operands of binary and ternary expressions.
+ ///
+ /// This is similar to ``AO_Align``, except when
+ /// ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so
+ /// that the wrapped operand is aligned with the operand on the first line.
+ /// \code
+ /// int aaa = bbbbbbbbbbbbbbb
+ /// + ccccccccccccccc;
+ /// \endcode
+ OAS_AlignAfterOperator,
+ };
+
/// If ``true``, horizontally align operands of binary and ternary
/// expressions.
- ///
- /// Specifically, this aligns operands of a single expression that needs to be
- /// split over multiple lines, e.g.:
- /// \code
- /// int aaa = bbbbbbbbbbbbbbb +
- /// ccccccccccccccc;
- /// \endcode
- bool AlignOperands;
+ OperandAlignmentStyle AlignOperands;
/// If ``true``, aligns trailing comments.
/// \code
@@ -216,6 +259,20 @@ struct FormatStyle {
/// \endcode
bool AllowAllParametersOfDeclarationOnNextLine;
+ /// Allow short enums on a single line.
+ /// \code
+ /// true:
+ /// enum { A, B } myEnum;
+ ///
+ /// false:
+ /// enum
+ /// {
+ /// A,
+ /// B
+ /// } myEnum;
+ /// \endcode
+ bool AllowShortEnumsOnASingleLine;
+
/// Different styles for merging short blocks containing at most one
/// statement.
enum ShortBlockStyle {
@@ -544,6 +601,35 @@ struct FormatStyle {
/// \endcode
bool BinPackArguments;
+ /// The style of inserting trailing commas into container literals.
+ enum TrailingCommaStyle {
+ /// Do not insert trailing commas.
+ TCS_None,
+ /// Insert trailing commas in container literals that were wrapped over
+ /// multiple lines. Note that this is conceptually incompatible with
+ /// bin-packing, because the trailing comma is used as an indicator
+ /// that a container should be formatted one-per-line (i.e. not bin-packed).
+ /// So inserting a trailing comma counteracts bin-packing.
+ TCS_Wrapped,
+ };
+
+ /// If set to ``TCS_Wrapped`` will insert trailing commas in container
+ /// literals (arrays and objects) that wrap across multiple lines.
+ /// It is currently only available for JavaScript
+ /// and disabled by default ``TCS_None``.
+ /// ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
+ /// as inserting the comma disables bin-packing.
+ /// \code
+ /// TSC_Wrapped:
+ /// const someArray = [
+ /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
+ /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
+ /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
+ /// // ^ inserted
+ /// ]
+ /// \endcode
+ TrailingCommaStyle InsertTrailingCommas;
+
/// If ``false``, a function declaration's or function definition's
/// parameters will either all be on the same line or will have one line each.
/// \code
@@ -942,7 +1028,7 @@ struct FormatStyle {
/// int foo();
/// }
/// \endcode
- bool AfterExternBlock;
+ bool AfterExternBlock; // Partially superseded by IndentExternBlock
/// Wrap before ``catch``.
/// \code
/// true:
@@ -973,6 +1059,37 @@ struct FormatStyle {
/// }
/// \endcode
bool BeforeElse;
+ /// Wrap lambda block.
+ /// \code
+ /// true:
+ /// connect(
+ /// []()
+ /// {
+ /// foo();
+ /// bar();
+ /// });
+ ///
+ /// false:
+ /// connect([]() {
+ /// foo();
+ /// bar();
+ /// });
+ /// \endcode
+ bool BeforeLambdaBody;
+ /// Wrap before ``while``.
+ /// \code
+ /// true:
+ /// do {
+ /// foo();
+ /// }
+ /// while (1);
+ ///
+ /// false:
+ /// do {
+ /// foo();
+ /// } while (1);
+ /// \endcode
+ bool BeforeWhile;
/// Indent the wrapped braces themselves.
bool IndentBraces;
/// If ``false``, empty function body can be put on a single line.
@@ -1308,13 +1425,25 @@ struct FormatStyle {
/// For example: TESTSUITE
std::vector<std::string> NamespaceMacros;
+ /// A vector of macros which are whitespace-sensitive and shouldn't be
+ /// touched.
+ ///
+ /// These are expected to be macros of the form:
+ /// \code
+ /// STRINGIZE(...)
+ /// \endcode
+ ///
+ /// For example: STRINGIZE
+ std::vector<std::string> WhitespaceSensitiveMacros;
+
tooling::IncludeStyle IncludeStyle;
/// Indent case labels one level from the switch statement.
///
/// When ``false``, use the same indentation level as for the switch
/// statement. Switch statement body is always indented one level more than
- /// case labels.
+ /// case labels (except the first block following the case label, which
+ /// itself indents the code - unless IndentCaseBlocks is enabled).
/// \code
/// false: true:
/// switch (fool) { vs. switch (fool) {
@@ -1327,6 +1456,28 @@ struct FormatStyle {
/// \endcode
bool IndentCaseLabels;
+ /// Indent case label blocks one level from the case label.
+ ///
+ /// When ``false``, the block following the case label uses the same
+ /// indentation level as for the case label, treating the case label the same
+ /// as an if-statement.
+ /// When ``true``, the block gets indented as a scope block.
+ /// \code
+ /// false: true:
+ /// switch (fool) { vs. switch (fool) {
+ /// case 1: { case 1:
+ /// bar(); {
+ /// } break; bar();
+ /// default: { }
+ /// plop(); break;
+ /// } default:
+ /// } {
+ /// plop();
+ /// }
+ /// }
+ /// \endcode
+ bool IndentCaseBlocks;
+
/// Indent goto labels.
///
/// When ``false``, goto labels are flushed left.
@@ -1377,6 +1528,45 @@ struct FormatStyle {
/// The preprocessor directive indenting style to use.
PPDirectiveIndentStyle IndentPPDirectives;
+ /// Indents extern blocks
+ enum IndentExternBlockStyle {
+ /// Backwards compatible with AfterExternBlock's indenting.
+ /// \code
+ /// IndentExternBlock: AfterExternBlock
+ /// BraceWrapping.AfterExternBlock: true
+ /// extern "C"
+ /// {
+ /// void foo();
+ /// }
+ /// \endcode
+ ///
+ /// \code
+ /// IndentExternBlock: AfterExternBlock
+ /// BraceWrapping.AfterExternBlock: false
+ /// extern "C" {
+ /// void foo();
+ /// }
+ /// \endcode
+ IEBS_AfterExternBlock,
+ /// Does not indent extern blocks.
+ /// \code
+ /// extern "C" {
+ /// void foo();
+ /// }
+ /// \endcode
+ IEBS_NoIndent,
+ /// Indents extern blocks.
+ /// \code
+ /// extern "C" {
+ /// void foo();
+ /// }
+ /// \endcode
+ IEBS_Indent,
+ };
+
+ /// IndentExternBlockStyle is the type of indenting of extern blocks.
+ IndentExternBlockStyle IndentExternBlock;
+
/// The number of columns to use for indentation.
/// \code
/// IndentWidth: 3
@@ -1646,6 +1836,29 @@ struct FormatStyle {
/// ``@property (readonly)`` instead of ``@property(readonly)``.
bool ObjCSpaceAfterProperty;
+ /// Break parameters list into lines when there is nested block
+ /// parameters in a fuction call.
+ /// \code
+ /// false:
+ /// - (void)_aMethod
+ /// {
+ /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
+ /// *u, NSNumber *v) {
+ /// u = c;
+ /// }]
+ /// }
+ /// true:
+ /// - (void)_aMethod
+ /// {
+ /// [self.test1 t:self
+ /// w:self
+ /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
+ /// u = c;
+ /// }]
+ /// }
+ /// \endcode
+ bool ObjCBreakBeforeNestedBlockParam;
+
/// Add a space in front of an Objective-C protocol list, i.e. use
/// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
bool ObjCSpaceBeforeProtocolList;
@@ -1872,6 +2085,17 @@ struct FormatStyle {
/// }
/// \endcode
SBPO_ControlStatements,
+ /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
+ /// ForEach macros. This is useful in projects where ForEach macros are
+ /// treated as function calls instead of control statements.
+ /// \code
+ /// void f() {
+ /// Q_FOREACH(...) {
+ /// f();
+ /// }
+ /// }
+ /// \endcode
+ SBPO_ControlStatementsExceptForEachMacros,
/// Put a space before opening parentheses only if the parentheses are not
/// empty i.e. '()'
/// \code
@@ -2047,8 +2271,12 @@ struct FormatStyle {
UT_Never,
/// Use tabs only for indentation.
UT_ForIndentation,
- /// Use tabs only for line continuation and indentation.
+ /// Fill all leading whitespace with tabs, and use spaces for alignment that
+ /// appears within a line (e.g. consecutive assignments and declarations).
UT_ForContinuationAndIndentation,
+ /// Use tabs for line continuation and indentation, and spaces for
+ /// alignment.
+ UT_AlignWithSpaces,
/// Use tabs whenever we need to fill whitespace that spans at least from
/// one tab stop to the next one.
UT_Always
@@ -2065,6 +2293,7 @@ struct FormatStyle {
return AccessModifierOffset == R.AccessModifierOffset &&
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
+ AlignConsecutiveBitFields == R.AlignConsecutiveBitFields &&
AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
AlignEscapedNewlines == R.AlignEscapedNewlines &&
AlignOperands == R.AlignOperands &&
@@ -2074,6 +2303,7 @@ struct FormatStyle {
R.AllowAllConstructorInitializersOnNextLine &&
AllowAllParametersOfDeclarationOnNextLine ==
R.AllowAllParametersOfDeclarationOnNextLine &&
+ AllowShortEnumsOnASingleLine == R.AllowShortEnumsOnASingleLine &&
AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
AllowShortCaseLabelsOnASingleLine ==
R.AllowShortCaseLabelsOnASingleLine &&
@@ -2119,8 +2349,10 @@ struct FormatStyle {
IncludeStyle.IncludeIsMainSourceRegex ==
R.IncludeStyle.IncludeIsMainSourceRegex &&
IndentCaseLabels == R.IndentCaseLabels &&
+ IndentCaseBlocks == R.IndentCaseBlocks &&
IndentGotoLabels == R.IndentGotoLabels &&
IndentPPDirectives == R.IndentPPDirectives &&
+ IndentExternBlock == R.IndentExternBlock &&
IndentWidth == R.IndentWidth && Language == R.Language &&
IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
JavaImportGroups == R.JavaImportGroups &&
@@ -2135,6 +2367,8 @@ struct FormatStyle {
NamespaceMacros == R.NamespaceMacros &&
ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
+ ObjCBreakBeforeNestedBlockParam ==
+ R.ObjCBreakBeforeNestedBlockParam &&
ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
PenaltyBreakAssignment == R.PenaltyBreakAssignment &&