Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Format/ContinuationIndenter.cpp
Show First 20 Lines • Show All 1,047 Lines • ▼ Show 20 Lines | unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, | ||||||||||||
if (CurrentState.AvoidBinPacking) { | if (CurrentState.AvoidBinPacking) { | ||||||||||||
// If we are breaking after '(', '{', '<', or this is the break after a ':' | // If we are breaking after '(', '{', '<', or this is the break after a ':' | ||||||||||||
// to start a member initializater list in a constructor, this should not | // to start a member initializater list in a constructor, this should not | ||||||||||||
// be considered bin packing unless the relevant AllowAll option is false or | // be considered bin packing unless the relevant AllowAll option is false or | ||||||||||||
// this is a dict/object literal. | // this is a dict/object literal. | ||||||||||||
bool PreviousIsBreakingCtorInitializerColon = | bool PreviousIsBreakingCtorInitializerColon = | ||||||||||||
PreviousNonComment && PreviousNonComment->is(TT_CtorInitializerColon) && | PreviousNonComment && PreviousNonComment->is(TT_CtorInitializerColon) && | ||||||||||||
Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon; | Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon; | ||||||||||||
bool AllowAllConstructorInitializersOnNextLine = | |||||||||||||
Style.PackConstructorInitializers == FormatStyle::PCIS_NextLine || | |||||||||||||
Style.PackConstructorInitializers == FormatStyle::PCIS_NextLineOnly; | |||||||||||||
if (!(Previous.isOneOf(tok::l_paren, tok::l_brace, TT_BinaryOperator) || | if (!(Previous.isOneOf(tok::l_paren, tok::l_brace, TT_BinaryOperator) || | ||||||||||||
PreviousIsBreakingCtorInitializerColon) || | PreviousIsBreakingCtorInitializerColon) || | ||||||||||||
(!Style.AllowAllParametersOfDeclarationOnNextLine && | (!Style.AllowAllParametersOfDeclarationOnNextLine && | ||||||||||||
State.Line->MustBeDeclaration) || | State.Line->MustBeDeclaration) || | ||||||||||||
(!Style.AllowAllArgumentsOnNextLine && | (!Style.AllowAllArgumentsOnNextLine && | ||||||||||||
!State.Line->MustBeDeclaration) || | !State.Line->MustBeDeclaration) || | ||||||||||||
(Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine && | (!AllowAllConstructorInitializersOnNextLine && | ||||||||||||
PreviousIsBreakingCtorInitializerColon) || | PreviousIsBreakingCtorInitializerColon) || | ||||||||||||
Previous.is(TT_DictLiteral)) { | Previous.is(TT_DictLiteral)) { | ||||||||||||
CurrentState.BreakBeforeParameter = true; | CurrentState.BreakBeforeParameter = true; | ||||||||||||
} | } | ||||||||||||
// If we are breaking after a ':' to start a member initializer list, | // If we are breaking after a ':' to start a member initializer list, | ||||||||||||
// and we allow all arguments on the next line, we should not break | // and we allow all arguments on the next line, we should not break | ||||||||||||
// before the next parameter. | // before the next parameter. | ||||||||||||
if (PreviousIsBreakingCtorInitializerColon && | if (PreviousIsBreakingCtorInitializerColon && | ||||||||||||
Style.PackConstructorInitializers == FormatStyle::PCIS_NextLine) { | AllowAllConstructorInitializersOnNextLine) { | ||||||||||||
CurrentState.BreakBeforeParameter = false; | CurrentState.BreakBeforeParameter = false; | ||||||||||||
} | } | ||||||||||||
} | } | ||||||||||||
return Penalty; | return Penalty; | ||||||||||||
} | } | ||||||||||||
unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { | unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { | ||||||||||||
▲ Show 20 Lines • Show All 315 Lines • ▼ Show 20 Lines | if (Current.is(TT_CtorInitializerColon) && | ||||||||||||
CurrentState.Indent = State.Column + (Style.BreakConstructorInitializers == | CurrentState.Indent = State.Column + (Style.BreakConstructorInitializers == | ||||||||||||
FormatStyle::BCIS_BeforeComma | FormatStyle::BCIS_BeforeComma | ||||||||||||
? 0 | ? 0 | ||||||||||||
: 2); | : 2); | ||||||||||||
CurrentState.NestedBlockIndent = CurrentState.Indent; | CurrentState.NestedBlockIndent = CurrentState.Indent; | ||||||||||||
if (Style.PackConstructorInitializers > FormatStyle::PCIS_BinPack) { | if (Style.PackConstructorInitializers > FormatStyle::PCIS_BinPack) { | ||||||||||||
CurrentState.AvoidBinPacking = true; | CurrentState.AvoidBinPacking = true; | ||||||||||||
CurrentState.BreakBeforeParameter = | CurrentState.BreakBeforeParameter = | ||||||||||||
Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine; | Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine && | ||||||||||||
Style.PackConstructorInitializers != FormatStyle::PCIS_NextLineOnly; | |||||||||||||
} else { | } else { | ||||||||||||
HazardyKnusperkeksUnsubmitted Done ReplyInline Actions
HazardyKnusperkeks: | |||||||||||||
CurrentState.BreakBeforeParameter = false; | CurrentState.BreakBeforeParameter = false; | ||||||||||||
} | } | ||||||||||||
} | } | ||||||||||||
if (Current.is(TT_CtorInitializerColon) && | if (Current.is(TT_CtorInitializerColon) && | ||||||||||||
Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon) { | Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon) { | ||||||||||||
CurrentState.Indent = | CurrentState.Indent = | ||||||||||||
State.FirstIndent + Style.ConstructorInitializerIndentWidth; | State.FirstIndent + Style.ConstructorInitializerIndentWidth; | ||||||||||||
CurrentState.NestedBlockIndent = CurrentState.Indent; | CurrentState.NestedBlockIndent = CurrentState.Indent; | ||||||||||||
▲ Show 20 Lines • Show All 1,186 Lines • Show Last 20 Lines |