StartOfTokenColumn,
56 boolIsAligned,
boolInPPDirective) {
61Spaces, StartOfTokenColumn, Newlines,
"",
"",
62IsAligned, InPPDirective && !Tok.
IsFirst,
70Changes.push_back(
Change(Tok,
false,
73 false, InPPDirective && !Tok.
IsFirst,
79 returnReplaces.
add(Replacement);
83 size_tLF =
Text.count(
'\n');
84 size_tCR =
Text.count(
'\r') * 2;
85 returnLF == CR ? DefaultToCRLF : CR > LF;
89 const FormatToken&Tok,
unsignedOffset,
unsignedReplaceChars,
90StringRef PreviousPostfix, StringRef CurrentPrefix,
boolInPPDirective,
91 unsignedNewlines,
intSpaces) {
98std::max(0, Spaces), Newlines, PreviousPostfix, CurrentPrefix,
99 true, InPPDirective && !Tok.
IsFirst,
108calculateLineBreakInformation();
109alignConsecutiveMacros();
110alignConsecutiveShortCaseStatements(
true);
111alignConsecutiveShortCaseStatements(
false);
112alignConsecutiveDeclarations();
113alignConsecutiveBitFields();
114alignConsecutiveAssignments();
116alignConsecutiveTableGenBreakingDAGArgColons();
117alignConsecutiveTableGenCondOperatorColons();
118alignConsecutiveTableGenDefinitions();
120alignChainedConditionals();
121alignTrailingComments();
122alignEscapedNewlines();
123alignArrayInitializers();
129voidWhitespaceManager::calculateLineBreakInformation() {
130Changes[0].PreviousEndOfTokenColumn = 0;
131Change *LastOutsideTokenChange = &Changes[0];
132 for(
unsignedI = 1, e = Changes.size(); I != e; ++I) {
133 auto&
C= Changes[I];
134 auto&
P= Changes[I - 1];
135 auto&PrevTokLength =
P.TokenLength;
137 C.OriginalWhitespaceRange.getBegin();
139 P.OriginalWhitespaceRange.getEnd();
140 unsignedOriginalWhitespaceStartOffset =
142 unsignedPreviousOriginalWhitespaceEndOffset =
144assert(PreviousOriginalWhitespaceEndOffset <=
145OriginalWhitespaceStartOffset);
146 const char*
constPreviousOriginalWhitespaceEndData =
148StringRef
Text(PreviousOriginalWhitespaceEndData,
150PreviousOriginalWhitespaceEndData);
172 autoNewlinePos =
Text.find_first_of(
'\n');
173 if(NewlinePos == StringRef::npos) {
174PrevTokLength = OriginalWhitespaceStartOffset -
175PreviousOriginalWhitespaceEndOffset +
176 C.PreviousLinePostfix.size() +
P.CurrentLinePrefix.size();
177 if(!
P.IsInsideToken)
178PrevTokLength = std::min(PrevTokLength,
P.Tok->ColumnWidth);
180PrevTokLength = NewlinePos +
P.CurrentLinePrefix.size();
185 if(
P.IsInsideToken &&
P.NewlinesBefore == 0)
186LastOutsideTokenChange->TokenLength += PrevTokLength +
P.Spaces;
188LastOutsideTokenChange = &
P;
190 C.PreviousEndOfTokenColumn =
P.StartOfTokenColumn + PrevTokLength;
192 P.IsTrailingComment =
193(
C.NewlinesBefore > 0 ||
C.Tok->is(tok::eof) ||
194(
C.IsInsideToken &&
C.Tok->is(tok::comment))) &&
195 P.Tok->is(tok::comment) &&
226OriginalWhitespaceStart != PreviousOriginalWhitespaceEnd;
230Changes.back().TokenLength = 0;
231Changes.back().IsTrailingComment = Changes.back().Tok->is(tok::comment);
233 constWhitespaceManager::Change *LastBlockComment =
nullptr;
234 for(
auto&Change : Changes) {
238 if(Change.IsInsideToken && Change.NewlinesBefore == 0)
239Change.IsTrailingComment =
false;
240Change.StartOfBlockComment =
nullptr;
241Change.IndentationOffset = 0;
242 if(Change.Tok->is(tok::comment)) {
243 if(Change.Tok->is(TT_LineComment) || !Change.IsInsideToken) {
244LastBlockComment = &Change;
245}
else if((Change.StartOfBlockComment = LastBlockComment)) {
246Change.IndentationOffset =
247Change.StartOfTokenColumn -
248Change.StartOfBlockComment->StartOfTokenColumn;
251LastBlockComment =
nullptr;
259SmallVector<bool, 16> ScopeStack;
260 intConditionalsLevel = 0;
261 for(
auto&Change : Changes) {
262 for(
unsignedi = 0, e = Change.Tok->FakeLParens.size(); i != e; ++i) {
263 boolisNestedConditional =
265!(i == 0 && Change.Tok->Previous &&
266Change.Tok->Previous->is(TT_ConditionalExpr) &&
267Change.Tok->Previous->is(tok::colon));
268 if(isNestedConditional)
270ScopeStack.push_back(isNestedConditional);
273Change.ConditionalsLevel = ConditionalsLevel;
275 for(
unsignedi = Change.Tok->FakeRParens; i > 0 && ScopeStack.size(); --i)
276 if(ScopeStack.pop_back_val())
285template<
typenameF>
288 unsigned Column,
boolRightJustify, F &&Matches,
290 boolFoundMatchOnLine =
false;
315 for(
unsignedi = Start; i != End; ++i) {
316 auto&CurrentChange = Changes[i];
317 if(ScopeStack.size() != 0 &&
318CurrentChange.indentAndNestingLevel() <
319Changes[ScopeStack.back()].indentAndNestingLevel()) {
320ScopeStack.pop_back();
325 unsignedPreviousNonComment = i - 1;
326 while(PreviousNonComment > Start &&
327Changes[PreviousNonComment].Tok->is(tok::comment)) {
328--PreviousNonComment;
330 if(i != Start && CurrentChange.indentAndNestingLevel() >
331Changes[PreviousNonComment].indentAndNestingLevel()) {
332ScopeStack.push_back(i);
335 boolInsideNestedScope = ScopeStack.size() != 0;
336 boolContinuedStringLiteral = i > Start &&
337CurrentChange.Tok->is(tok::string_literal) &&
338Changes[i - 1].Tok->is(tok::string_literal);
339 boolSkipMatchCheck = InsideNestedScope || ContinuedStringLiteral;
341 if(CurrentChange.NewlinesBefore > 0 && !SkipMatchCheck) {
343FoundMatchOnLine =
false;
349 if(!FoundMatchOnLine && !SkipMatchCheck && Matches(CurrentChange)) {
350FoundMatchOnLine =
true;
351Shift =
Column- (RightJustify ? CurrentChange.TokenLength : 0) -
352CurrentChange.StartOfTokenColumn;
353CurrentChange.Spaces += Shift;
356 if(CurrentChange.NewlinesBefore == 0) {
357CurrentChange.Spaces =
358std::max(CurrentChange.Spaces,
359 static_cast<int>(CurrentChange.Tok->SpacesRequiredBefore));
368 if(InsideNestedScope && CurrentChange.NewlinesBefore > 0) {
369 unsignedScopeStart = ScopeStack.back();
370 autoShouldShiftBeAdded = [&] {
372 if(Changes[ScopeStart - 1].Tok->is(TT_FunctionDeclarationName))
376 if(Changes[ScopeStart - 1].Tok->is(TT_LambdaLBrace))
380 if(ScopeStart > Start + 1 &&
381Changes[ScopeStart - 2].Tok->is(TT_FunctionDeclarationName)) {
386 if(ScopeStart > Start + 1 &&
387Changes[ScopeStart - 2].Tok->isOneOf(tok::identifier,
388TT_TemplateCloser) &&
389Changes[ScopeStart - 1].Tok->is(tok::l_paren) &&
390Changes[ScopeStart].Tok->isNot(TT_LambdaLSquare)) {
391 if(CurrentChange.Tok->MatchingParen &&
392CurrentChange.Tok->MatchingParen->is(TT_LambdaLBrace)) {
395 if(Changes[ScopeStart].NewlinesBefore > 0)
397 if(CurrentChange.Tok->is(tok::l_brace) &&
401 returnStyle.BinPackArguments;
405 if(CurrentChange.Tok->is(TT_ConditionalExpr))
409 if(CurrentChange.Tok->is(TT_DesignatedInitializerPeriod))
413 if(CurrentChange.Tok->Previous &&
414CurrentChange.Tok->Previous->is(TT_ConditionalExpr)) {
419 if(ScopeStart > Start + 1 &&
420Changes[ScopeStart - 2].Tok->is(tok::identifier) &&
421Changes[ScopeStart - 1].Tok->is(tok::l_brace) &&
422CurrentChange.Tok->is(tok::l_brace) &&
428 if(ScopeStart > Start + 1 &&
429Changes[ScopeStart - 2].Tok->isNot(tok::identifier) &&
430Changes[ScopeStart - 1].Tok->is(tok::l_brace) &&
431CurrentChange.Tok->isNot(tok::r_brace)) {
432 for(
unsignedOuterScopeStart : llvm::reverse(ScopeStack)) {
434 if(OuterScopeStart > Start &&
435Changes[OuterScopeStart - 1].Tok->is(TT_LambdaLBrace)) {
439 if(Changes[ScopeStart].NewlinesBefore > 0)
445 if(Changes[ScopeStart - 1].Tok->is(TT_TemplateOpener))
451 if(ShouldShiftBeAdded())
452CurrentChange.Spaces += Shift;
455 if(ContinuedStringLiteral)
456CurrentChange.Spaces += Shift;
459assert(Shift > 0 || Changes[i].NewlinesBefore > 0 ||
460CurrentChange.Spaces >=
461 static_cast<int>(Changes[i].Tok->SpacesRequiredBefore) ||
462CurrentChange.Tok->is(tok::eof));
464CurrentChange.StartOfTokenColumn += Shift;
465 if(i + 1 != Changes.size())
466Changes[i + 1].PreviousEndOfTokenColumn += Shift;
472CurrentChange.Spaces != 0 &&
473!CurrentChange.Tok->isOneOf(tok::equal, tok::r_paren,
474TT_TemplateCloser)) {
475 const boolReferenceNotRightAligned =
481assert(Changes[
Previous].Tok->isPointerOrReference());
482 if(Changes[
Previous].Tok->isNot(tok::star)) {
483 if(ReferenceNotRightAligned)
488Changes[
Previous+ 1].Spaces -= Shift;
489Changes[
Previous].Spaces += Shift;
490Changes[
Previous].StartOfTokenColumn += Shift;
527template<
typenameF>
532 boolRightJustify =
false) {
541 unsignedWidthLeft = 0;
544 unsignedWidthAnchor = 0;
547 unsignedWidthRight = 0;
550 unsignedStartOfSequence = 0;
551 unsignedEndOfSequence = 0;
555 autoIndentAndNestingLevel = StartAt < Changes.size()
556? Changes[StartAt].indentAndNestingLevel()
557: std::tuple<unsigned, unsigned, unsigned>();
562 unsignedCommasBeforeLastMatch = 0;
563 unsignedCommasBeforeMatch = 0;
566 boolFoundMatchOnLine =
false;
569 boolLineIsComment =
true;
578 autoAlignCurrentSequence = [&] {
579 if(StartOfSequence > 0 && StartOfSequence < EndOfSequence) {
581WidthLeft + WidthAnchor, RightJustify, Matches,
591 unsignedi = StartAt;
592 for(
unsignede = Changes.size(); i != e; ++i) {
593 auto&CurrentChange = Changes[i];
594 if(CurrentChange.indentAndNestingLevel() < IndentAndNestingLevel)
597 if(CurrentChange.NewlinesBefore != 0) {
598CommasBeforeMatch = 0;
602 boolEmptyLineBreak =
603(CurrentChange.NewlinesBefore > 1) && !ACS.AcrossEmptyLines;
608!FoundMatchOnLine && !(LineIsComment && ACS.AcrossComments);
610 if(EmptyLineBreak || NoMatchBreak)
611AlignCurrentSequence();
615 if(i == 0 || CurrentChange.Tok->isNot(tok::string_literal) ||
616Changes[i - 1].Tok->isNot(tok::string_literal)) {
617FoundMatchOnLine =
false;
619LineIsComment =
true;
622 if(CurrentChange.Tok->isNot(tok::comment))
623LineIsComment =
false;
625 if(CurrentChange.Tok->is(tok::comma)) {
627}
else if(CurrentChange.indentAndNestingLevel() > IndentAndNestingLevel) {
630 AlignTokens(Style, Matches, Changes, i, ACS, RightJustify);
635 if(!Matches(CurrentChange))
640 if(FoundMatchOnLine || CommasBeforeMatch != CommasBeforeLastMatch)
641AlignCurrentSequence();
643CommasBeforeLastMatch = CommasBeforeMatch;
644FoundMatchOnLine =
true;
646 if(StartOfSequence == 0)
649 unsignedChangeWidthLeft = CurrentChange.StartOfTokenColumn;
650 unsignedChangeWidthAnchor = 0;
651 unsignedChangeWidthRight = 0;
653 if(ACS.PadOperators)
654ChangeWidthAnchor = CurrentChange.TokenLength;
656ChangeWidthLeft += CurrentChange.TokenLength;
658ChangeWidthRight = CurrentChange.TokenLength;
659 for(
unsignedj = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) {
660ChangeWidthRight += Changes[j].Spaces;
666 if(!Changes[j].IsInsideToken)
667ChangeWidthRight += Changes[j].TokenLength;
671 unsignedNewLeft = std::max(ChangeWidthLeft, WidthLeft);
672 unsignedNewAnchor = std::max(ChangeWidthAnchor, WidthAnchor);
673 unsignedNewRight = std::max(ChangeWidthRight, WidthRight);
675 if(Style.ColumnLimit != 0 &&
676Style.ColumnLimit < NewLeft + NewAnchor + NewRight) {
677AlignCurrentSequence();
679WidthLeft = ChangeWidthLeft;
680WidthAnchor = ChangeWidthAnchor;
681WidthRight = ChangeWidthRight;
684WidthAnchor = NewAnchor;
685WidthRight = NewRight;
690AlignCurrentSequence();
702 unsigned&StartOfSequence,
unsigned&EndOfSequence,
unsigned&MinColumn,
705 if(StartOfSequence > 0 && StartOfSequence < EndOfSequence) {
706 boolFoundMatchOnLine =
false;
709 for(
unsignedI = StartOfSequence; I != EndOfSequence; ++I) {
710 if(Changes[I].NewlinesBefore > 0) {
712FoundMatchOnLine =
false;
718 if(!FoundMatchOnLine && Matches(Changes[I])) {
719FoundMatchOnLine =
true;
720Shift = MinColumn - Changes[I].StartOfTokenColumn;
721Changes[I].Spaces += Shift;
725Changes[I].StartOfTokenColumn += Shift;
726 if(I + 1 != Changes.size())
727Changes[I + 1].PreviousEndOfTokenColumn += Shift;
736voidWhitespaceManager::alignConsecutiveMacros() {
737 if(!Style.AlignConsecutiveMacros.Enabled)
740 autoAlignMacrosMatches = [](
constChange &
C) {
741 constFormatToken *Current =
C.Tok;
742 unsignedSpacesRequiredBefore = 1;
744 if(Current->SpacesRequiredBefore == 0 || !Current->Previous)
747Current = Current->Previous;
751 if(Current->is(tok::r_paren) && Current->MatchingParen) {
752Current = Current->MatchingParen->Previous;
753SpacesRequiredBefore = 0;
756 if(!Current || Current->isNot(tok::identifier))
759 if(!Current->Previous || Current->Previous->isNot(tok::pp_define))
766 returnCurrent->Next->SpacesRequiredBefore == SpacesRequiredBefore;
769 unsignedMinColumn = 0;
772 unsignedStartOfSequence = 0;
773 unsignedEndOfSequence = 0;
776 boolFoundMatchOnLine =
false;
779 boolLineIsComment =
true;
782 for(
unsigned E= Changes.size(); I !=
E; ++I) {
783 if(Changes[I].NewlinesBefore != 0) {
787 boolEmptyLineBreak = (Changes[I].NewlinesBefore > 1) &&
788!Style.AlignConsecutiveMacros.AcrossEmptyLines;
794!(LineIsComment && Style.AlignConsecutiveMacros.AcrossComments);
796 if(EmptyLineBreak || NoMatchBreak) {
798AlignMacrosMatches, Changes);
802FoundMatchOnLine =
false;
803LineIsComment =
true;
806 if(Changes[I].Tok->isNot(tok::comment))
807LineIsComment =
false;
809 if(!AlignMacrosMatches(Changes[I]))
812FoundMatchOnLine =
true;
814 if(StartOfSequence == 0)
817 unsignedChangeMinColumn = Changes[I].StartOfTokenColumn;
818MinColumn = std::max(MinColumn, ChangeMinColumn);
823AlignMacrosMatches, Changes);
826voidWhitespaceManager::alignConsecutiveAssignments() {
827 if(!Style.AlignConsecutiveAssignments.Enabled)
832[&](
constChange &
C) {
834 if(
C.NewlinesBefore > 0)
838 if(&
C!= &Changes.back() && (&
C+ 1)->NewlinesBefore > 0)
842FormatToken *
Previous=
C.Tok->getPreviousNonComment();
846 returnStyle.AlignConsecutiveAssignments.AlignCompound
848: (
C.Tok->is(tok::equal) ||
852(Style.isVerilog() &&
C.Tok->is(tok::lessequal) &&
855Changes,
0, Style.AlignConsecutiveAssignments,
859voidWhitespaceManager::alignConsecutiveBitFields() {
860alignConsecutiveColons(Style.AlignConsecutiveBitFields, TT_BitFieldColon);
863voidWhitespaceManager::alignConsecutiveColons(
864 constFormatStyle::AlignConsecutiveStyle &AlignStyle,
TokenTypeType) {
865 if(!AlignStyle.Enabled)
870[&](Change
const&
C) {
872 if(
C.NewlinesBefore > 0)
876 if(&
C!= &Changes.back() && (&
C+ 1)->NewlinesBefore > 0)
879 return C.Tok->is(Type);
881Changes,
0, AlignStyle);
884voidWhitespaceManager::alignConsecutiveShortCaseStatements(
boolIsExpr) {
885 if(!Style.AlignConsecutiveShortCaseStatements.Enabled ||
886!(IsExpr ? Style.AllowShortCaseExpressionOnASingleLine
887: Style.AllowShortCaseLabelsOnASingleLine)) {
891 const auto Type= IsExpr ? TT_CaseLabelArrow : TT_CaseLabelColon;
892 const auto&Option = Style.AlignConsecutiveShortCaseStatements;
893 const boolAlignArrowOrColon =
894IsExpr ? Option.AlignCaseArrows : Option.AlignCaseColons;
896 autoMatches = [&](
constChange &
C) {
897 if(AlignArrowOrColon)
898 return C.Tok->is(Type);
904 return!
C.IsInsideToken &&
C.Tok->Previous &&
C.Tok->Previous->is(Type);
907 unsignedMinColumn = 0;
912 unsignedMinEmptyCaseColumn = 0;
915 unsignedStartOfSequence = 0;
916 unsignedEndOfSequence = 0;
919 boolFoundMatchOnLine =
false;
921 boolLineIsComment =
true;
922 boolLineIsEmptyCase =
false;
925 for(
unsigned E= Changes.size(); I !=
E; ++I) {
926 if(Changes[I].NewlinesBefore != 0) {
928 boolEmptyLineBreak =
929(Changes[I].NewlinesBefore > 1) &&
930!Style.AlignConsecutiveShortCaseStatements.AcrossEmptyLines;
937Style.AlignConsecutiveShortCaseStatements.AcrossComments) &&
940 if(EmptyLineBreak || NoMatchBreak) {
943MinEmptyCaseColumn = 0;
947FoundMatchOnLine =
false;
948LineIsComment =
true;
949LineIsEmptyCase =
false;
952 if(Changes[I].Tok->isNot(tok::comment))
953LineIsComment =
false;
955 if(Changes[I].Tok->is(Type)) {
957!Changes[I].Tok->Next || Changes[I].Tok->Next->isTrailingComment();
959 if(LineIsEmptyCase) {
960 if(Style.AlignConsecutiveShortCaseStatements.AlignCaseColons) {
962std::max(MinEmptyCaseColumn, Changes[I].StartOfTokenColumn);
965std::max(MinEmptyCaseColumn, Changes[I].StartOfTokenColumn + 2);
970 if(!Matches(Changes[I]))
976FoundMatchOnLine =
true;
978 if(StartOfSequence == 0)
981EndOfSequence = I + 1;
983MinColumn = std::max(MinColumn, Changes[I].StartOfTokenColumn);
986MinColumn = std::max(MinColumn, MinEmptyCaseColumn);
993voidWhitespaceManager::alignConsecutiveTableGenBreakingDAGArgColons() {
994alignConsecutiveColons(Style.AlignConsecutiveTableGenBreakingDAGArgColons,
995TT_TableGenDAGArgListColonToAlign);
998voidWhitespaceManager::alignConsecutiveTableGenCondOperatorColons() {
999alignConsecutiveColons(Style.AlignConsecutiveTableGenCondOperatorColons,
1000TT_TableGenCondOperatorColon);
1003voidWhitespaceManager::alignConsecutiveTableGenDefinitions() {
1004alignConsecutiveColons(Style.AlignConsecutiveTableGenDefinitionColons,
1005TT_InheritanceColon);
1008voidWhitespaceManager::alignConsecutiveDeclarations() {
1009 if(!Style.AlignConsecutiveDeclarations.Enabled)
1014[&](Change
const&
C) {
1015 if(Style.AlignConsecutiveDeclarations.AlignFunctionPointers) {
1016for (const auto *Prev = C.Tok->Previous; Prev; Prev = Prev->Previous)
1017if (Prev->is(tok::equal))
1019if (C.Tok->is(TT_FunctionTypeLParen))
1022 if(
C.Tok->is(TT_FunctionDeclarationName))
1023 returnStyle.AlignConsecutiveDeclarations.AlignFunctionDeclarations;
1024 if(
C.Tok->isNot(TT_StartOfName))
1026 if(
C.Tok->Previous &&
1027 C.Tok->Previous->is(TT_StatementAttributeLikeMacro))
1030 for(FormatToken *Next =
C.Tok->Next; Next; Next = Next->Next) {
1031if (Next->is(tok::comment))
1033if (Next->is(TT_PointerOrReference))
1035if (!Next->Tok.getIdentifierInfo())
1037if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
1038tok::kw_operator)) {
1044Changes,
0, Style.AlignConsecutiveDeclarations);
1047voidWhitespaceManager::alignChainedConditionals() {
1048 if(Style.BreakBeforeTernaryOperators) {
1051[](Change
const&
C) {
1053 return C.Tok->is(TT_ConditionalExpr) &&
1054((
C.Tok->is(tok::question) && !
C.NewlinesBefore) ||
1055(
C.Tok->is(tok::colon) &&
C.Tok->Next &&
1056(
C.Tok->Next->FakeLParens.size() == 0 ||
1061 static autoAlignWrappedOperand = [](Change
const&
C) {
1062FormatToken *
Previous=
C.Tok->getPreviousNonComment();
1065(
C.Tok->FakeLParens.size() == 0 ||
1071 for(Change &
C: Changes)
1072 if(AlignWrappedOperand(
C))
1073 C.StartOfTokenColumn -= 2;
1076[
this](Change
const&
C) {
1080 return(
C.Tok->is(TT_ConditionalExpr) &&
C.Tok->is(tok::question) &&
1081&
C!= &Changes.back() && (&
C+ 1)->NewlinesBefore == 0 &&
1082!(&
C+ 1)->IsTrailingComment) ||
1083AlignWrappedOperand(
C);
1089voidWhitespaceManager::alignTrailingComments() {
1093 const int Size= Changes.size();
1095 intStartOfSequence = 0;
1096 boolBreakBeforeNext =
false;
1097 intNewLineThreshold = 1;
1099NewLineThreshold = Style.AlignTrailingComments.OverEmptyLines + 1;
1101 for(
intI = 0, MaxColumn =
INT_MAX, Newlines = 0; I <
Size; ++I) {
1102 auto&
C= Changes[I];
1103 if(
C.StartOfBlockComment)
1105Newlines +=
C.NewlinesBefore;
1106 if(!
C.IsTrailingComment)
1110 const intOriginalSpaces =
1111 C.OriginalWhitespaceRange.getEnd().getRawEncoding() -
1112 C.OriginalWhitespaceRange.getBegin().getRawEncoding() -
1113 C.Tok->LastNewlineOffset;
1114assert(OriginalSpaces >= 0);
1115 const autoRestoredLineLength =
1116 C.StartOfTokenColumn +
C.TokenLength + OriginalSpaces;
1119 if(RestoredLineLength >= Style.ColumnLimit && Style.ColumnLimit > 0)
1121 C.Spaces =
C.NewlinesBefore > 0 ?
C.Tok->OriginalColumn : OriginalSpaces;
1125 const intChangeMinColumn =
C.StartOfTokenColumn;
1126 intChangeMaxColumn;
1130 if(!
C.CreateReplacement)
1131ChangeMaxColumn = ChangeMinColumn;
1132 else if(Style.ColumnLimit == 0)
1134 else if(Style.ColumnLimit >=
C.TokenLength)
1135ChangeMaxColumn = Style.ColumnLimit -
C.TokenLength;
1137ChangeMaxColumn = ChangeMinColumn;
1139 if(I + 1 < Size && Changes[I + 1].ContinuesPPDirective &&
1140ChangeMaxColumn >= 2) {
1141ChangeMaxColumn -= 2;
1144 boolWasAlignedWithStartOfNextLine =
false;
1145 if(
C.NewlinesBefore >= 1) {
1146 const autoCommentColumn =
1148 for(
intJ = I + 1; J <
Size; ++J) {
1149 if(Changes[J].Tok->is(tok::comment))
1153Changes[J].OriginalWhitespaceRange.getEnd());
1156WasAlignedWithStartOfNextLine =
1157CommentColumn == NextColumn ||
1158CommentColumn == NextColumn + Style.IndentWidth;
1165 autoDontAlignThisComment = [](
const auto*Tok) {
1166 if(Tok->is(tok::semi)) {
1167Tok = Tok->getPreviousNonComment();
1171 if(Tok->is(tok::r_paren)) {
1173Tok = Tok->MatchingParen;
1176Tok = Tok->getPreviousNonComment();
1179 if(Tok->is(TT_DoWhile)) {
1180 const auto*Prev = Tok->getPreviousNonComment();
1189 if(Tok->isNot(tok::r_brace))
1192 while(Tok->Previous && Tok->Previous->is(tok::r_brace))
1193Tok = Tok->Previous;
1194 returnTok->NewlinesBefore > 0;
1197 if(I > 0 &&
C.NewlinesBefore == 0 &&
1198DontAlignThisComment(Changes[I - 1].Tok)) {
1199alignTrailingComments(StartOfSequence, I, MinColumn);
1204StartOfSequence = I + 1;
1205}
else if(BreakBeforeNext || Newlines > NewLineThreshold ||
1206(ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) ||
1209(
C.NewlinesBefore == 1 && I > 0 &&
1210!Changes[I - 1].IsTrailingComment) ||
1211WasAlignedWithStartOfNextLine) {
1212alignTrailingComments(StartOfSequence, I, MinColumn);
1213MinColumn = ChangeMinColumn;
1214MaxColumn = ChangeMaxColumn;
1215StartOfSequence = I;
1217MinColumn = std::max(MinColumn, ChangeMinColumn);
1218MaxColumn = std::min(MaxColumn, ChangeMaxColumn);
1220BreakBeforeNext = (I == 0) || (
C.NewlinesBefore > 1) ||
1223(
C.NewlinesBefore == 1 && StartOfSequence == I);
1226alignTrailingComments(StartOfSequence, Size, MinColumn);
1229voidWhitespaceManager::alignTrailingComments(
unsignedStart,
unsignedEnd,
1231 for(
unsignedi = Start; i != End; ++i) {
1233 if(Changes[i].IsTrailingComment)
1235 if(Changes[i].StartOfBlockComment) {
1236 Shift= Changes[i].IndentationOffset +
1237Changes[i].StartOfBlockComment->StartOfTokenColumn -
1238Changes[i].StartOfTokenColumn;
1242Changes[i].Spaces +=
Shift;
1243 if(i + 1 != Changes.size())
1244Changes[i + 1].PreviousEndOfTokenColumn +=
Shift;
1245Changes[i].StartOfTokenColumn +=
Shift;
1249voidWhitespaceManager::alignEscapedNewlines() {
1250 const autoAlign = Style.AlignEscapedNewlines;
1256 const autoMaxColumn = Style.ColumnLimit;
1257 unsignedMaxEndOfLine = AlignLeft ? 0 : MaxColumn;
1258 unsignedStartOfMacro = 0;
1259 for(
unsignedi = 1, e = Changes.size(); i < e; ++i) {
1260Change &
C= Changes[i];
1261 if(
C.NewlinesBefore == 0 && (!WithLastLine ||
C.Tok->isNot(tok::eof)))
1263 const boolInPPDirective =
C.ContinuesPPDirective;
1264 const autoBackslashColumn =
C.PreviousEndOfTokenColumn + 2;
1265 if(InPPDirective ||
1266(WithLastLine && (MaxColumn == 0 || BackslashColumn <= MaxColumn))) {
1267MaxEndOfLine = std::max(BackslashColumn, MaxEndOfLine);
1269 if(!InPPDirective) {
1270alignEscapedNewlines(StartOfMacro + 1, i, MaxEndOfLine);
1271MaxEndOfLine = AlignLeft ? 0 : MaxColumn;
1275alignEscapedNewlines(StartOfMacro + 1, Changes.size(), MaxEndOfLine);
1278voidWhitespaceManager::alignEscapedNewlines(
unsignedStart,
unsignedEnd,
1280 for(
unsignedi = Start; i < End; ++i) {
1281Change &
C= Changes[i];
1282 if(
C.NewlinesBefore > 0) {
1283assert(
C.ContinuesPPDirective);
1284 if(
C.PreviousEndOfTokenColumn + 1 >
Column)
1285 C.EscapedNewlineColumn = 0;
1287 C.EscapedNewlineColumn =
Column;
1292voidWhitespaceManager::alignArrayInitializers() {
1296 for(
unsignedChangeIndex = 1U, ChangeEnd = Changes.size();
1297ChangeIndex < ChangeEnd; ++ChangeIndex) {
1298 auto&
C= Changes[ChangeIndex];
1299 if(
C.Tok->IsArrayInitializer) {
1300 boolFoundComplete =
false;
1301 for(
unsignedInsideIndex = ChangeIndex + 1; InsideIndex < ChangeEnd;
1303 if(Changes[InsideIndex].Tok ==
C.Tok->MatchingParen) {
1304alignArrayInitializers(ChangeIndex, InsideIndex + 1);
1305ChangeIndex = InsideIndex + 1;
1306FoundComplete =
true;
1311ChangeIndex = ChangeEnd;
1316voidWhitespaceManager::alignArrayInitializers(
unsignedStart,
unsignedEnd) {
1319alignArrayInitializersRightJustified(getCells(Start, End));
1321alignArrayInitializersLeftJustified(getCells(Start, End));
1324voidWhitespaceManager::alignArrayInitializersRightJustified(
1325CellDescriptions &&CellDescs) {
1326 if(!CellDescs.isRectangular())
1329 const intBracePadding = Style.Cpp11BracedListStyle ? 0 : 1;
1330 auto&Cells = CellDescs.Cells;
1332 auto*CellIter = Cells.begin();
1333 for(
autoi = 0
U; i < CellDescs.CellCounts[0]; ++i, ++CellIter) {
1334 unsignedNetWidth = 0
U;
1335 if(isSplitCell(*CellIter))
1336NetWidth = getNetWidth(Cells.begin(), CellIter, CellDescs.InitialSpaces);
1337 autoCellWidth = getMaximumCellWidth(CellIter, NetWidth);
1339 if(Changes[CellIter->Index].Tok->is(tok::r_brace)) {
1343 const auto*Next = CellIter;
1345 constFormatToken *
Previous= Changes[Next->Index].Tok->Previous;
1347Changes[Next->Index].Spaces = BracePadding;
1348Changes[Next->Index].NewlinesBefore = 0;
1350Next = Next->NextColumnElement;
1354 if(CellIter != Cells.begin()) {
1356getNetWidth(Cells.begin(), CellIter, CellDescs.InitialSpaces);
1357 autoMaxNetWidth = getMaximumNetWidth(
1358Cells.begin(), CellIter, CellDescs.InitialSpaces,
1359CellDescs.CellCounts[0], CellDescs.CellCounts.size());
1360 if(ThisNetWidth < MaxNetWidth)
1361Changes[CellIter->Index].Spaces = (MaxNetWidth - ThisNetWidth);
1363 autoOffset = std::distance(Cells.begin(), CellIter);
1364 for(
const auto*Next = CellIter->NextColumnElement; Next;
1365Next = Next->NextColumnElement) {
1366 if(RowCount >= CellDescs.CellCounts.size())
1368 auto*Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
1369 auto*End = Start + Offset;
1370ThisNetWidth = getNetWidth(Start, End, CellDescs.InitialSpaces);
1371 if(ThisNetWidth < MaxNetWidth)
1372Changes[Next->Index].Spaces = (MaxNetWidth - ThisNetWidth);
1378calculateCellWidth(CellIter->Index, CellIter->EndIndex,
true) +
1380 if(Changes[CellIter->Index].NewlinesBefore == 0) {
1381Changes[CellIter->Index].Spaces = (CellWidth - (ThisWidth + NetWidth));
1382Changes[CellIter->Index].Spaces += (i > 0) ? 1 : BracePadding;
1384alignToStartOfCell(CellIter->Index, CellIter->EndIndex);
1385 for(
const auto*Next = CellIter->NextColumnElement; Next;
1386Next = Next->NextColumnElement) {
1388calculateCellWidth(Next->Index, Next->EndIndex,
true) + NetWidth;
1389 if(Changes[Next->Index].NewlinesBefore == 0) {
1390Changes[Next->Index].Spaces = (CellWidth - ThisWidth);
1391Changes[Next->Index].Spaces += (i > 0) ? 1 : BracePadding;
1393alignToStartOfCell(Next->Index, Next->EndIndex);
1399voidWhitespaceManager::alignArrayInitializersLeftJustified(
1400CellDescriptions &&CellDescs) {
1402 if(!CellDescs.isRectangular())
1405 const intBracePadding = Style.Cpp11BracedListStyle ? 0 : 1;
1406 auto&Cells = CellDescs.Cells;
1408 auto*CellIter = Cells.begin();
1410 for(
const auto*Next = CellIter; Next; Next = Next->NextColumnElement) {
1411 auto&Change = Changes[Next->Index];
1413Change.NewlinesBefore == 0 ? BracePadding : CellDescs.InitialSpaces;
1416 for(
autoi = 1U; i < CellDescs.CellCounts[0]; i++, ++CellIter) {
1417 autoMaxNetWidth = getMaximumNetWidth(
1418Cells.begin(), CellIter, CellDescs.InitialSpaces,
1419CellDescs.CellCounts[0], CellDescs.CellCounts.size());
1421getNetWidth(Cells.begin(), CellIter, CellDescs.InitialSpaces);
1422 if(Changes[CellIter->Index].NewlinesBefore == 0) {
1423Changes[CellIter->Index].Spaces =
1424MaxNetWidth - ThisNetWidth +
1425(Changes[CellIter->Index].Tok->isNot(tok::r_brace) ? 1
1429 autoOffset = std::distance(Cells.begin(), CellIter);
1430 for(
const auto*Next = CellIter->NextColumnElement; Next;
1431Next = Next->NextColumnElement) {
1432 if(RowCount >= CellDescs.CellCounts.size())
1434 auto*Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
1435 auto*End = Start + Offset;
1436 autoThisNetWidth = getNetWidth(Start, End, CellDescs.InitialSpaces);
1437 if(Changes[Next->Index].NewlinesBefore == 0) {
1438Changes[Next->Index].Spaces =
1439MaxNetWidth - ThisNetWidth +
1440(Changes[Next->Index].Tok->isNot(tok::r_brace) ? 1 : BracePadding);
1447boolWhitespaceManager::isSplitCell(
constCellDescription &Cell) {
1450 for(
const auto*Next = Cell.NextColumnElement; Next;
1451Next = Next->NextColumnElement) {
1458WhitespaceManager::CellDescriptions WhitespaceManager::getCells(
unsignedStart,
1463SmallVector<unsigned> CellCounts;
1464 unsignedInitialSpaces = 0;
1465 unsignedInitialTokenLength = 0;
1466 unsignedEndSpaces = 0;
1467SmallVector<CellDescription> Cells;
1468 constFormatToken *MatchingParen =
nullptr;
1469 for(
unsignedi = Start; i < End; ++i) {
1470 auto&
C= Changes[i];
1471 if(
C.Tok->is(tok::l_brace))
1473 else if(
C.Tok->is(tok::r_brace))
1476 if(
C.Tok->is(tok::l_brace)) {
1478MatchingParen =
C.Tok->MatchingParen;
1479 if(InitialSpaces == 0) {
1480InitialSpaces =
C.Spaces +
C.TokenLength;
1481InitialTokenLength =
C.TokenLength;
1483 for(; Changes[j].NewlinesBefore == 0 && j > Start; --j) {
1484InitialSpaces += Changes[j].Spaces + Changes[j].TokenLength;
1485InitialTokenLength += Changes[j].TokenLength;
1487 if(
C.NewlinesBefore == 0) {
1488InitialSpaces += Changes[j].Spaces + Changes[j].TokenLength;
1489InitialTokenLength += Changes[j].TokenLength;
1492}
else if(
C.Tok->is(tok::comma)) {
1494Cells.back().EndIndex = i;
1495 if(
const auto*Next =
C.Tok->getNextNonComment();
1496Next && Next->isNot(tok::r_brace)) {
1500}
else if(Depth == 1) {
1501 if(
C.Tok == MatchingParen) {
1503Cells.back().EndIndex = i;
1504Cells.push_back(CellDescription{i, ++Cell, i + 1,
false,
nullptr});
1505CellCounts.push_back(
C.Tok->Previous->isNot(tok::comma) ? Cell + 1
1508 const auto*NextNonComment =
C.Tok->getNextNonComment();
1509 while(NextNonComment && NextNonComment->is(tok::comma))
1510NextNonComment = NextNonComment->getNextNonComment();
1512 while(j < End && Changes[j].Tok != NextNonComment)
1514 if(j < End && Changes[j].NewlinesBefore == 0 &&
1515Changes[j].Tok->isNot(tok::r_brace)) {
1516Changes[j].NewlinesBefore = 1;
1518Changes[j].Spaces = InitialSpaces - InitialTokenLength;
1520}
else if(
C.Tok->is(tok::comment) &&
C.Tok->NewlinesBefore == 0) {
1522 C.Spaces = Changes[i - 1].Tok->is(tok::comma) ? 1 : 2;
1523}
else if(
C.Tok->is(tok::l_brace)) {
1527 for(; j > 0 && !Changes[j].Tok->ArrayInitializerLineStart; --j)
1529EndSpaces = Changes[j].Spaces;
1531}
else if(Depth == 0 &&
C.Tok->is(tok::r_brace)) {
1532 C.NewlinesBefore = 1;
1533 C.Spaces = EndSpaces;
1535 if(
C.Tok->StartsColumn) {
1538 boolHasSplit =
false;
1539 if(Changes[i].NewlinesBefore > 0) {
1555 if((j - 1) > Start && Changes[j].Tok->is(tok::comma) &&
1556Changes[j - 1].NewlinesBefore > 0) {
1558 autoLineLimit = Changes[j].Spaces + Changes[j].TokenLength;
1559 if(LineLimit < Style.ColumnLimit) {
1560Changes[i].NewlinesBefore = 0;
1561Changes[i].Spaces = 1;
1565 while(Changes[i].NewlinesBefore > 0 && Changes[i].Tok ==
C.Tok) {
1566Changes[i].Spaces = InitialSpaces;
1570 if(Changes[i].Tok !=
C.Tok)
1572Cells.push_back(CellDescription{i, Cell, i, HasSplit,
nullptr});
1576 returnlinkCells({Cells, CellCounts, InitialSpaces});
1579unsignedWhitespaceManager::calculateCellWidth(
unsignedStart,
unsignedEnd,
1580 boolWithSpaces)
const{
1581 unsignedCellWidth = 0;
1582 for(
autoi = Start; i < End; i++) {
1583 if(Changes[i].NewlinesBefore > 0)
1585CellWidth += Changes[i].TokenLength;
1586CellWidth += (WithSpaces ? Changes[i].Spaces : 0);
1591voidWhitespaceManager::alignToStartOfCell(
unsignedStart,
unsignedEnd) {
1592 if((End - Start) <= 1)
1596 for(
autoi = Start + 1; i < End; i++)
1597 if(Changes[i].NewlinesBefore > 0)
1598Changes[i].Spaces = Changes[Start].Spaces;
1601WhitespaceManager::CellDescriptions
1602WhitespaceManager::linkCells(CellDescriptions &&CellDesc) {
1603 auto&Cells = CellDesc.Cells;
1604 for(
auto*CellIter = Cells.begin(); CellIter != Cells.end(); ++CellIter) {
1605 if(!CellIter->NextColumnElement && (CellIter + 1) != Cells.end()) {
1606 for(
auto*NextIter = CellIter + 1; NextIter != Cells.end(); ++NextIter) {
1607 if(NextIter->Cell == CellIter->Cell) {
1608CellIter->NextColumnElement = &(*NextIter);
1614 returnstd::move(CellDesc);
1617voidWhitespaceManager::generateChanges() {
1618 for(
unsignedi = 0, e = Changes.size(); i != e; ++i) {
1619 constChange &
C= Changes[i];
1621 auto Last= Changes[i - 1].OriginalWhitespaceRange;
1622 autoNew = Changes[i].OriginalWhitespaceRange;
1664 if(
Last.getBegin() == New.getBegin() &&
1665(
Last.getEnd() !=
Last.getBegin() ||
1666New.getEnd() == New.getBegin())) {
1670 if(
C.CreateReplacement) {
1671std::string ReplacementText =
C.PreviousLinePostfix;
1672 if(
C.ContinuesPPDirective) {
1673appendEscapedNewlineText(ReplacementText,
C.NewlinesBefore,
1674 C.PreviousEndOfTokenColumn,
1675 C.EscapedNewlineColumn);
1677appendNewlineText(ReplacementText,
C);
1682ReplacementText,
C.Tok->IndentLevel, std::max(0,
C.Spaces),
1683std::max((
int)
C.StartOfTokenColumn,
C.Spaces) - std::max(0,
C.Spaces),
1685ReplacementText.append(
C.CurrentLinePrefix);
1686storeReplacement(
C.OriginalWhitespaceRange, ReplacementText);
1691voidWhitespaceManager::storeReplacement(SourceRange
Range, StringRef
Text) {
1696WhitespaceLength) ==
Text) {
1699 autoErr = Replaces.
add(tooling::Replacement(
1704llvm::errs() << llvm::toString(std::move(Err)) <<
"\n";
1709voidWhitespaceManager::appendNewlineText(std::string &
Text,
constChange &
C) {
1710 if(
C.NewlinesBefore <= 0)
1713StringRef Newline = UseCRLF ?
"\r\n":
"\n";
1714 Text.append(Newline);
1716 if(
C.Tok->HasFormFeedBefore)
1717 Text.append(
"\f");
1719 for(
unsignedI = 1; I <
C.NewlinesBefore; ++I)
1720 Text.append(Newline);
1723voidWhitespaceManager::appendEscapedNewlineText(
1724std::string &
Text,
unsignedNewlines,
unsignedPreviousEndOfTokenColumn,
1725 unsignedEscapedNewlineColumn) {
1728std::max<int>(1, EscapedNewlineColumn - PreviousEndOfTokenColumn - 1);
1729 for(
unsignedi = 0; i < Newlines; ++i) {
1730 Text.append(Spaces,
' ');
1731 Text.append(UseCRLF ?
"\\\r\n":
"\\\n");
1732Spaces = std::max<int>(0, EscapedNewlineColumn - 1);
1737voidWhitespaceManager::appendIndentText(std::string &
Text,
1738 unsignedIndentLevel,
unsignedSpaces,
1739 unsignedWhitespaceStartColumn,
1741 switch(Style.UseTab) {
1743 Text.append(Spaces,
' ');
1746 if(Style.TabWidth) {
1747 unsignedFirstTabWidth =
1748Style.TabWidth - WhitespaceStartColumn % Style.TabWidth;
1751 if(Spaces < FirstTabWidth || Spaces == 1) {
1752 Text.append(Spaces,
' ');
1756Spaces -= FirstTabWidth;
1757 Text.append(
"\t");
1759 Text.append(Spaces / Style.TabWidth,
'\t');
1760 Text.append(Spaces % Style.TabWidth,
' ');
1761}
else if(Spaces == 1) {
1762 Text.append(Spaces,
' ');
1767 if(WhitespaceStartColumn == 0) {
1768 unsignedIndentation = IndentLevel * Style.IndentWidth;
1769Spaces = appendTabIndent(
Text, Spaces, Indentation);
1771 Text.append(Spaces,
' ');
1774 if(WhitespaceStartColumn == 0)
1775Spaces = appendTabIndent(
Text, Spaces, Spaces);
1776 Text.append(Spaces,
' ');
1779 if(WhitespaceStartColumn == 0) {
1780 unsignedIndentation =
1781IsAligned ? IndentLevel * Style.IndentWidth : Spaces;
1782Spaces = appendTabIndent(
Text, Spaces, Indentation);
1784 Text.append(Spaces,
' ');
1789unsignedWhitespaceManager::appendTabIndent(std::string &
Text,
unsignedSpaces,
1790 unsignedIndentation) {
1793 if(Indentation > Spaces)
1794Indentation = Spaces;
1795 if(Style.TabWidth) {
1796 unsignedTabs = Indentation / Style.TabWidth;
1797 Text.append(Tabs,
'\t');
1798Spaces -= Tabs * Style.TabWidth;
WhitespaceManager class manages whitespace around tokens and their replacements.
static CharSourceRange getCharRange(SourceRange R)
Encodes a location in the source.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
unsigned getFileOffset(SourceLocation SpellingLoc) const
Returns the offset from the start of the file that the specified SourceLocation represents.
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer.
unsigned getSpellingColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Functor to sort changes in original source order.
bool operator()(const Change &C1, const Change &C2) const
void replaceWhitespaceInToken(const FormatToken &Tok, unsigned Offset, unsigned ReplaceChars, StringRef PreviousPostfix, StringRef CurrentPrefix, bool InPPDirective, unsigned Newlines, int Spaces)
Inserts or replaces whitespace in the middle of a token.
void addUntouchableToken(const FormatToken &Tok, bool InPPDirective)
Adds information about an unchangeable token's whitespace.
static bool inputUsesCRLF(StringRef Text, bool DefaultToCRLF)
Infers whether the input is using CRLF.
llvm::Error addReplacement(const tooling::Replacement &Replacement)
const tooling::Replacements & generateReplacements()
Returns all the Replacements created during formatting.
void replaceWhitespace(FormatToken &Tok, unsigned Newlines, unsigned Spaces, unsigned StartOfTokenColumn, bool IsAligned=false, bool InPPDirective=false)
Replaces the whitespace in front of Tok.
@ MR_ExpandedArg
The token was expanded from a macro argument when formatting the expanded token sequence.
static void AlignMatchingTokenSequence(unsigned &StartOfSequence, unsigned &EndOfSequence, unsigned &MinColumn, std::function< bool(const WhitespaceManager::Change &C)> Matches, SmallVector< WhitespaceManager::Change, 16 > &Changes)
static unsigned AlignTokens(const FormatStyle &Style, F &&Matches, SmallVector< WhitespaceManager::Change, 16 > &Changes, unsigned StartAt, const FormatStyle::AlignConsecutiveStyle &ACS={}, bool RightJustify=false)
static void AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End, unsigned Column, bool RightJustify, F &&Matches, SmallVector< WhitespaceManager::Change, 16 > &Changes)
TokenType
Determines the semantic type of a syntactic token, e.g.
The JSON file list parser is used to communicate input to InstallAPI.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
for(const auto &A :T->param_types())
The FormatStyle is used to configure the formatting to follow specific guidelines.
@ UT_AlignWithSpaces
Use tabs for line continuation and indentation, and spaces for alignment.
@ UT_ForContinuationAndIndentation
Fill all leading whitespace with tabs, and use spaces for alignment that appears within a line (e....
@ UT_ForIndentation
Use tabs only for indentation.
@ UT_Always
Use tabs whenever we need to fill whitespace that spans at least from one tab stop to the next one.
@ UT_Never
Never use tab.
@ TCAS_Never
Don't align trailing comments but other formatter applies.
@ TCAS_Leave
Leave trailing comments as they are.
@ TCAS_Always
Align trailing comments.
@ AIAS_Left
Align array column and left justify the columns e.g.:
@ AIAS_Right
Align array column and right justify the columns e.g.:
@ AIAS_None
Don't align array initializer columns.
@ ENAS_DontAlign
Don't align escaped newlines.
@ ENAS_Left
Align escaped newlines as far left as possible.
@ ENAS_LeftWithLastLine
Align escaped newlines as far left as possible, using the last line of the preprocessor directive as ...
@ PAS_Right
Align pointer to the right.
@ RAS_Right
Align reference to the right.
@ RAS_Pointer
Align reference like PointerAlignment.
A wrapper around a Token storing information about the whitespace characters preceding it.
unsigned OriginalColumn
The original 0-based column of this token, including expanded tabs.
SourceLocation getStartOfNonWhitespace() const
Returns actual token start location without leading escaped newlines and whitespace.
void setDecision(FormatDecision D)
unsigned Finalized
If true, this token has been fully formatted (indented and potentially re-formatted inside),...
std::optional< MacroExpansion > MacroCtx
unsigned NewlinesBefore
The number of newlines immediately before the Token.
unsigned IsFirst
Indicates that this is the first token of the file.
SourceRange WhitespaceRange
The range of the whitespace immediately preceding the Token.
Represents a change before a token, a break inside a token, or the layout of an unchanged token (or w...
Change(const FormatToken &Tok, bool CreateReplacement, SourceRange OriginalWhitespaceRange, int Spaces, unsigned StartOfTokenColumn, unsigned NewlinesBefore, StringRef PreviousLinePostfix, StringRef CurrentLinePrefix, bool IsAligned, bool ContinuesPPDirective, bool IsInsideToken)
Creates a Change.
const Change * StartOfBlockComment
SourceRange OriginalWhitespaceRange
std::string PreviousLinePostfix
std::string CurrentLinePrefix
unsigned StartOfTokenColumn
unsigned PreviousEndOfTokenColumn
unsigned EscapedNewlineColumn
bool ContinuesPPDirective
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