clang API Documentation

Public Member Functions | Public Attributes
clang::format::FormatToken Struct Reference

A wrapper around a Token storing information about the whitespace characters preceding it. More...

#include <FormatToken.h>

Collaboration diagram for clang::format::FormatToken:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 FormatToken ()
SourceLocation getStartOfNonWhitespace () const
 Returns actual token start location without leading escaped newlines and whitespace.
bool is (tok::TokenKind Kind) const
bool is (const IdentifierInfo *II) const
template<typename T >
bool isOneOf (T K1, T K2) const
template<typename T >
bool isOneOf (T K1, T K2, T K3) const
template<typename T >
bool isOneOf (T K1, T K2, T K3, T K4, T K5=tok::NUM_TOKENS, T K6=tok::NUM_TOKENS, T K7=tok::NUM_TOKENS, T K8=tok::NUM_TOKENS, T K9=tok::NUM_TOKENS, T K10=tok::NUM_TOKENS, T K11=tok::NUM_TOKENS, T K12=tok::NUM_TOKENS) const
template<typename T >
bool isNot (T Kind) const
bool isNot (IdentifierInfo *II) const
bool isStringLiteral () const
bool isObjCAtKeyword (tok::ObjCKeywordKind Kind) const
bool isAccessSpecifier (bool ColonRequired=true) const
bool isSimpleTypeSpecifier () const
 Determine whether the token is a simple-type-specifier.
bool isObjCAccessSpecifier () const
bool opensScope () const
 Returns whether Tok is ([{ or a template opening <.
bool closesScope () const
 Returns whether Tok is )]} or a template closing >.
bool isMemberAccess () const
 Returns true if this is a "." or "->" accessing a member.
bool isUnaryOperator () const
bool isBinaryOperator () const
bool isTrailingComment () const
bool isFunctionLikeKeyword () const
 Returns true if this is a keyword that can be used like a function call (e.g. sizeof, typeid, ...).
prec::Level getPrecedence () const
FormatTokengetPreviousNonComment () const
 Returns the previous token ignoring comments.
const FormatTokengetNextNonComment () const
 Returns the next token ignoring comments.
bool opensBlockTypeList (const FormatStyle &Style) const
 Returns true if this tokens starts a block-type list, i.e. a list that should be indented with a block indent.
bool closesBlockTypeList (const FormatStyle &Style) const
 Same as opensBlockTypeList, but for the closing token.

Public Attributes

Token Tok
 The Token.
unsigned NewlinesBefore
 The number of newlines immediately before the Token.
bool HasUnescapedNewline
 Whether there is at least one unescaped newline before the Token.
SourceRange WhitespaceRange
 The range of the whitespace immediately preceding the Token.
unsigned LastNewlineOffset
 The offset just past the last '
' in this token's leading whitespace (relative to WhiteSpaceStart). 0 if there is no '
'.
unsigned ColumnWidth
 The width of the non-whitespace parts of the token (or its first line for multi-line tokens) in columns. We need this to correctly measure number of columns a token spans.
unsigned LastLineColumnWidth
 Contains the width in columns of the last line of a multi-line token.
bool IsMultiline
 Whether the token text contains newlines (escaped or not).
bool IsFirst
 Indicates that this is the first token.
bool MustBreakBefore
 Whether there must be a line break before this token.
StringRef TokenText
 The raw text of the token.
bool IsUnterminatedLiteral
 Set to true if this token is an unterminated literal.
BraceBlockKind BlockKind
 Contains the kind of block if this token is a brace.
TokenType Type
unsigned SpacesRequiredBefore
 The number of spaces that should be inserted before this token.
bool CanBreakBefore
 true if it is allowed to break before this token.
bool ClosesTemplateDeclaration
unsigned ParameterCount
 Number of parameters, if this is "(", "[" or "<".
unsigned BlockParameterCount
 Number of parameters that are nested blocks, if this is "(", "[" or "<".
std::unique_ptr< TokenRoleRole
 A token can have a special role that can carry extra information about the token's formatting.
ParameterPackingKind PackingKind
 If this is an opening parenthesis, how are the parameters packed?
unsigned TotalLength
 The total length of the unwrapped line up to and including this token.
unsigned OriginalColumn
 The original 0-based column of this token, including expanded tabs. The configured TabWidth is used as tab width.
unsigned UnbreakableTailLength
 The length of following tokens until the next natural split point, or the next token that can be broken.
unsigned BindingStrength
 The binding strength of a token. This is a combined value of operator precedence, parenthesis nesting, etc.
unsigned NestingLevel
 The nesting level of this token, i.e. the number of surrounding (), [], {} or <>.
unsigned SplitPenalty
 Penalty for inserting a line break before this token.
unsigned LongestObjCSelectorName
 If this is the first ObjC selector name in an ObjC method definition or call, this contains the length of the longest name.
SmallVector< prec::Level, 4 > FakeLParens
 Stores the number of required fake parentheses and the corresponding operator precedence.
unsigned FakeRParens
 Insert this many fake ) after this token for correct indentation.
bool StartsBinaryExpression
 true if this token starts a binary expression, i.e. has at least one fake l_paren with a precedence greater than prec::Unknown.
bool EndsBinaryExpression
 true if this token ends a binary expression.
unsigned OperatorIndex
 Is this is an operator (or "."/"->") in a sequence of operators with the same precedence, contains the 0-based operator index.
bool LastOperator
 Is this the last operator (or "."/"->") in a sequence of operators with the same precedence?
bool PartOfMultiVariableDeclStmt
 Is this token part of a DeclStmt defining multiple variables?
bool IsForEachMacro
 Is this a foreach macro?
FormatTokenMatchingParen
FormatTokenPrevious
FormatTokenNext
SmallVector< AnnotatedLine *, 1 > Children
FormatDecision Decision
 Stores the formatting decision for the token once it was made.
bool Finalized
 If true, this token has been fully formatted (indented and potentially re-formatted inside), and we do not allow further formatting changes.

Detailed Description

A wrapper around a Token storing information about the whitespace characters preceding it.

Definition at line 103 of file FormatToken.h.


Constructor & Destructor Documentation

Definition at line 104 of file FormatToken.h.


Member Function Documentation

Same as opensBlockTypeList, but for the closing token.

Definition at line 419 of file FormatToken.h.

References MatchingParen, and opensBlockTypeList().

Referenced by clang::format::ContinuationIndenter::canBreak(), and clang::format::ContinuationIndenter::mustBreak().

Returns whether Tok is )]} or a template closing >.

Definition at line 331 of file FormatToken.h.

References isOneOf(), and clang::format::TT_TemplateCloser.

Referenced by clang::format::startsSegmentOfBuilderTypeCall().

Returns the next token ignoring comments.

Definition at line 402 of file FormatToken.h.

References is(), Next, and Tok.

Referenced by clang::format::CommaSeparatedList::precomputeFormattingInfos().

Returns the previous token ignoring comments.

Definition at line 394 of file FormatToken.h.

References is(), Previous, and Tok.

Referenced by clang::format::CommaSeparatedList::precomputeFormattingInfos().

Returns actual token start location without leading escaped newlines and whitespace.

This can be different to Tok.getLocation(), which includes leading escaped newlines.

Definition at line 166 of file FormatToken.h.

References clang::SourceRange::getEnd(), and WhitespaceRange.

Referenced by clang::format::WhitespaceManager::replaceWhitespaceInToken().

bool clang::format::FormatToken::is ( const IdentifierInfo II) const [inline]

Definition at line 274 of file FormatToken.h.

References clang::Token::getIdentifierInfo(), and Tok.

bool clang::format::FormatToken::isAccessSpecifier ( bool  ColonRequired = true) const [inline]

Definition at line 310 of file FormatToken.h.

References is(), isOneOf(), and Next.

