зеркало из https://github.com/microsoft/clang-1.git
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:
Родитель
b76d9718ca
Коммит
f39c8859b0
|
@ -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;
|
||||
|
|
|
@ -1006,10 +1006,10 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) {
|
|||
TEST_F(FormatTest, FormatsBuilderPattern) {
|
||||
verifyFormat(
|
||||
"return llvm::StringSwitch<Reference::Kind>(name)\n"
|
||||
" .StartsWith(\".eh_frame_hdr\", ORDER_EH_FRAMEHDR)\n"
|
||||
" .StartsWith(\".eh_frame\", ORDER_EH_FRAME).StartsWith(\".init\", ORDER_INIT)\n"
|
||||
" .StartsWith(\".fini\", ORDER_FINI).StartsWith(\".hash\", ORDER_HASH)\n"
|
||||
" .Default(ORDER_TEXT);\n");
|
||||
" .StartsWith(\".eh_frame_hdr\", ORDER_EH_FRAMEHDR)\n"
|
||||
" .StartsWith(\".eh_frame\", ORDER_EH_FRAME).StartsWith(\".init\", ORDER_INIT)\n"
|
||||
" .StartsWith(\".fini\", ORDER_FINI).StartsWith(\".hash\", ORDER_HASH)\n"
|
||||
" .Default(ORDER_TEXT);\n");
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, DoesNotBreakTrailingAnnotation) {
|
||||
|
@ -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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче