summaryrefslogtreecommitdiff
path: root/include/clang/Format
diff options
context:
space:
mode:
authorRonald Wampler <rdwampler@gmail.com>2019-03-26 20:18:14 +0000
committerRonald Wampler <rdwampler@gmail.com>2019-03-26 20:18:14 +0000
commit7e997c278b6a5b1e2e39c7242dd854b3d10b58ee (patch)
treef5d2d9b780088f6a7dabcc422a4324622fef9f7a /include/clang/Format
parent182d7fa38b05c20dea18a8d5c922710b2f0b7875 (diff)
downloadclang-7e997c278b6a5b1e2e39c7242dd854b3d10b58ee.tar.gz
[clang-format] Add style option AllowShortLambdasOnASingleLine
Summary: This option `AllowShortLambdasOnASingleLine` similar to the other `AllowShort*` options, but applied to C++ lambdas. Reviewers: djasper, klimek Reviewed By: klimek Subscribers: MyDeveloperDay, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57687 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357027 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Format')
-rw-r--r--include/clang/Format/Format.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h
index fd84c924ff..f9d3f03a6c 100644
--- a/include/clang/Format/Format.h
+++ b/include/clang/Format/Format.h
@@ -306,6 +306,39 @@ struct FormatStyle {
/// If ``true``, ``if (a) return;`` can be put on a single line.
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.
bool AllowShortLoopsOnASingleLine;
@@ -1805,6 +1838,7 @@ struct FormatStyle {
R.AllowShortFunctionsOnASingleLine &&
AllowShortIfStatementsOnASingleLine ==
R.AllowShortIfStatementsOnASingleLine &&
+ AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
AlwaysBreakBeforeMultilineStrings ==