Definition at line 359 of file FormatToken.h.

References clang::prec::Comma, and getPrecedence().

Returns true if this is a keyword that can be used like a function call (e.g. sizeof, typeid, ...).

Definition at line 371 of file FormatToken.h.

References clang::Token::getKind(), and Tok.

template<typename T >
bool clang::format::FormatToken::isNot ( Kind) const [inline]

Definition at line 302 of file FormatToken.h.

References clang::Token::getIdentifierInfo(), and Tok.

Definition at line 318 of file FormatToken.h.

References is(), isObjCAtKeyword(), and Next.

Definition at line 306 of file FormatToken.h.

References clang::Token::isObjCAtKeyword(), and Tok.

Referenced by isObjCAccessSpecifier().

template<typename T >
bool clang::format::FormatToken::isOneOf ( K1,
K2 
) const [inline]
template<typename T >
bool clang::format::FormatToken::isOneOf ( K1,
K2,
K3 
) const [inline]

Definition at line 284 of file FormatToken.h.

References is().

template<typename T >
bool clang::format::FormatToken::isOneOf ( K1,
K2,
K3,
K4,
K5 = tok::NUM_TOKENS,
K6 = tok::NUM_TOKENS,
K7 = tok::NUM_TOKENS,
K8 = tok::NUM_TOKENS,
K9 = tok::NUM_TOKENS,
K10 = tok::NUM_TOKENS,
K11 = tok::NUM_TOKENS,
K12 = tok::NUM_TOKENS 
) const [inline]

Definition at line 289 of file FormatToken.h.

References is().

Determine whether the token is a simple-type-specifier.

Definition at line 27 of file FormatToken.cpp.

References clang::Token::getKind(), and Tok.

Definition at line 304 of file FormatToken.h.

References clang::Token::getKind(), and Tok.

Definition at line 343 of file FormatToken.h.

References clang::Token::getKind(), and Tok.

Returns true if this tokens starts a block-type list, i.e. a list that should be indented with a block indent.

Definition at line 411 of file FormatToken.h.

References clang::format::BK_Block, BlockKind, clang::format::FormatStyle::Cpp11BracedListStyle, is(), clang::format::TT_ArrayInitializerLSquare, and clang::format::TT_DictLiteral.

Referenced by closesBlockTypeList().

