|
clang
5.0.0
|
Base class for strategies on how to break tokens. More...
Public Types | |
| typedef std::pair < StringRef::size_type, unsigned > | Split |
| Contains starting character index and length of split. More... | |
Public Member Functions | |
| virtual | ~BreakableToken () |
| virtual unsigned | getLineCount () const =0 |
| Returns the number of lines in this token in the original code. More... | |
| virtual unsigned | getLineLengthAfterSplit (unsigned LineIndex, unsigned TailOffset, StringRef::size_type Length) const =0 |
Returns the number of columns required to format the piece of line at LineIndex, from byte offset TailOffset with length Length. More... | |
| virtual Split | getSplit (unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, llvm::Regex &CommentPragmasRegex) const =0 |
Returns a range (offset, length) at which to break the line at LineIndex, if previously broken at TailOffset. More... | |
| virtual void | insertBreak (unsigned LineIndex, unsigned TailOffset, Split Split, WhitespaceManager &Whitespaces)=0 |
Emits the previously retrieved Split via Whitespaces. More... | |
| unsigned | getLineLengthAfterCompression (unsigned RemainingTokenColumns, Split Split) const |
Returns the number of columns required to format the piece of line at LineIndex, from byte offset TailOffset after the whitespace range Split has been compressed into a single space. More... | |
| virtual void | compressWhitespace (unsigned LineIndex, unsigned TailOffset, Split Split, WhitespaceManager &Whitespaces)=0 |
Replaces the whitespace range described by Split with a single space. More... | |
| virtual Split | getSplitBefore (unsigned LineIndex, unsigned PreviousEndColumn, unsigned ColumnLimit, llvm::Regex &CommentPragmasRegex) const |
Returns a whitespace range (offset, length) of the content at LineIndex such that the content preceding this range needs to be reformatted before any breaks are made to this line. More... | |
| virtual unsigned | getLineLengthAfterSplitBefore (unsigned LineIndex, unsigned TailOffset, unsigned PreviousEndColumn, unsigned ColumnLimit, Split SplitBefore) const |
Returns the number of columns required to format the piece of line at LineIndex after the content preceding the whitespace range specified SplitBefore has been reformatted, but before any breaks are made to this line. More... | |
| virtual void | replaceWhitespaceBefore (unsigned LineIndex, unsigned PreviousEndColumn, unsigned ColumnLimit, Split SplitBefore, WhitespaceManager &Whitespaces) |
Replaces the whitespace between LineIndex-1 and LineIndex. More... | |
| virtual void | updateNextToken (LineState &State) const |
Updates the next token of State to the next token after this one. More... | |
Protected Member Functions | |
| BreakableToken (const FormatToken &Tok, bool InPPDirective, encoding::Encoding Encoding, const FormatStyle &Style) | |
Protected Attributes | |
| const FormatToken & | Tok |
| const bool | InPPDirective |
| const encoding::Encoding | Encoding |
| const FormatStyle & | Style |
Base class for strategies on how to break tokens.
This is organised around the concept of a 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 3 operations:
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 lenght under the column limit:
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:
FIXME: The interface seems set in stone, so we might want to just pull the strategy into the class, instead of controlling it from the outside.
Definition at line 69 of file BreakableToken.h.
| typedef std::pair<StringRef::size_type, unsigned> clang::format::BreakableToken::Split |
Contains starting character index and length of split.
Definition at line 72 of file BreakableToken.h.
|
inlinevirtual |
Definition at line 74 of file BreakableToken.h.
|
inlineprotected |
Definition at line 153 of file BreakableToken.h.
|
pure virtual |
Replaces the whitespace range described by Split with a single space.
Implemented in clang::format::BreakableComment, and clang::format::BreakableStringLiteral.
|
pure virtual |
Returns the number of lines in this token in the original code.
Implemented in clang::format::BreakableComment, and clang::format::BreakableSingleLineToken.
| unsigned clang::format::BreakableToken::getLineLengthAfterCompression | ( | unsigned | RemainingTokenColumns, |
| Split | Split | ||
| ) | const |
Returns the number of columns required to format the piece of line at LineIndex, from byte offset TailOffset after the whitespace range Split has been compressed into a single space.
Definition at line 168 of file BreakableToken.cpp.
|
pure virtual |
Returns the number of columns required to format the piece of line at LineIndex, from byte offset TailOffset with length Length.
Note that previous breaks are not taken into account. TailOffset is always specified from the start of the (original) line. Length can be set to StringRef::npos, which means "to the end of line".
Implemented in clang::format::BreakableLineCommentSection, clang::format::BreakableBlockComment, and clang::format::BreakableSingleLineToken.
Referenced by getLineLengthAfterSplitBefore().
|
inlinevirtual |
Returns the number of columns required to format the piece of line at LineIndex after the content preceding the whitespace range specified SplitBefore has been reformatted, but before any breaks are made to this line.
Reimplemented in clang::format::BreakableLineCommentSection, and clang::format::BreakableBlockComment.
Definition at line 131 of file BreakableToken.h.
References getLineLengthAfterSplit().
|
pure virtual |
Returns a range (offset, length) at which to break the line at LineIndex, if previously broken at TailOffset.
If possible, do not violate ColumnLimit.
Implemented in clang::format::BreakableComment, and clang::format::BreakableStringLiteral.
|
inlinevirtual |
Returns a whitespace range (offset, length) of the content at LineIndex such that the content preceding this range needs to be reformatted before any breaks are made to this line.
PreviousEndColumn is the end column of the previous line after formatting.
A result having offset == StringRef::npos means that no piece of the line needs to be reformatted before any breaks are made.
Reimplemented in clang::format::BreakableLineCommentSection, and clang::format::BreakableBlockComment.
Definition at line 121 of file BreakableToken.h.
|
pure virtual |
Emits the previously retrieved Split via Whitespaces.
Implemented in clang::format::BreakableLineCommentSection, clang::format::BreakableBlockComment, and clang::format::BreakableStringLiteral.
|
inlinevirtual |
Replaces the whitespace between LineIndex-1 and LineIndex.
Performs a reformatting of the content at LineIndex preceding the whitespace range SplitBefore.
Reimplemented in clang::format::BreakableLineCommentSection, and clang::format::BreakableBlockComment.
Definition at line 142 of file BreakableToken.h.
|
inlinevirtual |
Updates the next token of State to the next token after this one.
This can be used when this token manages a set of underlying tokens as a unit and is responsible for the formatting of the them.
Reimplemented in clang::format::BreakableLineCommentSection.
Definition at line 150 of file BreakableToken.h.
|
protected |
Definition at line 160 of file BreakableToken.h.
Referenced by clang::format::BreakableSingleLineToken::getLineLengthAfterSplit(), clang::format::BreakableBlockComment::getLineLengthAfterSplit(), clang::format::BreakableLineCommentSection::getLineLengthAfterSplit(), clang::format::BreakableLineCommentSection::getLineLengthAfterSplitBefore(), clang::format::BreakableComment::getReflowSplit(), clang::format::BreakableStringLiteral::getSplit(), and clang::format::BreakableComment::getSplit().
|
protected |
|
protected |
Definition at line 161 of file BreakableToken.h.
Referenced by clang::format::BreakableSingleLineToken::getLineLengthAfterSplit(), clang::format::BreakableBlockComment::getLineLengthAfterSplit(), clang::format::BreakableLineCommentSection::getLineLengthAfterSplit(), clang::format::BreakableLineCommentSection::getLineLengthAfterSplitBefore(), clang::format::BreakableComment::getReflowSplit(), clang::format::BreakableStringLiteral::getSplit(), and clang::format::BreakableComment::getSplit().
|
protected |
Definition at line 158 of file BreakableToken.h.
Referenced by clang::format::BreakableBlockComment::BreakableBlockComment(), clang::format::BreakableLineCommentSection::BreakableLineCommentSection(), clang::format::BreakableStringLiteral::insertBreak(), clang::format::BreakableBlockComment::mayReflow(), clang::format::BreakableLineCommentSection::mayReflow(), and clang::format::BreakableComment::tokenAt().
1.8.6