->isOneOf(tok::kw_return, TT_RequiresClause));
93 intMatchingStackIndex = Stack.size() - 1;
99 while(MatchingStackIndex >= 0 && Stack[MatchingStackIndex].Tok != LBrace)
100--MatchingStackIndex;
101 returnMatchingStackIndex >= 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 &&
109End->Next->MatchingParen->isOneOf(
110tok::l_brace, TT_ArrayInitializerLSquare, tok::less)) {
111 const ParenState*State = FindParenState(End->Next->MatchingParen);
112 if(State && State->BreakBeforeClosingBrace)
134 boolHasTwoOperands =
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_tLParenPos = TokenText.substr(0, 19).find_first_of(
'(');
180 if(LParenPos == StringRef::npos)
182StringRef Delimiter = TokenText.substr(2, LParenPos - 2);
185 size_tRParenPos = TokenText.size() - Delimiter.size() - 2;
186 if(TokenText[RParenPos] !=
')')
188 if(!TokenText.substr(RParenPos + 1).starts_with(Delimiter))
200 returnStringRef(Format.CanonicalDelimiter);
207std::optional<FormatStyle> LanguageStyle =
209 if(!LanguageStyle) {
212RawStringFormat.Language, &PredefinedStyle)) {
214PredefinedStyle.
Language= RawStringFormat.Language;
216LanguageStyle = PredefinedStyle;
219 for(StringRef Delimiter : RawStringFormat.Delimiters)
221 for(StringRef EnclosingFunction : RawStringFormat.EnclosingFunctions)
226std::optional<FormatStyle>
234std::optional<FormatStyle>
236StringRef EnclosingFunction)
const{
248 boolBinPackInconclusiveFunctions)
249: Style(Style), Keywords(Keywords), SourceMgr(SourceMgr),
250Whitespaces(Whitespaces), Encoding(Encoding),
251BinPackInconclusiveFunctions(BinPackInconclusiveFunctions),
252CommentPragmasRegex(Style.CommentPragmas), RawStringFormats(Style) {}
255 unsignedFirstStartColumn,
259State.FirstIndent = FirstIndent;
260 if(FirstStartColumn &&
Line->First->NewlinesBefore == 0)
261State.Column = FirstStartColumn;
263State.Column = FirstIndent;
273State.NextToken =
Line->First;
274State.Stack.push_back(
ParenState(
nullptr, FirstIndent, FirstIndent,
277State.NoContinuation =
false;
278State.StartOfStringLiteral = 0;
279State.NoLineBreak =
false;
280State.StartOfLineLevel = 0;
281State.LowestLevelOnLine = 0;
282State.IgnoreStackForComparison =
false;
287 auto&CurrentState = State.Stack.back();
288CurrentState.AvoidBinPacking =
true;
289CurrentState.BreakBeforeParameter =
true;
290CurrentState.AlignColons =
false;
294moveStateToNextToken(State, DryRun,
false);
301 const auto&CurrentState = State.Stack.back();
302assert(&
Previous== Current.Previous);
303 if(!Current.CanBreakBefore && !(CurrentState.BreakBeforeClosingBrace &&
304Current.closesBlockOrBlockTypeList(Style))) {
309 if(!Current.MustBreakBefore &&
Previous.is(tok::l_brace) &&
312 Previous.Previous->isOneOf(tok::l_brace, tok::l_paren, tok::comma)) {
321State.LowestLevelOnLine < State.StartOfLineLevel &&
322State.LowestLevelOnLine < Current.NestingLevel) {
325 if(Current.isMemberAccess() && CurrentState.ContainsUnwrappedBuilder)
330 if(
Previous.is(tok::l_brace) && State.Stack.size() > 1 &&
331State.Stack[State.Stack.size() - 2].NestedBlockInlined &&
332State.Stack[State.Stack.size() - 2].HasMultipleNestedBlocks &&
339 if(Current.is(TT_FunctionDeclarationName)) {
346assert(State.Column >= State.FirstIndent);
347 if(State.Column - State.FirstIndent < 6)
355Current.is(tok::r_paren)) {
356 returnCurrentState.BreakBeforeClosingParen;
361 if(Current.is(tok::r_brace) && Current.MatchingParen &&
362Current.isBlockIndentedInitRBrace(Style)) {
363 returnCurrentState.BreakBeforeClosingBrace;
368 if(!Current.isOneOf(TT_BinaryOperator, tok::comma) &&
373Current.isNot(TT_LambdaLBrace)) &&
374CurrentState.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)) {
386assert(
Previous.MatchingParen->Previous->is(tok::r_brace));
390 return!State.NoLineBreak && !CurrentState.NoLineBreak;
396 const auto&CurrentState = State.Stack.back();
398Current.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) &&
412Current.isBlockIndentedInitRBrace(Style)))) {
415 if(CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
419Current.ObjCSelectorNameParts > 1 &&
420Current.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) &&
431State.Line->First->isNot(TT_AttributeSquare) && Style.
isCpp() &&
441 Previous.is(TT_ConditionalExpr))) &&
442CurrentState.BreakBeforeParameter && !Current.isTrailingComment() &&
443!Current.isOneOf(tok::r_paren, tok::r_brace)) {
446 if(CurrentState.IsChainedConditional &&
448Current.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 >
470CurrentState.BreakBeforeParameter) &&
471(!Current.isTrailingComment() || Current.NewlinesBefore > 0) &&
473Style.
ColumnLimit> 0 || Current.NewlinesBefore > 0)) {
477 if(Current.is(TT_ObjCMethodExpr) &&
Previous.isNot(TT_SelectorName) &&
478State.Line->startsWith(TT_ObjCMethodSpecifier)) {
481 if(Current.is(TT_SelectorName) &&
Previous.isNot(tok::at) &&
482CurrentState.ObjCSelectorNameFound && CurrentState.BreakBeforeParameter &&
484!Current.startsSequence(TT_SelectorName, tok::colon, tok::caret))) {
488 unsignedNewLineColumn = getNewLineColumn(State);
489 if(Current.isMemberAccess() && Style.
ColumnLimit!= 0 &&
491(State.Column > NewLineColumn ||
492Current.NestingLevel < State.StartOfLineLevel)) {
497(CurrentState.CallContinuation != 0 ||
498CurrentState.BreakBeforeParameter) &&
504!(State.Column <= NewLineColumn && Style.
isJavaScript()) &&
505!(
Previous.closesScopeAfterBlock() && State.Column <= NewLineColumn)) {
511 if(
Previous.ClosesTemplateDeclaration && CurrentState.BreakBeforeParameter &&
512Current.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) &&
525nextIsMultilineString(State)) {
532 if(
Previous.is(TT_BinaryOperator) && Current.CanBreakBefore) {
533 const autoPreviousPrecedence =
Previous.getPrecedence();
535CurrentState.BreakBeforeParameter && !Current.isTrailingComment()) {
536 const boolLHSIsBinaryExpr =
549 const boolIsComparison =
554 Previous.Previous->isNot(TT_BinaryOperator);
558}
else if(Current.is(TT_BinaryOperator) && Current.CanBreakBefore &&
559CurrentState.BreakBeforeParameter) {
564 if(Current.is(tok::lessless) && Current.isNot(TT_OverloadedOperator) &&
565CurrentState.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)) {
596Current.NewlinesBefore > 0);
598 if(
Previous.is(TT_FunctionAnnotationRParen) &&
602 if(
Previous.is(TT_LeadingJavaAnnotation) && Current.isNot(tok::l_paren) &&
603Current.isNot(TT_LeadingJavaAnnotation)) {
612 static constllvm::StringSet<> BreakBeforeDecoratedTokens = {
"get",
"set",
614 if(BreakBeforeDecoratedTokens.contains(Current.TokenText))
618 if(Current.is(TT_FunctionDeclarationName) &&
619!State.Line->ReturnTypeWrapped &&
626CurrentState.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 unsignedExtraSpaces) {
659assert(State.NextToken->Previous);
662assert(!State.Stack.empty());
663State.NoContinuation =
false;
665 if(Current.is(TT_ImplicitStringLiteral) &&
666(!
Previous.Tok.getIdentifierInfo() ||
667 Previous.Tok.getIdentifierInfo()->getPPKeywordID() ==
668tok::pp_not_keyword)) {
671 if(Current.LastNewlineOffset != 0) {
674State.Column = EndColumn;
676 unsignedStartColumn =
678assert(EndColumn >= StartColumn);
679State.Column += EndColumn - StartColumn;
681moveStateToNextToken(State, DryRun,
false);
685 unsignedPenalty = 0;
687Penalty = addTokenOnNewLine(State, DryRun);
689addTokenOnCurrentLine(State, DryRun, ExtraSpaces);
691 returnmoveStateToNextToken(State, DryRun, Newline) + Penalty;
694voidContinuationIndenter::addTokenOnCurrentLine(
LineState&State,
boolDryRun,
695 unsignedExtraSpaces) {
697assert(State.NextToken->Previous);
699 auto&CurrentState = State.Stack.back();
701 boolDisallowLineBreaksOnThisLine =
708Style.
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 autoBlockParameterCount = PrevNonComment->BlockParameterCount;
718 if(BlockParameterCount == 0)
722 if(BlockParameterCount > 1)
726 if(!PrevNonComment->Role)
728 autoComma = PrevNonComment->Role->lastComma();
731 autoNext = Comma->getNextNonComment();
733!Next->isOneOf(TT_LambdaLSquare, tok::l_brace, tok::caret);
736 if(DisallowLineBreaksOnThisLine)
737State.NoLineBreak =
true;
739 if(Current.is(tok::equal) &&
740(State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
741CurrentState.VariablePos == 0 &&
743 Previous.Previous->isNot(TT_DesignatedInitializerPeriod))) {
744CurrentState.VariablePos = State.Column;
746 constFormatToken *Tok = &
Previous;
747 while(Tok && CurrentState.VariablePos >= Tok->ColumnWidth) {
748CurrentState.VariablePos -= Tok->ColumnWidth;
749 if(Tok->SpacesRequiredBefore != 0)
753 if(
Previous.PartOfMultiVariableDeclStmt)
754CurrentState.LastSpace = CurrentState.VariablePos;
757 unsignedSpaces = Current.SpacesRequiredBefore + ExtraSpaces;
760 intPPColumnCorrection = 0;
762 Previous.is(tok::hash) && State.FirstIndent > 0 &&
766Spaces += State.FirstIndent;
773PPColumnCorrection = -1;
778State.Column + Spaces + PPColumnCorrection,
779 false, State.Line->InMacroBody);
785Current.is(TT_InheritanceColon)) {
786CurrentState.NoLineBreak =
true;
789 Previous.is(TT_InheritanceColon)) {
790CurrentState.NoLineBreak =
true;
793 if(Current.is(TT_SelectorName) && !CurrentState.ObjCSelectorNameFound) {
794 unsignedMinIndent = std::max(
796 unsignedFirstColonPos = State.Column + Spaces + Current.ColumnWidth;
797 if(Current.LongestObjCSelectorName == 0)
798CurrentState.AlignColons =
false;
799 else if(MinIndent + Current.LongestObjCSelectorName > FirstColonPos)
800CurrentState.ColonPos = MinIndent + Current.LongestObjCSelectorName;
802CurrentState.ColonPos = FirstColonPos;
809 autoIsOpeningBracket = [&](
constFormatToken &Tok) {
810 autoIsStartOfBracedList = [&]() {
811 returnTok.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 autoIsFunctionCallParen = [](
constFormatToken &Tok) {
827 returnTok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
828Tok.Previous->is(tok::identifier);
830 autoIsInTemplateString = [
this](
constFormatToken &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 autoStartsSimpleOneArgList = [&](
constFormatToken &TokAfterLParen) {
845assert(TokAfterLParen.isNot(tok::comment) || TokAfterLParen.Next);
847TokAfterLParen.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) ||
858Tok.isOneOf(tok::ellipsis, Keywords.
kw_await))) {
861 const auto*
Previous= Tok.Previous;
863TT_LambdaDefinitionLParen) &&
864!IsFunctionCallParen(*
Previous))) {
867 if(IsOpeningBracket(Tok) || IsInTemplateString(Tok))
869 const auto*Next = Tok.Next;
870 return!Next || Next->isMemberAccess() ||
871Next->is(TT_FunctionDeclarationLParen) || IsFunctionCallParen(*Next);
875IsOpeningBracket(
Previous) && State.Column > getNewLineColumn(State) &&
886!StartsSimpleOneArgList(Current)) {
887CurrentState.NoLineBreak =
true;
891CurrentState.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)) {
906CurrentState.Indent = State.Column + Spaces;
907CurrentState.IsAligned =
true;
910CurrentState.NoLineBreak =
true;
912CurrentState.NoLineBreak =
true;
915State.Column > getNewLineColumn(State)) {
916CurrentState.ContainsUnwrappedBuilder =
true;
920CurrentState.NoLineBreak =
true;
921 if(Current.isMemberAccess() &&
Previous.is(tok::r_paren) &&
930CurrentState.NoLineBreak =
true;
937 constFormatToken *
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 boolBreakBeforeOperator =
946 P->MustBreakBefore ||
P->is(tok::lessless) ||
947(
P->is(TT_BinaryOperator) &&
953 boolHasTwoOperands =
P->OperatorIndex == 0 && !
P->NextOperator &&
954 P->isNot(TT_ConditionalExpr);
955 if((!BreakBeforeOperator &&
958(!CurrentState.LastOperatorWrapped && BreakBeforeOperator)) {
959CurrentState.NoLineBreakInOperand =
true;
963State.Column += Spaces;
964 if(Current.isNot(tok::comment) &&
Previous.is(tok::l_paren) &&
969CurrentState.LastSpace = State.Column;
970CurrentState.NestedBlockIndent = State.Column;
971}
else if(!Current.isOneOf(tok::comment, tok::caret) &&
973 Previous.isNot(TT_OverloadedOperator)) ||
975CurrentState.LastSpace = State.Column;
976}
else if(
Previous.is(TT_CtorInitializerColon) &&
977(!Current.isTrailingComment() || Current.NewlinesBefore > 0) &&
980CurrentState.Indent = State.Column;
981CurrentState.LastSpace = State.Column;
982}
else if(
Previous.isOneOf(TT_ConditionalExpr, TT_CtorInitializerColon)) {
983CurrentState.LastSpace = State.Column;
984}
else if(
Previous.is(TT_BinaryOperator) &&
988Current.StartsBinaryExpression)) {
992CurrentState.LastSpace = State.Column;
993}
else if(
Previous.is(TT_InheritanceColon)) {
994CurrentState.Indent = State.Column;
995CurrentState.LastSpace = State.Column;
996}
else if(Current.is(TT_CSharpGenericTypeConstraintColon)) {
997CurrentState.ColonPos = State.Column;
998}
else if(
Previous.opensScope()) {
1005 constFormatToken *Next =
Previous.MatchingParen->getNextNonComment();
1006 if(Next && Next->isMemberAccess() && State.Stack.size() > 1 &&
1007State.Stack[State.Stack.size() - 2].CallContinuation == 0) {
1008CurrentState.LastSpace = State.Column;
1014unsignedContinuationIndenter::addTokenOnNewLine(LineState &State,
1016FormatToken &Current = *State.NextToken;
1017assert(State.NextToken->Previous);
1018 constFormatToken &
Previous= *State.NextToken->Previous;
1019 auto&CurrentState = State.Stack.back();
1023 unsignedPenalty = 0;
1025 constFormatToken *PreviousNonComment = Current.getPreviousNonComment();
1026 constFormatToken *NextNonComment =
Previous.getNextNonComment();
1027 if(!NextNonComment)
1028NextNonComment = &Current;
1031 if(!CurrentState.ContainsLineBreak)
1033CurrentState.ContainsLineBreak =
true;
1035Penalty += State.NextToken->SplitPenalty;
1040 if(NextNonComment->is(tok::lessless) && CurrentState.FirstLessLess == 0 &&
1042CurrentState.BreakBeforeParameter)) {
1046State.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) ||
1079CurrentState.NestedBlockIndent = State.Column;
1082 if(NextNonComment->isMemberAccess()) {
1083 if(CurrentState.CallContinuation == 0)
1084CurrentState.CallContinuation = State.Column;
1085}
else if(NextNonComment->is(TT_SelectorName)) {
1086 if(!CurrentState.ObjCSelectorNameFound) {
1087 if(NextNonComment->LongestObjCSelectorName == 0) {
1088CurrentState.AlignColons =
false;
1090CurrentState.ColonPos =
1092? std::max(CurrentState.Indent,
1094: CurrentState.Indent) +
1096NextNonComment->ColumnWidth);
1098}
else if(CurrentState.AlignColons &&
1099CurrentState.ColonPos <= NextNonComment->ColumnWidth) {
1100CurrentState.ColonPos = State.Column + NextNonComment->ColumnWidth;
1102}
else if(PreviousNonComment && PreviousNonComment->is(tok::colon) &&
1103PreviousNonComment->isOneOf(TT_ObjCMethodExpr, TT_DictLiteral)) {
1113 if(State.Stack.size() > 1) {
1114State.Stack[State.Stack.size() - 2].LastSpace =
1115std::max(CurrentState.LastSpace, CurrentState.Indent) +
1120 if((PreviousNonComment &&
1121PreviousNonComment->isOneOf(tok::comma, tok::semi) &&
1122!CurrentState.AvoidBinPacking) ||
1124CurrentState.BreakBeforeParameter =
false;
1126 if(PreviousNonComment &&
1127(PreviousNonComment->isOneOf(TT_TemplateCloser, TT_JavaAnnotation) ||
1128PreviousNonComment->ClosesRequiresClause) &&
1129Current.NestingLevel == 0) {
1130CurrentState.BreakBeforeParameter =
false;
1132 if(NextNonComment->is(tok::question) ||
1133(PreviousNonComment && PreviousNonComment->is(tok::question))) {
1134CurrentState.BreakBeforeParameter =
true;
1136 if(Current.is(TT_BinaryOperator) && Current.CanBreakBefore)
1137CurrentState.BreakBeforeParameter =
false;
1141 if(Current.is(tok::r_brace) && Current.MatchingParen &&
1144!Current.MatchingParen->Children.empty()) {
1148MaxEmptyLinesToKeep = 1;
1151std::max(1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
1152 boolContinuePPDirective =
1155CurrentState.IsAligned, ContinuePPDirective);
1158 if(!Current.isTrailingComment())
1159CurrentState.LastSpace = State.Column;
1160 if(Current.is(tok::lessless)) {
1164CurrentState.LastSpace += 3;
1167State.StartOfLineLevel = Current.NestingLevel;
1168State.LowestLevelOnLine = Current.NestingLevel;
1172 boolNestedBlockSpecialCase =
1173(!Style.
isCpp() && Current.is(tok::r_brace) && State.Stack.size() > 1 &&
1174State.Stack[State.Stack.size() - 2].NestedBlockInlined) ||
1178NestedBlockSpecialCase =
1179NestedBlockSpecialCase ||
1180(Current.MatchingParen &&
1181Current.MatchingParen->is(TT_RequiresExpressionLBrace));
1182 if(!NestedBlockSpecialCase) {
1183 autoParentLevelIt = std::next(State.Stack.rbegin());
1185Current.MatchingParen && Current.MatchingParen->is(TT_LambdaLBrace)) {
1200 autoFindCurrentLevel = [&](
const auto&It) {
1201 returnstd::find_if(It, State.Stack.rend(), [](
const auto&PState) {
1202return PState.Tok != nullptr;
1205 autoMaybeIncrement = [&](
const auto&It) {
1206 returnIt != State.Stack.rend() ? std::next(It) : It;
1208 autoLambdaLevelIt = FindCurrentLevel(State.Stack.rbegin());
1209 autoLevelContainingLambdaIt =
1210FindCurrentLevel(MaybeIncrement(LambdaLevelIt));
1211ParentLevelIt = MaybeIncrement(LevelContainingLambdaIt);
1213 for(
autoI = ParentLevelIt,
E= State.Stack.rend(); I !=
E; ++I)
1214I->BreakBeforeParameter =
true;
1217 if(PreviousNonComment &&
1218!PreviousNonComment->isOneOf(tok::comma, tok::colon, tok::semi) &&
1219((PreviousNonComment->isNot(TT_TemplateCloser) &&
1220!PreviousNonComment->ClosesRequiresClause) ||
1221Current.NestingLevel != 0) &&
1222!PreviousNonComment->isOneOf(
1223TT_BinaryOperator, TT_FunctionAnnotationRParen, TT_JavaAnnotation,
1224TT_LeadingJavaAnnotation) &&
1225Current.isNot(TT_BinaryOperator) && !PreviousNonComment->opensScope() &&
1229Current.isNot(TT_LambdaLBrace))) {
1230CurrentState.BreakBeforeParameter =
true;
1235 if(PreviousNonComment &&
1236(PreviousNonComment->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
1238CurrentState.BreakBeforeClosingBrace =
true;
1241 if(PreviousNonComment && PreviousNonComment->is(tok::l_paren)) {
1242CurrentState.BreakBeforeClosingParen =
1246 if(CurrentState.AvoidBinPacking) {
1251 boolPreviousIsBreakingCtorInitializerColon =
1252PreviousNonComment && PreviousNonComment->is(TT_CtorInitializerColon) &&
1254 boolAllowAllConstructorInitializersOnNextLine =
1257 if(!(
Previous.isOneOf(tok::l_paren, tok::l_brace, TT_BinaryOperator) ||
1258PreviousIsBreakingCtorInitializerColon) ||
1260State.Line->MustBeDeclaration) ||
1262!State.Line->MustBeDeclaration) ||
1263(!AllowAllConstructorInitializersOnNextLine &&
1264PreviousIsBreakingCtorInitializerColon) ||
1266CurrentState.BreakBeforeParameter =
true;
1272 if(PreviousIsBreakingCtorInitializerColon &&
1273AllowAllConstructorInitializersOnNextLine) {
1274CurrentState.BreakBeforeParameter =
false;
1279CurrentState.BreakBeforeParameter =
true;
1284unsignedContinuationIndenter::getNewLineColumn(
constLineState &State) {
1285 if(!State.NextToken || !State.NextToken->Previous)
1288FormatToken &Current = *State.NextToken;
1289 const auto&CurrentState = State.Stack.back();
1291 if(CurrentState.IsCSharpGenericTypeConstraint &&
1292Current.isNot(TT_CSharpGenericTypeConstraint)) {
1293 returnCurrentState.ColonPos + 2;
1296 constFormatToken &
Previous= *Current.Previous;
1298 unsignedContinuationIndent =
1299std::max(CurrentState.LastSpace, CurrentState.Indent) +
1301 constFormatToken *PreviousNonComment = Current.getPreviousNonComment();
1302 constFormatToken *NextNonComment =
Previous.getNextNonComment();
1303 if(!NextNonComment)
1304NextNonComment = &Current;
1309 returnstd::max(CurrentState.LastSpace,
1315 if(Style.
isVerilog() && PreviousNonComment &&
1317 returnState.FirstIndent;
1321State.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 ||
1330State.NextToken->is(TT_LambdaLBrace))) {
1331 returnState.FirstIndent;
1333 returnCurrentState.Indent;
1335 if(Current.is(TT_LambdaArrow) &&
1336 Previous.isOneOf(tok::kw_noexcept, tok::kw_mutable, tok::kw_constexpr,
1337tok::kw_consteval, tok::kw_static, TT_AttributeSquare)) {
1338 returnContinuationIndent;
1340 if((Current.isOneOf(tok::r_brace, tok::r_square) ||
1342State.Stack.size() > 1) {
1343 if(Current.closesBlockOrBlockTypeList(Style))
1344 returnState.Stack[State.Stack.size() - 2].NestedBlockIndent;
1345 if(Current.MatchingParen && Current.MatchingParen->is(
BK_BracedInit))
1346 returnState.Stack[State.Stack.size() - 2].LastSpace;
1347 returnState.FirstIndent;
1364 if(Current.is(tok::r_paren) && State.Stack.size() > 1 &&
1366Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
1367 returnState.Stack[State.Stack.size() - 2].LastSpace;
1371 if(Style.
isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
1372State.Stack.size() > 1) {
1373 returnState.Stack[State.Stack.size() - 2].LastSpace;
1376(Current.is(tok::r_paren) ||
1377(Current.is(tok::r_brace) && Current.MatchingParen &&
1379State.Stack.size() > 1) {
1380 returnState.Stack[State.Stack.size() - 2].LastSpace;
1382 if(NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())
1383 returnState.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 returnCurrentState.Indent;
1397 if(NextNonComment->is(TT_ObjCStringLiteral) &&
1398State.StartOfStringLiteral != 0) {
1399 returnState.StartOfStringLiteral - 1;
1401 if(NextNonComment->isStringLiteral() && State.StartOfStringLiteral != 0)
1402 returnState.StartOfStringLiteral;
1403 if(NextNonComment->is(tok::lessless) && CurrentState.FirstLessLess != 0)
1404 returnCurrentState.FirstLessLess;
1405 if(NextNonComment->isMemberAccess()) {
1406 if(CurrentState.CallContinuation == 0)
1407 returnContinuationIndent;
1408 returnCurrentState.CallContinuation;
1410 if(CurrentState.QuestionColumn != 0 &&
1411((NextNonComment->is(tok::colon) &&
1412NextNonComment->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 unsignedIndent = CurrentState.Indent;
1431 returnCurrentState.QuestionColumn;
1433 if(
Previous.is(tok::comma) && CurrentState.VariablePos != 0)
1434 returnCurrentState.VariablePos;
1435 if(Current.is(TT_RequiresClause)) {
1442 returnCurrentState.Indent;
1447 if(NextNonComment->isOneOf(TT_CtorInitializerColon, TT_InheritanceColon,
1448TT_InheritanceComma)) {
1451 if((PreviousNonComment &&
1452(PreviousNonComment->ClosesTemplateDeclaration ||
1453PreviousNonComment->ClosesRequiresClause ||
1454(PreviousNonComment->is(TT_AttributeMacro) &&
1455Current.isNot(tok::l_paren)) ||
1456PreviousNonComment->isOneOf(
1457TT_AttributeRParen, TT_AttributeSquare, TT_FunctionAnnotationRParen,
1458TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||
1460NextNonComment->isOneOf(tok::kw_operator, TT_FunctionDeclarationName))) {
1461 returnstd::max(CurrentState.LastSpace, CurrentState.Indent);
1463 if(NextNonComment->is(TT_SelectorName)) {
1464 if(!CurrentState.ObjCSelectorNameFound) {
1465 unsignedMinIndent = CurrentState.Indent;
1467MinIndent = std::max(MinIndent,
1480std::max(NextNonComment->LongestObjCSelectorName,
1481NextNonComment->ColumnWidth) -
1482NextNonComment->ColumnWidth;
1484 if(!CurrentState.AlignColons)
1485 returnCurrentState.Indent;
1486 if(CurrentState.ColonPos > NextNonComment->ColumnWidth)
1487 returnCurrentState.ColonPos - NextNonComment->ColumnWidth;
1488 returnCurrentState.Indent;
1490 if(NextNonComment->is(tok::colon) && NextNonComment->is(TT_ObjCMethodExpr))
1491 returnCurrentState.ColonPos;
1492 if(NextNonComment->is(TT_ArraySubscriptLSquare)) {
1493 if(CurrentState.StartOfArraySubscripts != 0) {
1494 returnCurrentState.StartOfArraySubscripts;
1497 returnCurrentState.Indent;
1499 returnContinuationIndent;
1504 if(State.Line->InPragmaDirective) {
1505FormatToken *PragmaType = State.Line->First->Next->Next;
1506 if(PragmaType && PragmaType->TokenText ==
"omp")
1512 if(NextNonComment->is(tok::identifier) && NextNonComment->FakeRParens == 0 &&
1513NextNonComment->Next && NextNonComment->Next->is(TT_ObjCMethodExpr)) {
1514 returnCurrentState.Indent;
1517 if(NextNonComment->isOneOf(TT_StartOfName, TT_PointerOrReference) ||
1518 Previous.isOneOf(tok::coloncolon, tok::equal, TT_JsTypeColon)) {
1519 returnContinuationIndent;
1521 if(PreviousNonComment && PreviousNonComment->is(tok::colon) &&
1522PreviousNonComment->isOneOf(TT_ObjCMethodExpr, TT_DictLiteral)) {
1523 returnContinuationIndent;
1525 if(NextNonComment->is(TT_CtorInitializerComma))
1526 returnCurrentState.Indent;
1527 if(PreviousNonComment && PreviousNonComment->is(TT_CtorInitializerColon) &&
1529 returnCurrentState.Indent;
1531 if(PreviousNonComment && PreviousNonComment->is(TT_InheritanceColon) &&
1533 returnCurrentState.Indent;
1536 Previous.isNot(TT_TableGenDAGArgOperatorToBreak) &&
1537!Current.isBinaryOperator() &&
1538!Current.isOneOf(tok::colon, tok::comment)) {
1539 returnContinuationIndent;
1541 if(Current.is(TT_ProtoExtensionLSquare))
1542 returnCurrentState.Indent;
1543 if(Current.isBinaryOperator() && CurrentState.UnindentOperator) {
1544 returnCurrentState.Indent - Current.Tok.getLength() -
1545Current.SpacesRequiredBefore;
1547 if(Current.is(tok::comment) && NextNonComment->isBinaryOperator() &&
1548CurrentState.UnindentOperator) {
1549 returnCurrentState.Indent - NextNonComment->Tok.getLength() -
1550NextNonComment->SpacesRequiredBefore;
1552 if(CurrentState.Indent == State.FirstIndent && PreviousNonComment &&
1553!PreviousNonComment->isOneOf(tok::r_brace, TT_CtorInitializerComma)) {
1558 returnCurrentState.Indent;
1564 if(
Previous->isNot(tok::l_paren))
1566 if(
Previous->ParameterCount > 1)
1573unsignedContinuationIndenter::moveStateToNextToken(LineState &State,
1574 boolDryRun,
boolNewline) {
1575assert(State.Stack.size());
1576 constFormatToken &Current = *State.NextToken;
1577 auto&CurrentState = State.Stack.back();
1579 if(Current.is(TT_CSharpGenericTypeConstraint))
1580CurrentState.IsCSharpGenericTypeConstraint =
true;
1581 if(Current.isOneOf(tok::comma, TT_BinaryOperator))
1582CurrentState.NoLineBreakInOperand =
false;
1583 if(Current.isOneOf(TT_InheritanceColon, TT_CSharpGenericTypeConstraintColon))
1584CurrentState.AvoidBinPacking =
true;
1585 if(Current.is(tok::lessless) && Current.isNot(TT_OverloadedOperator)) {
1586 if(CurrentState.FirstLessLess == 0)
1587CurrentState.FirstLessLess = State.Column;
1589CurrentState.LastOperatorWrapped = Newline;
1591 if(Current.is(TT_BinaryOperator) && Current.isNot(tok::lessless))
1592CurrentState.LastOperatorWrapped = Newline;
1593 if(Current.is(TT_ConditionalExpr) && Current.Previous &&
1594Current.Previous->isNot(TT_ConditionalExpr)) {
1595CurrentState.LastOperatorWrapped = Newline;
1597 if(Current.is(TT_ArraySubscriptLSquare) &&
1598CurrentState.StartOfArraySubscripts == 0) {
1599CurrentState.StartOfArraySubscripts = State.Column;
1602 autoIsWrappedConditional = [](
constFormatToken &Tok) {
1603 if(!(Tok.is(TT_ConditionalExpr) && Tok.is(tok::question)))
1605 if(Tok.MustBreakBefore)
1608 constFormatToken *Next = Tok.getNextNonComment();
1609 returnNext && Next->MustBreakBefore;
1611 if(IsWrappedConditional(Current))
1612CurrentState.IsWrappedConditional =
true;
1614CurrentState.QuestionColumn = State.Column;
1616 constFormatToken *
Previous= Current.Previous;
1620CurrentState.QuestionColumn = State.Column;
1622 if(!Current.opensScope() && !Current.closesScope() &&
1623Current.isNot(TT_PointerOrReference)) {
1624State.LowestLevelOnLine =
1625std::min(State.LowestLevelOnLine, Current.NestingLevel);
1627 if(Current.isMemberAccess())
1628CurrentState.StartOfFunctionCall = !Current.NextOperator ? 0 : State.Column;
1629 if(Current.is(TT_SelectorName))
1630CurrentState.ObjCSelectorNameFound =
true;
1631 if(Current.is(TT_CtorInitializerColon) &&
1642CurrentState.NestedBlockIndent = CurrentState.Indent;
1644CurrentState.AvoidBinPacking =
true;
1645CurrentState.BreakBeforeParameter =
1650CurrentState.BreakBeforeParameter =
false;
1653 if(Current.is(TT_CtorInitializerColon) &&
1655CurrentState.Indent =
1657CurrentState.NestedBlockIndent = CurrentState.Indent;
1659CurrentState.AvoidBinPacking =
true;
1661CurrentState.BreakBeforeParameter =
false;
1663 if(Current.is(TT_InheritanceColon)) {
1664CurrentState.Indent =
1667 if(Current.isOneOf(TT_BinaryOperator, TT_ConditionalExpr) && Newline)
1668CurrentState.NestedBlockIndent = State.Column + Current.ColumnWidth + 1;
1669 if(Current.isOneOf(TT_LambdaLSquare, TT_LambdaArrow))
1670CurrentState.LastSpace = State.Column;
1671 if(Current.is(TT_RequiresExpression) &&
1673CurrentState.NestedBlockIndent = State.Column;
1677 constFormatToken *
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))
1691PState.NoLineBreak =
true;
1692State.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)))) {
1697CurrentState.NestedBlockInlined =
1701moveStatePastFakeLParens(State, Newline);
1702moveStatePastScopeCloser(State);
1705 boolAllowBreak = !State.Stack.back().NoLineBreak &&
1706!State.Stack.back().NoLineBreakInOperand;
1707moveStatePastScopeOpener(State, Newline);
1708moveStatePastFakeRParens(State);
1710 if(Current.is(TT_ObjCStringLiteral) && State.StartOfStringLiteral == 0)
1711State.StartOfStringLiteral = State.Column + 1;
1712 if(Current.is(TT_CSharpStringLiteral) && State.StartOfStringLiteral == 0) {
1713State.StartOfStringLiteral = State.Column + 1;
1714}
else if(Current.is(TT_TableGenMultiLineString) &&
1715State.StartOfStringLiteral == 0) {
1716State.StartOfStringLiteral = State.Column + 1;
1717}
else if(Current.isStringLiteral() && State.StartOfStringLiteral == 0) {
1718State.StartOfStringLiteral = State.Column;
1719}
else if(!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&
1720!Current.isStringLiteral()) {
1721State.StartOfStringLiteral = 0;
1724State.Column += Current.ColumnWidth;
1725State.NextToken = State.NextToken->Next;
1730 if(Style.
isVerilog() && State.NextToken &&
1731State.NextToken->MustBreakBefore &&
1734CurrentState.Indent = State.FirstIndent;
1738handleEndOfLine(Current, State, DryRun, AllowBreak, Newline);
1741Current.Role->formatFromToken(State,
this, DryRun);
1748Penalty +=
Previous->Role->formatAfterToken(State,
this, DryRun);
1753voidContinuationIndenter::moveStatePastFakeLParens(LineState &State,
1755 constFormatToken &Current = *State.NextToken;
1756 if(Current.FakeLParens.empty())
1759 constFormatToken *
Previous= Current.getPreviousNonComment();
1764 boolSkipFirstExtraIndent =
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();
1773ParenState NewParenState = CurrentState;
1774NewParenState.Tok =
nullptr;
1775NewParenState.ContainsLineBreak =
false;
1776NewParenState.LastOperatorWrapped =
true;
1777NewParenState.IsChainedConditional =
false;
1778NewParenState.IsWrappedConditional =
false;
1779NewParenState.UnindentOperator =
false;
1780NewParenState.NoLineBreak =
1781NewParenState.NoLineBreak || CurrentState.NoLineBreakInOperand;
1785NewParenState.AvoidBinPacking =
false;
1790 if(!Current.isTrailingComment() &&
1796PrecedenceLevel >
prec::Comma|| Current.NestingLevel == 0) &&
1799TT_TableGenDAGArgListCommaToBreak)))) {
1800NewParenState.Indent = std::max(
1801std::max(State.Column, NewParenState.Indent), CurrentState.LastSpace);
1807 if(
Previous&&
Previous->endsSequence(tok::l_paren, tok::kw__Generic) &&
1808State.Stack.size() > 1) {
1809NewParenState.Indent = State.Stack[State.Stack.size() - 2].Indent +
1821NewParenState.UnindentOperator =
true;
1824NewParenState.IsAligned =
true;
1834NewParenState.LastSpace = std::max(NewParenState.LastSpace, State.Column);
1836Current.isNot(TT_UnaryOperator) &&
1838NewParenState.StartOfFunctionCall = State.Column;
1848&PrecedenceLevel == &Current.FakeLParens.back() &&
1849!CurrentState.IsWrappedConditional) {
1850NewParenState.IsChainedConditional =
true;
1851NewParenState.UnindentOperator = State.Stack.back().UnindentOperator;
1854!Current.isTrailingComment())) {
1858NewParenState.BreakBeforeParameter =
false;
1859State.Stack.push_back(NewParenState);
1860SkipFirstExtraIndent =
false;
1864voidContinuationIndenter::moveStatePastFakeRParens(LineState &State) {
1865 for(
unsignedi = 0, e = State.NextToken->FakeRParens; i != e; ++i) {
1866 unsignedVariablePos = State.Stack.back().VariablePos;
1867 if(State.Stack.size() == 1) {
1871State.Stack.pop_back();
1872State.Stack.back().VariablePos = VariablePos;
1878State.Stack.back().LastSpace -= Style.
IndentWidth;
1882voidContinuationIndenter::moveStatePastScopeOpener(LineState &State,
1884 constFormatToken &Current = *State.NextToken;
1885 if(!Current.opensScope())
1888 const auto&CurrentState = State.Stack.back();
1891 if(Current.isOneOf(tok::less, tok::l_paren) &&
1892CurrentState.IsCSharpGenericTypeConstraint) {
1896 if(Current.MatchingParen && Current.is(
BK_Block)) {
1897moveStateToNewBlock(State, Newline);
1902 unsignedLastSpace = CurrentState.LastSpace;
1903 boolAvoidBinPacking;
1904 boolBreakBeforeParameter =
false;
1905 unsignedNestedBlockIndent = std::max(CurrentState.StartOfFunctionCall,
1906CurrentState.NestedBlockIndent);
1907 if(Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
1909 if(Current.opensBlockOrBlockTypeList(Style)) {
1911std::min(State.Column, CurrentState.NestedBlockIndent);
1912}
else if(Current.is(tok::l_brace)) {
1919 constFormatToken *NextNonComment = Current.getNextNonComment();
1920 boolEndsInComma = Current.MatchingParen &&
1921Current.MatchingParen->Previous &&
1922Current.MatchingParen->Previous->is(tok::comma);
1923AvoidBinPacking = EndsInComma || Current.is(TT_DictLiteral) ||
1925(NextNonComment && NextNonComment->isOneOf(
1926TT_DesignatedInitializerPeriod,
1927TT_DesignatedInitializerLSquare));
1928BreakBeforeParameter = EndsInComma;
1929 if(Current.ParameterCount > 1)
1930NestedBlockIndent = std::max(NestedBlockIndent, State.Column + 1);
1934std::max(CurrentState.LastSpace, CurrentState.StartOfFunctionCall);
1936 if(Style.
isTableGen() && Current.is(TT_TableGenDAGArgOpenerToBreak) &&
1942 constFormatToken *Next = Current.Next;
1943 if(Next && Next->is(TT_TableGenDAGArgOperatorID))
1944NewIndent = State.Column + Next->TokenText.size() + 2;
1951 if(Current.is(tok::less) && Current.ParentBracket == tok::l_paren) {
1952NewIndent = std::max(NewIndent, CurrentState.Indent);
1953LastSpace = std::max(LastSpace, CurrentState.Indent);
1957Current.MatchingParen &&
1958Current.MatchingParen->getPreviousNonComment() &&
1959Current.MatchingParen->getPreviousNonComment()->is(tok::comma);
1963 boolObjCBinPackProtocolList =
1968 boolBinPackDeclaration =
1971(State.Line->Type ==
LT_ObjCDecl&& ObjCBinPackProtocolList);
1973 boolGenericSelection =
1974Current.getPreviousNonComment() &&
1975Current.getPreviousNonComment()->is(tok::kw__Generic);
1978(CurrentState.IsCSharpGenericTypeConstraint) || GenericSelection ||
1980(State.Line->MustBeDeclaration && !BinPackDeclaration) ||
1986 if(Current.is(TT_ObjCMethodExpr) && Current.MatchingParen &&
1993BreakBeforeParameter =
true;
1998 for(
constFormatToken *Tok = &Current;
1999Tok && Tok != Current.MatchingParen; Tok = Tok->Next) {
2000 if(Tok->MustBreakBefore ||
2001(Tok->CanBreakBefore && Tok->NewlinesBefore > 0)) {
2002BreakBeforeParameter =
true;
2010BreakBeforeParameter =
true;
2016Current.Children.empty() &&
2017!Current.isOneOf(TT_DictLiteral, TT_ArrayInitializerLSquare) &&
2018(CurrentState.NoLineBreak || CurrentState.NoLineBreakInOperand ||
2019(Current.is(TT_TemplateOpener) &&
2020CurrentState.ContainsUnwrappedBuilder));
2021State.Stack.push_back(
2022ParenState(&Current, NewIndent, LastSpace, AvoidBinPacking, NoLineBreak));
2023 auto&NewState = State.Stack.back();
2024NewState.NestedBlockIndent = NestedBlockIndent;
2025NewState.BreakBeforeParameter = BreakBeforeParameter;
2026NewState.HasMultipleNestedBlocks = (Current.BlockParameterCount > 1);
2029Current.is(tok::l_paren)) {
2031FormatToken
const*next = Current.Next;
2033 if(next->is(TT_LambdaLSquare)) {
2034NewState.HasMultipleNestedBlocks =
true;
2041NewState.IsInsideObjCArrayLiteral = Current.is(TT_ArrayInitializerLSquare) &&
2043Current.Previous->is(tok::at);
2046voidContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
2047 constFormatToken &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) ||
2056State.NextToken->is(TT_TemplateCloser) ||
2057State.NextToken->is(TT_TableGenListCloser) ||
2058(Current.is(tok::greater) && Current.is(TT_DictLiteral)))) {
2059State.Stack.pop_back();
2062 auto&CurrentState = State.Stack.back();
2074 if(CurrentState.BreakBeforeParameter && Current.MatchingParen &&
2075Current.MatchingParen->Previous) {
2076 constFormatToken &CurrentScopeOpener = *Current.MatchingParen->Previous;
2077 if(CurrentScopeOpener.is(TT_ObjCMethodExpr) &&
2078CurrentScopeOpener.MatchingParen) {
2079 intNecessarySpaceInLine =
2081CurrentScopeOpener.TotalLength - Current.TotalLength - 1;
2082 if(State.Column + Current.ColumnWidth + NecessarySpaceInLine <=
2084CurrentState.BreakBeforeParameter =
false;
2089 if(Current.is(tok::r_square)) {
2091 constFormatToken *NextNonComment = Current.getNextNonComment();
2092 if(NextNonComment && NextNonComment->isNot(tok::l_square))
2093CurrentState.StartOfArraySubscripts = 0;
2097voidContinuationIndenter::moveStateToNewBlock(LineState &State,
bool NewLine) {
2099State.NextToken->is(TT_LambdaLBrace) &&
2100!State.Line->MightBeFunctionDecl) {
2101State.Stack.back().NestedBlockIndent = State.FirstIndent;
2103 unsignedNestedBlockIndent = State.Stack.back().NestedBlockIndent;
2105 unsignedNewIndent =
2106NestedBlockIndent + (State.NextToken->is(TT_ObjCBlockLBrace)
2116State.NextToken->is(TT_LambdaLBrace);
2118State.Stack.push_back(ParenState(State.NextToken, NewIndent,
2119State.Stack.back().LastSpace,
2120 true, NoLineBreak));
2121State.Stack.back().NestedBlockIndent = NestedBlockIndent;
2122State.Stack.back().BreakBeforeParameter =
true;
2128 size_tLastNewlinePos =
Text.find_last_of(
"\n");
2129 if(LastNewlinePos == StringRef::npos) {
2130 returnStartColumn +
21340, TabWidth, Encoding);
2138unsignedContinuationIndenter::reformatRawStringLiteral(
2139 constFormatToken &Current, LineState &State,
2140 constFormatStyle &RawStringStyle,
boolDryRun,
boolNewline) {
2141 unsignedStartColumn = State.Column - Current.ColumnWidth;
2143StringRef NewDelimiter =
2145 if(NewDelimiter.empty())
2146NewDelimiter = OldDelimiter;
2149 unsignedOldPrefixSize = 3 + OldDelimiter.size();
2150 unsignedOldSuffixSize = 2 + OldDelimiter.size();
2153std::string RawText = std::string(
2154Current.TokenText.substr(OldPrefixSize).drop_back(OldSuffixSize));
2155 if(NewDelimiter != OldDelimiter) {
2158std::string CanonicalDelimiterSuffix = (
")"+ NewDelimiter +
"\"").str();
2159 if(StringRef(RawText).contains(CanonicalDelimiterSuffix))
2160NewDelimiter = OldDelimiter;
2163 unsignedNewPrefixSize = 3 + NewDelimiter.size();
2164 unsignedNewSuffixSize = 2 + NewDelimiter.size();
2167 unsignedFirstStartColumn = StartColumn + NewPrefixSize;
2178 boolContentStartsOnNewline = Current.TokenText[OldPrefixSize] ==
'\n';
2200 unsignedCurrentIndent =
2201(!Newline && Current.Next && Current.Next->is(tok::r_paren))
2202? State.Stack.back().NestedBlockIndent
2203: State.Stack.back().Indent;
2204 unsignedNextStartColumn = ContentStartsOnNewline
2216 unsignedLastStartColumn =
2217Current.NewlinesBefore ? FirstStartColumn - NewPrefixSize : CurrentIndent;
2220RawStringStyle, RawText, {tooling::Range(0, RawText.size())},
2221FirstStartColumn, NextStartColumn, LastStartColumn,
"<stdin>",
2225tooling::Replacements NoFixes;
2227 returnaddMultilineToken(Current, State);
2229 if(NewDelimiter != OldDelimiter) {
2232SourceLocation PrefixDelimiterStart =
2233Current.Tok.getLocation().getLocWithOffset(2);
2234 autoPrefixErr = Whitespaces.
addReplacement(tooling::Replacement(
2235SourceMgr, PrefixDelimiterStart, OldDelimiter.size(), NewDelimiter));
2238<<
"Failed to update the prefix delimiter of a raw string: " 2239<< llvm::toString(std::move(PrefixErr)) <<
"\n";
2243SourceLocation SuffixDelimiterStart =
2244Current.Tok.getLocation().getLocWithOffset(Current.TokenText.size() -
22451 - OldDelimiter.size());
2246 autoSuffixErr = Whitespaces.
addReplacement(tooling::Replacement(
2247SourceMgr, SuffixDelimiterStart, OldDelimiter.size(), NewDelimiter));
2250<<
"Failed to update the suffix delimiter of a raw string: " 2251<< llvm::toString(std::move(SuffixErr)) <<
"\n";
2254SourceLocation OriginLoc =
2255Current.Tok.getLocation().getLocWithOffset(OldPrefixSize);
2256 for(
consttooling::Replacement &Fix : Fixes.first) {
2258SourceMgr, OriginLoc.getLocWithOffset(Fix.getOffset()),
2259Fix.getLength(), Fix.getReplacementText()));
2261llvm::errs() <<
"Failed to reformat raw string: " 2262<< llvm::toString(std::move(Err)) <<
"\n";
2267*NewCode, FirstStartColumn, Style.
TabWidth, Encoding);
2268State.Column = RawLastLineEndColumn + NewSuffixSize;
2272 unsignedPrefixExcessCharacters =
2274? StartColumn + NewPrefixSize - Style.
ColumnLimit 2277ContentStartsOnNewline || (NewCode->find(
'\n') != std::string::npos);
2280 for(ParenState &
Paren: State.Stack)
2281 Paren.BreakBeforeParameter =
true;
2286unsignedContinuationIndenter::addMultilineToken(
constFormatToken &Current,
2289 for(ParenState &
Paren: State.Stack)
2290 Paren.BreakBeforeParameter =
true;
2292 unsignedColumnsUsed = State.Column;
2295State.Column = Current.LastLineColumnWidth;
2302unsignedContinuationIndenter::handleEndOfLine(
constFormatToken &Current,
2303LineState &State,
boolDryRun,
2304 boolAllowBreak,
boolNewline) {
2305 unsignedPenalty = 0;
2308 autoRawStringStyle = getRawStringStyle(Current, State);
2309 if(RawStringStyle && !Current.Finalized) {
2310Penalty = reformatRawStringLiteral(Current, State, *RawStringStyle, DryRun,
2312}
else if(Current.IsMultiline && Current.isNot(TT_BlockComment)) {
2315Penalty = addMultilineToken(Current, State);
2318LineState OriginalState = State;
2322 boolStrict =
false;
2325 boolExceeded =
false;
2326std::tie(Penalty, Exceeded) = breakProtrudingToken(
2327Current, State, AllowBreak,
true, Strict);
2331LineState StrictState = OriginalState;
2332 unsignedStrictPenalty =
2333breakProtrudingToken(Current, StrictState, AllowBreak,
2336Strict = StrictPenalty <= Penalty;
2338Penalty = StrictPenalty;
2339State = StrictState;
2345breakProtrudingToken(Current, OriginalState, AllowBreak,
false,
2350 unsignedExcessCharacters = 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))
2376std::optional<FormatStyle>
2377ContinuationIndenter::getRawStringStyle(
constFormatToken &Current,
2378 constLineState &State) {
2379 if(!Current.isStringLiteral())
2380 returnstd::nullopt;
2383 returnstd::nullopt;
2385 if(!RawStringStyle && Delimiter->empty()) {
2389 if(!RawStringStyle)
2390 returnstd::nullopt;
2392 returnRawStringStyle;
2395std::unique_ptr<BreakableToken>
2396ContinuationIndenter::createBreakableToken(
constFormatToken &Current,
2397LineState &State,
boolAllowBreak) {
2398 unsignedStartColumn = State.Column - Current.ColumnWidth;
2399 if(Current.isStringLiteral()) {
2416 if(Current.IsUnterminatedLiteral)
2420 if(State.Stack.back().IsInsideObjCArrayLiteral)
2427 if(Style.
isVerilog() && Current.Previous &&
2428Current.Previous->isOneOf(tok::kw_export, Keywords.
kw_import)) {
2431StringRef
Text= Current.TokenText;
2437 unsignedUnbreakableTailLength = (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 returnstd::make_unique<BreakableStringLiteralUsingOperators>(
2456Current, QuoteStyle,
2458UnbreakableTailLength, 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 returnstd::make_unique<BreakableStringLiteral>(
2476Current, StartColumn, Prefix, Postfix, UnbreakableTailLength,
2477State.Line->InPPDirective, Encoding, Style);
2479}
else if(Current.is(TT_BlockComment)) {
2487 returnstd::make_unique<BreakableBlockComment>(
2488Current, StartColumn, Current.OriginalColumn, !Current.Previous,
2489State.Line->InPPDirective, Encoding, Style, Whitespaces.
useCRLF());
2490}
else if(Current.is(TT_LineComment) &&
2491(!Current.Previous ||
2492Current.Previous->isNot(TT_ImplicitStringLiteral))) {
2493 boolRegularComments = [&]() {
2494 for(
constFormatToken *
T= &Current;
T&&
T->is(TT_LineComment);
2496 if(!(
T->TokenText.starts_with(
"//") ||
T->TokenText.starts_with(
"#")))
2502CommentPragmasRegex.match(Current.TokenText.substr(2)) ||
2506 returnstd::make_unique<BreakableLineCommentSection>(
2507Current, StartColumn,
false, Encoding, Style);
2512std::pair<unsigned, bool>
2513ContinuationIndenter::breakProtrudingToken(
constFormatToken &Current,
2514LineState &State,
boolAllowBreak,
2515 boolDryRun,
boolStrict) {
2516std::unique_ptr<const BreakableToken> Token =
2517createBreakableToken(Current, State, AllowBreak);
2520assert(Token->getLineCount() > 0);
2522 if(Current.is(TT_LineComment)) {
2526 if(ColumnLimit == 0) {
2529ColumnLimit = std::numeric_limits<
decltype(ColumnLimit)>
::max();
2531 if(Current.UnbreakableTailLength >= ColumnLimit)
2535 unsignedStartColumn = State.Column - Current.ColumnWidth;
2536 unsignedNewBreakPenalty = Current.isStringLiteral()
2541 boolExceeded =
false;
2543 boolBreakInserted = Token->introducesBreakBeforeToken();
2546 boolNewBreakBefore =
false;
2550 boolReflow =
false;
2553 unsignedTailOffset = 0;
2555 unsignedContentStartColumn =
2556Token->getContentStartColumn(0,
false);
2558 unsignedRemainingTokenColumns =
2559Token->getRemainingLength(0, TailOffset, ContentStartColumn);
2562Token->adaptStartOfLine(0, Whitespaces);
2564 unsignedContentIndent = 0;
2565 unsignedPenalty = 0;
2566LLVM_DEBUG(llvm::dbgs() <<
"Breaking protruding token at column " 2567<< StartColumn <<
".\n");
2568 for(
unsignedLineIndex = 0, EndIndex = Token->getLineCount();
2569LineIndex != EndIndex; ++LineIndex) {
2570LLVM_DEBUG(llvm::dbgs()
2571<<
" Line: "<< LineIndex <<
" (Reflow: "<< Reflow <<
")\n");
2572NewBreakBefore =
false;
2576 boolTryReflow = Reflow;
2578 while(ContentStartColumn + RemainingTokenColumns > ColumnLimit) {
2579LLVM_DEBUG(llvm::dbgs() <<
" Over limit, need: " 2580<< (ContentStartColumn + RemainingTokenColumns)
2581<<
", space: "<< ColumnLimit
2582<<
", reflown prefix: "<< ContentStartColumn
2583<<
", offset in line: "<< TailOffset <<
"\n");
2589Token->getSplit(LineIndex, TailOffset, ColumnLimit,
2590ContentStartColumn, CommentPragmasRegex);
2591 if(
Split.first == StringRef::npos) {
2594 if(LineIndex < EndIndex - 1) {
2598(ContentStartColumn + RemainingTokenColumns - ColumnLimit);
2600LLVM_DEBUG(llvm::dbgs() <<
" No break opportunity.\n");
2603assert(
Split.first != 0);
2605 if(Token->supportsReflow()) {
2625 unsignedToSplitColumns = Token->getRangeLength(
2626LineIndex, TailOffset,
Split.first, ContentStartColumn);
2627LLVM_DEBUG(llvm::dbgs() <<
" ToSplit: "<< ToSplitColumns <<
"\n");
2630LineIndex, TailOffset +
Split.first +
Split.second, ColumnLimit,
2631ContentStartColumn + ToSplitColumns + 1, CommentPragmasRegex);
2634 unsignedToNextSplitColumns = 0;
2635 if(NextSplit.first == StringRef::npos) {
2636ToNextSplitColumns = Token->getRemainingLength(LineIndex, TailOffset,
2637ContentStartColumn);
2639ToNextSplitColumns = Token->getRangeLength(
2640LineIndex, TailOffset,
2641 Split.first +
Split.second + NextSplit.first, ContentStartColumn);
2645ToNextSplitColumns =
2646Token->getLengthAfterCompression(ToNextSplitColumns, Split);
2647LLVM_DEBUG(llvm::dbgs()
2648<<
" ContentStartColumn: "<< ContentStartColumn <<
"\n");
2649LLVM_DEBUG(llvm::dbgs()
2650<<
" ToNextSplit: "<< ToNextSplitColumns <<
"\n");
2653 boolContinueOnLine =
2654ContentStartColumn + ToNextSplitColumns <= ColumnLimit;
2655 unsignedExcessCharactersPenalty = 0;
2656 if(!ContinueOnLine && !Strict) {
2659ExcessCharactersPenalty =
2660(ContentStartColumn + ToNextSplitColumns - ColumnLimit) *
2662LLVM_DEBUG(llvm::dbgs()
2663<<
" Penalty excess: "<< ExcessCharactersPenalty
2664<<
"\n break : "<< NewBreakPenalty <<
"\n");
2665 if(ExcessCharactersPenalty < NewBreakPenalty) {
2667ContinueOnLine =
true;
2670 if(ContinueOnLine) {
2671LLVM_DEBUG(llvm::dbgs() <<
" Continuing on line...\n");
2676Token->compressWhitespace(LineIndex, TailOffset, Split,
2680ContentStartColumn += ToSplitColumns + 1;
2681Penalty += ExcessCharactersPenalty;
2683RemainingTokenColumns = Token->getRemainingLength(
2684LineIndex, TailOffset, ContentStartColumn);
2688LLVM_DEBUG(llvm::dbgs() <<
" Breaking...\n");
2693ContentIndent = Token->getContentIndent(LineIndex);
2694LLVM_DEBUG(llvm::dbgs()
2695<<
" ContentIndent: "<< ContentIndent <<
"\n");
2696ContentStartColumn = ContentIndent + Token->getContentStartColumn(
2699 unsignedNewRemainingTokenColumns = Token->getRemainingLength(
2700LineIndex, TailOffset +
Split.first +
Split.second,
2701ContentStartColumn);
2702 if(NewRemainingTokenColumns == 0) {
2705ContentStartColumn =
2706Token->getContentStartColumn(LineIndex,
true);
2707NewRemainingTokenColumns = Token->getRemainingLength(
2708LineIndex, TailOffset +
Split.first +
Split.second,
2709ContentStartColumn);
2715 if(NewRemainingTokenColumns >= RemainingTokenColumns) {
2720LLVM_DEBUG(llvm::dbgs() <<
" Breaking at: "<< TailOffset +
Split.first
2721<<
", "<<
Split.second <<
"\n");
2723Token->insertBreak(LineIndex, TailOffset, Split, ContentIndent,
2727Penalty += NewBreakPenalty;
2729RemainingTokenColumns = NewRemainingTokenColumns;
2730BreakInserted =
true;
2731NewBreakBefore =
true;
2735 if(LineIndex + 1 != EndIndex) {
2736 unsignedNextLineIndex = LineIndex + 1;
2737 if(NewBreakBefore) {
2756ContentStartColumn += RemainingTokenColumns + 1;
2761Token->getReflowSplit(NextLineIndex, CommentPragmasRegex);
2762LLVM_DEBUG(llvm::dbgs()
2763<<
" Size of reflown text: "<< ContentStartColumn
2764<<
"\n Potential reflow split: ");
2765 if(SplitBeforeNext.first != StringRef::npos) {
2766LLVM_DEBUG(llvm::dbgs() << SplitBeforeNext.first <<
", " 2767<< SplitBeforeNext.second <<
"\n");
2768TailOffset = SplitBeforeNext.first + SplitBeforeNext.second;
2771RemainingTokenColumns = Token->getRemainingLength(
2772NextLineIndex, TailOffset, ContentStartColumn);
2774 if(ContentStartColumn + RemainingTokenColumns > ColumnLimit) {
2775LLVM_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");
2786Token->getSplit(NextLineIndex, TailOffset, ColumnLimit,
2787ContentStartColumn, CommentPragmasRegex);
2788 if(
Split.first == StringRef::npos) {
2789LLVM_DEBUG(llvm::dbgs() <<
" Did not find later break\n");
2795 unsignedToSplitColumns = Token->getRangeLength(
2796NextLineIndex, TailOffset,
Split.first, ContentStartColumn);
2797 if(ContentStartColumn + ToSplitColumns > ColumnLimit) {
2798LLVM_DEBUG(llvm::dbgs() <<
" Next split protrudes, need: " 2799<< (ContentStartColumn + ToSplitColumns)
2800<<
", space: "<< ColumnLimit);
2801 unsignedExcessCharactersPenalty =
2802(ContentStartColumn + ToSplitColumns - ColumnLimit) *
2804 if(NewBreakPenalty < ExcessCharactersPenalty)
2810LLVM_DEBUG(llvm::dbgs() <<
"not found.\n");
2818ContentStartColumn =
2819Token->getContentStartColumn(NextLineIndex,
false);
2820RemainingTokenColumns = Token->getRemainingLength(
2821NextLineIndex, TailOffset, ContentStartColumn);
2824Token->adaptStartOfLine(NextLineIndex, Whitespaces);
2839 if(NewBreakBefore) {
2840assert(Penalty >= NewBreakPenalty);
2841Penalty -= NewBreakPenalty;
2844Token->reflow(NextLineIndex, Whitespaces);
2850Token->getSplitAfterLastLine(TailOffset);
2851 if(SplitAfterLastLine.first != StringRef::npos) {
2852LLVM_DEBUG(llvm::dbgs() <<
"Replacing whitespace after last line.\n");
2857(ContentStartColumn + RemainingTokenColumns - ColumnLimit);
2860Token->replaceWhitespaceAfterLastLine(TailOffset, SplitAfterLastLine,
2863ContentStartColumn =
2864Token->getContentStartColumn(Token->getLineCount() - 1,
true);
2865RemainingTokenColumns = Token->getRemainingLength(
2866Token->getLineCount() - 1,
2867TailOffset + SplitAfterLastLine.first + SplitAfterLastLine.second,
2868ContentStartColumn);
2871State.Column = ContentStartColumn + RemainingTokenColumns -
2872Current.UnbreakableTailLength;
2874 if(BreakInserted) {
2876Token->updateAfterBroken(Whitespaces);
2881 if(Current.isNot(TT_LineComment))
2882 for(ParenState &
Paren: State.Stack)
2883 Paren.BreakBeforeParameter =
true;
2885 if(Current.is(TT_BlockComment))
2886State.NoContinuation =
true;
2888State.Stack.back().LastSpace = StartColumn;
2891Token->updateNextToken(State);
2893 return{Penalty, Exceeded};
2898 returnStyle.
ColumnLimit- (State.Line->InPPDirective ? 2 : 0);
2901boolContinuationIndenter::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() &&
2913Current.getNextNonComment()->isStringLiteral()) {
2917State.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