This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Recognize nested blocks
AbandonedPublic

Authored by sstwcw on May 12 2023, 8:37 AM.

Details

Summary

Now a block gets recognized as a block if it contains a block.

The special cases we added don't have additional tests because they
are already tested for example in FormatTest.FormatsLambdas and
FormatTestJS.ContainerLiterals.

Fixes https://github.com/llvm/llvm-project/issues/33891

Diff Detail

Event Timeline

sstwcw created this revision.May 12 2023, 8:37 AM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptMay 12 2023, 8:37 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sstwcw requested review of this revision.May 12 2023, 8:37 AM
sstwcw updated this revision to Diff 521667.May 12 2023, 8:51 AM
  • Remove the special case for operator[], it isn't necessary.

Coincidentally I also sent out a review to fix this issue yesterday, but went with a different approach of trying to scope the ProbablyBracedList logic by just looking at the lbrace previous token.

https://reviews.llvm.org/D150403

On this change I like the token annotator tests, and reusing the same stack instead of adding a second one which always has the same size.
But the code changes in D150403 seem to be better, at least I couldn't think directly on something which may not work.

clang/lib/Format/UnwrappedLineParser.cpp
492

Shouldn't it be called NextBraceIsProbablyLambda (or similar)?

659

How does this work on

{
int foo[]={2,5};
int bar[]{2};
}

or

{
SomeClass foo[]={{arg1, whatever}, {arg2, dontcare}};
SomeClass foo[]{{arg1, whatever}, {arg2, dontcare}};
}

?

clang/unittests/Format/TokenAnnotatorTest.cpp
43

Nice!

sstwcw abandoned this revision.May 12 2023, 6:20 PM

I like D150403 better.