summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/WhitespaceManager.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-01-25 13:58:58 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-01-25 13:58:58 +0000
commit91834227a3d58ecdb9e3f7300f587ab45c32ba06 (patch)
treeea69dbb58f44ddcc2ed095c59818658998aa5681 /clang/lib/Format/WhitespaceManager.cpp
parentf242ffa09581e22dfd3207223ca4e4d3e9327bff (diff)
downloadbcm5719-llvm-91834227a3d58ecdb9e3f7300f587ab45c32ba06.tar.gz
bcm5719-llvm-91834227a3d58ecdb9e3f7300f587ab45c32ba06.zip
[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 llvm-svn: 293055
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index b64506f3903..6b14af3f756 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/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.
OpenPOWER on IntegriCloud