[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

Indeed, I found another case with a regression:

  return iter::chain.from_iterable(
[](auto&& ite) -> auto&
{
  return ite.second;
});

it's format all inline.

And also another different in that case (without lambda):

ASSERT_NO_THROW(
{
iterator += 507408;
});

is now format like this:

ASSERT_NO_THROW({ iterator += 507408; });


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104222/new/

https://reviews.llvm.org/D104222

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

In D104222#2819422 , @MyDeveloperDay 
wrote:

> Add some of the failing cases identified by @Wawha

Thank for the fix. I test and discover a new case with a regression:

auto createObj = [this] -> std::unique_ptr
{
  return std::make_unique();
};

Like & and * a template return ending with > is not handle.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104222/new/

https://reviews.llvm.org/D104222

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

In D104222#2819358 , @MyDeveloperDay 
wrote:

> @Wawha your cases could be covered by the following (in mustBreakBefore)
>
>   if (Style.BraceWrapping.BeforeLambdaBody && Right.is(TT_LambdaLBrace) &&
>   Left.isOneOf(tok::star, tok::amp, tok::ampamp)) {
> return true;
>   }
>
> As I think  its the presence of & and * that causes it to not wrap.
>
> By all means if you would prefer to commandeer the patch I'm ok with that. I 
> was just on a bug fixing day. If you'd like to take this over and add the 
> unit tests @christophe-calmejane suggest, I'm happy to be the reviewer

Indeed, & and * could be the root cause.
About fixing that, I won't have the time in the next days. It will take time 
for me to re-read and re-understand that code.
But I could find time to test patch or modification in my code to check that 
there is no regression.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104222/new/

https://reviews.llvm.org/D104222

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

Hi @christophe-calmejane.
I test your code with a old version (few time after the merge of 
https://reviews.llvm.org/D44609), and the latest version (commit: e0c382a9d5a0 
), and in 
both cases I have the same result, which is near your output:

  noOtherParams(
[](int x)
{
call();
});
  paramBeforeLambda(
8,
[](int x)
{
call();
});
  paramAfterLambda(
[](int x)
{
call();
},
5);
  paramBeforeAndAfterLambda(
8,
[](int x)
{
call();
},
5);
  doubleLambda(
8,
[](int x)
{
call();
},
6,
[](float f)
{
return f * 2;
},
5);
  nestedLambda1(
[](int x)
{
return [](float f)
{
return f * 2;
};
});
  nestedLambda2(
[](int x)
{
call(
[](float f)
{
return f * 2;
});
});
  noExceptCall(
[](int x) noexcept
{
call();
});
  mutableCall(
[](int x) mutable
{
call();
});
  
  funcCallFunc(
call(),
[](int x)
{
call();
});
  
  auto const l = [](char v)
  {
if(v)
call();
  };
  void f()
  {
return [](char v)
{
if(v)
return v++;
};
  }

The only different is for cases with multiples parameters.

  paramBeforeLambda(
8,
[](int x)
{
call();
}

I though I add multiples cases, but looking at UnitTests with inline lambda 
"None", I see only few tests, perhaps some are missing.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104222/new/

https://reviews.llvm.org/D104222

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-15 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

In D104222#2817147 , @MyDeveloperDay 
wrote:

> @Wawha do you have a project that perhaps uses this work your did? I would 
> like to ensure I didn't break anything

@MyDeveloperDay Good idea!
I just test on my code, and I see 2 types of regressions due to that patch.
This code:

auto select = [this]() -> const Library::Object*
{
return MyAssignment::SelectFromList(this);
};

Become:

auto select = [this]() -> const Library::Object* {
return MyAssignment::SelectFromList(this);
};

And this code,

auto Items()
{
return iter::imap(
[this](const std::unique_ptr& iItem) -> T&
{
return *GetItem(*iItem)->Item;
},
m_Root->Items());
}

Become:

auto Items()
{
return iter::imap(
[this](const std::unique_ptr& iItem) -> T& {
return *GetItem(*iItem)->Item;
},
m_Root->Items());
}

I'm surprise, because the both cases, should be present inside the UnitTest.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104222/new/

https://reviews.llvm.org/D104222

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-14 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3760
-  (isAllmanBraceIncludedBreakableLambda(Left, ShortLambdaOption) ||
-   isAllmanBraceIncludedBreakableLambda(Right, ShortLambdaOption))) {
-return true;

Without this code, you should be able to remove functions 
isAllmanBraceIncludedBreakableLambda(), isItAInlineLambdaAllowed() and 
isOneChildWithoutMustBreakBefore().

Thank you for the fix.

When I implement that part, I have some difficulty to handle inline lambda and 
BreakBeforeLambdaBody. At the beginning, I implement the solution without 
inline lambda option (not yet present). But I have to handle it before merging 
the patch. And, this modification was added at this moment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104222/new/

https://reviews.llvm.org/D104222

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99031: [clang-format] Fix CompactNamespaces corner case when AllowShortLambdasOnASingleLine/BraceWrapping.BeforeLambdaBody are set

2021-03-21 Thread Francois JEAN via Phabricator via cfe-commits
Wawha accepted this revision.
Wawha added a comment.
This revision is now accepted and ready to land.

Thank you for the fix!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99031/new/

https://reviews.llvm.org/D99031

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79320: [clang-format [PR45791] BeforeLambdaBody is confused by comment inside lambda

2020-05-04 Thread Francois JEAN via Phabricator via cfe-commits
Wawha accepted this revision.
Wawha added a comment.
This revision is now accepted and ready to land.

Thanks for the patch !


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79320/new/

https://reviews.llvm.org/D79320



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79022: [clang-format] Fix a bug causing BeforeLambdaBody to affect brace initialiser formatting

2020-04-28 Thread Francois JEAN via Phabricator via cfe-commits
Wawha accepted this revision.
Wawha added a comment.

Thanks for the fix!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79022/new/

https://reviews.llvm.org/D79022



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78909: [clang-format] NFC clang-format the clang-format sources

2020-04-27 Thread Francois JEAN via Phabricator via cfe-commits
Wawha accepted this revision.
Wawha added a comment.

Thank for the changes !


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78909/new/

https://reviews.llvm.org/D78909



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [clang-format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2020-02-26 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

In D44609#1893390 , 
@christophe-calmejane wrote:

> Nice to finally see this patch integrated!
>
> But, it looks like you didn't include all the test case I posted 1.5y ago in 
> this post, that are still problematic and not formatting correctly with your 
> patch:
>  For example, this simple case do not format correctly:
>
>   paramBeforeAndAfterLambda(8,[](int x){call();},5);
>
>
> The output is:
>
>   paramBeforeAndAfterLambda(
>   8,
>   [](int x)
>   {
>   call();
>   },
>   5);
>  
>
>
> although I would expect to see
>
>   paramBeforeAndAfterLambda(8,
>   [](int x)
>   {
>   call();
>   },
>   5);
>  
>
>
> See my proposed fix in the discussion, but note that I don't think it's clean 
> enough to be accepted :)


Thank for the feedback.

Looking back at your comment and patch, I integrate most of your proposal in 
order to fix the problem with "noexcept" .
I even have a comment of MyDevelopperDay because I reuse the keyword "auto" for 
nextTok variable like it was in your proposal :)

For the bug your are reporting with the line wrap for first parameter, looking 
at the tests I wrote, I see two tests which have should cover that case:

  verifyFormat("FctWithMultipleParams_SLS_Empty(A, B,\n"
  " []()\n"
  " {\n"
  " return 17;\n"
  " });", LLVMWithBeforeLambdaBody);
  
  verifyFormat("TwoNestedLambdas_SLS_Empty(A,\n"
   " []()\n"
   " {\n"
   " return Call([]() {});\n"
   " });", LLVMWithBeforeLambdaBody);

So perhaps there is a mistake, depending of the options or if there is an extra 
parameter after the lambda.
I do not have a PC in the next 10 Days to check that but I Will try have a look 
later.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44609/new/

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [clang-format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2020-02-13 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

In D44609#1871612 , @MyDeveloperDay 
wrote:

> Correct follow that description on how to request commit access


It's done. I have the commit right, and push that change on github : 
https://github.com/llvm/llvm-project/commit/fa0118e6e588fe303b08e7e06ba28ac1f8d50c68

Thank you for the review and advices!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44609/new/

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [clang-format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2020-02-13 Thread Francois JEAN via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfa0118e6e588: [clang-format] Add new option BeforeLambdaBody 
in Allman style. (authored by Wawha).
Herald added a reviewer: jdoerfert.

Changed prior to commit:
  https://reviews.llvm.org/D44609?vs=241875=244523#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44609/new/

https://reviews.llvm.org/D44609

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12673,6 +12673,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterExternBlock);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeLambdaBody);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
@@ -13962,6 +13963,245 @@
"function([]() { return b; }, a)", MergeInline);
   verifyFormat("function(a, []() { return b; })",
"function(a, []() { return b; })", MergeInline);
+
+  // Check option "BraceWrapping.BeforeLambdaBody" and different state of
+  // AllowShortLambdasOnASingleLine
+  FormatStyle LLVMWithBeforeLambdaBody = getLLVMStyle();
+  LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
+  LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_None;
+  verifyFormat("FctWithOneNestedLambdaInline_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmpty_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto fct_SLS_None = []()\n"
+   "{\n"
+   "  return 17;\n"
+   "};",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call(\n"
+   "  []()\n"
+   "  {\n"
+   "return 17;\n"
+   "  });\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("void Fct()\n"
+   "{\n"
+   "  return {[]()\n"
+   "  {\n"
+   "return 17;\n"
+   "  }};\n"
+   "}",
+   LLVMWithBeforeLambdaBody);
+
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_Empty;
+  verifyFormat("FctWithOneNestedLambdaInline_SLS_Empty(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmpty_SLS_Empty([]() {});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmptyInsideAVeryVeryVeryVeryVeryVeryVeryL"
+   "ongFunctionName_SLS_Empty(\n"
+   "[]() {});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithMultipleParams_SLS_Empty(A, B,\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto fct_SLS_Empty = []()\n"
+   "{\n"
+   "  return 17;\n"
+   "};",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_Empty(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call([]() {});\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_Empty(A,\n"
+   "   []()\n"
+   "   {\n"
+   " return Call([]() {});\n"
+   "   });",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat(
+  "FctWithLongLineInLambda_SLS_Empty(\n"
+  "[]()\n"
+  "{\n"
+  "  return 

[PATCH] D44609: [clang-format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2020-02-11 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

Thank you @MyDeveloperDay for the validation! I'm happy that my contribution 
(and my work to do it well) is accepted.

And yes, I will be there to help to maintain that code and fix bugs if 
necessary.

About the permission in order to land that patch, I'm not sure that I will need 
to do. On that page, 
https://llvm.org/docs/DeveloperPolicy.html#new-contributors, I see that we can 
contact Chris to have permission on the repo. Is it what you propose? Or is 
there another way to have the permission only on llvm Phabricator?

Once I will know the right way to ask for that permission, I will do it :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44609/new/

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [clang-format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2020-02-10 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

Hi @MyDeveloperDay
Is the last change ok? That is the next step to be able to validate this patch?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44609/new/

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [clang-format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2020-02-01 Thread Francois JEAN via Phabricator via cfe-commits
Wawha updated this revision to Diff 241874.
Wawha marked an inline comment as done.
Wawha added a comment.

@MyDeveloperDay
I launch docs/tools/dump_style.py on ClangFormatStyleOptions.rst (it seems to 
generate the same result as the previous diff) and add an entry in the Release 
Note. Tell me if there other documentation to update.

I also removed the "auto" keyword! And rebase with the last version of master 
to check the compilation and UnitTest are still OK.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44609/new/

https://reviews.llvm.org/D44609

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12673,6 +12673,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterExternBlock);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeLambdaBody);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
@@ -13962,6 +13963,245 @@
"function([]() { return b; }, a)", MergeInline);
   verifyFormat("function(a, []() { return b; })",
"function(a, []() { return b; })", MergeInline);
+
+  // Check option "BraceWrapping.BeforeLambdaBody" and different state of
+  // AllowShortLambdasOnASingleLine
+  FormatStyle LLVMWithBeforeLambdaBody = getLLVMStyle();
+  LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
+  LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_None;
+  verifyFormat("FctWithOneNestedLambdaInline_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmpty_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto fct_SLS_None = []()\n"
+   "{\n"
+   "  return 17;\n"
+   "};",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call(\n"
+   "  []()\n"
+   "  {\n"
+   "return 17;\n"
+   "  });\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("void Fct()\n"
+   "{\n"
+   "  return {[]()\n"
+   "  {\n"
+   "return 17;\n"
+   "  }};\n"
+   "}",
+   LLVMWithBeforeLambdaBody);
+
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_Empty;
+  verifyFormat("FctWithOneNestedLambdaInline_SLS_Empty(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmpty_SLS_Empty([]() {});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmptyInsideAVeryVeryVeryVeryVeryVeryVeryL"
+   "ongFunctionName_SLS_Empty(\n"
+   "[]() {});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithMultipleParams_SLS_Empty(A, B,\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto fct_SLS_Empty = []()\n"
+   "{\n"
+   "  return 17;\n"
+   "};",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_Empty(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call([]() {});\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_Empty(A,\n"
+   "   []()\n"
+   "   {\n"
+   " return Call([]() {});\n"
+   "   });",
+   

[PATCH] D44609: [clang-format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2020-02-01 Thread Francois JEAN via Phabricator via cfe-commits
Wawha updated this revision to Diff 241875.
Wawha marked an inline comment as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44609/new/

https://reviews.llvm.org/D44609

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12673,6 +12673,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterExternBlock);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeLambdaBody);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
@@ -13962,6 +13963,245 @@
"function([]() { return b; }, a)", MergeInline);
   verifyFormat("function(a, []() { return b; })",
"function(a, []() { return b; })", MergeInline);
+
+  // Check option "BraceWrapping.BeforeLambdaBody" and different state of
+  // AllowShortLambdasOnASingleLine
+  FormatStyle LLVMWithBeforeLambdaBody = getLLVMStyle();
+  LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
+  LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_None;
+  verifyFormat("FctWithOneNestedLambdaInline_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmpty_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto fct_SLS_None = []()\n"
+   "{\n"
+   "  return 17;\n"
+   "};",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call(\n"
+   "  []()\n"
+   "  {\n"
+   "return 17;\n"
+   "  });\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("void Fct()\n"
+   "{\n"
+   "  return {[]()\n"
+   "  {\n"
+   "return 17;\n"
+   "  }};\n"
+   "}",
+   LLVMWithBeforeLambdaBody);
+
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_Empty;
+  verifyFormat("FctWithOneNestedLambdaInline_SLS_Empty(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmpty_SLS_Empty([]() {});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmptyInsideAVeryVeryVeryVeryVeryVeryVeryL"
+   "ongFunctionName_SLS_Empty(\n"
+   "[]() {});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithMultipleParams_SLS_Empty(A, B,\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto fct_SLS_Empty = []()\n"
+   "{\n"
+   "  return 17;\n"
+   "};",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_Empty(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call([]() {});\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_Empty(A,\n"
+   "   []()\n"
+   "   {\n"
+   " return Call([]() {});\n"
+   "   });",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat(
+  "FctWithLongLineInLambda_SLS_Empty(\n"
+  "[]()\n"
+  "{\n"
+  "  return HereAVeryLongLine(ThatWillBeFormatted, OnMultipleLine,\n"
+  "   AndShouldNotBeConsiderAsInline,\n"
+  "   LambdaBodyMustBeBreak);\n"
+  "});",
+  LLVMWithBeforeLambdaBody);
+
+  

[PATCH] D44609: [Clang-Format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2020-01-20 Thread Francois JEAN via Phabricator via cfe-commits
Wawha marked 2 inline comments as done.
Wawha added a comment.

Hello,
@klimek will you have time to review this patch? The current patch integrate 
the last remarks and also modification due to inline lambda.




Comment at: lib/Format/ContinuationIndenter.cpp:1179
+   Current.is(TT_LambdaLSquare;
   }
 

MyDeveloperDay wrote:
> oh boy... I have to say.. that I don't like these kinds of massive if 
> statements without some sort of comment.. as to what it's doing, it's so 
> hard, later on, to read through the various clauses and understand which bit 
> of functionality this section covers
I make some change in the last patch. Hope it's better.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44609/new/

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2020-01-12 Thread Francois JEAN via Phabricator via cfe-commits
Wawha updated this revision to Diff 237563.
Wawha added a comment.

Here a new version of the patch with the last version of the source.
It fixes problem with inline lambda. I add more more UnitTest to test.
I also make few small changes to follow remarks.

Do not hesitate to make remarks, I hope that it will be integrate in the coming 
version.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44609/new/

https://reviews.llvm.org/D44609

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12582,6 +12582,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterExternBlock);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeLambdaBody);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
@@ -13865,6 +13866,245 @@
"function([]() { return b; }, a)", MergeInline);
   verifyFormat("function(a, []() { return b; })",
"function(a, []() { return b; })", MergeInline);
+
+  // Check option "BraceWrapping.BeforeLambdaBody" and different state of
+  // AllowShortLambdasOnASingleLine
+  FormatStyle LLVMWithBeforeLambdaBody = getLLVMStyle();
+  LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
+  LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_None;
+  verifyFormat("FctWithOneNestedLambdaInline_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmpty_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto fct_SLS_None = []()\n"
+   "{\n"
+   "  return 17;\n"
+   "};",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_None(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call(\n"
+   "  []()\n"
+   "  {\n"
+   "return 17;\n"
+   "  });\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("void Fct()\n"
+   "{\n"
+   "  return {[]()\n"
+   "  {\n"
+   "return 17;\n"
+   "  }};\n"
+   "}",
+   LLVMWithBeforeLambdaBody);
+
+  LLVMWithBeforeLambdaBody.AllowShortLambdasOnASingleLine =
+  FormatStyle::ShortLambdaStyle::SLS_Empty;
+  verifyFormat("FctWithOneNestedLambdaInline_SLS_Empty(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmpty_SLS_Empty([]() {});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithOneNestedLambdaEmptyInsideAVeryVeryVeryVeryVeryVeryVeryL"
+   "ongFunctionName_SLS_Empty(\n"
+   "[]() {});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FctWithMultipleParams_SLS_Empty(A, B,\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto fct_SLS_Empty = []()\n"
+   "{\n"
+   "  return 17;\n"
+   "};",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_Empty(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call([]() {});\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas_SLS_Empty(A,\n"
+   "   []()\n"
+   "   {\n"
+   " return Call([]() {});\n"
+   "   });",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat(
+  "FctWithLongLineInLambda_SLS_Empty(\n"
+  "[]()\n"
+  "{\n"
+  "  return 

[PATCH] D44609: [Clang-Format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2019-08-20 Thread Francois JEAN via Phabricator via cfe-commits
Wawha updated this revision to Diff 216061.
Wawha added a comment.
Herald added a subscriber: ormris.

I update the patch for the last version of clang format, especially since 
option "AllowShortLambdasOnASingleLine" has been added (which require more 
change for this patch).
Indeed, for AllowShortLambdasOnASingleLine patch 
(https://reviews.llvm.org/D57687), the isAllmanBrace() function has been 
changed (adding TT_LambdaLBrace) which require more test to handle break for 
lambda body.

Unfortunately, there is one case I'm not able to handle correctly for the 
moment.
With option "BeforeLambdaBody : true", "AllowShortLambdasOnASingleLine : 
SLS_All;" and "BinPackParameters : false", the expected code below:

  FctWithLonglineInLambda(
param,
[]()
{
  return 
HereAVeryLongLineThatWillBeFormattedOnMultipleLineAndShouldNotBeConsiderAsInline;
});

Is formatted like this with the current patch:

  FctWithLonglineInLambda(param, []() {
  return 
HereAVeryLongLineThatWillBeFormattedOnMultipleLineAndShouldNotBeConsiderAsInline;
});

Can someone help me and tell where to look to set break for parameters (and 
lambda) when the whole parameters line (included the lambda body, which is not 
the case actually) do not fit the inside one line.
Before the AllowShortLambdasOnASingleLine option, there is no need for that, 
due to the fact that the lambda was always break. But with this new option, we 
need to handle that too.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44609/new/

https://reviews.llvm.org/D44609

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2018-09-04 Thread Francois JEAN via Phabricator via cfe-commits
Wawha marked an inline comment as done.
Wawha added inline comments.



Comment at: lib/Format/ContinuationIndenter.cpp:1307
+   (Style.BraceWrapping.BeforeLambdaBody && Current.Next != nullptr &&
+Current.Next->is(TT_LambdaLSquare)));
   State.Stack.back().IsInsideObjCArrayLiteral =

klimek wrote:
> Wawha wrote:
> > klimek wrote:
> > > klimek wrote:
> > > > I think I misunderstood some of this the first time around (and thanks 
> > > > for bearing with me :) - iiuc we want to break for Allman even when 
> > > > there's only one nested block. I think I'll need to take another look 
> > > > when I'm back from vacation, unless Daniel or somebody else finds time 
> > > > before then (will be back in 1.5 weeks)
> > > So, HasMultipleNestedBlocks should only be true if there are multiple 
> > > nested blocks.
> > > What tests break if you remove this change to HasMultipleNestedBlocks?
> > All cases with only one lambda in parameter are break. The Lambda body with 
> > be put on the same line as the function and aligned with [] instead of 
> > putting the body [] on another line with just one simple indentation.
> > 
> > So if restore the line to :
> > 
> > ```
> > State.Stack.back().HasMultipleNestedBlocks = Current.BlockParameterCount > 
> > 1;
> > ```
> > 
> > Here some cases.
> > FormatTest.cpp, ligne 11412:
> > 
> > ```
> > // With my modification
> > FunctionWithOneParam(
> > []()
> > {
> >   // A cool function...
> >   return 43;
> > });
> > 
> > // Without my modification
> > FunctionWithOneParam([]()
> >  {
> >// A cool function...
> >return 43;
> >  });
> > ```
> > The "{" block of the lambda will be aligned on the "[" depending of the 
> > function name length.
> > 
> > 
> > You have the same case with multiple lambdas (FormatTest.cpp, ligne 11433):
> > 
> > ```
> > // With my modification
> > TwoNestedLambdas(
> > []()
> > {
> >   return Call(
> >   []()
> >   {
> > return 17;
> >   });
> > });
> > 
> > // Without my modification
> > TwoNestedLambdas([]()
> >  {
> >return Call([]()
> >{
> >  return 17;
> >});
> >  });
> > ```
> Do we want to always break before lambdas in Allman style?
Perhaps not always. I make that current implementation, because, I have some 
difficulty to make the other. I alreay tried to modified the code to have that :

```
TwoNestedLambdas([]()
{
  return Call(
  []()
  {
return 17;
  });
});
```
With just a tabulation after the line return. But with no success for the 
moment.

I could try again to implement it, and why not, add an option to tell if we 
break or not before the lambda. And set it to false by default.



Repository:
  rC Clang

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2018-09-01 Thread Francois JEAN via Phabricator via cfe-commits
Wawha marked 2 inline comments as done.
Wawha added inline comments.



Comment at: lib/Format/ContinuationIndenter.cpp:1307
+   (Style.BraceWrapping.BeforeLambdaBody && Current.Next != nullptr &&
+Current.Next->is(TT_LambdaLSquare)));
   State.Stack.back().IsInsideObjCArrayLiteral =

klimek wrote:
> klimek wrote:
> > I think I misunderstood some of this the first time around (and thanks for 
> > bearing with me :) - iiuc we want to break for Allman even when there's 
> > only one nested block. I think I'll need to take another look when I'm back 
> > from vacation, unless Daniel or somebody else finds time before then (will 
> > be back in 1.5 weeks)
> So, HasMultipleNestedBlocks should only be true if there are multiple nested 
> blocks.
> What tests break if you remove this change to HasMultipleNestedBlocks?
All cases with only one lambda in parameter are break. The Lambda body with be 
put on the same line as the function and aligned with [] instead of putting the 
body [] on another line with just one simple indentation.

So if restore the line to :

```
State.Stack.back().HasMultipleNestedBlocks = Current.BlockParameterCount > 1;
```

Here some cases.
FormatTest.cpp, ligne 11412:

```
// With my modification
FunctionWithOneParam(
[]()
{
  // A cool function...
  return 43;
});

// Without my modification
FunctionWithOneParam([]()
 {
   // A cool function...
   return 43;
 });
```
The "{" block of the lambda will be aligned on the "[" depending of the 
function name length.


You have the same case with multiple lambdas (FormatTest.cpp, ligne 11433):

```
// With my modification
TwoNestedLambdas(
[]()
{
  return Call(
  []()
  {
return 17;
  });
});

// Without my modification
TwoNestedLambdas([]()
 {
   return Call([]()
   {
 return 17;
   });
 });
```


Repository:
  rC Clang

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2018-08-25 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

  Hi klimek,

do you have time to take a look again to this patch?
Is my last patch ok for you?

best regards,
François


Repository:
  rC Clang

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2018-07-12 Thread Francois JEAN via Phabricator via cfe-commits
Wawha updated this revision to Diff 155254.
Wawha retitled this revision from "[Clang-Format] New option 
BreakBeforeLambdaBody to manage lambda line break inside function parameter 
call" to "[Clang-Format] New option BeforeLambdaBody to manage lambda line 
break inside function parameter call (in Allman style)".
Wawha added a comment.

Here a new patch, which is very similar to the second patch. I just remove the 
extra line parsing which was no necessary since a new tag TT_LambdaLSquare was 
added.
I'm agree with klimek, my third patch was quite weird and after some test 
contain an error in the code and unittest (inside the first test I added...)

This 4th version is far better while it's very similar to the 2nd patch.


Repository:
  rC Clang

https://reviews.llvm.org/D44609

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10461,6 +10461,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterExternBlock);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeLambdaBody);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
@@ -11403,6 +11404,48 @@
   "> {\n"
   "  //\n"
   "});");
+
+  // Check option "BraceWrapping.BeforeLambdaBody"
+  FormatStyle LLVMWithBeforeLambdaBody = getLLVMStyle();
+  LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
+  LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
+  verifyFormat("FunctionWithOneParam(\n"
+   "[]()\n"
+   "{\n"
+   "  // A cool function...\n"
+   "  return 43;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FunctionWithTwoParams(\n"
+   "[]()\n"
+   "{\n"
+   "  // A cool function...\n"
+   "  return 43;\n"
+   "},\n"
+   "87);",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FunctionWithOneNestedLambdas(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call(\n"
+   "  []()\n"
+   "  {\n"
+   "return 17;\n"
+   "  });\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto array = {[]()\n"
+   "  {\n"
+   "return 43;\n"
+   "  },\n"
+   "  MyFunctor};",
+   LLVMWithBeforeLambdaBody);
 }
 
 TEST_F(FormatTest, EmptyLinesInLambdas) {
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1404,6 +1404,7 @@
   return true;
 }
   }
+  FormatTok->Type = TT_LambdaLBrace;
   LSquare.Type = TT_LambdaLSquare;
   parseChildBlock();
   return true;
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1108,11 +1108,11 @@
 
 // Reset token type in case we have already looked at it and then
 // recovered from an error (e.g. failure to find the matching >).
-if (!CurrentToken->isOneOf(TT_LambdaLSquare, TT_ForEachMacro,
-   TT_FunctionLBrace, TT_ImplicitStringLiteral,
-   TT_InlineASMBrace, TT_JsFatArrow, TT_LambdaArrow,
-   TT_OverloadedOperator, TT_RegexLiteral,
-   TT_TemplateString, TT_ObjCStringLiteral))
+if (!CurrentToken->isOneOf(
+TT_LambdaLSquare, TT_LambdaLBrace, TT_ForEachMacro,
+TT_FunctionLBrace, TT_ImplicitStringLiteral, TT_InlineASMBrace,
+TT_JsFatArrow, TT_LambdaArrow, TT_OverloadedOperator,
+TT_RegexLiteral, TT_TemplateString, TT_ObjCStringLiteral))
   CurrentToken->Type = TT_Unknown;
 CurrentToken->Role.reset();
 CurrentToken->MatchingParen = nullptr;
@@ -2896,7 +2896,9 @@
   if (Right.is(TT_InlineASMBrace))
 return 

[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-07-03 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:627
 }
+if(Style.BraceWrapping.BeforeLambdaBody && Current->is(TT_LambdaLSquare)) {
+++Left->BlockParameterCount;

klimek wrote:
> Why do we want to increase the parameter count here? Specifically, why is it 
> not enough to || this condition to the first is in the function?
I'm not sure to understand. You want to move this test in the first "if" of 
updateParameterCount()?
Like :

```
if ((Current->is(tok::l_brace) && Current->BlockKind == BK_Block) ||
 Style.BraceWrapping.BeforeLambdaBody && Current->is(TT_LambdaLSquare))
++Left->BlockParameterCount;
```
If it's the case, doing that won't work, because updateParameterCount() is call 
only for brace, not square, so the condition while be true only once and the 
BlockParameterCount while be equal to 1.
And ContinuationIndenter::moveStatePastScopeOpener() while require a value 
greater than 1 to flag true 'HasMultipleNestedBlocks'.
Same for ParameterCount.

I had this code because I was thinking that you want me to have this 
BlockParameterCount equal to 2 in case a lambda is alone inside a function.


Repository:
  rC Clang

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-07-02 Thread Francois JEAN via Phabricator via cfe-commits
Wawha updated this revision to Diff 153813.
Wawha added a comment.

Here the third version to manage break with lambda in Allman.
I implement the modification propose by klimek.
If a lambda is detected, the BlockParameterCount and ParameterCount are 
increment one more time in order to avoid extra line parsing after. It's lead 
to less code and less computation time, so I prefer this modification too.
Thank to klimek for this great remark :).

I hope that the patch is now ok for a submission. If there is other needs or 
remarks, tell me.


Repository:
  rC Clang

https://reviews.llvm.org/D44609

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10461,6 +10461,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterExternBlock);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeLambdaBody);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
@@ -11403,6 +11404,49 @@
   "> {\n"
   "  //\n"
   "});");
+
+  // Check option "BraceWrapping.BeforeLambdaBody"
+  FormatStyle LLVMWithBeforeLambdaBody = getLLVMStyle();
+  LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
+  LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
+  verifyFormat("FunctionWithOneParam(\n"
+   "[]()\n"
+   "{\n"
+   "  // A cool function...\n"
+   "  return 43;\n"
+   "},\n"
+   "87);",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FunctionWithTwoParams(\n"
+   "[]()\n"
+   "{\n"
+   "  // A cool function...\n"
+   "  return 43;\n"
+   "},\n"
+   "87);",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FunctionWithOneNestedLambdas(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call(\n"
+   "  []()\n"
+   "  {\n"
+   "return 17;\n"
+   "  });\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto array = {[]()\n"
+   "  {\n"
+   "return 43;\n"
+   "  },\n"
+   "  MyFunctor};",
+   LLVMWithBeforeLambdaBody);
 }
 
 TEST_F(FormatTest, EmptyLinesInLambdas) {
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1404,6 +1404,7 @@
   return true;
 }
   }
+  FormatTok->Type = TT_LambdaLBrace;
   LSquare.Type = TT_LambdaLSquare;
   parseChildBlock();
   return true;
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -624,6 +624,10 @@
 } else if (Left->ParameterCount == 0 && Current->isNot(tok::comment)) {
   Left->ParameterCount = 1;
 }
+if(Style.BraceWrapping.BeforeLambdaBody && Current->is(TT_LambdaLSquare)) {
+++Left->BlockParameterCount;
+++Left->ParameterCount;
+}
   }
 
   bool parseConditional() {
@@ -1108,11 +1112,11 @@
 
 // Reset token type in case we have already looked at it and then
 // recovered from an error (e.g. failure to find the matching >).
-if (!CurrentToken->isOneOf(TT_LambdaLSquare, TT_ForEachMacro,
-   TT_FunctionLBrace, TT_ImplicitStringLiteral,
-   TT_InlineASMBrace, TT_JsFatArrow, TT_LambdaArrow,
-   TT_OverloadedOperator, TT_RegexLiteral,
-   TT_TemplateString, TT_ObjCStringLiteral))
+if (!CurrentToken->isOneOf(
+TT_LambdaLSquare, TT_LambdaLBrace, TT_ForEachMacro,
+TT_FunctionLBrace, TT_ImplicitStringLiteral, TT_InlineASMBrace,
+TT_JsFatArrow, TT_LambdaArrow, TT_OverloadedOperator,
+TT_RegexLiteral, TT_TemplateString, TT_ObjCStringLiteral))
   CurrentToken->Type = 

[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-06-26 Thread Francois JEAN via Phabricator via cfe-commits
Wawha marked 2 inline comments as done.
Wawha added a comment.

  Hello,

after my last modification (require by previous comment), I do not see any 
feedback or validation for this patch.
Is their something special to do in order to go forward on this patch?

Lambda are more an more used in modern C++, and it's very annoying to not have 
a way to format them in allman style.


Repository:
  rC Clang

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-04-28 Thread Francois JEAN via Phabricator via cfe-commits
Wawha updated this revision to Diff 144460.
Wawha added a reviewer: klimek.
Wawha added a comment.

Hi klimek,
I upload a new patch with the modifications you proposed.
The option is now enable by default in Allman style. So I move the option to 
the BraceWrappingFlags struct, which make more sense.

I also make the second modification you propose to avoid parsing the complete 
line.
Tell me if it's fit your remarks.


Repository:
  rC Clang

https://reviews.llvm.org/D44609

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  lib/Format/TokenAnnotator.h
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10461,6 +10461,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterExternBlock);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeLambdaBody);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
@@ -11403,6 +11404,49 @@
   "> {\n"
   "  //\n"
   "});");
+
+  // Check option "BraceWrapping.BeforeLambdaBody"
+  FormatStyle LLVMWithBeforeLambdaBody = getLLVMStyle();
+  LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
+  LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
+  verifyFormat("FunctionWithOneParam(\n"
+   "[]()\n"
+   "{\n"
+   "  // A cool function...\n"
+   "  return 43;\n"
+   "},\n"
+   "87);",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FunctionWithTwoParams(\n"
+   "[]()\n"
+   "{\n"
+   "  // A cool function...\n"
+   "  return 43;\n"
+   "},\n"
+   "87);",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FunctionWithOneNestedLambdas(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call(\n"
+   "  []()\n"
+   "  {\n"
+   "return 17;\n"
+   "  });\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto array = {[]()\n"
+   "  {\n"
+   "return 43;\n"
+   "  },\n"
+   "  MyFunctor};",
+   LLVMWithBeforeLambdaBody);
 }
 
 TEST_F(FormatTest, EmptyLinesInLambdas) {
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1404,6 +1404,7 @@
   return true;
 }
   }
+  FormatTok->Type = TT_LambdaLBrace;
   LSquare.Type = TT_LambdaLSquare;
   parseChildBlock();
   return true;
Index: lib/Format/TokenAnnotator.h
===
--- lib/Format/TokenAnnotator.h
+++ lib/Format/TokenAnnotator.h
@@ -95,6 +95,17 @@
   template  bool endsWith(Ts... Tokens) const {
 return Last && Last->endsSequence(Tokens...);
   }
+  /// \c true if this line, starting at token 'Start', contains the given tokens in order,
+  /// ignoring comments.
+  template  bool containsAfter(const FormatToken& Start, Ts... Tokens) const {
+const FormatToken *Tok = 
+while (Tok) {
+if(Tok->startsSequence(Tokens...))
+return true;
+Tok = Tok->Next;
+}
+return false;
+  }
 
   /// \c true if this line looks like a function definition instead of a
   /// function declaration. Asserts MightBeFunctionDecl.
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1108,11 +1108,11 @@
 
 // Reset token type in case we have already looked at it and then
 // recovered from an error (e.g. failure to find the matching >).
-if (!CurrentToken->isOneOf(TT_LambdaLSquare, TT_ForEachMacro,
-   TT_FunctionLBrace, TT_ImplicitStringLiteral,
-   TT_InlineASMBrace, TT_JsFatArrow, TT_LambdaArrow,
-   TT_OverloadedOperator, TT_RegexLiteral,
-   

[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-04-27 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

  Hi klimek,

many thank for your comments. I will made the modifications you propose and 
then update this patch.


Repository:
  rC Clang

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-04-23 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

  Hi djasper,

Here a project where there is lambda and allman style for them : 
https://github.com/boostorg/hof/blob/develop/example/in.cpp
https://github.com/boostorg/hof/blob/develop/example/sequence.cpp

Example of code:

  // Function to find an iterator using a containers built-in find if available
  BOOST_HOF_STATIC_LAMBDA_FUNCTION(find_iterator) = first_of(
  [](const std::string& s, const auto& x)
  {
  auto index = s.find(x);
  if (index == std::string::npos) return s.end();
  else return s.begin() + index;
  },
  #ifdef _MSC_VER
  // On MSVC, trailing decltype doesn't work with generic lambdas, so a
  // seperate function can be used instead.
  BOOST_HOF_LIFT(member_find),
  #else
  [](const auto& r, const auto& x) BOOST_HOF_RETURNS(r.find(x)),
  #endif
  [](const auto& r, const auto& x)
  {
  using std::begin;
  using std::end;
  return std::find(begin(r), end(r), x);
  }
  );

What could be the next to move forward on this topic?
Do you think that some modification should be make on this patch? Change option 
name? Make it default behavior for allman?


Repository:
  rC Clang

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-04-06 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

I'm not working on a public project with a public style guide, so not sure it 
will fit all the requirement inside. But perhaps the request of Rian for 
bareflank (https://bugs.llvm.org//show_bug.cgi?id=32151#c4) could help to fit 
the needs.

The current patch do not exactly do what he ask, but like you say, it's not 
easy to find all options or one options to match lambda formatting.

In my case, the main requirement is to be able **avoid** a lambda in one line. 
It's not easy to manage, when you put a breakpoint on a such line. It could 
break when the function taking the lambda in arg is call, or when the lambda 
body is executed. Which very annoying for debugging.
As example:

  return something([] ()  { somethingelse(); }); // Breakpoint one this line 
will break when calling something() AND somethingelse()

For the moment, there is no way to format is code in another way. We could have 
this possibilities:

  return something(
   [] ()
   {
 somethingelse();
   });

or

  return something([] ()  {
 somethingelse();
   });

or

  return something(
   [] ()  {
 somethingelse();
   });

The current patch are able to manage the first case, and I'm agree it make 
sense in allman option. So I'm ok to have it by default for allman.


Repository:
  rC Clang

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-03-28 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

I do not know which reviewer to add for this review. Is it possible to give the 
name of the person that will be able to review this code ?


Repository:
  rC Clang

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-03-18 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

In https://reviews.llvm.org/D44609#1041260, @lebedev.ri wrote:

> Also, tests?


Sorry, the test files was missing with the first patch. I make mistake using 
svn... I create the new patch with git, it's easier for me.
There is 4 small tests inside unittests/Format/FormatTest.cpp. The first 3 are 
testing the new options, and the last one is here to check that there is no 
regression with initialiser list which contain lambda.


Repository:
  rC Clang

https://reviews.llvm.org/D44609



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-03-18 Thread Francois JEAN via Phabricator via cfe-commits
Wawha updated this revision to Diff 138859.
Wawha added a comment.

I upload the full context for these files.


Repository:
  rC Clang

https://reviews.llvm.org/D44609

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Format/TokenAnnotator.h
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11357,6 +11357,42 @@
   "> {\n"
   "  //\n"
   "});");
+
+  // Check option "BreakBeforeLambdaBody"
+  FormatStyle LLVMWithBreakBeforeLambdaBody = getLLVMStyle();
+  LLVMWithBreakBeforeLambdaBody.BreakBeforeLambdaBody = true;
+  verifyFormat("FunctionWithOneParam(\n"
+   "[]()\n"
+   "{\n"
+   "  // A cool function...\n"
+   "  return 43;\n"
+   "},\n"
+   "87);",
+   LLVMWithBreakBeforeLambdaBody);
+  verifyFormat("FunctionWithTwoParams(\n"
+   "[]()\n"
+   "{\n"
+   "  // A cool function...\n"
+   "  return 43;\n"
+   "},\n"
+   "87);",
+   LLVMWithBreakBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call(\n"
+   "  []()\n"
+   "  {\n"
+   "return 17;\n"
+   "  });\n"
+   "});",
+   LLVMWithBreakBeforeLambdaBody);
+  verifyFormat("auto array = {[]()\n"
+   "  {\n"
+   "return 43;\n"
+   "  },\n"
+   "  MyFunctor};",
+   LLVMWithBreakBeforeLambdaBody);
 }
 
 TEST_F(FormatTest, EmptyLinesInLambdas) {
Index: lib/Format/TokenAnnotator.h
===
--- lib/Format/TokenAnnotator.h
+++ lib/Format/TokenAnnotator.h
@@ -94,6 +94,28 @@
   template  bool endsWith(Ts... Tokens) const {
 return Last && Last->endsSequence(Tokens...);
   }
+  /// \c true if this line, starting at token 'Start', contains the given tokens in reverse order,
+  /// ignoring comments.
+  template  bool containsBefore(const FormatToken& Start, Ts... Tokens) const {
+const FormatToken *Tok = 
+while (Tok) {
+if(Tok->startsSequence(Tokens...))
+return true;
+Tok = Tok->Previous;
+}
+return false;
+  }
+  /// \c true if this line, starting at token 'Start', contains the given tokens in order,
+  /// ignoring comments.
+  template  bool containsAfter(const FormatToken& Start, Ts... Tokens) const {
+const FormatToken *Tok = 
+while (Tok) {
+if(Tok->startsSequence(Tokens...))
+return true;
+Tok = Tok->Next;
+}
+return false;
+  }
 
   /// \c true if this line looks like a function definition instead of a
   /// function declaration. Asserts MightBeFunctionDecl.
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2841,7 +2841,8 @@
   if (Right.is(TT_InlineASMBrace))
 return Right.HasUnescapedNewline;
   if (isAllmanBrace(Left) || isAllmanBrace(Right))
-return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
+return (Line.containsBefore(Right, TT_LambdaLSquare) && Style.BreakBeforeLambdaBody) ||
+   (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_typedef, tok::kw_enum) &&
 Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) ||
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -337,6 +337,7 @@
 IO.mapOptional("BreakBeforeBraces", Style.BreakBeforeBraces);
 IO.mapOptional("BreakBeforeInheritanceComma",
Style.BreakBeforeInheritanceComma);
+IO.mapOptional("BreakBeforeLambdaBody", Style.BreakBeforeLambdaBody);
 IO.mapOptional("BreakBeforeTernaryOperators",
Style.BreakBeforeTernaryOperators);
 
@@ -623,6 +624,7 @@
   LLVMStyle.BreakAfterJavaFieldAnnotations = false;
   LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
   LLVMStyle.BreakBeforeInheritanceComma = false;
+  LLVMStyle.BreakBeforeLambdaBody = false;
   LLVMStyle.BreakStringLiterals = true;
   LLVMStyle.ColumnLimit = 80;
   LLVMStyle.CommentPragmas = "^ IWYU pragma:";
Index: lib/Format/ContinuationIndenter.cpp

[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-03-18 Thread Francois JEAN via Phabricator via cfe-commits
Wawha created this revision.
Herald added subscribers: cfe-commits, klimek.

This is a patch to fix the problem identify by this bug: 
https://bugs.llvm.org/show_bug.cgi?id=27640.

When formatting this code with option "BreakBeforeBraces: Allman", the lambda 
body are not put entirely on new lines if the lambda is inside a function call.
Here an example of the current formatting in "allman":

  connect([]() {
foo();
bar();
  });

We the new option, the formatting is like that:

  connect(
[]()
{
  foo();
  bar();
});

It's my first patch for this project, so if I made some mistake, do not 
hesitate to explain me that is wrong.
I write few test to check that the new option work and check that there is no 
regression.

This patch should also meet the request of this bug/request: 
https://bugs.llvm.org//show_bug.cgi?id=32151


Repository:
  rC Clang

https://reviews.llvm.org/D44609

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Format/TokenAnnotator.h

Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -872,6 +872,24 @@
   /// \endcode
   bool BreakBeforeInheritanceComma;
 
+  /// \brief Wrap lambda block inside function parameters list.
+  /// \code
+  ///   true:
+  ///   connect(
+  /// []()
+  /// {
+  ///   foo();
+  ///   bar();
+  /// });
+  ///
+  ///   false:
+  ///   connect([]() {
+  /// foo();
+  /// bar();
+  ///   });
+  /// \endcode
+  bool BreakBeforeLambdaBody;
+
   /// \brief If ``true``, consecutive namespace declarations will be on the same
   /// line. If ``false``, each namespace is declared on a new line.
   /// \code
@@ -1723,6 +1741,7 @@
BreakStringLiterals == R.BreakStringLiterals &&
ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
BreakBeforeInheritanceComma == R.BreakBeforeInheritanceComma &&
+   BreakBeforeLambdaBody == R.BreakBeforeLambdaBody &&
ConstructorInitializerAllOnOneLineOrOnePerLine ==
R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
ConstructorInitializerIndentWidth ==
Index: lib/Format/TokenAnnotator.h
===
--- lib/Format/TokenAnnotator.h
+++ lib/Format/TokenAnnotator.h
@@ -94,6 +94,28 @@
   template  bool endsWith(Ts... Tokens) const {
 return Last && Last->endsSequence(Tokens...);
   }
+  /// \c true if this line, starting at token 'Start', contains the given tokens in reverse order,
+  /// ignoring comments.
+  template  bool containsBefore(const FormatToken& Start, Ts... Tokens) const {
+const FormatToken *Tok = 
+while (Tok) {
+if(Tok->startsSequence(Tokens...))
+return true;
+Tok = Tok->Previous;
+}
+return false;
+  }
+  /// \c true if this line, starting at token 'Start', contains the given tokens in order,
+  /// ignoring comments.
+  template  bool containsAfter(const FormatToken& Start, Ts... Tokens) const {
+const FormatToken *Tok = 
+while (Tok) {
+if(Tok->startsSequence(Tokens...))
+return true;
+Tok = Tok->Next;
+}
+return false;
+  }
 
   /// \c true if this line looks like a function definition instead of a
   /// function declaration. Asserts MightBeFunctionDecl.
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2841,7 +2841,8 @@
   if (Right.is(TT_InlineASMBrace))
 return Right.HasUnescapedNewline;
   if (isAllmanBrace(Left) || isAllmanBrace(Right))
-return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
+return (Line.containsBefore(Right, TT_LambdaLSquare) && Style.BreakBeforeLambdaBody) ||
+   (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_typedef, tok::kw_enum) &&
 Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) ||
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -337,6 +337,7 @@
 IO.mapOptional("BreakBeforeBraces", Style.BreakBeforeBraces);
 IO.mapOptional("BreakBeforeInheritanceComma",
Style.BreakBeforeInheritanceComma);
+IO.mapOptional("BreakBeforeLambdaBody", Style.BreakBeforeLambdaBody);
 IO.mapOptional("BreakBeforeTernaryOperators",
Style.BreakBeforeTernaryOperators);
 
@@ -623,6 +624,7 @@
   LLVMStyle.BreakAfterJavaFieldAnnotations = false;
   LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
   LLVMStyle.BreakBeforeInheritanceComma =