This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Implement comment reflowing (again).
AbandonedPublic

Authored by krasimir on Dec 14 2016, 5:48 AM.

Details

Reviewers
klimek
Summary

Join line comments tokens that belong to the same section together in the same unwrapped line.
Adapt ContinuationIndenter to pass more fields to the BreakableToken to make reflow possible.
Join BreakableBlockComment and BreakableLineComment into a single BreakableComment class.
Implement reflowing within BreakableComment::replaceWhitespaceBefore.
Add a bunch of comment reflowing tests.

Event Timeline

krasimir updated this revision to Diff 81371.Dec 14 2016, 5:48 AM
krasimir retitled this revision from to [clang-format] Implement comment reflowing..
krasimir updated this object.
krasimir added a reviewer: djasper.
krasimir added a subscriber: klimek.

Question is, do I split the newly introduced BreakableComment into two separate classes now (BreakableBlockComment and BreakableLineCommentSection), since there's not a whole lot of reflow reuse functionality -- we need to do totally different things in these two cases.

krasimir retitled this revision from [clang-format] Implement comment reflowing. to [clang-format] Implement comment reflowing (again)..Dec 14 2016, 5:57 AM
krasimir added a subscriber: cfe-commits.
klimek added inline comments.Dec 14 2016, 6:59 AM
lib/Format/BreakableToken.cpp
457

Without looking into this in a lot of detail: this looks like you want a BreakableComment base class, and have BreakableBlockComment and BreakableLineCommentSection derive from it and implement this method.

Scanning it a bit, it seems like there is still overlap - perhaps it's also possible to pull out a couple of smaller sized methods in the interface and write the algorithm in terms of those? That could also make it easier to understand in general (large method alarm ;)

lib/Format/ContinuationIndenter.cpp
1174–1176

Nice that this whole section required so few changes.
Why do we need to call into this in DryRun mode now, though? Does it need to keep state inside in DryRun?

krasimir added inline comments.Dec 14 2016, 7:43 AM
lib/Format/BreakableToken.cpp
457

Next step I'm doing: will extract two subclasses and try to factor out the common functionality. I already did a bit of that with getReflowSplit, but there's more potential for extracting common stuff.

lib/Format/ContinuationIndenter.cpp
1174–1176

Yes, replaceWhitespaceBefore recomputes the ContentColumn in case a reflow with the previous line is decided to be made.
Basically, the whole reflow functionality is inside replaceWhitespaceBefore now (except for a bit of control flow stuff, like updating the ReflowInProgress member variable).

ioeric added a subscriber: ioeric.Dec 14 2016, 7:45 AM
klimek added inline comments.Dec 14 2016, 8:37 AM
lib/Format/ContinuationIndenter.cpp
1174–1176

For my curiosity: what's the reason we can't precompute those in the constructor? Is that too much things we do outside of the flow here?

krasimir updated this revision to Diff 81551.Dec 15 2016, 2:01 AM
  • Split BreakableComment back into a BreakableBlockComment and BreakableLineCommentSection
  • Extract common reflow computation functionality
krasimir updated this revision to Diff 82081.Dec 20 2016, 2:52 AM
  • Put LastLineNeedsDecoration and Decoration and Prefix to the appropriate subclasses
  • Fixed a double indentation bug caused by the WhitespaceManager.

Next 2 steps: will implement a simple heuristic about some sorts of ascii-art types of things; next will branch and produce a version that takes the reflow state out of the BreakableComment classes and puts it in the breakProtrudingToken implementation.

krasimir updated this revision to Diff 82089.Dec 20 2016, 3:40 AM

Ready for review.

  • Split BreakableComment back into a BreakableBlockComment and BreakableLineCommentSection
  • Extract common reflow computation functionality
  • Put LastLineNeedsDecoration and Decoration and Prefix to the appropriate subclasses
  • Fixed a double indentation bug caused by the WhitespaceManager.
  • Implement a simple heuristic to detect ascii-art to stop reflow early
djasper edited reviewers, added: klimek; removed: djasper.Jan 9 2017, 1:23 AM
djasper edited subscribers, added: djasper; removed: klimek.
krasimir abandoned this revision.Feb 3 2017, 2:24 AM
lib/Format/CMakeLists.txt