diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-23 16:58:21 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-23 16:58:21 +0000 |
commit | f39c8859b087151617aa2c8b193d0b332503e3ca (patch) | |
tree | d864eca2d40acd7ed13808ab971358851e6b9342 /lib/Format/Format.cpp | |
parent | b76d9718caea48b9333979b3da6f3a80110840cb (diff) |
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
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r-- | lib/Format/Format.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 9b6067c37b..eb18be82b3 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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; |