class BreakableComment
Declaration
class BreakableComment : public BreakableToken { /* full declaration omitted */ };
Description
Base class for tokens / ranges of tokens that can allow breaking within the tokens - for example, to avoid whitespace beyond the column limit, or to reflow text. Generally, a breakable token consists of logical lines, addressed by a line index. For example, in a sequence of line comments, each line comment is its own logical line; similarly, for a block comment, each line in the block comment is on its own logical line. There are two methods to compute the layout of the token: - getRangeLength measures the number of columns needed for a range of text within a logical line, and - getContentStartColumn returns the start column at which we want the content of a logical line to start (potentially after introducing a line break). The mechanism to adapt the layout of the breakable token is organised around the concept of a \c Split, which is a whitespace range that signifies a position of the content of a token where a reformatting might be done. Operating with splits is divided into two operations: - getSplit, for finding a split starting at a position, - insertBreak, for executing the split using a whitespace manager. There is a pair of operations that are used to compress a long whitespace range with a single space if that will bring the line length under the column limit: - getLineLengthAfterCompression, for calculating the size in columns of the line after a whitespace range has been compressed, and - compressWhitespace, for executing the whitespace compression using a whitespace manager; note that the compressed whitespace may be in the middle of the original line and of the reformatted line. For tokens where the whitespace before each line needs to be also reformatted, for example for tokens supporting reflow, there are analogous operations that might be executed before the main line breaking occurs: - getReflowSplit, for finding a split such that the content preceding it needs to be specially reflown, - reflow, for executing the split using a whitespace manager, - introducesBreakBefore, for checking if reformatting the beginning of the content introduces a line break before it, - adaptStartOfLine, for executing the reflow using a whitespace manager. For tokens that require the whitespace after the last line to be reformatted, for example in multiline jsdoc comments that require the trailing '*/' to be on a line of itself, there are analogous operations that might be executed after the last line has been reformatted: - getSplitAfterLastLine, for finding a split after the last line that needs to be reflown, - replaceWhitespaceAfterLastLine, for executing the reflow using a whitespace manager.
Declared at: clang/lib/Format/BreakableToken.h:286
Inherits from: BreakableToken
Member Variables
- protected SmallVector<llvm::StringRef, 16> Lines
- protected SmallVector<llvm::StringRef, 16> Content
- protected SmallVector<clang::format::FormatToken*, 16> Tokens
- protected SmallVector<int, 16> ContentColumn
- protected unsigned int StartColumn
- protected llvm::StringRef ReflowPrefix = " "
Inherited from BreakableToken:
Method Overview
- protected BreakableComment(const clang::format::FormatToken & Token, unsigned int StartColumn, bool InPPDirective, encoding::Encoding Encoding, const clang::format::FormatStyle & Style)
- public void compressWhitespace(unsigned int LineIndex, unsigned int TailOffset, clang::format::BreakableToken::Split Split, clang::format::WhitespaceManager & Whitespaces) const
- public unsigned int getLineCount() const
- public clang::format::BreakableToken::Split getSplit(unsigned int LineIndex, unsigned int TailOffset, unsigned int ColumnLimit, unsigned int ContentStartColumn, const llvm::Regex & CommentPragmasRegex) const
- protected virtual bool mayReflow(unsigned int LineIndex, const llvm::Regex & CommentPragmasRegex) const
- public bool supportsReflow() const
- protected const clang::format::FormatToken & tokenAt(unsigned int LineIndex) const
Inherited from BreakableToken:
- public adaptStartOfLine
- public compressWhitespace
- public getContentIndent
- public getContentStartColumn
- public getLengthAfterCompression
- public getLineCount
- public getRangeLength
- public getReflowSplit
- public getRemainingLength
- public getSplit
- public getSplitAfterLastLine
- public insertBreak
- public introducesBreakBeforeToken
- public reflow
- public replaceWhitespaceAfterLastLine
- public supportsReflow
- public updateNextToken
Methods
¶BreakableComment(
const clang::format::FormatToken& Token,
unsigned int StartColumn,
bool InPPDirective,
encoding::Encoding Encoding,
const clang::format::FormatStyle& Style)
BreakableComment(
const clang::format::FormatToken& Token,
unsigned int StartColumn,
bool InPPDirective,
encoding::Encoding Encoding,
const clang::format::FormatStyle& Style)
Description
Creates a breakable token for a comment. \p StartColumn specifies the column in which the comment will start after formatting.
Declared at: clang/lib/Format/BreakableToken.h:292
Parameters
- const clang::format::FormatToken& Token
- unsigned int StartColumn
- bool InPPDirective
- encoding::Encoding Encoding
- const clang::format::FormatStyle& Style
¶void compressWhitespace(
unsigned int LineIndex,
unsigned int TailOffset,
clang::format::BreakableToken::Split Split,
clang::format::WhitespaceManager& Whitespaces)
const
void compressWhitespace(
unsigned int LineIndex,
unsigned int TailOffset,
clang::format::BreakableToken::Split Split,
clang::format::WhitespaceManager& Whitespaces)
const
Description
Replaces the whitespace range described by \p Split with a single space.
Declared at: clang/lib/Format/BreakableToken.h:302
Parameters
- unsigned int LineIndex
- unsigned int TailOffset
- clang::format::BreakableToken::Split Split
- clang::format::WhitespaceManager& Whitespaces
¶unsigned int getLineCount() const
unsigned int getLineCount() const
Description
Returns the number of lines in this token in the original code.
Declared at: clang/lib/Format/BreakableToken.h:298
¶clang::format::BreakableToken::Split getSplit(
unsigned int LineIndex,
unsigned int TailOffset,
unsigned int ColumnLimit,
unsigned int ContentStartColumn,
const llvm::Regex& CommentPragmasRegex) const
clang::format::BreakableToken::Split getSplit(
unsigned int LineIndex,
unsigned int TailOffset,
unsigned int ColumnLimit,
unsigned int ContentStartColumn,
const llvm::Regex& CommentPragmasRegex) const
Description
Returns a range (offset, length) at which to break the line at\p LineIndex, if previously broken at \p TailOffset. If possible, do not violate \p ColumnLimit, assuming the text starting at \p TailOffset in the token is formatted starting at ContentStartColumn in the reformatted file.
Declared at: clang/lib/Format/BreakableToken.h:299
Parameters
- unsigned int LineIndex
- unsigned int TailOffset
- unsigned int ColumnLimit
- unsigned int ContentStartColumn
- const llvm::Regex& CommentPragmasRegex
¶virtual bool mayReflow(
unsigned int LineIndex,
const llvm::Regex& CommentPragmasRegex) const
virtual bool mayReflow(
unsigned int LineIndex,
const llvm::Regex& CommentPragmasRegex) const
Declared at: clang/lib/Format/BreakableToken.h:311
Parameters
- unsigned int LineIndex
- const llvm::Regex& CommentPragmasRegex
¶bool supportsReflow() const
bool supportsReflow() const
Description
Returns whether the token supports reflowing text.
Declared at: clang/lib/Format/BreakableToken.h:297
¶const clang::format::FormatToken& tokenAt(
unsigned int LineIndex) const
const clang::format::FormatToken& tokenAt(
unsigned int LineIndex) const
Declared at: clang/lib/Format/BreakableToken.h:307
Parameters
- unsigned int LineIndex