clang  5.0.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
clang::format::BreakableToken Class Referenceabstract

Base class for strategies on how to break tokens. More...

#include "/usr/local/google/work/llvm-www-releases/5.0.0/docsbuild/llvm.src/tools/clang/lib/Format/BreakableToken.h"

Inheritance diagram for clang::format::BreakableToken:
[legend]
Collaboration diagram for clang::format::BreakableToken:
[legend]

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 FormatTokenTok
 
const bool InPPDirective
 
const encoding::Encoding Encoding
 
const FormatStyleStyle
 

Detailed Description

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.

Member Typedef Documentation

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.

Constructor & Destructor Documentation

virtual clang::format::BreakableToken::~BreakableToken ( )
inlinevirtual

Definition at line 74 of file BreakableToken.h.

clang::format::BreakableToken::BreakableToken ( const FormatToken Tok,
bool  InPPDirective,
encoding::Encoding  Encoding,
const FormatStyle Style 
)
inlineprotected

Definition at line 153 of file BreakableToken.h.

Member Function Documentation

virtual void clang::format::BreakableToken::compressWhitespace ( unsigned  LineIndex,
unsigned  TailOffset,
Split  Split,
WhitespaceManager Whitespaces 
)
pure virtual

Replaces the whitespace range described by Split with a single space.

Implemented in clang::format::BreakableComment, and clang::format::BreakableStringLiteral.

virtual unsigned clang::format::BreakableToken::getLineCount ( ) const
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.

virtual unsigned clang::format::BreakableToken::getLineLengthAfterSplit ( unsigned  LineIndex,
unsigned  TailOffset,
StringRef::size_type  Length 
) const
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().

virtual unsigned clang::format::BreakableToken::getLineLengthAfterSplitBefore ( unsigned  LineIndex,
unsigned  TailOffset,
unsigned  PreviousEndColumn,
unsigned  ColumnLimit,
Split  SplitBefore 
) const
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().

virtual Split clang::format::BreakableToken::getSplit ( unsigned  LineIndex,
unsigned  TailOffset,
unsigned  ColumnLimit,
llvm::Regex &  CommentPragmasRegex 
) const
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.

virtual Split clang::format::BreakableToken::getSplitBefore ( unsigned  LineIndex,
unsigned  PreviousEndColumn,
unsigned  ColumnLimit,
llvm::Regex &  CommentPragmasRegex 
) const
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.

virtual void clang::format::BreakableToken::insertBreak ( unsigned  LineIndex,
unsigned  TailOffset,
Split  Split,
WhitespaceManager Whitespaces 
)
pure virtual

Emits the previously retrieved Split via Whitespaces.

Implemented in clang::format::BreakableLineCommentSection, clang::format::BreakableBlockComment, and clang::format::BreakableStringLiteral.

virtual void clang::format::BreakableToken::replaceWhitespaceBefore ( unsigned  LineIndex,
unsigned  PreviousEndColumn,
unsigned  ColumnLimit,
Split  SplitBefore,
WhitespaceManager Whitespaces 
)
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.

virtual void clang::format::BreakableToken::updateNextToken ( LineState State) const
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.

Member Data Documentation

const encoding::Encoding clang::format::BreakableToken::Encoding
protected
const bool clang::format::BreakableToken::InPPDirective
protected
const FormatStyle& clang::format::BreakableToken::Style
protected
const FormatToken& clang::format::BreakableToken::Tok
protected

The documentation for this class was generated from the following files: