aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp16
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;