A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://clang.llvm.org/doxygen/ContinuationIndenter_8cpp_source.html below:

clang: lib/Format/ContinuationIndenter.cpp Source File

23#include "llvm/ADT/StringSet.h" 24#include "llvm/Support/Debug.h" 27#define DEBUG_TYPE "format-indenter" 44 Previous

->isOneOf(tok::kw_return, TT_RequiresClause));

93 int

MatchingStackIndex = Stack.size() - 1;

99 while

(MatchingStackIndex >= 0 && Stack[MatchingStackIndex].Tok != LBrace)

100

--MatchingStackIndex;

101 return

MatchingStackIndex >= 0 ? &Stack[MatchingStackIndex] :

nullptr

;

103 for

(; End->Next; End = End->Next) {

104 if

(End->Next->CanBreakBefore)

106 if

(!End->Next->closesScope())

108 if

(End->Next->MatchingParen &&

109

End->Next->MatchingParen->isOneOf(

110

tok::l_brace, TT_ArrayInitializerLSquare, tok::less)) {

111 const ParenState

*State = FindParenState(End->Next->MatchingParen);

112 if

(State && State->BreakBeforeClosingBrace)

134 bool

HasTwoOperands =

Token

.OperatorIndex == 0 && !

Token

.NextOperator;

135 return Token

.

is

(TT_BinaryOperator) && !HasTwoOperands &&

159 if

(LessTok.

isNot

(tok::less))

171 if

(TokenText.size() < 5

172

|| !TokenText.starts_with(

"R\""

) || !TokenText.ends_with(

"\""

)) {

179 size_t

LParenPos = TokenText.substr(0, 19).find_first_of(

'('

);

180 if

(LParenPos == StringRef::npos)

182

StringRef Delimiter = TokenText.substr(2, LParenPos - 2);

185 size_t

RParenPos = TokenText.size() - Delimiter.size() - 2;

186 if

(TokenText[RParenPos] !=

')'

)

188 if

(!TokenText.substr(RParenPos + 1).starts_with(Delimiter))

200 return

StringRef(Format.CanonicalDelimiter);

207

std::optional<FormatStyle> LanguageStyle =

209 if

(!LanguageStyle) {

212

RawStringFormat.Language, &PredefinedStyle)) {

214

PredefinedStyle.

Language

= RawStringFormat.Language;

216

LanguageStyle = PredefinedStyle;

219 for

(StringRef Delimiter : RawStringFormat.Delimiters)

221 for

(StringRef EnclosingFunction : RawStringFormat.EnclosingFunctions)

226

std::optional<FormatStyle>

234

std::optional<FormatStyle>

236

StringRef EnclosingFunction)

const

{

248 bool

BinPackInconclusiveFunctions)

249

: Style(Style), Keywords(Keywords), SourceMgr(SourceMgr),

250

Whitespaces(Whitespaces), Encoding(Encoding),

251

BinPackInconclusiveFunctions(BinPackInconclusiveFunctions),

252

CommentPragmasRegex(Style.CommentPragmas), RawStringFormats(Style) {}

255 unsigned

FirstStartColumn,

259

State.FirstIndent = FirstIndent;

260 if

(FirstStartColumn &&

Line

->First->NewlinesBefore == 0)

261

State.Column = FirstStartColumn;

263

State.Column = FirstIndent;

273

State.NextToken =

Line

->First;

274

State.Stack.push_back(

ParenState

(

nullptr

, FirstIndent, FirstIndent,

277

State.NoContinuation =

false

;

278

State.StartOfStringLiteral = 0;

279

State.NoLineBreak =

false

;

280

State.StartOfLineLevel = 0;

281

State.LowestLevelOnLine = 0;

282

State.IgnoreStackForComparison =

false

;

287 auto

&CurrentState = State.Stack.back();

288

CurrentState.AvoidBinPacking =

true

;

289

CurrentState.BreakBeforeParameter =

true

;

290

CurrentState.AlignColons =

false

;

294

moveStateToNextToken(State, DryRun,

false

);

301 const auto

&CurrentState = State.Stack.back();

302

assert(&

Previous

== Current.Previous);

303 if

(!Current.CanBreakBefore && !(CurrentState.BreakBeforeClosingBrace &&

304

Current.closesBlockOrBlockTypeList(Style))) {

309 if

(!Current.MustBreakBefore &&

Previous

.is(tok::l_brace) &&

312 Previous

.Previous->isOneOf(tok::l_brace, tok::l_paren, tok::comma)) {

321

State.LowestLevelOnLine < State.StartOfLineLevel &&

322

State.LowestLevelOnLine < Current.NestingLevel) {

325 if

(Current.isMemberAccess() && CurrentState.ContainsUnwrappedBuilder)

330 if

(

Previous

.is(tok::l_brace) && State.Stack.size() > 1 &&

331

State.Stack[State.Stack.size() - 2].NestedBlockInlined &&

332

State.Stack[State.Stack.size() - 2].HasMultipleNestedBlocks &&

339 if

(Current.is(TT_FunctionDeclarationName)) {

346

assert(State.Column >= State.FirstIndent);

347 if

(State.Column - State.FirstIndent < 6)

355

Current.is(tok::r_paren)) {

356 return

CurrentState.BreakBeforeClosingParen;

361 if

(Current.is(tok::r_brace) && Current.MatchingParen &&

362

Current.isBlockIndentedInitRBrace(Style)) {

363 return

CurrentState.BreakBeforeClosingBrace;

368 if

(!Current.isOneOf(TT_BinaryOperator, tok::comma) &&

373

Current.isNot(TT_LambdaLBrace)) &&

374

CurrentState.NoLineBreakInOperand) {

381 if

(Current.is(TT_ConditionalExpr) &&

Previous

.is(tok::r_paren) &&

383 Previous

.MatchingParen->Previous->MatchingParen &&

384 Previous

.MatchingParen->Previous->MatchingParen->is(TT_LambdaLBrace)) {

386

assert(

Previous

.MatchingParen->Previous->is(tok::r_brace));

390 return

!State.NoLineBreak && !CurrentState.NoLineBreak;

396 const auto

&CurrentState = State.Stack.back();

398

Current.is(TT_LambdaLBrace) &&

Previous

.isNot(TT_LineComment)) {

402 if

(Current.MustBreakBefore ||

403

(Current.is(TT_InlineASMColon) &&

409 if

(CurrentState.BreakBeforeClosingBrace &&

410

(Current.closesBlockOrBlockTypeList(Style) ||

411

(Current.is(tok::r_brace) &&

412

Current.isBlockIndentedInitRBrace(Style)))) {

415 if

(CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))

419

Current.ObjCSelectorNameParts > 1 &&

420

Current.startsSequence(TT_SelectorName, tok::colon, tok::caret)) {

425 if

(CurrentState.IsCSharpGenericTypeConstraint &&

426 Previous

.isNot(TT_CSharpGenericTypeConstraintComma)) {

430

(

Previous

.is(TT_TemplateCloser) && Current.is(TT_StartOfName) &&

431

State.Line->First->isNot(TT_AttributeSquare) && Style.

isCpp

() &&

441 Previous

.is(TT_ConditionalExpr))) &&

442

CurrentState.BreakBeforeParameter && !Current.isTrailingComment() &&

443

!Current.isOneOf(tok::r_paren, tok::r_brace)) {

446 if

(CurrentState.IsChainedConditional &&

448

Current.is(tok::colon)) ||

454

(

Previous

.is(TT_ArrayInitializerLSquare) &&

463 const FormatToken

&BreakConstructorInitializersToken =

467 if

(BreakConstructorInitializersToken.

is

(TT_CtorInitializerColon) &&

468

(State.Column + State.Line->Last->TotalLength -

Previous

.TotalLength >

470

CurrentState.BreakBeforeParameter) &&

471

(!Current.isTrailingComment() || Current.NewlinesBefore > 0) &&

473

Style.

ColumnLimit

> 0 || Current.NewlinesBefore > 0)) {

477 if

(Current.is(TT_ObjCMethodExpr) &&

Previous

.isNot(TT_SelectorName) &&

478

State.Line->startsWith(TT_ObjCMethodSpecifier)) {

481 if

(Current.is(TT_SelectorName) &&

Previous

.isNot(tok::at) &&

482

CurrentState.ObjCSelectorNameFound && CurrentState.BreakBeforeParameter &&

484

!Current.startsSequence(TT_SelectorName, tok::colon, tok::caret))) {

488 unsigned

NewLineColumn = getNewLineColumn(State);

489 if

(Current.isMemberAccess() && Style.

ColumnLimit

!= 0 &&

491

(State.Column > NewLineColumn ||

492

Current.NestingLevel < State.StartOfLineLevel)) {

497

(CurrentState.CallContinuation != 0 ||

498

CurrentState.BreakBeforeParameter) &&

504

!(State.Column <= NewLineColumn && Style.

isJavaScript

()) &&

505

!(

Previous

.closesScopeAfterBlock() && State.Column <= NewLineColumn)) {

511 if

(

Previous

.ClosesTemplateDeclaration && CurrentState.BreakBeforeParameter &&

512

Current.CanBreakBefore) {

516 if

(State.Line->First->isNot(tok::kw_enum) && State.Column <= NewLineColumn)

521 Previous

.is(tok::comma) || Current.NestingLevel < 2) &&

522

!

Previous

.isOneOf(tok::kw_return, tok::lessless, tok::at,

524

!

Previous

.isOneOf(TT_InlineASMColon, TT_ConditionalExpr) &&

525

nextIsMultilineString(State)) {

532 if

(

Previous

.is(TT_BinaryOperator) && Current.CanBreakBefore) {

533 const auto

PreviousPrecedence =

Previous

.getPrecedence();

535

CurrentState.BreakBeforeParameter && !Current.isTrailingComment()) {

536 const bool

LHSIsBinaryExpr =

549 const bool

IsComparison =

554 Previous

.Previous->isNot(TT_BinaryOperator);

558

}

else if

(Current.is(TT_BinaryOperator) && Current.CanBreakBefore &&

559

CurrentState.BreakBeforeParameter) {

564 if

(Current.is(tok::lessless) && Current.isNot(TT_OverloadedOperator) &&

565

CurrentState.BreakBeforeParameter && CurrentState.FirstLessLess == 0) {

569 if

(Current.NestingLevel == 0 && !Current.isTrailingComment()) {

574 if

(

Previous

.ClosesTemplateDeclaration) {

575 if

(Current.is(tok::kw_concept)) {

585 if

(Current.is(TT_RequiresClause)) {

596

Current.NewlinesBefore > 0);

598 if

(

Previous

.is(TT_FunctionAnnotationRParen) &&

602 if

(

Previous

.is(TT_LeadingJavaAnnotation) && Current.isNot(tok::l_paren) &&

603

Current.isNot(TT_LeadingJavaAnnotation)) {

612 static const

llvm::StringSet<> BreakBeforeDecoratedTokens = {

"get"

,

"set"

,

614 if

(BreakBeforeDecoratedTokens.contains(Current.TokenText))

618 if

(Current.is(TT_FunctionDeclarationName) &&

619

!State.Line->ReturnTypeWrapped &&

626

CurrentState.BreakBeforeParameter) {

635

!Current.isOneOf(tok::r_brace, tok::comment)) {

639 if

(Current.is(tok::lessless) &&

641

(

Previous

.Tok.isLiteral() && (

Previous

.TokenText.ends_with(

"\\n\""

) ||

642 Previous

.TokenText ==

"\'\\n\'"

)))) {

649 if

(State.NoContinuation)

657 unsigned

ExtraSpaces) {

659

assert(State.NextToken->Previous);

662

assert(!State.Stack.empty());

663

State.NoContinuation =

false

;

665 if

(Current.is(TT_ImplicitStringLiteral) &&

666

(!

Previous

.Tok.getIdentifierInfo() ||

667 Previous

.Tok.getIdentifierInfo()->getPPKeywordID() ==

668

tok::pp_not_keyword)) {

671 if

(Current.LastNewlineOffset != 0) {

674

State.Column = EndColumn;

676 unsigned

StartColumn =

678

assert(EndColumn >= StartColumn);

679

State.Column += EndColumn - StartColumn;

681

moveStateToNextToken(State, DryRun,

false

);

685 unsigned

Penalty = 0;

687

Penalty = addTokenOnNewLine(State, DryRun);

689

addTokenOnCurrentLine(State, DryRun, ExtraSpaces);

691 return

moveStateToNextToken(State, DryRun, Newline) + Penalty;

694void

ContinuationIndenter::addTokenOnCurrentLine(

LineState

&State,

bool

DryRun,

695 unsigned

ExtraSpaces) {

697

assert(State.NextToken->Previous);

699 auto

&CurrentState = State.Stack.back();

701 bool

DisallowLineBreaksOnThisLine =

708

Style.

isCpp

() && [&] {

710 if

(

Previous

.is(TT_BlockComment) && Current.SpacesRequiredBefore == 0)

712 const auto

*PrevNonComment = Current.getPreviousNonComment();

713 if

(!PrevNonComment || PrevNonComment->isNot(tok::l_paren))

715 if

(Current.isOneOf(tok::comment, tok::l_paren, TT_LambdaLSquare))

717 auto

BlockParameterCount = PrevNonComment->BlockParameterCount;

718 if

(BlockParameterCount == 0)

722 if

(BlockParameterCount > 1)

726 if

(!PrevNonComment->Role)

728 auto

Comma = PrevNonComment->Role->lastComma();

731 auto

Next = Comma->getNextNonComment();

733

!Next->isOneOf(TT_LambdaLSquare, tok::l_brace, tok::caret);

736 if

(DisallowLineBreaksOnThisLine)

737

State.NoLineBreak =

true

;

739 if

(Current.is(tok::equal) &&

740

(State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&

741

CurrentState.VariablePos == 0 &&

743 Previous

.Previous->isNot(TT_DesignatedInitializerPeriod))) {

744

CurrentState.VariablePos = State.Column;

746 const

FormatToken *Tok = &

Previous

;

747 while

(Tok && CurrentState.VariablePos >= Tok->ColumnWidth) {

748

CurrentState.VariablePos -= Tok->ColumnWidth;

749 if

(Tok->SpacesRequiredBefore != 0)

753 if

(

Previous

.PartOfMultiVariableDeclStmt)

754

CurrentState.LastSpace = CurrentState.VariablePos;

757 unsigned

Spaces = Current.SpacesRequiredBefore + ExtraSpaces;

760 int

PPColumnCorrection = 0;

762 Previous

.is(tok::hash) && State.FirstIndent > 0 &&

766

Spaces += State.FirstIndent;

773

PPColumnCorrection = -1;

778

State.Column + Spaces + PPColumnCorrection,

779 false

, State.Line->InMacroBody);

785

Current.is(TT_InheritanceColon)) {

786

CurrentState.NoLineBreak =

true

;

789 Previous

.is(TT_InheritanceColon)) {

790

CurrentState.NoLineBreak =

true

;

793 if

(Current.is(TT_SelectorName) && !CurrentState.ObjCSelectorNameFound) {

794 unsigned

MinIndent = std::max(

796 unsigned

FirstColonPos = State.Column + Spaces + Current.ColumnWidth;

797 if

(Current.LongestObjCSelectorName == 0)

798

CurrentState.AlignColons =

false

;

799 else if

(MinIndent + Current.LongestObjCSelectorName > FirstColonPos)

800

CurrentState.ColonPos = MinIndent + Current.LongestObjCSelectorName;

802

CurrentState.ColonPos = FirstColonPos;

809 auto

IsOpeningBracket = [&](

const

FormatToken &Tok) {

810 auto

IsStartOfBracedList = [&]() {

811 return

Tok.is(tok::l_brace) && Tok.isNot(

BK_Block

) &&

814 if

(!Tok.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) &&

815

!IsStartOfBracedList()) {

820 if

(Tok.Previous->isIf())

822 return

!Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,

826 auto

IsFunctionCallParen = [](

const

FormatToken &Tok) {

827 return

Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&

828

Tok.Previous->is(tok::identifier);

830 auto

IsInTemplateString = [

this

](

const

FormatToken &Tok) {

833 for

(

const auto

*Prev = &Tok; Prev; Prev = Prev->Previous) {

834 if

(Prev->is(TT_TemplateString) && Prev->opensScope())

836 if

(Prev->opensScope() ||

837

(Prev->is(TT_TemplateString) && Prev->closesScope())) {

844 auto

StartsSimpleOneArgList = [&](

const

FormatToken &TokAfterLParen) {

845

assert(TokAfterLParen.isNot(tok::comment) || TokAfterLParen.Next);

847

TokAfterLParen.is(tok::comment) ? *TokAfterLParen.Next : TokAfterLParen;

848 if

(!Tok.FakeLParens.empty() && Tok.FakeLParens.back() >

prec::Unknown

)

854 if

(Tok.is(tok::kw_new) || Tok.startsSequence(tok::coloncolon, tok::kw_new))

856 if

(Tok.is(TT_UnaryOperator) ||

858

Tok.isOneOf(tok::ellipsis, Keywords.

kw_await

))) {

861 const auto

*

Previous

= Tok.Previous;

863

TT_LambdaDefinitionLParen) &&

864

!IsFunctionCallParen(*

Previous

))) {

867 if

(IsOpeningBracket(Tok) || IsInTemplateString(Tok))

869 const auto

*Next = Tok.Next;

870 return

!Next || Next->isMemberAccess() ||

871

Next->is(TT_FunctionDeclarationLParen) || IsFunctionCallParen(*Next);

875

IsOpeningBracket(

Previous

) && State.Column > getNewLineColumn(State) &&

886

!StartsSimpleOneArgList(Current)) {

887

CurrentState.NoLineBreak =

true

;

891

CurrentState.NoLineBreak =

true

;

898

!CurrentState.IsCSharpGenericTypeConstraint &&

Previous

.opensScope() &&

900 Previous

.isNot(TT_TableGenDAGArgOpener) &&

901 Previous

.isNot(TT_TableGenDAGArgOpenerToBreak) &&

902

!(Current.MacroParent &&

Previous

.MacroParent) &&

903

(Current.isNot(TT_LineComment) ||

905

!IsInTemplateString(Current)) {

906

CurrentState.Indent = State.Column + Spaces;

907

CurrentState.IsAligned =

true

;

910

CurrentState.NoLineBreak =

true

;

912

CurrentState.NoLineBreak =

true

;

915

State.Column > getNewLineColumn(State)) {

916

CurrentState.ContainsUnwrappedBuilder =

true

;

920

CurrentState.NoLineBreak =

true

;

921 if

(Current.isMemberAccess() &&

Previous

.is(tok::r_paren) &&

930

CurrentState.NoLineBreak =

true

;

937 const

FormatToken *

P

= Current.getPreviousNonComment();

938 if

(Current.isNot(tok::comment) &&

P

&&

939

(

P

->isOneOf(TT_BinaryOperator, tok::comma) ||

940

(

P

->is(TT_ConditionalExpr) &&

P

->is(tok::colon))) &&

941

!

P

->isOneOf(TT_OverloadedOperator, TT_CtorInitializerComma) &&

945 bool

BreakBeforeOperator =

946 P

->MustBreakBefore ||

P

->is(tok::lessless) ||

947

(

P

->is(TT_BinaryOperator) &&

953 bool

HasTwoOperands =

P

->OperatorIndex == 0 && !

P

->NextOperator &&

954 P

->isNot(TT_ConditionalExpr);

955 if

((!BreakBeforeOperator &&

958

(!CurrentState.LastOperatorWrapped && BreakBeforeOperator)) {

959

CurrentState.NoLineBreakInOperand =

true

;

963

State.Column += Spaces;

964 if

(Current.isNot(tok::comment) &&

Previous

.is(tok::l_paren) &&

969

CurrentState.LastSpace = State.Column;

970

CurrentState.NestedBlockIndent = State.Column;

971

}

else if

(!Current.isOneOf(tok::comment, tok::caret) &&

973 Previous

.isNot(TT_OverloadedOperator)) ||

975

CurrentState.LastSpace = State.Column;

976

}

else if

(

Previous

.is(TT_CtorInitializerColon) &&

977

(!Current.isTrailingComment() || Current.NewlinesBefore > 0) &&

980

CurrentState.Indent = State.Column;

981

CurrentState.LastSpace = State.Column;

982

}

else if

(

Previous

.isOneOf(TT_ConditionalExpr, TT_CtorInitializerColon)) {

983

CurrentState.LastSpace = State.Column;

984

}

else if

(

Previous

.is(TT_BinaryOperator) &&

988

Current.StartsBinaryExpression)) {

992

CurrentState.LastSpace = State.Column;

993

}

else if

(

Previous

.is(TT_InheritanceColon)) {

994

CurrentState.Indent = State.Column;

995

CurrentState.LastSpace = State.Column;

996

}

else if

(Current.is(TT_CSharpGenericTypeConstraintColon)) {

997

CurrentState.ColonPos = State.Column;

998

}

else if

(

Previous

.opensScope()) {

1005 const

FormatToken *Next =

Previous

.MatchingParen->getNextNonComment();

1006 if

(Next && Next->isMemberAccess() && State.Stack.size() > 1 &&

1007

State.Stack[State.Stack.size() - 2].CallContinuation == 0) {

1008

CurrentState.LastSpace = State.Column;

1014unsigned

ContinuationIndenter::addTokenOnNewLine(LineState &State,

1016

FormatToken &Current = *State.NextToken;

1017

assert(State.NextToken->Previous);

1018 const

FormatToken &

Previous

= *State.NextToken->Previous;

1019 auto

&CurrentState = State.Stack.back();

1023 unsigned

Penalty = 0;

1025 const

FormatToken *PreviousNonComment = Current.getPreviousNonComment();

1026 const

FormatToken *NextNonComment =

Previous

.getNextNonComment();

1027 if

(!NextNonComment)

1028

NextNonComment = &Current;

1031 if

(!CurrentState.ContainsLineBreak)

1033

CurrentState.ContainsLineBreak =

true

;

1035

Penalty += State.NextToken->SplitPenalty;

1040 if

(NextNonComment->is(tok::lessless) && CurrentState.FirstLessLess == 0 &&

1042

CurrentState.BreakBeforeParameter)) {

1046

State.Column = getNewLineColumn(State);

1060 if

(State.Column > State.FirstIndent) {

1075 if

(Current.isNot(TT_LambdaArrow) &&

1076

(!Style.

isJavaScript

() || Current.NestingLevel != 0 ||

1077

!PreviousNonComment || PreviousNonComment->isNot(tok::equal) ||

1079

CurrentState.NestedBlockIndent = State.Column;

1082 if

(NextNonComment->isMemberAccess()) {

1083 if

(CurrentState.CallContinuation == 0)

1084

CurrentState.CallContinuation = State.Column;

1085

}

else if

(NextNonComment->is(TT_SelectorName)) {

1086 if

(!CurrentState.ObjCSelectorNameFound) {

1087 if

(NextNonComment->LongestObjCSelectorName == 0) {

1088

CurrentState.AlignColons =

false

;

1090

CurrentState.ColonPos =

1092

? std::max(CurrentState.Indent,

1094

: CurrentState.Indent) +

1096

NextNonComment->ColumnWidth);

1098

}

else if

(CurrentState.AlignColons &&

1099

CurrentState.ColonPos <= NextNonComment->ColumnWidth) {

1100

CurrentState.ColonPos = State.Column + NextNonComment->ColumnWidth;

1102

}

else if

(PreviousNonComment && PreviousNonComment->is(tok::colon) &&

1103

PreviousNonComment->isOneOf(TT_ObjCMethodExpr, TT_DictLiteral)) {

1113 if

(State.Stack.size() > 1) {

1114

State.Stack[State.Stack.size() - 2].LastSpace =

1115

std::max(CurrentState.LastSpace, CurrentState.Indent) +

1120 if

((PreviousNonComment &&

1121

PreviousNonComment->isOneOf(tok::comma, tok::semi) &&

1122

!CurrentState.AvoidBinPacking) ||

1124

CurrentState.BreakBeforeParameter =

false

;

1126 if

(PreviousNonComment &&

1127

(PreviousNonComment->isOneOf(TT_TemplateCloser, TT_JavaAnnotation) ||

1128

PreviousNonComment->ClosesRequiresClause) &&

1129

Current.NestingLevel == 0) {

1130

CurrentState.BreakBeforeParameter =

false

;

1132 if

(NextNonComment->is(tok::question) ||

1133

(PreviousNonComment && PreviousNonComment->is(tok::question))) {

1134

CurrentState.BreakBeforeParameter =

true

;

1136 if

(Current.is(TT_BinaryOperator) && Current.CanBreakBefore)

1137

CurrentState.BreakBeforeParameter =

false

;

1141 if

(Current.is(tok::r_brace) && Current.MatchingParen &&

1144

!Current.MatchingParen->Children.empty()) {

1148

MaxEmptyLinesToKeep = 1;

1151

std::max(1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));

1152 bool

ContinuePPDirective =

1155

CurrentState.IsAligned, ContinuePPDirective);

1158 if

(!Current.isTrailingComment())

1159

CurrentState.LastSpace = State.Column;

1160 if

(Current.is(tok::lessless)) {

1164

CurrentState.LastSpace += 3;

1167

State.StartOfLineLevel = Current.NestingLevel;

1168

State.LowestLevelOnLine = Current.NestingLevel;

1172 bool

NestedBlockSpecialCase =

1173

(!Style.

isCpp

() && Current.is(tok::r_brace) && State.Stack.size() > 1 &&

1174

State.Stack[State.Stack.size() - 2].NestedBlockInlined) ||

1178

NestedBlockSpecialCase =

1179

NestedBlockSpecialCase ||

1180

(Current.MatchingParen &&

1181

Current.MatchingParen->is(TT_RequiresExpressionLBrace));

1182 if

(!NestedBlockSpecialCase) {

1183 auto

ParentLevelIt = std::next(State.Stack.rbegin());

1185

Current.MatchingParen && Current.MatchingParen->is(TT_LambdaLBrace)) {

1200 auto

FindCurrentLevel = [&](

const auto

&It) {

1201 return

std::find_if(It, State.Stack.rend(), [](

const auto

&PState) {

1202

return PState.Tok != nullptr;

1205 auto

MaybeIncrement = [&](

const auto

&It) {

1206 return

It != State.Stack.rend() ? std::next(It) : It;

1208 auto

LambdaLevelIt = FindCurrentLevel(State.Stack.rbegin());

1209 auto

LevelContainingLambdaIt =

1210

FindCurrentLevel(MaybeIncrement(LambdaLevelIt));

1211

ParentLevelIt = MaybeIncrement(LevelContainingLambdaIt);

1213 for

(

auto

I = ParentLevelIt,

E

= State.Stack.rend(); I !=

E

; ++I)

1214

I->BreakBeforeParameter =

true

;

1217 if

(PreviousNonComment &&

1218

!PreviousNonComment->isOneOf(tok::comma, tok::colon, tok::semi) &&

1219

((PreviousNonComment->isNot(TT_TemplateCloser) &&

1220

!PreviousNonComment->ClosesRequiresClause) ||

1221

Current.NestingLevel != 0) &&

1222

!PreviousNonComment->isOneOf(

1223

TT_BinaryOperator, TT_FunctionAnnotationRParen, TT_JavaAnnotation,

1224

TT_LeadingJavaAnnotation) &&

1225

Current.isNot(TT_BinaryOperator) && !PreviousNonComment->opensScope() &&

1229

Current.isNot(TT_LambdaLBrace))) {

1230

CurrentState.BreakBeforeParameter =

true

;

1235 if

(PreviousNonComment &&

1236

(PreviousNonComment->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||

1238

CurrentState.BreakBeforeClosingBrace =

true

;

1241 if

(PreviousNonComment && PreviousNonComment->is(tok::l_paren)) {

1242

CurrentState.BreakBeforeClosingParen =

1246 if

(CurrentState.AvoidBinPacking) {

1251 bool

PreviousIsBreakingCtorInitializerColon =

1252

PreviousNonComment && PreviousNonComment->is(TT_CtorInitializerColon) &&

1254 bool

AllowAllConstructorInitializersOnNextLine =

1257 if

(!(

Previous

.isOneOf(tok::l_paren, tok::l_brace, TT_BinaryOperator) ||

1258

PreviousIsBreakingCtorInitializerColon) ||

1260

State.Line->MustBeDeclaration) ||

1262

!State.Line->MustBeDeclaration) ||

1263

(!AllowAllConstructorInitializersOnNextLine &&

1264

PreviousIsBreakingCtorInitializerColon) ||

1266

CurrentState.BreakBeforeParameter =

true

;

1272 if

(PreviousIsBreakingCtorInitializerColon &&

1273

AllowAllConstructorInitializersOnNextLine) {

1274

CurrentState.BreakBeforeParameter =

false

;

1279

CurrentState.BreakBeforeParameter =

true

;

1284unsigned

ContinuationIndenter::getNewLineColumn(

const

LineState &State) {

1285 if

(!State.NextToken || !State.NextToken->Previous)

1288

FormatToken &Current = *State.NextToken;

1289 const auto

&CurrentState = State.Stack.back();

1291 if

(CurrentState.IsCSharpGenericTypeConstraint &&

1292

Current.isNot(TT_CSharpGenericTypeConstraint)) {

1293 return

CurrentState.ColonPos + 2;

1296 const

FormatToken &

Previous

= *Current.Previous;

1298 unsigned

ContinuationIndent =

1299

std::max(CurrentState.LastSpace, CurrentState.Indent) +

1301 const

FormatToken *PreviousNonComment = Current.getPreviousNonComment();

1302 const

FormatToken *NextNonComment =

Previous

.getNextNonComment();

1303 if

(!NextNonComment)

1304

NextNonComment = &Current;

1309 return

std::max(CurrentState.LastSpace,

1315 if

(Style.

isVerilog

() && PreviousNonComment &&

1317 return

State.FirstIndent;

1321

State.Line->First->is(tok::kw_enum)) {

1322 return

(Style.

IndentWidth

* State.Line->First->IndentLevel) +

1326 if

((NextNonComment->is(tok::l_brace) && NextNonComment->is(

BK_Block

)) ||

1328 if

(Current.NestingLevel == 0 ||

1330

State.NextToken->is(TT_LambdaLBrace))) {

1331 return

State.FirstIndent;

1333 return

CurrentState.Indent;

1335 if

(Current.is(TT_LambdaArrow) &&

1336 Previous

.isOneOf(tok::kw_noexcept, tok::kw_mutable, tok::kw_constexpr,

1337

tok::kw_consteval, tok::kw_static, TT_AttributeSquare)) {

1338 return

ContinuationIndent;

1340 if

((Current.isOneOf(tok::r_brace, tok::r_square) ||

1342

State.Stack.size() > 1) {

1343 if

(Current.closesBlockOrBlockTypeList(Style))

1344 return

State.Stack[State.Stack.size() - 2].NestedBlockIndent;

1345 if

(Current.MatchingParen && Current.MatchingParen->is(

BK_BracedInit

))

1346 return

State.Stack[State.Stack.size() - 2].LastSpace;

1347 return

State.FirstIndent;

1364 if

(Current.is(tok::r_paren) && State.Stack.size() > 1 &&

1366

Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {

1367 return

State.Stack[State.Stack.size() - 2].LastSpace;

1371 if

(Style.

isTableGen

() && Current.is(TT_TableGenDAGArgCloser) &&

1372

State.Stack.size() > 1) {

1373 return

State.Stack[State.Stack.size() - 2].LastSpace;

1376

(Current.is(tok::r_paren) ||

1377

(Current.is(tok::r_brace) && Current.MatchingParen &&

1379

State.Stack.size() > 1) {

1380 return

State.Stack[State.Stack.size() - 2].LastSpace;

1382 if

(NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())

1383 return

State.Stack[State.Stack.size() - 2].LastSpace;

1391 if

(Current.is(tok::identifier) && Current.Next &&

1392

(!Style.

isVerilog

() || Current.Next->is(tok::colon)) &&

1393

(Current.Next->is(TT_DictLiteral) ||

1394

(Style.

isProto

() && Current.Next->isOneOf(tok::less, tok::l_brace)))) {

1395 return

CurrentState.Indent;

1397 if

(NextNonComment->is(TT_ObjCStringLiteral) &&

1398

State.StartOfStringLiteral != 0) {

1399 return

State.StartOfStringLiteral - 1;

1401 if

(NextNonComment->isStringLiteral() && State.StartOfStringLiteral != 0)

1402 return

State.StartOfStringLiteral;

1403 if

(NextNonComment->is(tok::lessless) && CurrentState.FirstLessLess != 0)

1404 return

CurrentState.FirstLessLess;

1405 if

(NextNonComment->isMemberAccess()) {

1406 if

(CurrentState.CallContinuation == 0)

1407 return

ContinuationIndent;

1408 return

CurrentState.CallContinuation;

1410 if

(CurrentState.QuestionColumn != 0 &&

1411

((NextNonComment->is(tok::colon) &&

1412

NextNonComment->is(TT_ConditionalExpr)) ||

1413 Previous

.is(TT_ConditionalExpr))) {

1414 if

(((NextNonComment->is(tok::colon) && NextNonComment->Next &&

1415

!NextNonComment->Next->FakeLParens.empty() &&

1417

(

Previous

.is(tok::colon) && !Current.FakeLParens.empty() &&

1419

!CurrentState.IsWrappedConditional) {

1424 unsigned

Indent = CurrentState.Indent;

1431 return

CurrentState.QuestionColumn;

1433 if

(

Previous

.is(tok::comma) && CurrentState.VariablePos != 0)

1434 return

CurrentState.VariablePos;

1435 if

(Current.is(TT_RequiresClause)) {

1442 return

CurrentState.Indent;

1447 if

(NextNonComment->isOneOf(TT_CtorInitializerColon, TT_InheritanceColon,

1448

TT_InheritanceComma)) {

1451 if

((PreviousNonComment &&

1452

(PreviousNonComment->ClosesTemplateDeclaration ||

1453

PreviousNonComment->ClosesRequiresClause ||

1454

(PreviousNonComment->is(TT_AttributeMacro) &&

1455

Current.isNot(tok::l_paren)) ||

1456

PreviousNonComment->isOneOf(

1457

TT_AttributeRParen, TT_AttributeSquare, TT_FunctionAnnotationRParen,

1458

TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||

1460

NextNonComment->isOneOf(tok::kw_operator, TT_FunctionDeclarationName))) {

1461 return

std::max(CurrentState.LastSpace, CurrentState.Indent);

1463 if

(NextNonComment->is(TT_SelectorName)) {

1464 if

(!CurrentState.ObjCSelectorNameFound) {

1465 unsigned

MinIndent = CurrentState.Indent;

1467

MinIndent = std::max(MinIndent,

1480

std::max(NextNonComment->LongestObjCSelectorName,

1481

NextNonComment->ColumnWidth) -

1482

NextNonComment->ColumnWidth;

1484 if

(!CurrentState.AlignColons)

1485 return

CurrentState.Indent;

1486 if

(CurrentState.ColonPos > NextNonComment->ColumnWidth)

1487 return

CurrentState.ColonPos - NextNonComment->ColumnWidth;

1488 return

CurrentState.Indent;

1490 if

(NextNonComment->is(tok::colon) && NextNonComment->is(TT_ObjCMethodExpr))

1491 return

CurrentState.ColonPos;

1492 if

(NextNonComment->is(TT_ArraySubscriptLSquare)) {

1493 if

(CurrentState.StartOfArraySubscripts != 0) {

1494 return

CurrentState.StartOfArraySubscripts;

1497 return

CurrentState.Indent;

1499 return

ContinuationIndent;

1504 if

(State.Line->InPragmaDirective) {

1505

FormatToken *PragmaType = State.Line->First->Next->Next;

1506 if

(PragmaType && PragmaType->TokenText ==

"omp"

)

1512 if

(NextNonComment->is(tok::identifier) && NextNonComment->FakeRParens == 0 &&

1513

NextNonComment->Next && NextNonComment->Next->is(TT_ObjCMethodExpr)) {

1514 return

CurrentState.Indent;

1517 if

(NextNonComment->isOneOf(TT_StartOfName, TT_PointerOrReference) ||

1518 Previous

.isOneOf(tok::coloncolon, tok::equal, TT_JsTypeColon)) {

1519 return

ContinuationIndent;

1521 if

(PreviousNonComment && PreviousNonComment->is(tok::colon) &&

1522

PreviousNonComment->isOneOf(TT_ObjCMethodExpr, TT_DictLiteral)) {

1523 return

ContinuationIndent;

1525 if

(NextNonComment->is(TT_CtorInitializerComma))

1526 return

CurrentState.Indent;

1527 if

(PreviousNonComment && PreviousNonComment->is(TT_CtorInitializerColon) &&

1529 return

CurrentState.Indent;

1531 if

(PreviousNonComment && PreviousNonComment->is(TT_InheritanceColon) &&

1533 return

CurrentState.Indent;

1536 Previous

.isNot(TT_TableGenDAGArgOperatorToBreak) &&

1537

!Current.isBinaryOperator() &&

1538

!Current.isOneOf(tok::colon, tok::comment)) {

1539 return

ContinuationIndent;

1541 if

(Current.is(TT_ProtoExtensionLSquare))

1542 return

CurrentState.Indent;

1543 if

(Current.isBinaryOperator() && CurrentState.UnindentOperator) {

1544 return

CurrentState.Indent - Current.Tok.getLength() -

1545

Current.SpacesRequiredBefore;

1547 if

(Current.is(tok::comment) && NextNonComment->isBinaryOperator() &&

1548

CurrentState.UnindentOperator) {

1549 return

CurrentState.Indent - NextNonComment->Tok.getLength() -

1550

NextNonComment->SpacesRequiredBefore;

1552 if

(CurrentState.Indent == State.FirstIndent && PreviousNonComment &&

1553

!PreviousNonComment->isOneOf(tok::r_brace, TT_CtorInitializerComma)) {

1558 return

CurrentState.Indent;

1564 if

(

Previous

->isNot(tok::l_paren))

1566 if

(

Previous

->ParameterCount > 1)

1573unsigned

ContinuationIndenter::moveStateToNextToken(LineState &State,

1574 bool

DryRun,

bool

Newline) {

1575

assert(State.Stack.size());

1576 const

FormatToken &Current = *State.NextToken;

1577 auto

&CurrentState = State.Stack.back();

1579 if

(Current.is(TT_CSharpGenericTypeConstraint))

1580

CurrentState.IsCSharpGenericTypeConstraint =

true

;

1581 if

(Current.isOneOf(tok::comma, TT_BinaryOperator))

1582

CurrentState.NoLineBreakInOperand =

false

;

1583 if

(Current.isOneOf(TT_InheritanceColon, TT_CSharpGenericTypeConstraintColon))

1584

CurrentState.AvoidBinPacking =

true

;

1585 if

(Current.is(tok::lessless) && Current.isNot(TT_OverloadedOperator)) {

1586 if

(CurrentState.FirstLessLess == 0)

1587

CurrentState.FirstLessLess = State.Column;

1589

CurrentState.LastOperatorWrapped = Newline;

1591 if

(Current.is(TT_BinaryOperator) && Current.isNot(tok::lessless))

1592

CurrentState.LastOperatorWrapped = Newline;

1593 if

(Current.is(TT_ConditionalExpr) && Current.Previous &&

1594

Current.Previous->isNot(TT_ConditionalExpr)) {

1595

CurrentState.LastOperatorWrapped = Newline;

1597 if

(Current.is(TT_ArraySubscriptLSquare) &&

1598

CurrentState.StartOfArraySubscripts == 0) {

1599

CurrentState.StartOfArraySubscripts = State.Column;

1602 auto

IsWrappedConditional = [](

const

FormatToken &Tok) {

1603 if

(!(Tok.is(TT_ConditionalExpr) && Tok.is(tok::question)))

1605 if

(Tok.MustBreakBefore)

1608 const

FormatToken *Next = Tok.getNextNonComment();

1609 return

Next && Next->MustBreakBefore;

1611 if

(IsWrappedConditional(Current))

1612

CurrentState.IsWrappedConditional =

true

;

1614

CurrentState.QuestionColumn = State.Column;

1616 const

FormatToken *

Previous

= Current.Previous;

1620

CurrentState.QuestionColumn = State.Column;

1622 if

(!Current.opensScope() && !Current.closesScope() &&

1623

Current.isNot(TT_PointerOrReference)) {

1624

State.LowestLevelOnLine =

1625

std::min(State.LowestLevelOnLine, Current.NestingLevel);

1627 if

(Current.isMemberAccess())

1628

CurrentState.StartOfFunctionCall = !Current.NextOperator ? 0 : State.Column;

1629 if

(Current.is(TT_SelectorName))

1630

CurrentState.ObjCSelectorNameFound =

true

;

1631 if

(Current.is(TT_CtorInitializerColon) &&

1642

CurrentState.NestedBlockIndent = CurrentState.Indent;

1644

CurrentState.AvoidBinPacking =

true

;

1645

CurrentState.BreakBeforeParameter =

1650

CurrentState.BreakBeforeParameter =

false

;

1653 if

(Current.is(TT_CtorInitializerColon) &&

1655

CurrentState.Indent =

1657

CurrentState.NestedBlockIndent = CurrentState.Indent;

1659

CurrentState.AvoidBinPacking =

true

;

1661

CurrentState.BreakBeforeParameter =

false

;

1663 if

(Current.is(TT_InheritanceColon)) {

1664

CurrentState.Indent =

1667 if

(Current.isOneOf(TT_BinaryOperator, TT_ConditionalExpr) && Newline)

1668

CurrentState.NestedBlockIndent = State.Column + Current.ColumnWidth + 1;

1669 if

(Current.isOneOf(TT_LambdaLSquare, TT_LambdaArrow))

1670

CurrentState.LastSpace = State.Column;

1671 if

(Current.is(TT_RequiresExpression) &&

1673

CurrentState.NestedBlockIndent = State.Column;

1677 const

FormatToken *

Previous

= Current.getPreviousNonComment();

1685 if

(Current.isNot(tok::comment) && !Current.ClosesRequiresClause &&

1686 Previous

&&

Previous

->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&

1687 Previous

->isNot(TT_DictLiteral) && State.Stack.size() > 1 &&

1688

!CurrentState.HasMultipleNestedBlocks) {

1689 if

(State.Stack[State.Stack.size() - 2].NestedBlockInlined && Newline)

1690 for

(ParenState &PState : llvm::drop_end(State.Stack))

1691

PState.NoLineBreak =

true

;

1692

State.Stack[State.Stack.size() - 2].NestedBlockInlined =

false

;

1694 if

(

Previous

&& (

Previous

->isOneOf(TT_BinaryOperator, TT_ConditionalExpr) ||

1695

(

Previous

->isOneOf(tok::l_paren, tok::comma, tok::colon) &&

1696

!

Previous

->isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)))) {

1697

CurrentState.NestedBlockInlined =

1701

moveStatePastFakeLParens(State, Newline);

1702

moveStatePastScopeCloser(State);

1705 bool

AllowBreak = !State.Stack.back().NoLineBreak &&

1706

!State.Stack.back().NoLineBreakInOperand;

1707

moveStatePastScopeOpener(State, Newline);

1708

moveStatePastFakeRParens(State);

1710 if

(Current.is(TT_ObjCStringLiteral) && State.StartOfStringLiteral == 0)

1711

State.StartOfStringLiteral = State.Column + 1;

1712 if

(Current.is(TT_CSharpStringLiteral) && State.StartOfStringLiteral == 0) {

1713

State.StartOfStringLiteral = State.Column + 1;

1714

}

else if

(Current.is(TT_TableGenMultiLineString) &&

1715

State.StartOfStringLiteral == 0) {

1716

State.StartOfStringLiteral = State.Column + 1;

1717

}

else if

(Current.isStringLiteral() && State.StartOfStringLiteral == 0) {

1718

State.StartOfStringLiteral = State.Column;

1719

}

else if

(!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&

1720

!Current.isStringLiteral()) {

1721

State.StartOfStringLiteral = 0;

1724

State.Column += Current.ColumnWidth;

1725

State.NextToken = State.NextToken->Next;

1730 if

(Style.

isVerilog

() && State.NextToken &&

1731

State.NextToken->MustBreakBefore &&

1734

CurrentState.Indent = State.FirstIndent;

1738

handleEndOfLine(Current, State, DryRun, AllowBreak, Newline);

1741

Current.Role->formatFromToken(State,

this

, DryRun);

1748

Penalty +=

Previous

->Role->formatAfterToken(State,

this

, DryRun);

1753void

ContinuationIndenter::moveStatePastFakeLParens(LineState &State,

1755 const

FormatToken &Current = *State.NextToken;

1756 if

(Current.FakeLParens.empty())

1759 const

FormatToken *

Previous

= Current.getPreviousNonComment();

1764 bool

SkipFirstExtraIndent =

1767 Previous

->isOneOf(tok::semi, tok::kw_return, TT_RequiresClause) ||

1771 for

(

const auto

&PrecedenceLevel : llvm::reverse(Current.FakeLParens)) {

1772 const auto

&CurrentState = State.Stack.back();

1773

ParenState NewParenState = CurrentState;

1774

NewParenState.Tok =

nullptr

;

1775

NewParenState.ContainsLineBreak =

false

;

1776

NewParenState.LastOperatorWrapped =

true

;

1777

NewParenState.IsChainedConditional =

false

;

1778

NewParenState.IsWrappedConditional =

false

;

1779

NewParenState.UnindentOperator =

false

;

1780

NewParenState.NoLineBreak =

1781

NewParenState.NoLineBreak || CurrentState.NoLineBreakInOperand;

1785

NewParenState.AvoidBinPacking =

false

;

1790 if

(!Current.isTrailingComment() &&

1796

PrecedenceLevel >

prec::Comma

|| Current.NestingLevel == 0) &&

1799

TT_TableGenDAGArgListCommaToBreak)))) {

1800

NewParenState.Indent = std::max(

1801

std::max(State.Column, NewParenState.Indent), CurrentState.LastSpace);

1807 if

(

Previous

&&

Previous

->endsSequence(tok::l_paren, tok::kw__Generic) &&

1808

State.Stack.size() > 1) {

1809

NewParenState.Indent = State.Stack[State.Stack.size() - 2].Indent +

1821

NewParenState.UnindentOperator =

true

;

1824

NewParenState.IsAligned =

true

;

1834

NewParenState.LastSpace = std::max(NewParenState.LastSpace, State.Column);

1836

Current.isNot(TT_UnaryOperator) &&

1838

NewParenState.StartOfFunctionCall = State.Column;

1848

&PrecedenceLevel == &Current.FakeLParens.back() &&

1849

!CurrentState.IsWrappedConditional) {

1850

NewParenState.IsChainedConditional =

true

;

1851

NewParenState.UnindentOperator = State.Stack.back().UnindentOperator;

1854

!Current.isTrailingComment())) {

1858

NewParenState.BreakBeforeParameter =

false

;

1859

State.Stack.push_back(NewParenState);

1860

SkipFirstExtraIndent =

false

;

1864void

ContinuationIndenter::moveStatePastFakeRParens(LineState &State) {

1865 for

(

unsigned

i = 0, e = State.NextToken->FakeRParens; i != e; ++i) {

1866 unsigned

VariablePos = State.Stack.back().VariablePos;

1867 if

(State.Stack.size() == 1) {

1871

State.Stack.pop_back();

1872

State.Stack.back().VariablePos = VariablePos;

1878

State.Stack.back().LastSpace -= Style.

IndentWidth

;

1882void

ContinuationIndenter::moveStatePastScopeOpener(LineState &State,

1884 const

FormatToken &Current = *State.NextToken;

1885 if

(!Current.opensScope())

1888 const auto

&CurrentState = State.Stack.back();

1891 if

(Current.isOneOf(tok::less, tok::l_paren) &&

1892

CurrentState.IsCSharpGenericTypeConstraint) {

1896 if

(Current.MatchingParen && Current.is(

BK_Block

)) {

1897

moveStateToNewBlock(State, Newline);

1902 unsigned

LastSpace = CurrentState.LastSpace;

1903 bool

AvoidBinPacking;

1904 bool

BreakBeforeParameter =

false

;

1905 unsigned

NestedBlockIndent = std::max(CurrentState.StartOfFunctionCall,

1906

CurrentState.NestedBlockIndent);

1907 if

(Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||

1909 if

(Current.opensBlockOrBlockTypeList(Style)) {

1911

std::min(State.Column, CurrentState.NestedBlockIndent);

1912

}

else if

(Current.is(tok::l_brace)) {

1919 const

FormatToken *NextNonComment = Current.getNextNonComment();

1920 bool

EndsInComma = Current.MatchingParen &&

1921

Current.MatchingParen->Previous &&

1922

Current.MatchingParen->Previous->is(tok::comma);

1923

AvoidBinPacking = EndsInComma || Current.is(TT_DictLiteral) ||

1925

(NextNonComment && NextNonComment->isOneOf(

1926

TT_DesignatedInitializerPeriod,

1927

TT_DesignatedInitializerLSquare));

1928

BreakBeforeParameter = EndsInComma;

1929 if

(Current.ParameterCount > 1)

1930

NestedBlockIndent = std::max(NestedBlockIndent, State.Column + 1);

1934

std::max(CurrentState.LastSpace, CurrentState.StartOfFunctionCall);

1936 if

(Style.

isTableGen

() && Current.is(TT_TableGenDAGArgOpenerToBreak) &&

1942 const

FormatToken *Next = Current.Next;

1943 if

(Next && Next->is(TT_TableGenDAGArgOperatorID))

1944

NewIndent = State.Column + Next->TokenText.size() + 2;

1951 if

(Current.is(tok::less) && Current.ParentBracket == tok::l_paren) {

1952

NewIndent = std::max(NewIndent, CurrentState.Indent);

1953

LastSpace = std::max(LastSpace, CurrentState.Indent);

1957

Current.MatchingParen &&

1958

Current.MatchingParen->getPreviousNonComment() &&

1959

Current.MatchingParen->getPreviousNonComment()->is(tok::comma);

1963 bool

ObjCBinPackProtocolList =

1968 bool

BinPackDeclaration =

1971

(State.Line->Type ==

LT_ObjCDecl

&& ObjCBinPackProtocolList);

1973 bool

GenericSelection =

1974

Current.getPreviousNonComment() &&

1975

Current.getPreviousNonComment()->is(tok::kw__Generic);

1978

(CurrentState.IsCSharpGenericTypeConstraint) || GenericSelection ||

1980

(State.Line->MustBeDeclaration && !BinPackDeclaration) ||

1986 if

(Current.is(TT_ObjCMethodExpr) && Current.MatchingParen &&

1993

BreakBeforeParameter =

true

;

1998 for

(

const

FormatToken *Tok = &Current;

1999

Tok && Tok != Current.MatchingParen; Tok = Tok->Next) {

2000 if

(Tok->MustBreakBefore ||

2001

(Tok->CanBreakBefore && Tok->NewlinesBefore > 0)) {

2002

BreakBeforeParameter =

true

;

2010

BreakBeforeParameter =

true

;

2016

Current.Children.empty() &&

2017

!Current.isOneOf(TT_DictLiteral, TT_ArrayInitializerLSquare) &&

2018

(CurrentState.NoLineBreak || CurrentState.NoLineBreakInOperand ||

2019

(Current.is(TT_TemplateOpener) &&

2020

CurrentState.ContainsUnwrappedBuilder));

2021

State.Stack.push_back(

2022

ParenState(&Current, NewIndent, LastSpace, AvoidBinPacking, NoLineBreak));

2023 auto

&NewState = State.Stack.back();

2024

NewState.NestedBlockIndent = NestedBlockIndent;

2025

NewState.BreakBeforeParameter = BreakBeforeParameter;

2026

NewState.HasMultipleNestedBlocks = (Current.BlockParameterCount > 1);

2029

Current.is(tok::l_paren)) {

2031

FormatToken

const

*next = Current.Next;

2033 if

(next->is(TT_LambdaLSquare)) {

2034

NewState.HasMultipleNestedBlocks =

true

;

2041

NewState.IsInsideObjCArrayLiteral = Current.is(TT_ArrayInitializerLSquare) &&

2043

Current.Previous->is(tok::at);

2046void

ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {

2047 const

FormatToken &Current = *State.NextToken;

2048 if

(!Current.closesScope())

2053 if

(State.Stack.size() > 1 &&

2054

(Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||

2055

(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||

2056

State.NextToken->is(TT_TemplateCloser) ||

2057

State.NextToken->is(TT_TableGenListCloser) ||

2058

(Current.is(tok::greater) && Current.is(TT_DictLiteral)))) {

2059

State.Stack.pop_back();

2062 auto

&CurrentState = State.Stack.back();

2074 if

(CurrentState.BreakBeforeParameter && Current.MatchingParen &&

2075

Current.MatchingParen->Previous) {

2076 const

FormatToken &CurrentScopeOpener = *Current.MatchingParen->Previous;

2077 if

(CurrentScopeOpener.is(TT_ObjCMethodExpr) &&

2078

CurrentScopeOpener.MatchingParen) {

2079 int

NecessarySpaceInLine =

2081

CurrentScopeOpener.TotalLength - Current.TotalLength - 1;

2082 if

(State.Column + Current.ColumnWidth + NecessarySpaceInLine <=

2084

CurrentState.BreakBeforeParameter =

false

;

2089 if

(Current.is(tok::r_square)) {

2091 const

FormatToken *NextNonComment = Current.getNextNonComment();

2092 if

(NextNonComment && NextNonComment->isNot(tok::l_square))

2093

CurrentState.StartOfArraySubscripts = 0;

2097void

ContinuationIndenter::moveStateToNewBlock(LineState &State,

bool NewLine

) {

2099

State.NextToken->is(TT_LambdaLBrace) &&

2100

!State.Line->MightBeFunctionDecl) {

2101

State.Stack.back().NestedBlockIndent = State.FirstIndent;

2103 unsigned

NestedBlockIndent = State.Stack.back().NestedBlockIndent;

2105 unsigned

NewIndent =

2106

NestedBlockIndent + (State.NextToken->is(TT_ObjCBlockLBrace)

2116

State.NextToken->is(TT_LambdaLBrace);

2118

State.Stack.push_back(ParenState(State.NextToken, NewIndent,

2119

State.Stack.back().LastSpace,

2120 true

, NoLineBreak));

2121

State.Stack.back().NestedBlockIndent = NestedBlockIndent;

2122

State.Stack.back().BreakBeforeParameter =

true

;

2128 size_t

LastNewlinePos =

Text

.find_last_of(

"\n"

);

2129 if

(LastNewlinePos == StringRef::npos) {

2130 return

StartColumn +

2134

0, TabWidth, Encoding);

2138unsigned

ContinuationIndenter::reformatRawStringLiteral(

2139 const

FormatToken &Current, LineState &State,

2140 const

FormatStyle &RawStringStyle,

bool

DryRun,

bool

Newline) {

2141 unsigned

StartColumn = State.Column - Current.ColumnWidth;

2143

StringRef NewDelimiter =

2145 if

(NewDelimiter.empty())

2146

NewDelimiter = OldDelimiter;

2149 unsigned

OldPrefixSize = 3 + OldDelimiter.size();

2150 unsigned

OldSuffixSize = 2 + OldDelimiter.size();

2153

std::string RawText = std::string(

2154

Current.TokenText.substr(OldPrefixSize).drop_back(OldSuffixSize));

2155 if

(NewDelimiter != OldDelimiter) {

2158

std::string CanonicalDelimiterSuffix = (

")"

+ NewDelimiter +

"\""

).str();

2159 if

(StringRef(RawText).contains(CanonicalDelimiterSuffix))

2160

NewDelimiter = OldDelimiter;

2163 unsigned

NewPrefixSize = 3 + NewDelimiter.size();

2164 unsigned

NewSuffixSize = 2 + NewDelimiter.size();

2167 unsigned

FirstStartColumn = StartColumn + NewPrefixSize;

2178 bool

ContentStartsOnNewline = Current.TokenText[OldPrefixSize] ==

'\n'

;

2200 unsigned

CurrentIndent =

2201

(!Newline && Current.Next && Current.Next->is(tok::r_paren))

2202

? State.Stack.back().NestedBlockIndent

2203

: State.Stack.back().Indent;

2204 unsigned

NextStartColumn = ContentStartsOnNewline

2216 unsigned

LastStartColumn =

2217

Current.NewlinesBefore ? FirstStartColumn - NewPrefixSize : CurrentIndent;

2220

RawStringStyle, RawText, {tooling::Range(0, RawText.size())},

2221

FirstStartColumn, NextStartColumn, LastStartColumn,

"<stdin>"

,

2225

tooling::Replacements NoFixes;

2227 return

addMultilineToken(Current, State);

2229 if

(NewDelimiter != OldDelimiter) {

2232

SourceLocation PrefixDelimiterStart =

2233

Current.Tok.getLocation().getLocWithOffset(2);

2234 auto

PrefixErr = Whitespaces.

addReplacement

(tooling::Replacement(

2235

SourceMgr, PrefixDelimiterStart, OldDelimiter.size(), NewDelimiter));

2238

<<

"Failed to update the prefix delimiter of a raw string: " 2239

<< llvm::toString(std::move(PrefixErr)) <<

"\n"

;

2243

SourceLocation SuffixDelimiterStart =

2244

Current.Tok.getLocation().getLocWithOffset(Current.TokenText.size() -

2245

1 - OldDelimiter.size());

2246 auto

SuffixErr = Whitespaces.

addReplacement

(tooling::Replacement(

2247

SourceMgr, SuffixDelimiterStart, OldDelimiter.size(), NewDelimiter));

2250

<<

"Failed to update the suffix delimiter of a raw string: " 2251

<< llvm::toString(std::move(SuffixErr)) <<

"\n"

;

2254

SourceLocation OriginLoc =

2255

Current.Tok.getLocation().getLocWithOffset(OldPrefixSize);

2256 for

(

const

tooling::Replacement &Fix : Fixes.first) {

2258

SourceMgr, OriginLoc.getLocWithOffset(Fix.getOffset()),

2259

Fix.getLength(), Fix.getReplacementText()));

2261

llvm::errs() <<

"Failed to reformat raw string: " 2262

<< llvm::toString(std::move(Err)) <<

"\n"

;

2267

*NewCode, FirstStartColumn, Style.

TabWidth

, Encoding);

2268

State.Column = RawLastLineEndColumn + NewSuffixSize;

2272 unsigned

PrefixExcessCharacters =

2274

? StartColumn + NewPrefixSize - Style.

ColumnLimit 2277

ContentStartsOnNewline || (NewCode->find(

'\n'

) != std::string::npos);

2280 for

(ParenState &

Paren

: State.Stack)

2281 Paren

.BreakBeforeParameter =

true

;

2286unsigned

ContinuationIndenter::addMultilineToken(

const

FormatToken &Current,

2289 for

(ParenState &

Paren

: State.Stack)

2290 Paren

.BreakBeforeParameter =

true

;

2292 unsigned

ColumnsUsed = State.Column;

2295

State.Column = Current.LastLineColumnWidth;

2302unsigned

ContinuationIndenter::handleEndOfLine(

const

FormatToken &Current,

2303

LineState &State,

bool

DryRun,

2304 bool

AllowBreak,

bool

Newline) {

2305 unsigned

Penalty = 0;

2308 auto

RawStringStyle = getRawStringStyle(Current, State);

2309 if

(RawStringStyle && !Current.Finalized) {

2310

Penalty = reformatRawStringLiteral(Current, State, *RawStringStyle, DryRun,

2312

}

else if

(Current.IsMultiline && Current.isNot(TT_BlockComment)) {

2315

Penalty = addMultilineToken(Current, State);

2318

LineState OriginalState = State;

2322 bool

Strict =

false

;

2325 bool

Exceeded =

false

;

2326

std::tie(Penalty, Exceeded) = breakProtrudingToken(

2327

Current, State, AllowBreak,

true

, Strict);

2331

LineState StrictState = OriginalState;

2332 unsigned

StrictPenalty =

2333

breakProtrudingToken(Current, StrictState, AllowBreak,

2336

Strict = StrictPenalty <= Penalty;

2338

Penalty = StrictPenalty;

2339

State = StrictState;

2345

breakProtrudingToken(Current, OriginalState, AllowBreak,

false

,

2350 unsigned

ExcessCharacters = State.Column -

getColumnLimit

(State);

2361 if

(!Tok || Tok->isNot(tok::l_paren))

2366 if

(Tok->is(TT_TemplateCloser)) {

2371 if

(!Tok || Tok->isNot(tok::identifier))

2376

std::optional<FormatStyle>

2377

ContinuationIndenter::getRawStringStyle(

const

FormatToken &Current,

2378 const

LineState &State) {

2379 if

(!Current.isStringLiteral())

2380 return

std::nullopt;

2383 return

std::nullopt;

2385 if

(!RawStringStyle && Delimiter->empty()) {

2389 if

(!RawStringStyle)

2390 return

std::nullopt;

2392 return

RawStringStyle;

2395

std::unique_ptr<BreakableToken>

2396

ContinuationIndenter::createBreakableToken(

const

FormatToken &Current,

2397

LineState &State,

bool

AllowBreak) {

2398 unsigned

StartColumn = State.Column - Current.ColumnWidth;

2399 if

(Current.isStringLiteral()) {

2416 if

(Current.IsUnterminatedLiteral)

2420 if

(State.Stack.back().IsInsideObjCArrayLiteral)

2427 if

(Style.

isVerilog

() && Current.Previous &&

2428

Current.Previous->isOneOf(tok::kw_export, Keywords.

kw_import

)) {

2431

StringRef

Text

= Current.TokenText;

2437 unsigned

UnbreakableTailLength = (State.NextToken &&

canBreak

(State))

2439

: Current.UnbreakableTailLength;

2445 Text

.ends_with(

"'"

)) {

2447

}

else if

(Style.

isCSharp

() &&

Text

.starts_with(

"@\""

) &&

2448 Text

.ends_with(

"\""

)) {

2450

}

else if

(

Text

.starts_with(

"\""

) &&

Text

.ends_with(

"\""

)) {

2455 return

std::make_unique<BreakableStringLiteralUsingOperators>(

2456

Current, QuoteStyle,

2458

UnbreakableTailLength, State.Line->InPPDirective, Encoding, Style);

2467 if

((

Text

.ends_with(Postfix =

"\""

) &&

2468

(

Text

.starts_with(Prefix =

"@\""

) ||

Text

.starts_with(Prefix =

"\""

) ||

2469 Text

.starts_with(Prefix =

"u\""

) ||

2470 Text

.starts_with(Prefix =

"U\""

) ||

2471 Text

.starts_with(Prefix =

"u8\""

) ||

2472 Text

.starts_with(Prefix =

"L\""

))) ||

2473

(

Text

.starts_with(Prefix =

"_T(\""

) &&

2474 Text

.ends_with(Postfix =

"\")"

))) {

2475 return

std::make_unique<BreakableStringLiteral>(

2476

Current, StartColumn, Prefix, Postfix, UnbreakableTailLength,

2477

State.Line->InPPDirective, Encoding, Style);

2479

}

else if

(Current.is(TT_BlockComment)) {

2487 return

std::make_unique<BreakableBlockComment>(

2488

Current, StartColumn, Current.OriginalColumn, !Current.Previous,

2489

State.Line->InPPDirective, Encoding, Style, Whitespaces.

useCRLF

());

2490

}

else if

(Current.is(TT_LineComment) &&

2491

(!Current.Previous ||

2492

Current.Previous->isNot(TT_ImplicitStringLiteral))) {

2493 bool

RegularComments = [&]() {

2494 for

(

const

FormatToken *

T

= &Current;

T

&&

T

->is(TT_LineComment);

2496 if

(!(

T

->TokenText.starts_with(

"//"

) ||

T

->TokenText.starts_with(

"#"

)))

2502

CommentPragmasRegex.match(Current.TokenText.substr(2)) ||

2506 return

std::make_unique<BreakableLineCommentSection>(

2507

Current, StartColumn,

false

, Encoding, Style);

2512

std::pair<unsigned, bool>

2513

ContinuationIndenter::breakProtrudingToken(

const

FormatToken &Current,

2514

LineState &State,

bool

AllowBreak,

2515 bool

DryRun,

bool

Strict) {

2516

std::unique_ptr<const BreakableToken> Token =

2517

createBreakableToken(Current, State, AllowBreak);

2520

assert(Token->getLineCount() > 0);

2522 if

(Current.is(TT_LineComment)) {

2526 if

(ColumnLimit == 0) {

2529

ColumnLimit = std::numeric_limits<

decltype

(ColumnLimit)>

::max

();

2531 if

(Current.UnbreakableTailLength >= ColumnLimit)

2535 unsigned

StartColumn = State.Column - Current.ColumnWidth;

2536 unsigned

NewBreakPenalty = Current.isStringLiteral()

2541 bool

Exceeded =

false

;

2543 bool

BreakInserted = Token->introducesBreakBeforeToken();

2546 bool

NewBreakBefore =

false

;

2550 bool

Reflow =

false

;

2553 unsigned

TailOffset = 0;

2555 unsigned

ContentStartColumn =

2556

Token->getContentStartColumn(0,

false

);

2558 unsigned

RemainingTokenColumns =

2559

Token->getRemainingLength(0, TailOffset, ContentStartColumn);

2562

Token->adaptStartOfLine(0, Whitespaces);

2564 unsigned

ContentIndent = 0;

2565 unsigned

Penalty = 0;

2566

LLVM_DEBUG(llvm::dbgs() <<

"Breaking protruding token at column " 2567

<< StartColumn <<

".\n"

);

2568 for

(

unsigned

LineIndex = 0, EndIndex = Token->getLineCount();

2569

LineIndex != EndIndex; ++LineIndex) {

2570

LLVM_DEBUG(llvm::dbgs()

2571

<<

" Line: "

<< LineIndex <<

" (Reflow: "

<< Reflow <<

")\n"

);

2572

NewBreakBefore =

false

;

2576 bool

TryReflow = Reflow;

2578 while

(ContentStartColumn + RemainingTokenColumns > ColumnLimit) {

2579

LLVM_DEBUG(llvm::dbgs() <<

" Over limit, need: " 2580

<< (ContentStartColumn + RemainingTokenColumns)

2581

<<

", space: "

<< ColumnLimit

2582

<<

", reflown prefix: "

<< ContentStartColumn

2583

<<

", offset in line: "

<< TailOffset <<

"\n"

);

2589

Token->getSplit(LineIndex, TailOffset, ColumnLimit,

2590

ContentStartColumn, CommentPragmasRegex);

2591 if

(

Split

.first == StringRef::npos) {

2594 if

(LineIndex < EndIndex - 1) {

2598

(ContentStartColumn + RemainingTokenColumns - ColumnLimit);

2600

LLVM_DEBUG(llvm::dbgs() <<

" No break opportunity.\n"

);

2603

assert(

Split

.first != 0);

2605 if

(Token->supportsReflow()) {

2625 unsigned

ToSplitColumns = Token->getRangeLength(

2626

LineIndex, TailOffset,

Split

.first, ContentStartColumn);

2627

LLVM_DEBUG(llvm::dbgs() <<

" ToSplit: "

<< ToSplitColumns <<

"\n"

);

2630

LineIndex, TailOffset +

Split

.first +

Split

.second, ColumnLimit,

2631

ContentStartColumn + ToSplitColumns + 1, CommentPragmasRegex);

2634 unsigned

ToNextSplitColumns = 0;

2635 if

(NextSplit.first == StringRef::npos) {

2636

ToNextSplitColumns = Token->getRemainingLength(LineIndex, TailOffset,

2637

ContentStartColumn);

2639

ToNextSplitColumns = Token->getRangeLength(

2640

LineIndex, TailOffset,

2641 Split

.first +

Split

.second + NextSplit.first, ContentStartColumn);

2645

ToNextSplitColumns =

2646

Token->getLengthAfterCompression(ToNextSplitColumns, Split);

2647

LLVM_DEBUG(llvm::dbgs()

2648

<<

" ContentStartColumn: "

<< ContentStartColumn <<

"\n"

);

2649

LLVM_DEBUG(llvm::dbgs()

2650

<<

" ToNextSplit: "

<< ToNextSplitColumns <<

"\n"

);

2653 bool

ContinueOnLine =

2654

ContentStartColumn + ToNextSplitColumns <= ColumnLimit;

2655 unsigned

ExcessCharactersPenalty = 0;

2656 if

(!ContinueOnLine && !Strict) {

2659

ExcessCharactersPenalty =

2660

(ContentStartColumn + ToNextSplitColumns - ColumnLimit) *

2662

LLVM_DEBUG(llvm::dbgs()

2663

<<

" Penalty excess: "

<< ExcessCharactersPenalty

2664

<<

"\n break : "

<< NewBreakPenalty <<

"\n"

);

2665 if

(ExcessCharactersPenalty < NewBreakPenalty) {

2667

ContinueOnLine =

true

;

2670 if

(ContinueOnLine) {

2671

LLVM_DEBUG(llvm::dbgs() <<

" Continuing on line...\n"

);

2676

Token->compressWhitespace(LineIndex, TailOffset, Split,

2680

ContentStartColumn += ToSplitColumns + 1;

2681

Penalty += ExcessCharactersPenalty;

2683

RemainingTokenColumns = Token->getRemainingLength(

2684

LineIndex, TailOffset, ContentStartColumn);

2688

LLVM_DEBUG(llvm::dbgs() <<

" Breaking...\n"

);

2693

ContentIndent = Token->getContentIndent(LineIndex);

2694

LLVM_DEBUG(llvm::dbgs()

2695

<<

" ContentIndent: "

<< ContentIndent <<

"\n"

);

2696

ContentStartColumn = ContentIndent + Token->getContentStartColumn(

2699 unsigned

NewRemainingTokenColumns = Token->getRemainingLength(

2700

LineIndex, TailOffset +

Split

.first +

Split

.second,

2701

ContentStartColumn);

2702 if

(NewRemainingTokenColumns == 0) {

2705

ContentStartColumn =

2706

Token->getContentStartColumn(LineIndex,

true

);

2707

NewRemainingTokenColumns = Token->getRemainingLength(

2708

LineIndex, TailOffset +

Split

.first +

Split

.second,

2709

ContentStartColumn);

2715 if

(NewRemainingTokenColumns >= RemainingTokenColumns) {

2720

LLVM_DEBUG(llvm::dbgs() <<

" Breaking at: "

<< TailOffset +

Split

.first

2721

<<

", "

<<

Split

.second <<

"\n"

);

2723

Token->insertBreak(LineIndex, TailOffset, Split, ContentIndent,

2727

Penalty += NewBreakPenalty;

2729

RemainingTokenColumns = NewRemainingTokenColumns;

2730

BreakInserted =

true

;

2731

NewBreakBefore =

true

;

2735 if

(LineIndex + 1 != EndIndex) {

2736 unsigned

NextLineIndex = LineIndex + 1;

2737 if

(NewBreakBefore) {

2756

ContentStartColumn += RemainingTokenColumns + 1;

2761

Token->getReflowSplit(NextLineIndex, CommentPragmasRegex);

2762

LLVM_DEBUG(llvm::dbgs()

2763

<<

" Size of reflown text: "

<< ContentStartColumn

2764

<<

"\n Potential reflow split: "

);

2765 if

(SplitBeforeNext.first != StringRef::npos) {

2766

LLVM_DEBUG(llvm::dbgs() << SplitBeforeNext.first <<

", " 2767

<< SplitBeforeNext.second <<

"\n"

);

2768

TailOffset = SplitBeforeNext.first + SplitBeforeNext.second;

2771

RemainingTokenColumns = Token->getRemainingLength(

2772

NextLineIndex, TailOffset, ContentStartColumn);

2774 if

(ContentStartColumn + RemainingTokenColumns > ColumnLimit) {

2775

LLVM_DEBUG(llvm::dbgs()

2776

<<

" Over limit after reflow, need: " 2777

<< (ContentStartColumn + RemainingTokenColumns)

2778

<<

", space: "

<< ColumnLimit

2779

<<

", reflown prefix: "

<< ContentStartColumn

2780

<<

", offset in line: "

<< TailOffset <<

"\n"

);

2786

Token->getSplit(NextLineIndex, TailOffset, ColumnLimit,

2787

ContentStartColumn, CommentPragmasRegex);

2788 if

(

Split

.first == StringRef::npos) {

2789

LLVM_DEBUG(llvm::dbgs() <<

" Did not find later break\n"

);

2795 unsigned

ToSplitColumns = Token->getRangeLength(

2796

NextLineIndex, TailOffset,

Split

.first, ContentStartColumn);

2797 if

(ContentStartColumn + ToSplitColumns > ColumnLimit) {

2798

LLVM_DEBUG(llvm::dbgs() <<

" Next split protrudes, need: " 2799

<< (ContentStartColumn + ToSplitColumns)

2800

<<

", space: "

<< ColumnLimit);

2801 unsigned

ExcessCharactersPenalty =

2802

(ContentStartColumn + ToSplitColumns - ColumnLimit) *

2804 if

(NewBreakPenalty < ExcessCharactersPenalty)

2810

LLVM_DEBUG(llvm::dbgs() <<

"not found.\n"

);

2818

ContentStartColumn =

2819

Token->getContentStartColumn(NextLineIndex,

false

);

2820

RemainingTokenColumns = Token->getRemainingLength(

2821

NextLineIndex, TailOffset, ContentStartColumn);

2824

Token->adaptStartOfLine(NextLineIndex, Whitespaces);

2839 if

(NewBreakBefore) {

2840

assert(Penalty >= NewBreakPenalty);

2841

Penalty -= NewBreakPenalty;

2844

Token->reflow(NextLineIndex, Whitespaces);

2850

Token->getSplitAfterLastLine(TailOffset);

2851 if

(SplitAfterLastLine.first != StringRef::npos) {

2852

LLVM_DEBUG(llvm::dbgs() <<

"Replacing whitespace after last line.\n"

);

2857

(ContentStartColumn + RemainingTokenColumns - ColumnLimit);

2860

Token->replaceWhitespaceAfterLastLine(TailOffset, SplitAfterLastLine,

2863

ContentStartColumn =

2864

Token->getContentStartColumn(Token->getLineCount() - 1,

true

);

2865

RemainingTokenColumns = Token->getRemainingLength(

2866

Token->getLineCount() - 1,

2867

TailOffset + SplitAfterLastLine.first + SplitAfterLastLine.second,

2868

ContentStartColumn);

2871

State.Column = ContentStartColumn + RemainingTokenColumns -

2872

Current.UnbreakableTailLength;

2874 if

(BreakInserted) {

2876

Token->updateAfterBroken(Whitespaces);

2881 if

(Current.isNot(TT_LineComment))

2882 for

(ParenState &

Paren

: State.Stack)

2883 Paren

.BreakBeforeParameter =

true

;

2885 if

(Current.is(TT_BlockComment))

2886

State.NoContinuation =

true

;

2888

State.Stack.back().LastSpace = StartColumn;

2891

Token->updateNextToken(State);

2893 return

{Penalty, Exceeded};

2898 return

Style.

ColumnLimit

- (State.Line->InPPDirective ? 2 : 0);

2901bool

ContinuationIndenter::nextIsMultilineString(

const LineState

&State) {

2903 if

(!Current.isStringLiteral() || Current.is(TT_ImplicitStringLiteral))

2908 if

(Current.TokenText.starts_with(

"R\""

))

2910 if

(Current.IsMultiline)

2912 if

(Current.getNextNonComment() &&

2913

Current.getNextNonComment()->isStringLiteral()) {

2917

State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >

Declares BreakableToken, BreakableStringLiteral, BreakableComment, BreakableBlockComment and Breakabl...

This file implements an indenter that manages the indentation of continuations.

This file declares Format APIs to be used internally by the formatting library implementation.

This file contains the declaration of the FormatToken, a wrapper around Token with additional informa...

Various functions to configurably format source code.

Defines and computes precedence levels for binary/ternary operators.

Defines the SourceManager interface.

unsigned LongestObjCSelectorName

Defines the clang::TokenKind enum and support functions.

WhitespaceManager class manages whitespace around tokens and their replacements.

__DEVICE__ int max(int __a, int __b)

This class handles loading and caching of source files into memory.

unsigned getSpellingColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const

Token - This structure provides full information about a lexed token.

bool is(tok::TokenKind K) const

is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....

std::pair< StringRef::size_type, unsigned > Split

Contains starting character index and length of split.

bool canBreak(const LineState &State)

Returns true, if a line break after State is allowed.

unsigned addTokenToState(LineState &State, bool Newline, bool DryRun, unsigned ExtraSpaces=0)

Appends the next token to State and updates information necessary for indentation.

unsigned getColumnLimit(const LineState &State) const

Get the column limit for this line.

LineState getInitialState(unsigned FirstIndent, unsigned FirstStartColumn, const AnnotatedLine *Line, bool DryRun)

Get the initial state, i.e.

ContinuationIndenter(const FormatStyle &Style, const AdditionalKeywords &Keywords, const SourceManager &SourceMgr, WhitespaceManager &Whitespaces, encoding::Encoding Encoding, bool BinPackInconclusiveFunctions)

Constructs a ContinuationIndenter to format Line starting in column FirstIndent.

bool mustBreak(const LineState &State)

Returns true, if a line break after State is mandatory.

Manages the whitespaces around tokens and their replacements.

llvm::Error addReplacement(const tooling::Replacement &Replacement)

void replaceWhitespace(FormatToken &Tok, unsigned Newlines, unsigned Spaces, unsigned StartOfTokenColumn, bool IsAligned=false, bool InPPDirective=false)

Replaces the whitespace in front of Tok.

unsigned columnWidthWithTabs(StringRef Text, unsigned StartColumn, unsigned TabWidth, Encoding Encoding)

Returns the number of columns required to display the Text, starting from the StartColumn on a termin...

std::pair< tooling::Replacements, unsigned > reformat(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, unsigned FirstStartColumn, unsigned NextStartColumn, unsigned LastStartColumn, StringRef FileName, FormattingAttemptStatus *Status)

Reformats the given Ranges in the code fragment Code.

static bool mustBreakBinaryOperation(const FormatToken &Current, const FormatStyle &Style)

static unsigned getLastLineEndColumn(StringRef Text, unsigned StartColumn, unsigned TabWidth, encoding::Encoding Encoding)

static bool shouldUnindentNextOperator(const FormatToken &Tok)

FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language=FormatStyle::LanguageKind::LK_Cpp)

Returns a format style complying with the LLVM coding standards: http://llvm.org/docs/CodingStandards...

bool switchesFormatting(const FormatToken &Token)

Checks if Token switches formatting, like /* clang-format off *‍/.

static bool hasNestedBlockInlined(const FormatToken *Previous, const FormatToken &Current, const FormatStyle &Style)

static bool startsSegmentOfBuilderTypeCall(const FormatToken &Tok)

static unsigned getLengthToNextOperator(const FormatToken &Tok)

static bool isAlignableBinaryOperator(const FormatToken &Token)

static unsigned getLengthToMatchingParen(const FormatToken &Tok, ArrayRef< ParenState > Stack)

static bool shouldIndentWrappedSelectorName(const FormatStyle &Style, LineType LineType)

bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)

Gets a predefined style for the specified language by name.

static std::optional< StringRef > getRawStringDelimiter(StringRef TokenText)

static StringRef getCanonicalRawStringDelimiter(const FormatStyle &Style, FormatStyle::LanguageKind Language)

static bool startsNextOperand(const FormatToken &Current)

static bool opensProtoMessageField(const FormatToken &LessTok, const FormatStyle &Style)

static StringRef getEnclosingFunctionName(const FormatToken &Current)

@ LT_PreprocessorDirective

bool startsNextParameter(const FormatToken &Current, const FormatStyle &Style)

The JSON file list parser is used to communicate input to InstallAPI.

if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))

Language

The language for the input, used to select and validate the language standard and possible actions.

const FunctionProtoType * T

Encapsulates keywords that are context sensitive or for languages not properly supported by Clang's l...

bool isVerilogBegin(const FormatToken &Tok) const

Returns whether Tok is a Verilog keyword that opens a block.

bool isVerilogEndOfLabel(const FormatToken &Tok) const

IdentifierInfo * kw_import

IdentifierInfo * kw_dollar

IdentifierInfo * kw_async

IdentifierInfo * kw_await

IdentifierInfo * kw_implements

IdentifierInfo * kw_function

IdentifierInfo * kw_extends

bool BeforeLambdaBody

Wrap lambda block.

The FormatStyle is used to configure the formatting to follow specific guidelines.

@ UT_Never

Never use tab.

unsigned ContinuationIndentWidth

Indent width for line continuations.

bool AlwaysBreakBeforeMultilineStrings

This option is renamed to BreakAfterReturnType.

ReturnTypeBreakingStyle BreakAfterReturnType

The function declaration return type breaking style to use.

LanguageKind

Supported languages.

@ LK_Java

Should be used for Java.

@ LK_ObjC

Should be used for Objective-C, Objective-C++.

@ LK_Proto

Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).

@ LK_TextProto

Should be used for Protocol Buffer messages in text format (https://developers.google....

bool Cpp11BracedListStyle

If true, format braced lists as best suited for C++11 braced lists.

BreakInheritanceListStyle BreakInheritanceList

The inheritance list style to use.

unsigned IndentWidth

The number of columns to use for indentation.

bool IndentRequiresClause

Indent the requires clause in a template.

std::vector< RawStringFormat > RawStringFormats

Defines hints for detecting supported languages code blocks in raw strings.

PPDirectiveIndentStyle IndentPPDirectives

The preprocessor directive indenting style to use.

@ BPPS_BinPack

Bin-pack parameters.

BinaryOperatorStyle BreakBeforeBinaryOperators

The way to wrap binary operators.

@ BPS_Auto

Automatically determine parameter bin-packing behavior.

@ BPS_Always

Always bin-pack parameters.

@ RCS_Never

Leave comments untouched.

@ BCIS_AfterColon

Break constructor initializers after the colon and commas.

@ BCIS_BeforeColon

Break constructor initializers before the colon and after the commas.

@ BCIS_BeforeComma

Break constructor initializers before the colon and commas, and align the commas with the colon.

BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations

The concept declaration style to use.

BreakTemplateDeclarationsStyle BreakTemplateDeclarations

The template declaration breaking style to use.

@ BOS_None

Break after operators.

bool IndentWrappedFunctionNames

Indent if a function definition or declaration is wrapped after the type.

LanguageKind Language

Language, this format style is targeted at.

@ BAS_DontAlign

Don't align, instead use ContinuationIndentWidth, e.g.:

@ BAS_AlwaysBreak

Always break after an open bracket, if the parameters don't fit on a single line, e....

@ BAS_BlockIndent

Always break after an open bracket, if the parameters don't fit on a single line.

@ BBIAS_Always

Always break before inline ASM colon.

@ BBIAS_OnlyMultiline

Break before inline ASM colon if the line length is longer than column limit.

unsigned TabWidth

The number of columns used for tab stops.

@ PPDIS_AfterHash

Indents directives after the hash.

@ LBI_OuterScope

For statements within block scope, align lambda body relative to the indentation level of the outer s...

@ LBI_Signature

Align lambda body relative to the lambda signature.

unsigned PenaltyBreakFirstLessLess

The penalty for breaking before the first <<.

unsigned ObjCBlockIndentWidth

The number of characters to use for indentation of ObjC blocks.

std::optional< FormatStyle > GetLanguageStyle(LanguageKind Language) const

std::optional< unsigned > BracedInitializerIndentWidth

The number of columns to use to indent the contents of braced init lists.

bool ExperimentalAutoDetectBinPacking

If true, clang-format detects whether function calls and definitions are formatted with one parameter...

bool ObjCBreakBeforeNestedBlockParam

Break parameters list into lines when there is nested block parameters in a function call.

OperandAlignmentStyle AlignOperands

If true, horizontally align operands of binary and ternary expressions.

@ BTDS_No

Do not force break before declaration.

@ BTDS_Leave

Do not change the line breaking before the declaration.

BreakBinaryOperationsStyle BreakBinaryOperations

The break binary operations style to use.

BreakConstructorInitializersStyle BreakConstructorInitializers

The break constructor initializers style to use.

bool BreakStringLiterals

Allow breaking string literals when formatting.

@ PCIS_NextLineOnly

Put all constructor initializers on the next line if they fit.

@ PCIS_BinPack

Bin-pack constructor initializers.

@ PCIS_NextLine

Same as PCIS_CurrentLine except that if all constructor initializers do not fit on the current line,...

BraceBreakingStyle BreakBeforeBraces

The brace breaking style to use.

@ BILS_AfterColon

Break inheritance list after the colon and commas.

@ BILS_BeforeComma

Break inheritance list before the colon and commas, and align the commas with the colon.

unsigned PenaltyExcessCharacter

The penalty for each character outside of the column limit.

@ DAS_BreakElements

Break inside DAGArg after each list element but for the last.

unsigned ConstructorInitializerIndentWidth

This option is deprecated.

@ RCPS_OwnLineWithBrace

As with OwnLine, except, unless otherwise prohibited, place a following open brace (of a function def...

@ RCPS_OwnLine

Always put the requires clause on its own line (possibly followed by a semicolon).

@ RCPS_WithPreceding

Try to put the clause together with the preceding part of a declaration.

@ RCPS_SingleLine

Try to put everything in the same line if possible.

@ RCPS_WithFollowing

Try to put the requires clause together with the class or function declaration.

RequiresClausePositionStyle RequiresClausePosition

The position of the requires clause.

BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon

The inline ASM colon style to use.

@ BS_Whitesmiths

Like Allman but always indent braces and line up code with braces.

bool BinPackArguments

If false, a function call's arguments will either be all on the same line or will have one line each.

@ REI_Keyword

Align requires expression body relative to the requires keyword.

PackConstructorInitializersStyle PackConstructorInitializers

The pack constructor initializers style to use.

@ BBCDS_Allowed

Breaking between template declaration and concept is allowed.

@ BBCDS_Never

Keep the template declaration line together with concept.

@ BBCDS_Always

Always break before concept, putting it in the line after the template declaration.

ReflowCommentsStyle ReflowComments

Comment reformatting style.

bool AllowAllParametersOfDeclarationOnNextLine

This option is deprecated.

BracketAlignmentStyle AlignAfterOpenBracket

If true, horizontally aligns arguments after an open bracket.

BinPackParametersStyle BinPackParameters

The bin pack parameters style to use.

unsigned MaxEmptyLinesToKeep

The maximum number of consecutive empty lines to keep.

BinPackStyle ObjCBinPackProtocolList

Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when t...

bool isJavaScript() const

DAGArgStyle TableGenBreakInsideDAGArg

The styles of the line break inside the DAGArg in TableGen.

LambdaBodyIndentationKind LambdaBodyIndentation

The indentation style of lambda bodies.

@ BBO_Never

Don't break binary operations.

BraceWrappingFlags BraceWrapping

Control of individual brace wrapping cases.

unsigned PenaltyBreakString

The penalty for each line break introduced inside a string literal.

RequiresExpressionIndentationKind RequiresExpressionIndentation

The indentation used for requires expression bodies.

unsigned PenaltyIndentedWhitespace

Penalty for each character of whitespace indentation (counted relative to leading non-whitespace colu...

bool AllowAllArgumentsOnNextLine

If a function call or braced initializer list doesn't fit on a line, allow putting all arguments onto...

unsigned PenaltyBreakComment

The penalty for each line break introduced inside a comment.

@ RTBS_ExceptShortType

Same as Automatic above, except that there is no break after short return types.

@ RTBS_None

This is deprecated. See Automatic below.

UseTabStyle UseTab

The way to use tab characters in the resulting file.

@ OAS_AlignAfterOperator

Horizontally align operands of binary and ternary expressions.

@ OAS_DontAlign

Do not align operands of binary and ternary expressions.

bool BreakBeforeTernaryOperators

If true, ternary operators will be placed after line breaks.

unsigned ColumnLimit

The column limit.

A wrapper around a Token storing information about the whitespace characters preceding it.

unsigned NestingLevel

The nesting level of this token, i.e.

bool isMemberAccess() const

Returns true if this is a "." or "->" accessing a member.

unsigned CanBreakBefore

true if it is allowed to break before this token.

StringRef TokenText

The raw text of the token.

FormatToken * getPreviousNonComment() const

Returns the previous token ignoring comments.

bool closesScope() const

Returns whether Tok is )]} or a closing > of a template or in protos.

bool is(tok::TokenKind Kind) const

unsigned TotalLength

The total length of the unwrapped line up to and including this token.

bool isTrailingComment() const

FormatToken * NextOperator

If this is an operator (or "."/"->") in a sequence of operators with the same precedence,...

FormatToken * MatchingParen

If this is a bracket, this points to the matching one.

FormatToken * Previous

The previous token in the unwrapped line.

The current state when indenting a unwrapped line.

llvm::StringMap< FormatStyle > EnclosingFunctionStyle

std::optional< FormatStyle > getDelimiterStyle(StringRef Delimiter) const

std::optional< FormatStyle > getEnclosingFunctionStyle(StringRef EnclosingFunction) const

RawStringFormatStyleManager(const FormatStyle &CodeStyle)

llvm::StringMap< FormatStyle > DelimiterStyle


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4