15#ifndef LLVM_CLANG_LIB_FORMAT_WHITESPACEMANAGER_H
16#define LLVM_CLANG_LIB_FORMAT_WHITESPACEMANAGER_H
39 : SourceMgr(SourceMgr), Style(Style), UseCRLF(UseCRLF) {}
53 unsigned StartOfTokenColumn,
bool IsAligned =
false,
54 bool InPPDirective =
false);
79 unsigned ReplaceChars,
80 StringRef PreviousPostfix,
81 StringRef CurrentPrefix,
bool InPPDirective,
82 unsigned Newlines,
int Spaces);
176 struct CellDescription {
179 unsigned EndIndex = 0;
180 bool HasSplit =
false;
181 CellDescription *NextColumnElement =
nullptr;
184 return Index ==
Other.Index && Cell ==
Other.Cell &&
185 EndIndex ==
Other.EndIndex;
187 constexpr bool operator!=(
const CellDescription &
Other)
const {
188 return !(*
this ==
Other);
192 struct CellDescriptions {
193 SmallVector<CellDescription> Cells;
194 SmallVector<unsigned> CellCounts;
195 unsigned InitialSpaces = 0;
199 bool isRectangular()
const {
200 if (CellCounts.size() < 2)
203 for (
auto NumberOfColumns : CellCounts)
204 if (NumberOfColumns != CellCounts[0])
213 void calculateLineBreakInformation();
216 void alignConsecutiveMacros();
219 void alignConsecutiveAssignments();
222 void alignConsecutiveBitFields();
226 alignConsecutiveColons(
const FormatStyle::AlignConsecutiveStyle &AlignStyle,
230 void alignConsecutiveDeclarations();
233 void alignChainedConditionals();
236 void alignConsecutiveShortCaseStatements(
bool IsExpr);
239 void alignConsecutiveTableGenBreakingDAGArgColons();
242 void alignConsecutiveTableGenCondOperatorColons();
245 void alignConsecutiveTableGenDefinitions();
248 void alignTrailingComments();
252 void alignTrailingComments(
unsigned Start,
unsigned End,
unsigned Column);
255 void alignEscapedNewlines();
259 void alignEscapedNewlines(
unsigned Start,
unsigned End,
unsigned Column);
262 void alignArrayInitializers();
266 void alignArrayInitializers(
unsigned Start,
unsigned End);
270 void alignArrayInitializersRightJustified(CellDescriptions &&CellDescs);
274 void alignArrayInitializersLeftJustified(CellDescriptions &&CellDescs);
277 unsigned calculateCellWidth(
unsigned Start,
unsigned End,
278 bool WithSpaces =
false)
const;
282 CellDescriptions getCells(
unsigned Start,
unsigned End);
285 static bool isSplitCell(
const CellDescription &Cell);
288 template <
typename I>
289 auto getNetWidth(
const I &Start,
const I &End,
unsigned InitialSpaces)
const {
290 auto NetWidth = InitialSpaces;
291 for (
auto PrevIter = Start; PrevIter != End; ++PrevIter) {
294 assert(PrevIter->Index < Changes.size());
295 if (Changes[PrevIter->Index].NewlinesBefore > 0)
298 calculateCellWidth(PrevIter->Index, PrevIter->EndIndex,
true) + 1;
304 template <
typename I>
305 unsigned getMaximumCellWidth(I CellIter,
unsigned NetWidth)
const {
307 calculateCellWidth(CellIter->Index, CellIter->EndIndex,
true);
308 if (Changes[CellIter->Index].NewlinesBefore == 0)
309 CellWidth += NetWidth;
310 for (
const auto *Next = CellIter->NextColumnElement; Next;
311 Next = Next->NextColumnElement) {
312 auto ThisWidth = calculateCellWidth(Next->Index, Next->EndIndex,
true);
313 if (Changes[Next->Index].NewlinesBefore == 0)
314 ThisWidth += NetWidth;
315 CellWidth = std::max(CellWidth, ThisWidth);
321 template <
typename I>
322 unsigned getMaximumNetWidth(
const I &CellStart,
const I &CellStop,
323 unsigned InitialSpaces,
unsigned CellCount,
324 unsigned MaxRowCount)
const {
325 auto MaxNetWidth = getNetWidth(CellStart, CellStop, InitialSpaces);
327 auto Offset = std::distance(CellStart, CellStop);
328 for (
const auto *Next = CellStop->NextColumnElement; Next;
329 Next = Next->NextColumnElement) {
330 if (RowCount >= MaxRowCount)
332 auto Start = (CellStart + RowCount * CellCount);
333 auto End = Start + Offset;
335 std::max(MaxNetWidth, getNetWidth(Start, End, InitialSpaces));
342 void alignToStartOfCell(
unsigned Start,
unsigned End);
345 static CellDescriptions linkCells(CellDescriptions &&CellDesc);
348 void generateChanges();
351 void storeReplacement(SourceRange
Range, StringRef
Text);
352 void appendNewlineText(std::string &
Text,
unsigned Newlines);
353 void appendEscapedNewlineText(std::string &
Text,
unsigned Newlines,
354 unsigned PreviousEndOfTokenColumn,
355 unsigned EscapedNewlineColumn);
356 void appendIndentText(std::string &
Text,
unsigned IndentLevel,
357 unsigned Spaces,
unsigned WhitespaceStartColumn,
359 unsigned appendTabIndent(std::string &
Text,
unsigned Spaces,
360 unsigned Indentation);
362 SmallVector<Change, 16> Changes;
363 const SourceManager &SourceMgr;
364 tooling::Replacements Replaces;
365 const FormatStyle &Style;
Defines the SourceManager interface.
This file implements a token annotator, i.e.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
The JSON file list parser is used to communicate input to InstallAPI.
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)