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();
239 void alignConsecutiveTableGenCondOperatorColons();
242 void alignConsecutiveTableGenDefinitions();
245 void alignTrailingComments();
249 void alignTrailingComments(
unsigned Start,
unsigned End,
unsigned Column);
252 void alignEscapedNewlines();
256 void alignEscapedNewlines(
unsigned Start,
unsigned End,
unsigned Column);
259 void alignArrayInitializers();
263 void alignArrayInitializers(
unsigned Start,
unsigned End);
267 void alignArrayInitializersRightJustified(CellDescriptions &&CellDescs);
271 void alignArrayInitializersLeftJustified(CellDescriptions &&CellDescs);
274 unsigned calculateCellWidth(
unsigned Start,
unsigned End,
275 bool WithSpaces =
false)
const;
279 CellDescriptions getCells(
unsigned Start,
unsigned End);
282 static bool isSplitCell(
const CellDescription &Cell);
285 template <
typename I>
286 auto getNetWidth(
const I &Start,
const I &End,
unsigned InitialSpaces)
const {
287 auto NetWidth = InitialSpaces;
288 for (
auto PrevIter = Start; PrevIter != End; ++PrevIter) {
291 assert(PrevIter->Index < Changes.size());
292 if (Changes[PrevIter->Index].NewlinesBefore > 0)
295 calculateCellWidth(PrevIter->Index, PrevIter->EndIndex,
true) + 1;
301 template <
typename I>
302 unsigned getMaximumCellWidth(I CellIter,
unsigned NetWidth)
const {
304 calculateCellWidth(CellIter->Index, CellIter->EndIndex,
true);
305 if (Changes[CellIter->Index].NewlinesBefore == 0)
306 CellWidth += NetWidth;
307 for (
const auto *Next = CellIter->NextColumnElement; Next;
308 Next = Next->NextColumnElement) {
309 auto ThisWidth = calculateCellWidth(Next->Index, Next->EndIndex,
true);
310 if (Changes[Next->Index].NewlinesBefore == 0)
311 ThisWidth += NetWidth;
312 CellWidth = std::max(CellWidth, ThisWidth);
318 template <
typename I>
319 unsigned getMaximumNetWidth(
const I &CellStart,
const I &CellStop,
320 unsigned InitialSpaces,
unsigned CellCount,
321 unsigned MaxRowCount)
const {
322 auto MaxNetWidth = getNetWidth(CellStart, CellStop, InitialSpaces);
324 auto Offset = std::distance(CellStart, CellStop);
325 for (
const auto *Next = CellStop->NextColumnElement; Next;
326 Next = Next->NextColumnElement) {
327 if (RowCount >= MaxRowCount)
329 auto Start = (CellStart + RowCount * CellCount);
330 auto End = Start + Offset;
332 std::max(MaxNetWidth, getNetWidth(Start, End, InitialSpaces));
339 void alignToStartOfCell(
unsigned Start,
unsigned End);
342 static CellDescriptions linkCells(CellDescriptions &&CellDesc);
345 void generateChanges();
348 void storeReplacement(SourceRange Range, StringRef
Text);
349 void appendNewlineText(std::string &
Text,
unsigned Newlines);
350 void appendEscapedNewlineText(std::string &
Text,
unsigned Newlines,
351 unsigned PreviousEndOfTokenColumn,
352 unsigned EscapedNewlineColumn);
353 void appendIndentText(std::string &
Text,
unsigned IndentLevel,
354 unsigned Spaces,
unsigned WhitespaceStartColumn,
356 unsigned appendTabIndent(std::string &
Text,
unsigned Spaces,
357 unsigned Indentation);
359 SmallVector<Change, 16> Changes;
360 const SourceManager &SourceMgr;
361 tooling::Replacements Replaces;
362 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)