summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/WhitespaceManager.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-11-08 23:31:14 +0000
committerDaniel Jasper <djasper@google.com>2013-11-08 23:31:14 +0000
commit0e93cdb0d02e7e078ef9187f688626673f02515d (patch)
tree2e81c7dfee734610ab4fc048b807e63a7fbb997e /clang/lib/Format/WhitespaceManager.cpp
parent9969d3e6e86236878fd4b4fab55473870290d709 (diff)
downloadbcm5719-llvm-0e93cdb0d02e7e078ef9187f688626673f02515d.tar.gz
bcm5719-llvm-0e93cdb0d02e7e078ef9187f688626673f02515d.zip
clang-format: Improve clang-format's detection about comment binding.
Before, existing code in the form of: int a; // this is a. // This is // b. int b; Got turned into: int a; // this is a. // This is // b. int b; llvm-svn: 194294
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index c24ccdfee4d..26a8d41e874 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -141,19 +141,21 @@ void WhitespaceManager::alignTrailingComments() {
bool FollowsRBraceInColumn0 = i > 0 && Changes[i].NewlinesBefore == 0 &&
Changes[i - 1].Kind == tok::r_brace &&
Changes[i - 1].StartOfTokenColumn == 0;
- bool WasAlignedWithStartOfNextLine =
- // A comment on its own line.
- Changes[i].NewlinesBefore == 1 &&
- // Not the last line.
- i + 1 != e &&
- // The start of the next token was previously aligned with
- // the start of this comment.
- (SourceMgr.getSpellingColumnNumber(
- Changes[i].OriginalWhitespaceRange.getEnd()) ==
- SourceMgr.getSpellingColumnNumber(
- Changes[i + 1].OriginalWhitespaceRange.getEnd())) &&
- // Which is not a comment itself.
- Changes[i + 1].Kind != tok::comment;
+ bool WasAlignedWithStartOfNextLine = false;
+ if (Changes[i].NewlinesBefore == 1) { // A comment on its own line.
+ for (unsigned j = i + 1; j != e; ++j) {
+ if (Changes[j].Kind != tok::comment) { // Skip over comments.
+ // The start of the next token was previously aligned with the
+ // start of this comment.
+ WasAlignedWithStartOfNextLine =
+ (SourceMgr.getSpellingColumnNumber(
+ Changes[i].OriginalWhitespaceRange.getEnd()) ==
+ SourceMgr.getSpellingColumnNumber(
+ Changes[j].OriginalWhitespaceRange.getEnd()));
+ break;
+ }
+ }
+ }
if (!Style.AlignTrailingComments || FollowsRBraceInColumn0) {
alignTrailingComments(StartOfSequence, i, MinColumn);
MinColumn = ChangeMinColumn;
OpenPOWER on IntegriCloud