Don't try to align builder-type continuations on assignments.

Before:
int aaaa = aaaaa().aaaaa() // force break
           .aaaaa();
After:
int aaaa = aaaaa().aaaaa() // force break
    .aaaaa();

The other indent is just wrong and confusing.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173273 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Jasper 2013-01-23 16:58:21 +00:00
Родитель b76d9718ca
Коммит f39c8859b0
2 изменённых файлов: 20 добавлений и 8 удалений

Просмотреть файл

@ -421,9 +421,9 @@ private:
struct ParenState {
ParenState(unsigned Indent, unsigned LastSpace)
: Indent(Indent), LastSpace(LastSpace), FirstLessLess(0),
BreakBeforeClosingBrace(false), BreakAfterComma(false),
HasMultiParameterLine(false) {}
: Indent(Indent), LastSpace(LastSpace), AssignmentColumn(0),
FirstLessLess(0), BreakBeforeClosingBrace(false),
BreakAfterComma(false), HasMultiParameterLine(false) {}
/// \brief The position to which a specific parenthesis level needs to be
/// indented.
@ -436,6 +436,9 @@ private:
/// OtherParameter));
unsigned LastSpace;
/// \brief This is the column of the first token after an assignment.
unsigned AssignmentColumn;
/// \brief The position the first "<<" operator encountered on each level.
///
/// Used to align "<<" operators. 0 if no such operator has been encountered
@ -457,6 +460,8 @@ private:
return Indent < Other.Indent;
if (LastSpace != Other.LastSpace)
return LastSpace < Other.LastSpace;
if (AssignmentColumn != Other.AssignmentColumn)
return AssignmentColumn < Other.AssignmentColumn;
if (FirstLessLess != Other.FirstLessLess)
return FirstLessLess < Other.FirstLessLess;
if (BreakBeforeClosingBrace != Other.BreakBeforeClosingBrace)
@ -547,6 +552,9 @@ private:
State.Column = State.ForLoopVariablePos;
} else if (State.NextToken->Parent->ClosesTemplateDeclaration) {
State.Column = State.Stack[ParenLevel].Indent - 4;
} else if (Previous.Type == TT_BinaryOperator &&
State.Stack.back().AssignmentColumn != 0) {
State.Column = State.Stack.back().AssignmentColumn;
} else {
State.Column = State.Stack[ParenLevel].Indent;
}
@ -587,7 +595,7 @@ private:
if (RootToken.isNot(tok::kw_for) && ParenLevel == 0 &&
(getPrecedence(Previous) == prec::Assignment ||
Previous.is(tok::kw_return)))
State.Stack[ParenLevel].Indent = State.Column + Spaces;
State.Stack.back().AssignmentColumn = State.Column + Spaces;
if (Previous.is(tok::l_paren) || Previous.is(tok::l_brace) ||
State.NextToken->Parent->Type == TT_TemplateOpener)
State.Stack[ParenLevel].Indent = State.Column + Spaces;

Просмотреть файл

@ -1042,6 +1042,10 @@ TEST_F(FormatTest, BreaksAfterAssignments) {
verifyFormat(
"CharSourceRange LineRange = CharSourceRange::getTokenRange(\n"
" Line.Tokens.front().Tok.getLo(), Line.Tokens.back().Tok.getLoc());");
verifyFormat(
"aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa = aaaaaaaaaaaaaa(0).aaaa()\n"
" .aaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaaaaaaa);");
}
TEST_F(FormatTest, AlignsAfterAssignments) {