diff options
author | Krasimir Georgiev <krasimir@google.com> | 2017-01-25 13:58:58 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2017-01-25 13:58:58 +0000 |
commit | 281837fef458eab3b3de82646e7e086cd2f2b518 (patch) | |
tree | a1bb3102c1673f844a63d467b7c639956dac60fc /lib/Format/WhitespaceManager.cpp | |
parent | f04cedd83ef0c835d54da5ede81a0be72081feba (diff) | |
download | clang-281837fef458eab3b3de82646e7e086cd2f2b518.tar.gz |
[clang-format] Implement comment reflowing.
Summary:
This presents a version of the comment reflowing with less mutable state inside
the comment breakable token subclasses. The state has been pushed into the
driving breakProtrudingToken method. For this, the API of BreakableToken is enriched
by the methods getSplitBefore and getLineLengthAfterSplitBefore.
Reviewers: klimek
Reviewed By: klimek
Subscribers: djasper, klimek, mgorny, cfe-commits, ioeric
Differential Revision: https://reviews.llvm.org/D28764
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293055 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/WhitespaceManager.cpp')
-rw-r--r-- | lib/Format/WhitespaceManager.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index b64506f390..6b14af3f75 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -127,7 +127,38 @@ void WhitespaceManager::calculateLineBreakInformation() { Changes[i - 1].IsTrailingComment = (Changes[i].NewlinesBefore > 0 || Changes[i].Kind == tok::eof || (Changes[i].IsInsideToken && Changes[i].Kind == tok::comment)) && - Changes[i - 1].Kind == tok::comment; + Changes[i - 1].Kind == tok::comment && + // FIXME: This is a dirty hack. The problem is that + // BreakableLineCommentSection does comment reflow changes and here is + // the aligning of trailing comments. Consider the case where we reflow + // the second line up in this example: + // + // // line 1 + // // line 2 + // + // That amounts to 2 changes by BreakableLineCommentSection: + // - the first, delimited by (), for the whitespace between the tokens, + // - and second, delimited by [], for the whitespace at the beginning + // of the second token: + // + // // line 1( + // )[// ]line 2 + // + // So in the end we have two changes like this: + // + // // line1()[ ]line 2 + // + // Note that the OriginalWhitespaceStart of the second change is the + // same as the PreviousOriginalWhitespaceEnd of the first change. + // In this case, the below check ensures that the second change doesn't + // get treated as a trailing comment change here, since this might + // trigger additional whitespace to be wrongly inserted before "line 2" + // by the comment aligner here. + // + // For a proper solution we need a mechanism to say to WhitespaceManager + // that a particular change breaks the current sequence of trailing + // comments. + OriginalWhitespaceStart != PreviousOriginalWhitespaceEnd; } // FIXME: The last token is currently not always an eof token; in those // cases, setting TokenLength of the last token to 0 is wrong. |