diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-06-17 12:59:44 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-06-17 12:59:44 +0000 |
commit | 4d26b6efef3a71e583409b148506c3dd6d3a87bb (patch) | |
tree | 34cdef3dfb45841bd3467c9acb18910a02ac3609 /clang/lib/Format | |
parent | 2ab0ac5360e15a5303469a871c420c3f06dea660 (diff) | |
download | bcm5719-llvm-4d26b6efef3a71e583409b148506c3dd6d3a87bb.tar.gz bcm5719-llvm-4d26b6efef3a71e583409b148506c3dd6d3a87bb.zip |
Fixes incorrect indentation of line comments after break and re-alignment.
Summary:
Selectively propagate the information about token kind in
WhitespaceManager::replaceWhitespaceInToken.For correct alignment of new
segments of line comments in order to align them correctly. Don't set
BreakBeforeParameter in breakProtrudingToken for line comments, as it introduces
a break after the _next_ parameter. Added tests for related functions.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D980
llvm-svn: 184076
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/Format.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 11 |
2 files changed, 15 insertions, 6 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 92d58ba04c7..14337e9760e 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -873,8 +873,14 @@ private: if (BreakInserted) { State.Column = PositionAfterLastLineInToken; - for (unsigned i = 0, e = State.Stack.size(); i != e; ++i) - State.Stack[i].BreakBeforeParameter = true; + // If we break the token inside a parameter list, we need to break before + // the next parameter on all levels, so that the next parameter is clearly + // visible. Line comments already introduce a break. + if (Current.Type != TT_LineComment) { + for (unsigned i = 0, e = State.Stack.size(); i != e; ++i) + State.Stack[i].BreakBeforeParameter = true; + } + State.Stack.back().LastSpace = StartColumn; } return Penalty; diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index e3ca32c1865..e69e15cf809 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -65,10 +65,13 @@ void WhitespaceManager::replaceWhitespaceInToken( Tok.getStartOfNonWhitespace().getLocWithOffset( Offset + ReplaceChars)), Spaces, Spaces, Newlines, PreviousPostfix, CurrentPrefix, - // FIXME: Unify token adjustment, so we don't split it between - // BreakableToken and the WhitespaceManager. That would also allow us to - // correctly store a tok::TokenKind instead of rolling our own enum. - tok::unknown, InPPDirective && !Tok.IsFirst)); + // If we don't add a newline this change doesn't start a comment. Thus, + // when we align line comments, we don't need to treat this change as one. + // FIXME: We still need to take this change in account to properly + // calculate the new length of the comment and to calculate the changes + // for which to do the alignment when aligning comments. + Tok.Type == TT_LineComment && Newlines > 0 ? tok::comment : tok::unknown, + InPPDirective && !Tok.IsFirst)); } const tooling::Replacements &WhitespaceManager::generateReplacements() { |