This is an archive of the discontinued LLVM Phabricator instance.

[clang-format][NFC] Handle wrapping after => in mustBreakBefore()
ClosedPublic

Authored by owenpan on Dec 17 2021, 12:28 PM.

Details

Summary

Move the handling of brace wrapping after => from unwrapped line parser to token annotator and clean up the parser.

Diff Detail

Unit TestsFailed

Event Timeline

owenpan requested review of this revision.Dec 17 2021, 12:28 PM
owenpan created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 17 2021, 12:28 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
clang/lib/Format/UnwrappedLineParser.cpp
1640–1641

Should we add the isCSharp check?

owenpan added inline comments.Dec 17 2021, 1:17 PM
clang/lib/Format/UnwrappedLineParser.cpp
1640–1641

No. It was not there before, and adding it would fail several JavaScript test cases.

This revision is now accepted and ready to land.Dec 17 2021, 1:39 PM
owenpan updated this revision to Diff 395380.Dec 19 2021, 11:12 PM

Additional cleanups:

  • Restrict parsing => to JavaScript and C#.
  • Rename tryToParseCSharpLambda to tryToParseChildBlock.
  • Remove redundant caret case.
owenpan marked an inline comment as done.Dec 19 2021, 11:15 PM
owenpan added inline comments.
clang/lib/Format/UnwrappedLineParser.cpp
1640–1641

Should we add the isCSharp check?

Added checking for either JavaScript or C#.

owenpan requested review of this revision.Dec 19 2021, 11:18 PM
MyDeveloperDay added inline comments.Dec 20 2021, 2:00 AM
clang/lib/Format/UnwrappedLineParser.cpp
2005

Is this case not covered by this? I presume not as you didn't remove any unit tests

https://github.com/llvm/llvm-project/commit/516e054c05fcf92b89fbac3e22048f2c00cf218f

void f() {
   int i = {[operation setCompletionBlock : ^{
     [self onOperationDone];
   }] };
 }
owenpan added inline comments.Dec 20 2021, 2:24 AM
clang/lib/Format/UnwrappedLineParser.cpp
2005

I had checked the commit you mentioned above before I decided to remove this case. Apparently it's redundant to the caret case in parseStructuralElement().

MyDeveloperDay accepted this revision.Dec 20 2021, 2:27 AM

LGTM, (the original code had a unit test so we should be good).

This revision is now accepted and ready to land.Dec 20 2021, 2:27 AM
peterstys added inline comments.Dec 20 2021, 2:39 AM
clang/lib/Format/UnwrappedLineParser.cpp
1955–1958

It seems that this block could be removed altogether, because this is already done on lines 1964-165, and it's done regardless if it the language is C# or not.

owenpan added inline comments.Dec 20 2021, 3:32 PM
clang/lib/Format/UnwrappedLineParser.cpp
1955–1958

Lines 1964-1965 only apply to JavaScript because of line 1958, so lines 1955-1957 cannot be removed.

owenpan added inline comments.Dec 20 2021, 4:26 PM
clang/lib/Format/UnwrappedLineParser.cpp
1963–1964

Removing these two lines doesn't fail FormatTests.

owenpan updated this revision to Diff 395544.Dec 20 2021, 4:30 PM

Removed more redundant code.

owenpan requested review of this revision.Dec 20 2021, 4:34 PM
owenpan added a reviewer: krasimir.
This revision is now accepted and ready to land.Dec 21 2021, 2:05 AM
peterstys added inline comments.Dec 21 2021, 2:22 AM
clang/lib/Format/UnwrappedLineParser.cpp
1955–1958

Oh yes, sorry I missed the Javascript block. I wonder if in that case wouldn't be more consistent to add Javascript check on the line 1955 to be consistent with how the same block of logic is handled on the lines 1641-1645.

owenpan added inline comments.Dec 21 2021, 2:42 AM
clang/lib/Format/UnwrappedLineParser.cpp
1955–1958

I don't think so because here we must parse the optional async function part first for JavaScript only.

Good that you renamed the method.

This revision was landed with ongoing or failed builds.Dec 21 2021, 5:00 PM
This revision was automatically updated to reflect the committed changes.