diff options
author | Daniel Jasper <djasper@google.com> | 2013-07-01 11:22:57 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-07-01 11:22:57 +0000 |
commit | 251b3c9e7efe38e9f86d1a17279e03f57e963376 (patch) | |
tree | b34730222d887b9c9bb59eb7e31f21e8e8ca18f7 /clang/lib/Format/WhitespaceManager.cpp | |
parent | 7a1ad5e6056e5c033c4f9f041a5166c6581998cf (diff) | |
download | llvm-251b3c9e7efe38e9f86d1a17279e03f57e963376.zip llvm-251b3c9e7efe38e9f86d1a17279e03f57e963376.tar.gz llvm-251b3c9e7efe38e9f86d1a17279e03f57e963376.tar.bz2 |
Don't align "} // namespace" comments.
This is not all bad, but people are often surprised by it.
Before:
namespace {
int SomeVariable = 0; // comment
} // namespace
After:
namespace {
int SomeVariable = 0; // comment
} // namespace
llvm-svn: 185327
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index e69e15c..90f856b 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -124,6 +124,9 @@ void WhitespaceManager::alignTrailingComments() { unsigned ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength; Newlines += Changes[i].NewlinesBefore; if (Changes[i].IsTrailingComment) { + 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 && @@ -137,13 +140,20 @@ void WhitespaceManager::alignTrailingComments() { Changes[i + 1].OriginalWhitespaceRange.getEnd())) && // Which is not a comment itself. Changes[i + 1].Kind != tok::comment; - if (BreakBeforeNext || Newlines > 1 || - (ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) || - // Break the comment sequence if the previous line did not end - // in a trailing comment. - (Changes[i].NewlinesBefore == 1 && i > 0 && - !Changes[i - 1].IsTrailingComment) || - WasAlignedWithStartOfNextLine) { + if (FollowsRBraceInColumn0) { + // If this comment follows an } in column 0, it probably documents the + // closing of a namespace and we don't want to align it. + alignTrailingComments(StartOfSequence, i, MinColumn); + MinColumn = ChangeMinColumn; + MaxColumn = ChangeMinColumn; + StartOfSequence = i; + } else if (BreakBeforeNext || Newlines > 1 || + (ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) || + // Break the comment sequence if the previous line did not end + // in a trailing comment. + (Changes[i].NewlinesBefore == 1 && i > 0 && + !Changes[i - 1].IsTrailingComment) || + WasAlignedWithStartOfNextLine) { alignTrailingComments(StartOfSequence, i, MinColumn); MinColumn = ChangeMinColumn; MaxColumn = ChangeMaxColumn; |