39 : SourceMgr(SourceMgr), Style(Style), UseCRLF(UseCRLF) {}
58 unsigned StartOfTokenColumn,
60 bool InPPDirective =
false,
61 unsigned IndentedFromColumn = 0,
62 bool CreateReplacement =
true);
87 unsigned ReplaceChars,
88 StringRef PreviousPostfix,
89 StringRef CurrentPrefix,
bool InPPDirective,
185 return std::make_tuple(
Tok->IndentLevel,
Tok->NestingLevel,
191 struct CellDescription {
194 unsigned EndIndex = 0;
195 bool HasSplit =
false;
196 CellDescription *NextColumnElement =
nullptr;
199 return Index ==
Other.Index && Cell ==
Other.Cell &&
200 EndIndex ==
Other.EndIndex;
203 return !(*
this ==
Other);
207 struct CellDescriptions {
208 SmallVector<CellDescription> Cells;
209 SmallVector<unsigned> CellCounts;
210 unsigned InitialSpaces = 0;
214 bool isRectangular()
const {
215 if (CellCounts.size() < 2)
218 for (
auto NumberOfColumns : CellCounts)
219 if (NumberOfColumns != CellCounts[0])
228 void calculateLineBreakInformation();
231 void alignConsecutiveMacros();
234 void alignConsecutiveAssignments();
237 void alignConsecutiveBitFields();
241 alignConsecutiveColons(
const FormatStyle::AlignConsecutiveStyle &AlignStyle,
245 void alignConsecutiveDeclarations();
248 void alignChainedConditionals();
251 void alignConsecutiveShortCaseStatements(
bool IsExpr);
254 void alignConsecutiveTableGenBreakingDAGArgColons();
257 void alignConsecutiveTableGenCondOperatorColons();
260 void alignConsecutiveTableGenDefinitions();
263 void alignTrailingComments();
267 void alignTrailingComments(
unsigned Start,
unsigned End,
unsigned Column);
270 void alignEscapedNewlines();
274 void alignEscapedNewlines(
unsigned Start,
unsigned End,
unsigned Column);
277 void alignArrayInitializers();
281 void alignArrayInitializers(
unsigned Start,
unsigned End);
285 void alignArrayInitializersRightJustified(CellDescriptions &&CellDescs);
289 void alignArrayInitializersLeftJustified(CellDescriptions &&CellDescs);
292 unsigned calculateCellWidth(
unsigned Start,
unsigned End,
293 bool WithSpaces =
false)
const;
297 CellDescriptions getCells(
unsigned Start,
unsigned End);
300 static bool isSplitCell(
const CellDescription &Cell);
303 template <
typename I>
304 auto getNetWidth(
const I &Start,
const I &End,
unsigned InitialSpaces)
const {
305 auto NetWidth = InitialSpaces;
306 for (
auto PrevIter = Start; PrevIter != End; ++PrevIter) {
309 assert(PrevIter->Index < Changes.size());
310 if (Changes[PrevIter->Index].NewlinesBefore > 0)
313 calculateCellWidth(PrevIter->Index, PrevIter->EndIndex,
true) + 1;
319 template <
typename I>
320 unsigned getMaximumCellWidth(I CellIter,
unsigned NetWidth)
const {
322 calculateCellWidth(CellIter->Index, CellIter->EndIndex,
true);
323 if (Changes[CellIter->Index].NewlinesBefore == 0)
324 CellWidth += NetWidth;
325 for (
const auto *
Next = CellIter->NextColumnElement;
Next;
327 auto ThisWidth = calculateCellWidth(
Next->Index,
Next->EndIndex,
true);
328 if (Changes[
Next->Index].NewlinesBefore == 0)
329 ThisWidth += NetWidth;
330 CellWidth = std::max(CellWidth, ThisWidth);
336 template <
typename I>
337 unsigned getMaximumNetWidth(
const I &CellStart,
const I &CellStop,
338 unsigned InitialSpaces,
unsigned CellCount,
339 unsigned MaxRowCount)
const {
340 auto MaxNetWidth = getNetWidth(CellStart, CellStop, InitialSpaces);
342 auto Offset = std::distance(CellStart, CellStop);
343 for (
const auto *
Next = CellStop->NextColumnElement;
Next;
345 if (RowCount >= MaxRowCount)
347 auto Start = (CellStart + RowCount * CellCount);
348 auto End = Start + Offset;
350 std::max(MaxNetWidth, getNetWidth(Start, End, InitialSpaces));
357 void alignToStartOfCell(
unsigned Start,
unsigned End);
360 static CellDescriptions linkCells(CellDescriptions &&CellDesc);
362 void setChangeSpaces(
unsigned Start,
unsigned Spaces);
365 void generateChanges();
368 void storeReplacement(SourceRange Range, StringRef
Text);
369 void appendNewlineText(std::string &
Text,
const Change &
C);
370 void appendEscapedNewlineText(std::string &
Text,
unsigned Newlines,
371 unsigned PreviousEndOfTokenColumn,
372 unsigned EscapedNewlineColumn);
374 unsigned Spaces,
unsigned WhitespaceStartColumn,
376 unsigned appendTabIndent(std::string &
Text,
unsigned Spaces,
377 unsigned Indentation);
379 SmallVector<Change, 16> Changes;
380 const SourceManager &SourceMgr;
381 tooling::Replacements Replaces;
382 const FormatStyle &Style;