summaryrefslogtreecommitdiffstats
path: root/include/clang/Format/Format.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/Format/Format.h')
-rw-r--r--include/clang/Format/Format.h168
1 files changed, 159 insertions, 9 deletions
diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h
index cb37b0c890..fcbe0a7e93 100644
--- a/include/clang/Format/Format.h
+++ b/include/clang/Format/Format.h
@@ -1,9 +1,8 @@
//===--- Format.h - Format C++ code -----------------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
@@ -155,6 +154,38 @@ struct FormatStyle {
/// \endcode
bool AlignTrailingComments;
+ /// \brief If a function call or braced initializer list doesn't fit on a
+ /// line, allow putting all arguments onto the next line, even if
+ /// ``BinPackArguments`` is ``false``.
+ /// \code
+ /// true:
+ /// callFunction(
+ /// a, b, c, d);
+ ///
+ /// false:
+ /// callFunction(a,
+ /// b,
+ /// c,
+ /// d);
+ /// \endcode
+ bool AllowAllArgumentsOnNextLine;
+
+ /// \brief If a constructor definition with a member initializer list doesn't
+ /// fit on a single line, allow putting all member initializers onto the next
+ /// line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true.
+ /// Note that this parameter has no effect if
+ /// ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is false.
+ /// \code
+ /// true:
+ /// MyClass::MyClass() :
+ /// member0(0), member1(2) {}
+ ///
+ /// false:
+ /// MyClass::MyClass() :
+ /// member0(0),
+ /// member1(2) {}
+ bool AllowAllConstructorInitializersOnNextLine;
+
/// If the function declaration doesn't fit on a line,
/// allow putting all parameters of a function declaration onto
/// the next line even if ``BinPackParameters`` is ``false``.
@@ -242,8 +273,71 @@ struct FormatStyle {
/// single line.
ShortFunctionStyle AllowShortFunctionsOnASingleLine;
+ /// Different styles for handling short if lines
+ enum ShortIfStyle {
+ /// Never put short ifs on the same line.
+ /// \code
+ /// if (a)
+ /// return ;
+ /// else {
+ /// return;
+ /// }
+ /// \endcode
+ SIS_Never,
+ /// Without else put short ifs on the same line only if
+ /// the else is not a compound statement.
+ /// \code
+ /// if (a) return;
+ /// else
+ /// return;
+ /// \endcode
+ SIS_WithoutElse,
+ /// Always put short ifs on the same line if
+ /// the else is not a compound statement or not.
+ /// \code
+ /// if (a) return;
+ /// else {
+ /// return;
+ /// }
+ /// \endcode
+ SIS_Always,
+ };
+
/// If ``true``, ``if (a) return;`` can be put on a single line.
- bool AllowShortIfStatementsOnASingleLine;
+ ShortIfStyle AllowShortIfStatementsOnASingleLine;
+
+ /// Different styles for merging short lambdas containing at most one
+ /// statement.
+ enum ShortLambdaStyle {
+ /// Never merge lambdas into a single line.
+ SLS_None,
+ /// Only merge empty lambdas.
+ /// \code
+ /// auto lambda = [](int a) {}
+ /// auto lambda2 = [](int a) {
+ /// return a;
+ /// };
+ /// \endcode
+ SLS_Empty,
+ /// Merge lambda into a single line if argument of a function.
+ /// \code
+ /// auto lambda = [](int a) {
+ /// return a;
+ /// };
+ /// sort(a.begin(), a.end(), ()[] { return x < y; })
+ /// \endcode
+ SLS_Inline,
+ /// Merge all lambdas fitting on a single line.
+ /// \code
+ /// auto lambda = [](int a) {}
+ /// auto lambda2 = [](int a) { return a; };
+ /// \endcode
+ SLS_All,
+ };
+
+ /// Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
+ /// single line.
+ ShortLambdaStyle AllowShortLambdasOnASingleLine;
/// If ``true``, ``while (true) continue;`` can be put on a single
/// line.
@@ -621,6 +715,22 @@ struct FormatStyle {
/// AfterClass: true
/// \endcode
struct BraceWrappingFlags {
+ /// Wrap case labels.
+ /// \code
+ /// false: true:
+ /// switch (foo) { vs. switch (foo) {
+ /// case 1: { case 1:
+ /// bar(); {
+ /// break; bar();
+ /// } break;
+ /// default: { }
+ /// plop(); default:
+ /// } {
+ /// } plop();
+ /// }
+ /// }
+ /// \endcode
+ bool AfterCaseLabel;
/// Wrap class definitions.
/// \code
/// true:
@@ -1029,7 +1139,7 @@ struct FormatStyle {
/// true: false:
/// namespace a { vs. namespace a {
/// foo(); foo();
- /// } // namespace a; }
+ /// } // namespace a }
/// \endcode
bool FixNamespaceComments;
@@ -1097,7 +1207,16 @@ struct FormatStyle {
/// # endif
/// #endif
/// \endcode
- PPDIS_AfterHash
+ PPDIS_AfterHash,
+ /// Indents directives before the hash.
+ /// \code
+ /// #if FOO
+ /// #if BAR
+ /// #include <foo>
+ /// #endif
+ /// #endif
+ /// \endcode
+ PPDIS_BeforeHash
};
/// The preprocessor directive indenting style to use.
@@ -1131,7 +1250,7 @@ struct FormatStyle {
/// A vector of prefixes ordered by the desired groups for Java imports.
///
- /// Each group is seperated by a newline. Static imports will also follow the
+ /// Each group is separated by a newline. Static imports will also follow the
/// same grouping convention above all non-static imports. One group's prefix
/// can be a subset of another - the longest prefix is always matched. Within
/// a group, the imports are ordered lexicographically.
@@ -1220,6 +1339,8 @@ struct FormatStyle {
LK_None,
/// Should be used for C, C++.
LK_Cpp,
+ /// Should be used for C#.
+ LK_CSharp,
/// Should be used for Java.
LK_Java,
/// Should be used for JavaScript.
@@ -1236,6 +1357,7 @@ struct FormatStyle {
LK_TextProto
};
bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
+ bool isCSharp() const { return Language == LK_CSharp; }
/// Language, this format style is targeted at.
LanguageKind Language;
@@ -1522,6 +1644,13 @@ struct FormatStyle {
/// \endcode
bool SpaceAfterCStyleCast;
+ /// If ``true``, a space is inserted after the logical not operator (``!``).
+ /// \code
+ /// true: false:
+ /// ! someExpression(); vs. !someExpression();
+ /// \endcode
+ bool SpaceAfterLogicalNot;
+
/// If \c true, a space will be inserted after the 'template' keyword.
/// \code
/// true: false:
@@ -1584,6 +1713,17 @@ struct FormatStyle {
/// }
/// \endcode
SBPO_ControlStatements,
+ /// Put a space before opening parentheses only if the parentheses are not
+ /// empty i.e. '()'
+ /// \code
+ /// void() {
+ /// if (true) {
+ /// f();
+ /// g (x, y, z);
+ /// }
+ /// }
+ /// \endcode
+ SBPO_NonEmptyParentheses,
/// Always put a space before opening parentheses, except when it's
/// prohibited by the syntax rules (in function-like macro definitions) or
/// when determined by other style rules (after unary operators, opening
@@ -1720,6 +1860,9 @@ struct FormatStyle {
AlignEscapedNewlines == R.AlignEscapedNewlines &&
AlignOperands == R.AlignOperands &&
AlignTrailingComments == R.AlignTrailingComments &&
+ AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
+ AllowAllConstructorInitializersOnNextLine ==
+ R.AllowAllConstructorInitializersOnNextLine &&
AllowAllParametersOfDeclarationOnNextLine ==
R.AllowAllParametersOfDeclarationOnNextLine &&
AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
@@ -1729,6 +1872,7 @@ struct FormatStyle {
R.AllowShortFunctionsOnASingleLine &&
AllowShortIfStatementsOnASingleLine ==
R.AllowShortIfStatementsOnASingleLine &&
+ AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
AlwaysBreakBeforeMultilineStrings ==
@@ -1790,6 +1934,7 @@ struct FormatStyle {
PointerAlignment == R.PointerAlignment &&
RawStringFormats == R.RawStringFormats &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
+ SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
@@ -1850,7 +1995,8 @@ private:
/// Returns a format style complying with the LLVM coding standards:
/// http://llvm.org/docs/CodingStandards.html.
-FormatStyle getLLVMStyle();
+FormatStyle getLLVMStyle(
+ FormatStyle::LanguageKind Language = FormatStyle::LanguageKind::LK_Cpp);
/// Returns a format style complying with one of Google's style guides:
/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
@@ -2051,6 +2197,8 @@ inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
switch (Language) {
case FormatStyle::LK_Cpp:
return "C++";
+ case FormatStyle::LK_CSharp:
+ return "CSharp";
case FormatStyle::LK_ObjC:
return "Objective-C";
case FormatStyle::LK_Java:
@@ -2059,6 +2207,8 @@ inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
return "JavaScript";
case FormatStyle::LK_Proto:
return "Proto";
+ case FormatStyle::LK_TableGen:
+ return "TableGen";
case FormatStyle::LK_TextProto:
return "TextProto";
default: