class WhitespaceManager

Declaration

class WhitespaceManager { /* full declaration omitted */ };

Description

Manages the whitespaces around tokens and their replacements. This includes special handling for certain constructs, e.g. the alignment of trailing line comments. To guarantee correctness of alignment operations, the \c WhitespaceManager must be informed about every token in the source file; for each token, there must be exactly one call to either \c replaceWhitespace or\c addUntouchableToken. There may be multiple calls to \c breakToken for a given token.

Declared at: clang/lib/Format/WhitespaceManager.h:40

Member Variables

private SmallVector< clang::format::WhitespaceManager::Change, 16> Changes
private const clang::SourceManager& SourceMgr
private tooling::Replacements Replaces
private const clang::format::FormatStyle& Style
private bool UseCRLF

Method Overview

Methods

WhitespaceManager(
    const clang::SourceManager& SourceMgr,
    const clang::format::FormatStyle& Style,
    bool UseCRLF)

Declared at: clang/lib/Format/WhitespaceManager.h:42

Parameters

const clang::SourceManager& SourceMgr
const clang::format::FormatStyle& Style
bool UseCRLF

llvm::Error addReplacement(
    const tooling::Replacement& Replacement)

Declared at: clang/lib/Format/WhitespaceManager.h:67

Parameters

const tooling::Replacement& Replacement

void addUntouchableToken(
    const clang::format::FormatToken& Tok,
    bool InPPDirective)

Description

Adds information about an unchangeable token's whitespace. Needs to be called for every token for which \c replaceWhitespace was not called.

Declared at: clang/lib/Format/WhitespaceManager.h:65

Parameters

const clang::format::FormatToken& Tok
bool InPPDirective

void alignArrayInitializers(unsigned int Start,
                            unsigned int End)

Description

Align Array Initializers from change \p Start to change \p End at the specified \p Column.

Declared at: clang/lib/Format/WhitespaceManager.h:254

Parameters

unsigned int Start
unsigned int End

void alignArrayInitializers()

Description

Align Array Initializers over all \c Changes.

Declared at: clang/lib/Format/WhitespaceManager.h:250

void alignArrayInitializersLeftJustified(
    clang::format::WhitespaceManager::
        CellDescriptions&& CellDescs)

Description

Align Array Initializers being careful to left justify the columns as described by \p CellDescs.

Declared at: clang/lib/Format/WhitespaceManager.h:262

Parameters

clang::format::WhitespaceManager:: CellDescriptions&& CellDescs

void alignArrayInitializersRightJustified(
    clang::format::WhitespaceManager::
        CellDescriptions&& CellDescs)

Description

Align Array Initializers being careful to right justify the columns as described by \p CellDescs.

Declared at: clang/lib/Format/WhitespaceManager.h:258

Parameters

clang::format::WhitespaceManager:: CellDescriptions&& CellDescs

void alignChainedConditionals()

Description

Align consecutive declarations over all \c Changes.

Declared at: clang/lib/Format/WhitespaceManager.h:233

void alignConsecutiveAssignments()

Description

Align consecutive assignments over all \c Changes.

Declared at: clang/lib/Format/WhitespaceManager.h:224

void alignConsecutiveBitFields()

Description

Align consecutive bitfields over all \c Changes.

Declared at: clang/lib/Format/WhitespaceManager.h:227

void alignConsecutiveDeclarations()

Description

Align consecutive declarations over all \c Changes.

Declared at: clang/lib/Format/WhitespaceManager.h:230

void alignConsecutiveMacros()

Description

Align consecutive C/C++ preprocessor macros over all \c Changes.

Declared at: clang/lib/Format/WhitespaceManager.h:221

void alignEscapedNewlines(unsigned int Start,
                          unsigned int End,
                          unsigned int Column)

Description

Align escaped newlines from change \p Start to change \p End at the specified \p Column.

Declared at: clang/lib/Format/WhitespaceManager.h:247

Parameters