Returns whether Tok is ([{ or a template opening <.

Definition at line 326 of file FormatToken.h.

References isOneOf(), and clang::format::TT_TemplateOpener.

Referenced by clang::format::TokenAnnotator::calculateFormattingInformation(), and clang::format::ContinuationIndenter::canBreak().


Member Data Documentation

The binding strength of a token. This is a combined value of operator precedence, parenthesis nesting, etc.

Definition at line 225 of file FormatToken.h.

Referenced by clang::format::TokenAnnotator::calculateFormattingInformation().

Number of parameters that are nested blocks, if this is "(", "[" or "<".

Definition at line 201 of file FormatToken.h.

Definition at line 190 of file FormatToken.h.

Referenced by clang::format::ContinuationIndenter::mustBreak().

The width of the non-whitespace parts of the token (or its first line for multi-line tokens) in columns. We need this to correctly measure number of columns a token spans.

Definition at line 143 of file FormatToken.h.

Referenced by clang::format::TokenAnnotator::calculateFormattingInformation(), clang::format::CodePointsBetween(), and clang::format::CommaSeparatedList::formatAfterToken().

Stores the formatting decision for the token once it was made.

Definition at line 431 of file FormatToken.h.

Referenced by clang::format::WhitespaceManager::replaceWhitespace().

true if this token ends a binary expression.

Definition at line 254 of file FormatToken.h.

Referenced by clang::format::ContinuationIndenter::mustBreak().

Stores the number of required fake parentheses and the corresponding operator precedence.

If multiple fake parentheses start at a token, this vector stores them in reverse order, i.e. inner fake parenthesis first.

Definition at line 246 of file FormatToken.h.

Insert this many fake ) after this token for correct indentation.

Definition at line 248 of file FormatToken.h.

Referenced by clang::format::consumeRParens().

If true, this token has been fully formatted (indented and potentially re-formatted inside), and we do not allow further formatting changes.

Definition at line 436 of file FormatToken.h.

Referenced by clang::format::WhitespaceManager::addUntouchableToken(), clang::format::WhitespaceManager::replaceWhitespace(), and clang::format::WhitespaceManager::replaceWhitespaceInToken().

Whether there is at least one unescaped newline before the Token.

Definition at line 131 of file FormatToken.h.

Referenced by clang::format::TokenAnnotator::calculateFormattingInformation(), and clang::format::CommaSeparatedList::precomputeFormattingInfos().

Is this a foreach macro?

Definition at line 270 of file FormatToken.h.

Whether the token text contains newlines (escaped or not).

Definition at line 150 of file FormatToken.h.

Referenced by clang::format::TokenAnnotator::calculateFormattingInformation().

Set to true if this token is an unterminated literal.

Definition at line 177 of file FormatToken.h.

Contains the width in columns of the last line of a multi-line token.

Definition at line 147 of file FormatToken.h.

The offset just past the last '
' in this token's leading whitespace (relative to WhiteSpaceStart). 0 if there is no '
'.

Definition at line 138 of file FormatToken.h.

Is this the last operator (or "."/"->") in a sequence of operators with the same precedence?

Definition at line 262 of file FormatToken.h.

If this is the first ObjC selector name in an ObjC method definition or call, this contains the length of the longest name.

This being set to 0 means that the selectors should not be colon-aligned, e.g. because several of them are block-type.

Definition at line 239 of file FormatToken.h.

The number of newlines immediately before the Token.

This can be used to determine what the user wrote in the original code and thereby e.g. leave an empty line between two function definitions.

Definition at line 127 of file FormatToken.h.

Referenced by clang::format::WhitespaceManager::addUntouchableToken(), and isTrailingComment().

Is this is an operator (or "."/"->") in a sequence of operators with the same precedence, contains the 0-based operator index.

Definition at line 258 of file FormatToken.h.

The original 0-based column of this token, including expanded tabs. The configured TabWidth is used as tab width.

Definition at line 216 of file FormatToken.h.

Referenced by clang::format::WhitespaceManager::addUntouchableToken().

If this is an opening parenthesis, how are the parameters packed?

Definition at line 208 of file FormatToken.h.

Number of parameters, if this is "(", "[" or "<".

This is initialized to 1 as we don't need to distinguish functions with 0 parameters from functions with 1 parameter. Thus, we can simply count the number of commas.

Definition at line 197 of file FormatToken.h.

Is this token part of a DeclStmt defining multiple variables?

Only set if Type == TT_StartOfName.

Definition at line 267 of file FormatToken.h.

A token can have a special role that can carry extra information about the token's formatting.

Definition at line 205 of file FormatToken.h.

Referenced by clang::format::TokenAnnotator::calculateFormattingInformation().

The number of spaces that should be inserted before this token.

Definition at line 185 of file FormatToken.h.

Referenced by clang::format::TokenAnnotator::annotate(), and clang::format::TokenAnnotator::calculateFormattingInformation().

Penalty for inserting a line break before this token.

Definition at line 232 of file FormatToken.h.

Referenced by clang::format::TokenAnnotator::calculateFormattingInformation().

true if this token starts a binary expression, i.e. has at least one fake l_paren with a precedence greater than prec::Unknown.

Definition at line 252 of file FormatToken.h.

The total length of the unwrapped line up to and including this token.

Definition at line 212 of file FormatToken.h.

Referenced by clang::format::TokenAnnotator::calculateFormattingInformation(), clang::format::CodePointsBetween(), and clang::format::getLengthToMatchingParen().

The length of following tokens until the next natural split point, or the next token that can be broken.

Definition at line 220 of file FormatToken.h.


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