Improve indentation of assignments.

Before:
unsigned OriginalStartColumn = SourceMgr.getSpellingColumnNumber(
    Current.FormatTok.getStartOfNonWhitespace()) -
                               1;

After:
unsigned OriginalStartColumn =
    SourceMgr.getSpellingColumnNumber(
        Current.FormatTok.getStartOfNonWhitespace()) -
    1;

llvm-svn: 182733
This commit is contained in:
Daniel Jasper 2013-05-27 12:45:09 +00:00
parent 75081b5cf8
commit 7b27a10b1e
2 changed files with 8 additions and 1 deletions

View File

@ -640,7 +640,10 @@ private:
else if ((Previous.Type == TT_BinaryOperator ||
Previous.Type == TT_ConditionalExpr ||
Previous.Type == TT_CtorInitializerColon) &&
getPrecedence(Previous) != prec::Assignment)
!(getPrecedence(Previous) == prec::Assignment &&
Current.FakeLParens.empty()))
// Always indent relative to the RHS of the expression unless this is a
// simple assignment without binary expression on the RHS.
State.Stack.back().LastSpace = State.Column;
else if (Previous.Type == TT_InheritanceColon)
State.Stack.back().Indent = State.Column;

View File

@ -2336,6 +2336,10 @@ TEST_F(FormatTest, BreaksAfterAssignments) {
verifyFormat(
"aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa = aaaaaaaaaaaaaa(0).aaaa()\n"
" .aaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaaaaaaa);");
verifyFormat("unsigned OriginalStartColumn =\n"
" SourceMgr.getSpellingColumnNumber(\n"
" Current.FormatTok.getStartOfNonWhitespace()) -\n"
" 1;");
}
TEST_F(FormatTest, AlignsAfterAssignments) {