diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-21 22:49:20 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-21 22:49:20 +0000 |
commit | 821627e5865c29357aef0e4f175b0abd083bf191 (patch) | |
tree | 76688f04da52bb84480fec6e1e0f3d7fce6fdded /lib/Format/Format.cpp | |
parent | ed01f84d20a1586b2d639b47463cf1f22418f0f6 (diff) |
Remove "incorrect" aligning of trailing comments.
We used to align trailing comments belong to different things.
Before:
void f() { // some function..
}
int a; // some variable..
After:
void f() { // some function..
}
int a; // some variable..
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173100 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r-- | lib/Format/Format.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 6fb1bc2cb7..05c96bd38d 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -202,7 +202,13 @@ public: void replaceWhitespace(const AnnotatedToken &Tok, unsigned NewLines, unsigned Spaces, unsigned WhitespaceStartColumn, const FormatStyle &Style) { - if (Tok.Type == TT_LineComment && NewLines < 2 && + // 2+ newlines mean an empty line separating logic scopes. + if (NewLines >= 2) + alignComments(); + + // Align line comments if they are trailing or if they continue other + // trailing comments. + if (Tok.Type == TT_LineComment && (Tok.Parent != NULL || !Comments.empty())) { if (Style.ColumnLimit >= Spaces + WhitespaceStartColumn + Tok.FormatTok.TokenLength) { @@ -215,10 +221,11 @@ public: Spaces - Tok.FormatTok.TokenLength; return; } - } else if (NewLines == 0 && Tok.Children.empty() && - Tok.Type != TT_LineComment) { - alignComments(); } + + // If this line does not have a trailing comment, align the stored comments. + if (Tok.Children.empty() && Tok.Type != TT_LineComment) + alignComments(); storeReplacement(Tok.FormatTok, std::string(NewLines, '\n') + std::string(Spaces, ' ')); } |