unsigned int Start
unsigned int End
unsigned int Column

void alignEscapedNewlines()

Description

Align escaped newlines over all \c Changes.

Declared at: clang/lib/Format/WhitespaceManager.h:243

void alignToStartOfCell(unsigned int Start,
                        unsigned int End)

Description

Align a split cell with a newline to the first element in the cell.

Declared at: clang/lib/Format/WhitespaceManager.h:329

Parameters

unsigned int Start
unsigned int End

void alignTrailingComments()

Description

Align trailing comments over all \c Changes.

Declared at: clang/lib/Format/WhitespaceManager.h:236

void alignTrailingComments(unsigned int Start,
                           unsigned int End,
                           unsigned int Column)

Description

Align trailing comments from change \p Start to change \p End at the specified \p Column.

Declared at: clang/lib/Format/WhitespaceManager.h:240

Parameters

unsigned int Start
unsigned int End
unsigned int Column

void appendEscapedNewlineText(
    std::string& Text,
    unsigned int Newlines,
    unsigned int PreviousEndOfTokenColumn,
    unsigned int EscapedNewlineColumn)

Declared at: clang/lib/Format/WhitespaceManager.h:340

Parameters

std::string& Text
unsigned int Newlines
unsigned int PreviousEndOfTokenColumn
unsigned int EscapedNewlineColumn

void appendIndentText(
    std::string& Text,
    unsigned int IndentLevel,
    unsigned int Spaces,
    unsigned int WhitespaceStartColumn,
    bool IsAligned)

Declared at: clang/lib/Format/WhitespaceManager.h:343

Parameters

std::string& Text
unsigned int IndentLevel
unsigned int Spaces
unsigned int WhitespaceStartColumn
bool IsAligned

void appendNewlineText(std::string& Text,
                       unsigned int Newlines)

Declared at: clang/lib/Format/WhitespaceManager.h:339

Parameters

std::string& Text
unsigned int Newlines

unsigned int appendTabIndent(
    std::string& Text,
    unsigned int Spaces,
    unsigned int Indentation)

Declared at: clang/lib/Format/WhitespaceManager.h:346

Parameters

std::string& Text
unsigned int Spaces
unsigned int Indentation

unsigned int calculateCellWidth(
    unsigned int Start,
    unsigned int End,
    bool WithSpaces = false) const

Description

Calculate the cell width between two indexes.

Declared at: clang/lib/Format/WhitespaceManager.h:265

Parameters

unsigned int Start
unsigned int End
bool WithSpaces = false

void calculateLineBreakInformation()

Description

Calculate \c IsTrailingComment, \c TokenLength for the last tokens or token parts in a line and \c PreviousEndOfTokenColumn and\c EscapedNewlineColumn for the first tokens or token parts in a line.

Declared at: clang/lib/Format/WhitespaceManager.h:218

void generateChanges()

Description

Fill \c Replaces with the replacements for all effective changes.

Declared at: clang/lib/Format/WhitespaceManager.h:335

const tooling::Replacements&
generateReplacements()

Description

Returns all the \c Replacements created during formatting.

Declared at: clang/lib/Format/WhitespaceManager.h:90

clang::format::WhitespaceManager::CellDescriptions
getCells(unsigned int Start, unsigned int End)

Description

Get a set of fully specified CellDescriptions between \p Start and\p End of the change list.

Declared at: clang/lib/Format/WhitespaceManager.h:270

Parameters

unsigned int Start
unsigned int End

template <typename I>
unsigned int getMaximumCellWidth(
    I CellIter,
    unsigned int NetWidth) const

Description

Get the maximum width of a cell in a sequence of columns.

Declared at: clang/lib/Format/WhitespaceManager.h:292

Templates

I

Parameters

I CellIter
unsigned int NetWidth

template <typename I>
unsigned int getMaximumNetWidth(
    const I& CellStart,
    const I& CellStop,
    unsigned int InitialSpaces,
    unsigned int CellCount,
    unsigned int MaxRowCount) const

Description

Get The maximum width of all columns to a given cell.

Declared at: clang/lib/Format/WhitespaceManager.h:309

Templates

I

Parameters

const I& CellStart
const I& CellStop
unsigned int InitialSpaces
unsigned int CellCount
unsigned int MaxRowCount

template <typename I>
auto getNetWidth(const I& Start,
                 const I& End,
                 unsigned int InitialSpaces) const

Description

Get the width of the preceding cells from \p Start to \p End.

Declared at: clang/lib/Format/WhitespaceManager.h:277

Templates

I

Parameters

const I& Start
const I& End
unsigned int InitialSpaces

static bool inputUsesCRLF(llvm::StringRef Text,
                          bool DefaultToCRLF)

Description

Infers whether the input is using CRLF.

Declared at: clang/lib/Format/WhitespaceManager.h:49

Parameters

llvm::StringRef Text
bool DefaultToCRLF

static bool isSplitCell(
    const clang::format::WhitespaceManager::
        CellDescription& Cell)

Description

Does this \p Cell contain a split element?

Declared at: clang/lib/Format/WhitespaceManager.h:273

Parameters

const clang::format::WhitespaceManager:: CellDescription& Cell

static clang::format::WhitespaceManager::
    CellDescriptions
    linkCells(clang::format::WhitespaceManager::
                  CellDescriptions&& CellDesc)

Description

Link the Cell pointers in the list of Cells.

Declared at: clang/lib/Format/WhitespaceManager.h:332

Parameters

clang::format::WhitespaceManager:: CellDescriptions&& CellDesc

void replaceWhitespace(
    clang::format::FormatToken& Tok,
    unsigned int Newlines,
    unsigned int Spaces,
    unsigned int StartOfTokenColumn,
    bool isAligned = false,
    bool InPPDirective = false)

Description

Replaces the whitespace in front of \p Tok. Only call once for each \c AnnotatedToken. \p StartOfTokenColumn is the column at which the token will start after this replacement. It is needed for determining how \p Spaces is turned into tabs and spaces for some format styles.

Declared at: clang/lib/Format/WhitespaceManager.h:57

Parameters

clang::format::FormatToken& Tok
unsigned int Newlines
unsigned int Spaces
unsigned int StartOfTokenColumn
bool isAligned = false
bool InPPDirective = false

void replaceWhitespaceInToken(
    const clang::format::FormatToken& Tok,
    unsigned int Offset,
    unsigned int ReplaceChars,
    llvm::StringRef PreviousPostfix,
    llvm::StringRef CurrentPrefix,
    bool InPPDirective,
    unsigned int Newlines,
    int Spaces)

Description

Inserts or replaces whitespace in the middle of a token. Inserts \p PreviousPostfix, \p Newlines, \p Spaces and \p CurrentPrefix (in this order) at \p Offset inside \p Tok, replacing \p ReplaceChars characters. Note: \p Spaces can be negative to retain information about initial relative column offset between a line of a block comment and the start of the comment. This negative offset may be compensated by trailing comment alignment here. In all other cases negative \p Spaces will be truncated to 0. When \p InPPDirective is true, escaped newlines are inserted. \p Spaces is used to align backslashes correctly.

Declared at: clang/lib/Format/WhitespaceManager.h:83

Parameters

const clang::format::FormatToken& Tok
unsigned int Offset
unsigned int ReplaceChars
llvm::StringRef PreviousPostfix
llvm::StringRef CurrentPrefix
bool InPPDirective
unsigned int Newlines
int Spaces

void storeReplacement(clang::SourceRange Range,
                      llvm::StringRef Text)

Description

Stores \p Text as the replacement for the whitespace in \p Range.

Declared at: clang/lib/Format/WhitespaceManager.h:338

Parameters

clang::SourceRange Range
llvm::StringRef Text

bool useCRLF() const

Declared at: clang/lib/Format/WhitespaceManager.h:46