clang 19.0.0git
Public Member Functions | Public Attributes | List of all members
clang::format::FormatToken Struct Reference

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

#include "/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/Format/FormatToken.h"

Public Member Functions

 FormatToken ()
 
BraceBlockKind getBlockKind () const
 
void setBlockKind (BraceBlockKind BBK)
 
FormatDecision getDecision () const
 
void setDecision (FormatDecision D)
 
ParameterPackingKind getPackingKind () const
 
void setPackingKind (ParameterPackingKind K)
 
TokenType getType () const
 Returns the token's type, e.g.
 
void setType (TokenType T)
 
void setFinalizedType (TokenType T)
 Sets the type and also the finalized flag.
 
void overwriteFixedType (TokenType T)
 
bool isTypeFinalized () const
 
bool is (tok::TokenKind Kind) const
 
bool is (TokenType TT) const
 
bool is (const IdentifierInfo *II) const
 
bool is (tok::PPKeywordKind Kind) const
 
bool is (BraceBlockKind BBK) const
 
bool is (ParameterPackingKind PPK) const
 
template<typename A , typename B >
bool isOneOf (A K1, B K2) const
 
template<typename A , typename B , typename... Ts>
bool isOneOf (A K1, B K2, Ts... Ks) const
 
template<typename T >
bool isNot (T Kind) const
 
bool isIf (bool AllowConstexprMacro=true) const
 
bool closesScopeAfterBlock () const
 
template<typename A , typename... Ts>
bool startsSequence (A K1, Ts... Tokens) const
 true if this token starts a sequence with the given tokens in order, following the Next pointers, ignoring comments.
 
template<typename A , typename... Ts>
bool endsSequence (A K1, Ts... Tokens) const
 true if this token ends a sequence with the given tokens in order, following the Previous pointers, ignoring comments.
 
bool isStringLiteral () const
 
bool isAttribute () const
 
bool isObjCAtKeyword (tok::ObjCKeywordKind Kind) const
 
bool isAccessSpecifier (bool ColonRequired=true) const
 
bool canBePointerOrReferenceQualifier () const
 
bool isSimpleTypeSpecifier () const
 Determine whether the token is a simple-type-specifier.
 
bool isTypeName () const
 
bool isTypeOrIdentifier () const
 
bool isObjCAccessSpecifier () const
 
bool opensScope () const
 Returns whether Tok is ([{ or an opening < of a template or in protos.
 
bool closesScope () const
 Returns whether Tok is )]} or a closing > of a template or in protos.
 
bool isMemberAccess () const
 Returns true if this is a "." or "->" accessing a member.
 
bool isPointerOrReference () const
 
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.
 
bool isLabelString () const
 Returns true if this is a string literal that's like a label, e.g.
 
SourceLocation getStartOfNonWhitespace () const
 Returns actual token start location without leading escaped newlines and whitespace.
 
bool hasWhitespaceBefore () const
 Returns true if the range of whitespace immediately preceding the Token is not empty.
 
prec::Level getPrecedence () const
 
FormatTokengetPreviousNonComment () const
 Returns the previous token ignoring comments.
 
FormatTokengetNextNonComment () const
 Returns the next token ignoring comments.
 
bool isBlockIndentedInitRBrace (const FormatStyle &Style) const
 Returns true if this token ends a block indented initializer list.
 
bool opensBlockOrBlockTypeList (const FormatStyle &Style) const
 Returns true if this tokens starts a block-type list, i.e.
 
bool isCppStructuredBinding () const
 Returns whether the token is the left square bracket of a C++ structured binding declaration.
 
bool closesBlockOrBlockTypeList (const FormatStyle &Style) const
 Same as opensBlockOrBlockTypeList, but for the closing token.
 
const FormatTokengetNamespaceToken () const
 Return the actual namespace token, if this token starts a namespace block.
 
void copyFrom (const FormatToken &Tok)
 

Public Attributes

Token Tok
 The Token.
 
StringRef TokenText
 The raw text of the token.
 
std::shared_ptr< TokenRoleRole
 A token can have a special role that can carry extra information about the token's formatting.
 
SourceRange WhitespaceRange
 The range of the whitespace immediately preceding the Token.
 
unsigned HasUnescapedNewline: 1
 Whether there is at least one unescaped newline before the Token.
 
unsigned IsMultiline: 1
 Whether the token text contains newlines (escaped or not).
 
unsigned IsFirst: 1
 Indicates that this is the first token of the file.
 
unsigned MustBreakBefore: 1
 Whether there must be a line break before this token.
 
unsigned MustBreakBeforeFinalized: 1
 Whether MustBreakBefore is finalized during parsing and must not be reset between runs.
 
unsigned IsUnterminatedLiteral: 1
 Set to true if this token is an unterminated literal.
 
unsigned CanBreakBefore: 1
 true if it is allowed to break before this token.
 
unsigned ClosesTemplateDeclaration: 1
 true if this is the ">" of "template<..>".
 
unsigned StartsBinaryExpression: 1
 true if this token starts a binary expression, i.e.
 
unsigned EndsBinaryExpression: 1
 true if this token ends a binary expression.
 
unsigned PartOfMultiVariableDeclStmt: 1
 Is this token part of a DeclStmt defining multiple variables?
 
unsigned ContinuesLineCommentSection: 1
 Does this line comment continue a line comment section?
 
unsigned Finalized: 1
 If true, this token has been fully formatted (indented and potentially re-formatted inside), and we do not allow further formatting changes.
 
unsigned ClosesRequiresClause: 1
 true if this is the last token within requires clause.
 
unsigned EndsCppAttributeGroup: 1
 true if this token ends a group of C++ attributes.
 
prec::Level ForcedPrecedence = prec::Unknown
 Used to set an operator precedence explicitly.
 
unsigned NewlinesBefore = 0
 The number of newlines immediately before the Token.
 
int Newlines = -1
 The number of newlines immediately before the Token after formatting.
 
unsigned LastNewlineOffset = 0
 The offset just past the last '
' in this token's leading whitespace (relative to WhiteSpaceStart).
 
unsigned ColumnWidth = 0
 The width of the non-whitespace parts of the token (or its first line for multi-line tokens) in columns.
 
unsigned LastLineColumnWidth = 0
 Contains the width in columns of the last line of a multi-line token.
 
unsigned SpacesRequiredBefore = 0
 The number of spaces that should be inserted before this token.
 
unsigned ParameterCount = 0
 Number of parameters, if this is "(", "[" or "<".
 
unsigned BlockParameterCount = 0
 Number of parameters that are nested blocks, if this is "(", "[" or "<".
 
tok::TokenKind ParentBracket = tok::unknown
 If this is a bracket ("<", "(", "[" or "{"), contains the kind of the surrounding bracket.
 
unsigned TotalLength = 0
 The total length of the unwrapped line up to and including this token.
 
unsigned OriginalColumn = 0
 The original 0-based column of this token, including expanded tabs.
 
unsigned UnbreakableTailLength = 0
 The length of following tokens until the next natural split point, or the next token that can be broken.
 
unsigned BindingStrength = 0
 The binding strength of a token.
 
unsigned NestingLevel = 0
 The nesting level of this token, i.e.
 
unsigned IndentLevel = 0
 The indent level of this token. Copied from the surrounding line.
 
unsigned SplitPenalty = 0
 Penalty for inserting a line break before this token.
 
unsigned LongestObjCSelectorName = 0
 If this is the first ObjC selector name in an ObjC method definition or call, this contains the length of the longest name.
 
unsigned ObjCSelectorNameParts = 0
 If this is the first ObjC selector name in an ObjC method definition or call, this contains the number of parts that the whole selector consist of.
 
unsigned ParameterIndex = 0
 The 0-based index of the parameter/argument.
 
SmallVector< prec::Level, 4 > FakeLParens
 Stores the number of required fake parentheses and the corresponding operator precedence.
 
unsigned FakeRParens = 0
 Insert this many fake ) after this token for correct indentation.
 
unsigned OperatorIndex = 0
 If this is an operator (or "."/"->") in a sequence of operators with the same precedence, contains the 0-based operator index.
 
FormatTokenNextOperator = nullptr
 If this is an operator (or "."/"->") in a sequence of operators with the same precedence, points to the next operator.
 
FormatTokenMatchingParen = nullptr
 If this is a bracket, this points to the matching one.
 
FormatTokenPrevious = nullptr
 The previous token in the unwrapped line.
 
FormatTokenNext = nullptr
 The next token in the unwrapped line.
 
bool StartsColumn = false
 The first token in set of column elements.
 
bool ArrayInitializerLineStart = false
 This notes the start of the line of an array initializer.
 
bool IsArrayInitializer = false
 This starts an array initializer.
 
bool Optional = false
 Is optional and can be removed.
 
int8_t BraceCount = 0
 Number of optional braces to be inserted after this token: -1: a single left brace 0: no braces >0: number of right braces.
 
SmallVector< AnnotatedLine *, 1 > Children
 If this token starts a block, this contains all the unwrapped lines in it.
 
std::optional< MacroExpansionMacroCtx
 
bool MacroParent = false
 When macro expansion introduces nodes with children, those are marked as MacroParent.
 

Detailed Description

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

Definition at line 283 of file FormatToken.h.

Constructor & Destructor Documentation

◆ FormatToken()

clang::format::FormatToken::FormatToken ( )
inline

Definition at line 284 of file FormatToken.h.

Member Function Documentation

◆ canBePointerOrReferenceQualifier()

bool clang::format::FormatToken::canBePointerOrReferenceQualifier ( ) const
inline

Definition at line 663 of file FormatToken.h.

◆ closesBlockOrBlockTypeList()

bool clang::format::FormatToken::closesBlockOrBlockTypeList ( const FormatStyle Style) const
inline

Same as opensBlockOrBlockTypeList, but for the closing token.

Definition at line 833 of file FormatToken.h.

◆ closesScope()

bool clang::format::FormatToken::closesScope ( ) const
inline

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

Definition at line 698 of file FormatToken.h.

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

◆ closesScopeAfterBlock()

bool clang::format::FormatToken::closesScopeAfterBlock ( ) const
inline

Definition at line 618 of file FormatToken.h.

References endsSequence(), and is().

◆ copyFrom()

void clang::format::FormatToken::copyFrom ( const FormatToken Tok)
inline

Definition at line 854 of file FormatToken.h.

Referenced by clang::format::MacroExpander::expand().

◆ endsSequence()

template<typename A , typename... Ts>
bool clang::format::FormatToken::endsSequence ( K1,
Ts...  Tokens 
) const
inline

true if this token ends a sequence with the given tokens in order, following the Previous pointers, ignoring comments.

For example, given tokens [T1, T2, T3], the function returns true if 3 tokens ending at this (ignoring comments) are [T3, T2, T1]. In other words, the tokens passed to this function need to the reverse of the order the tokens appear in code.

Definition at line 640 of file FormatToken.h.

Referenced by clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), closesScopeAfterBlock(), and clang::format::AnnotatedLine::endsWith().

◆ getBlockKind()

BraceBlockKind clang::format::FormatToken::getBlockKind ( ) const
inline

Definition at line 375 of file FormatToken.h.

Referenced by opensBlockOrBlockTypeList().

◆ getDecision()

FormatDecision clang::format::FormatToken::getDecision ( ) const
inline

Definition at line 388 of file FormatToken.h.

◆ getNamespaceToken()

const FormatToken * clang::format::FormatToken::getNamespaceToken ( ) const
inline

Return the actual namespace token, if this token starts a namespace block.

Definition at line 841 of file FormatToken.h.

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

◆ getNextNonComment()

FormatToken * clang::format::FormatToken::getNextNonComment ( ) const
inline

◆ getPackingKind()

ParameterPackingKind clang::format::FormatToken::getPackingKind ( ) const
inline

Definition at line 401 of file FormatToken.h.

Referenced by isOneOf().

◆ getPrecedence()

prec::Level clang::format::FormatToken::getPrecedence ( ) const
inline

◆ getPreviousNonComment()

FormatToken * clang::format::FormatToken::getPreviousNonComment ( ) const
inline

◆ getStartOfNonWhitespace()

SourceLocation clang::format::FormatToken::getStartOfNonWhitespace ( ) const
inline

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 779 of file FormatToken.h.

Referenced by clang::format::LeftRightQualifierAlignmentFixer::analyzeRight(), and clang::format::WhitespaceManager::replaceWhitespaceInToken().

◆ getType()

TokenType clang::format::FormatToken::getType ( ) const
inline

Returns the token's type, e.g.

whether "<" is a template opener or binary operator.

Definition at line 416 of file FormatToken.h.

◆ hasWhitespaceBefore()

bool clang::format::FormatToken::hasWhitespaceBefore ( ) const
inline

Returns true if the range of whitespace immediately preceding the Token is not empty.

Definition at line 785 of file FormatToken.h.

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

◆ is() [1/6]

bool clang::format::FormatToken::is ( BraceBlockKind  BBK) const
inline

Definition at line 601 of file FormatToken.h.

◆ is() [2/6]

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

Definition at line 594 of file FormatToken.h.

◆ is() [3/6]

bool clang::format::FormatToken::is ( ParameterPackingKind  PPK) const
inline

Definition at line 602 of file FormatToken.h.

◆ is() [4/6]

bool clang::format::FormatToken::is ( tok::PPKeywordKind  Kind) const
inline

Definition at line 597 of file FormatToken.h.

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

◆ is() [5/6]

bool clang::format::FormatToken::is ( tok::TokenKind  Kind) const
inline

Definition at line 592 of file FormatToken.h.

Referenced by clang::format::NamespaceEndCommentsFixer::analyze(), clang::format::JavaScriptImportSorter::analyze(), clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), clang::format::LeftRightQualifierAlignmentFixer::analyzeRight(), clang::format::BreakableBlockComment::BreakableBlockComment(), clang::format::BreakableLineCommentSection::BreakableLineCommentSection(), clang::format::TokenAnnotator::calculateFormattingInformation(), closesScopeAfterBlock(), clang::format::computeNewlines(), clang::format::continuesLineCommentSection(), clang::format::UnwrappedLineFormatter::format(), clang::format::CommaSeparatedList::formatAfterToken(), clang::format::AnnotatedLine::getFirstNonComment(), clang::format::getFunctionName(), clang::format::AnnotatedLine::getLastNonComment(), clang::format::getNamespaceToken(), clang::format::hasNestedBlockInlined(), clang::format::isAllmanBrace(), clang::format::isAllmanLambdaBrace(), isBlockIndentedInitRBrace(), clang::format::AnnotatedLine::isComment(), clang::format::LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(), clang::format::isCtorOrDtorName(), clang::format::isFunctionDeclarationName(), isIf(), clang::format::LeftRightQualifierAlignmentFixer::isQualifierOrType(), isTypeName(), clang::format::markOptionalBraces(), clang::format::mustBeJSIdent(), clang::format::ContinuationIndenter::mustBreak(), opensBlockOrBlockTypeList(), clang::format::opensProtoMessageField(), clang::format::MacroExpander::DefinitionParser::parse(), clang::format::CommaSeparatedList::precomputeFormattingInfos(), clang::format::ShouldBreakBeforeBrace(), and clang::format::startsNextParameter().

◆ is() [6/6]

bool clang::format::FormatToken::is ( TokenType  TT) const
inline

Definition at line 593 of file FormatToken.h.

◆ isAccessSpecifier()

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

Definition at line 654 of file FormatToken.h.

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

◆ isAttribute()

bool clang::format::FormatToken::isAttribute ( ) const
inline

Definition at line 646 of file FormatToken.h.

◆ isBinaryOperator()

bool clang::format::FormatToken::isBinaryOperator ( ) const
inline

Definition at line 734 of file FormatToken.h.

◆ isBlockIndentedInitRBrace()

bool clang::format::FormatToken::isBlockIndentedInitRBrace ( const FormatStyle Style) const

Returns true if this token ends a block indented initializer list.

Definition at line 91 of file FormatToken.cpp.

References clang::format::FormatStyle::BAS_BlockIndent, clang::format::BK_BracedInit, is(), and MatchingParen.

◆ isCppStructuredBinding()

bool clang::format::FormatToken::isCppStructuredBinding ( ) const
inline

Returns whether the token is the left square bracket of a C++ structured binding declaration.

Definition at line 821 of file FormatToken.h.

◆ isFunctionLikeKeyword()

bool clang::format::FormatToken::isFunctionLikeKeyword ( ) const
inline

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

sizeof, typeid, ...).

Definition at line 746 of file FormatToken.h.

◆ isIf()

bool clang::format::FormatToken::isIf ( bool  AllowConstexprMacro = true) const
inline

Definition at line 613 of file FormatToken.h.

References is(), and isOneOf().

◆ isLabelString()

bool clang::format::FormatToken::isLabelString ( ) const
inline

Returns true if this is a string literal that's like a label, e.g.

ends with "=" or ":".

Definition at line 761 of file FormatToken.h.

◆ isMemberAccess()

bool clang::format::FormatToken::isMemberAccess ( ) const
inline

Returns true if this is a "." or "->" accessing a member.

Definition at line 708 of file FormatToken.h.

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

◆ isNot()

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

◆ isObjCAccessSpecifier()

bool clang::format::FormatToken::isObjCAccessSpecifier ( ) const
inline

Definition at line 678 of file FormatToken.h.

◆ isObjCAtKeyword()

bool clang::format::FormatToken::isObjCAtKeyword ( tok::ObjCKeywordKind  Kind) const
inline

Definition at line 650 of file FormatToken.h.

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

◆ isOneOf() [1/2]

template<typename A , typename B >
bool clang::format::FormatToken::isOneOf ( K1,
K2 
) const
inline

◆ isOneOf() [2/2]

template<typename A , typename B , typename... Ts>
bool clang::format::FormatToken::isOneOf ( K1,
K2,
Ts...  Ks 
) const
inline

Definition at line 608 of file FormatToken.h.

References getPackingKind().

◆ isPointerOrReference()

bool clang::format::FormatToken::isPointerOrReference ( ) const
inline

Definition at line 714 of file FormatToken.h.

References isOneOf().

Referenced by clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft().

◆ isSimpleTypeSpecifier()

bool clang::format::FormatToken::isSimpleTypeSpecifier ( ) const

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

Definition at line 38 of file FormatToken.cpp.

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

Referenced by isTypeName().

◆ isStringLiteral()

bool clang::format::FormatToken::isStringLiteral ( ) const
inline

Definition at line 644 of file FormatToken.h.

◆ isTrailingComment()

bool clang::format::FormatToken::isTrailingComment ( ) const
inline

◆ isTypeFinalized()

bool clang::format::FormatToken::isTypeFinalized ( ) const
inline

Definition at line 443 of file FormatToken.h.

References MacroCtx, and clang::format::MR_UnexpandedArg.

◆ isTypeName()

bool clang::format::FormatToken::isTypeName ( ) const

◆ isTypeOrIdentifier()

bool clang::format::FormatToken::isTypeOrIdentifier ( ) const

Definition at line 87 of file FormatToken.cpp.

References isOneOf(), and isTypeName().

◆ isUnaryOperator()

bool clang::format::FormatToken::isUnaryOperator ( ) const
inline

Definition at line 718 of file FormatToken.h.

◆ opensBlockOrBlockTypeList()

bool clang::format::FormatToken::opensBlockOrBlockTypeList ( 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.

Definition at line 106 of file FormatToken.cpp.

References clang::format::BK_Block, clang::format::BK_BracedInit, getBlockKind(), is(), NestingLevel, and opensScope().

◆ opensScope()

bool clang::format::FormatToken::opensScope ( ) const
inline

Returns whether Tok is ([{ or an opening < of a template or in protos.

Definition at line 688 of file FormatToken.h.

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

◆ overwriteFixedType()

void clang::format::FormatToken::overwriteFixedType ( TokenType  T)
inline

Definition at line 437 of file FormatToken.h.

References MacroCtx, and clang::format::MR_UnexpandedArg.

◆ setBlockKind()

void clang::format::FormatToken::setBlockKind ( BraceBlockKind  BBK)
inline

Definition at line 378 of file FormatToken.h.

◆ setDecision()

void clang::format::FormatToken::setDecision ( FormatDecision  D)
inline

Definition at line 391 of file FormatToken.h.

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

◆ setFinalizedType()

void clang::format::FormatToken::setFinalizedType ( TokenType  T)
inline

Sets the type and also the finalized flag.

This prevents the type to be reset in TokenAnnotator::resetTokenMetadata(). If the type needs to be set to another one please use overwriteFixedType, or even better remove the need to reassign the type.

Definition at line 431 of file FormatToken.h.

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

◆ setPackingKind()

void clang::format::FormatToken::setPackingKind ( ParameterPackingKind  K)
inline

Definition at line 404 of file FormatToken.h.

◆ setType()

void clang::format::FormatToken::setType ( TokenType  T)
inline

Definition at line 417 of file FormatToken.h.

◆ startsSequence()

template<typename A , typename... Ts>
bool clang::format::FormatToken::startsSequence ( K1,
Ts...  Tokens 
) const
inline

true if this token starts a sequence with the given tokens in order, following the Next pointers, ignoring comments.

Definition at line 629 of file FormatToken.h.

Referenced by clang::format::AnnotatedLine::startsWith().

Member Data Documentation

◆ ArrayInitializerLineStart

bool clang::format::FormatToken::ArrayInitializerLineStart = false

This notes the start of the line of an array initializer.

Definition at line 561 of file FormatToken.h.

◆ BindingStrength

unsigned clang::format::FormatToken::BindingStrength = 0

The binding strength of a token.

This is a combined value of operator precedence, parenthesis nesting, etc.

Definition at line 502 of file FormatToken.h.

◆ BlockParameterCount

unsigned clang::format::FormatToken::BlockParameterCount = 0

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

Definition at line 481 of file FormatToken.h.

◆ BraceCount

int8_t clang::format::FormatToken::BraceCount = 0

Number of optional braces to be inserted after this token: -1: a single left brace 0: no braces >0: number of right braces.

Definition at line 573 of file FormatToken.h.

◆ CanBreakBefore

unsigned clang::format::FormatToken::CanBreakBefore

true if it is allowed to break before this token.

Definition at line 338 of file FormatToken.h.

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

◆ Children

SmallVector<AnnotatedLine *, 1> clang::format::FormatToken::Children

If this token starts a block, this contains all the unwrapped lines in it.

Definition at line 577 of file FormatToken.h.

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

◆ ClosesRequiresClause

unsigned clang::format::FormatToken::ClosesRequiresClause

true if this is the last token within requires clause.

Definition at line 365 of file FormatToken.h.

Referenced by clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), and clang::format::LeftRightQualifierAlignmentFixer::analyzeRight().

◆ ClosesTemplateDeclaration

unsigned clang::format::FormatToken::ClosesTemplateDeclaration

true if this is the ">" of "template<..>".

Definition at line 341 of file FormatToken.h.

Referenced by clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), and clang::format::LeftRightQualifierAlignmentFixer::analyzeRight().

◆ ColumnWidth

unsigned clang::format::FormatToken::ColumnWidth = 0

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 467 of file FormatToken.h.

◆ ContinuesLineCommentSection

unsigned clang::format::FormatToken::ContinuesLineCommentSection

Does this line comment continue a line comment section?

Only set to true if Type == TT_LineComment.

Definition at line 357 of file FormatToken.h.

◆ EndsBinaryExpression

unsigned clang::format::FormatToken::EndsBinaryExpression

true if this token ends a binary expression.

Definition at line 347 of file FormatToken.h.

◆ EndsCppAttributeGroup

unsigned clang::format::FormatToken::EndsCppAttributeGroup

true if this token ends a group of C++ attributes.

Definition at line 368 of file FormatToken.h.

◆ FakeLParens

SmallVector<prec::Level, 4> clang::format::FormatToken::FakeLParens

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 536 of file FormatToken.h.

◆ FakeRParens

unsigned clang::format::FormatToken::FakeRParens = 0

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

Definition at line 538 of file FormatToken.h.

◆ Finalized

unsigned clang::format::FormatToken::Finalized

◆ ForcedPrecedence

prec::Level clang::format::FormatToken::ForcedPrecedence = prec::Unknown

Used to set an operator precedence explicitly.

Definition at line 446 of file FormatToken.h.

◆ HasUnescapedNewline

unsigned clang::format::FormatToken::HasUnescapedNewline

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

Definition at line 316 of file FormatToken.h.

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

◆ IndentLevel

unsigned clang::format::FormatToken::IndentLevel = 0

The indent level of this token. Copied from the surrounding line.

Definition at line 509 of file FormatToken.h.

Referenced by clang::format::WhitespaceManager::Change::indentAndNestingLevel().

◆ IsArrayInitializer

bool clang::format::FormatToken::IsArrayInitializer = false

This starts an array initializer.

Definition at line 564 of file FormatToken.h.

◆ IsFirst

unsigned clang::format::FormatToken::IsFirst

◆ IsMultiline

unsigned clang::format::FormatToken::IsMultiline

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

Definition at line 319 of file FormatToken.h.

◆ IsUnterminatedLiteral

unsigned clang::format::FormatToken::IsUnterminatedLiteral

Set to true if this token is an unterminated literal.

Definition at line 335 of file FormatToken.h.

◆ LastLineColumnWidth

unsigned clang::format::FormatToken::LastLineColumnWidth = 0

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

Definition at line 471 of file FormatToken.h.

◆ LastNewlineOffset

unsigned clang::format::FormatToken::LastNewlineOffset = 0

The offset just past the last '
' in this token's leading whitespace (relative to WhiteSpaceStart).

0 if there is no '
'.

Definition at line 462 of file FormatToken.h.

◆ LongestObjCSelectorName

unsigned clang::format::FormatToken::LongestObjCSelectorName = 0

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 519 of file FormatToken.h.

◆ MacroCtx

std::optional<MacroExpansion> clang::format::FormatToken::MacroCtx

◆ MacroParent

bool clang::format::FormatToken::MacroParent = false

When macro expansion introduces nodes with children, those are marked as MacroParent.

FIXME: The formatting code currently hard-codes the assumption that child nodes are introduced by blocks following an opening brace. This is deeply baked into the code and disentangling this will require signficant refactorings. MacroParent allows us to special-case the cases in which we treat parents as block-openers for now.

Definition at line 590 of file FormatToken.h.

◆ MatchingParen

FormatToken* clang::format::FormatToken::MatchingParen = nullptr

◆ MustBreakBefore

unsigned clang::format::FormatToken::MustBreakBefore

Whether there must be a line break before this token.

This happens for example when a preprocessor directive ended directly before the token.

Definition at line 328 of file FormatToken.h.

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

◆ MustBreakBeforeFinalized

unsigned clang::format::FormatToken::MustBreakBeforeFinalized

Whether MustBreakBefore is finalized during parsing and must not be reset between runs.

Definition at line 332 of file FormatToken.h.

◆ NestingLevel

unsigned clang::format::FormatToken::NestingLevel = 0

The nesting level of this token, i.e.

the number of surrounding (), [], {} or <>.

Definition at line 506 of file FormatToken.h.

Referenced by clang::format::WhitespaceManager::Change::indentAndNestingLevel(), clang::format::isFunctionDeclarationName(), opensBlockOrBlockTypeList(), and clang::format::opensProtoMessageField().

◆ Newlines

int clang::format::FormatToken::Newlines = -1

The number of newlines immediately before the Token after formatting.

This is used to avoid overlapping whitespace replacements when Newlines is recomputed for a finalized preprocessor branching directive.

Definition at line 458 of file FormatToken.h.

◆ NewlinesBefore

unsigned clang::format::FormatToken::NewlinesBefore = 0

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 452 of file FormatToken.h.

Referenced by clang::format::WhitespaceManager::addUntouchableToken(), clang::format::NamespaceEndCommentsFixer::analyze(), clang::format::JavaScriptImportSorter::analyze(), clang::format::UnwrappedLineFormatter::format(), clang::format::mustBreakAfterAttributes(), and clang::format::TokenAnnotator::setCommentLineLevels().

◆ Next

FormatToken* clang::format::FormatToken::Next = nullptr

◆ NextOperator

FormatToken* clang::format::FormatToken::NextOperator = nullptr

If this is an operator (or "."/"->") in a sequence of operators with the same precedence, points to the next operator.

Definition at line 546 of file FormatToken.h.

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

◆ ObjCSelectorNameParts

unsigned clang::format::FormatToken::ObjCSelectorNameParts = 0

If this is the first ObjC selector name in an ObjC method definition or call, this contains the number of parts that the whole selector consist of.

Definition at line 524 of file FormatToken.h.

◆ OperatorIndex

unsigned clang::format::FormatToken::OperatorIndex = 0

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

Definition at line 542 of file FormatToken.h.

◆ Optional

bool clang::format::FormatToken::Optional = false

Is optional and can be removed.

Definition at line 567 of file FormatToken.h.

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

◆ OriginalColumn

unsigned clang::format::FormatToken::OriginalColumn = 0

The original 0-based column of this token, including expanded tabs.

The configured TabWidth is used as tab width.

Definition at line 493 of file FormatToken.h.

Referenced by clang::format::WhitespaceManager::addUntouchableToken(), clang::format::UnwrappedLineFormatter::format(), and clang::format::TokenAnnotator::setCommentLineLevels().

◆ ParameterCount

unsigned clang::format::FormatToken::ParameterCount = 0

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

Definition at line 477 of file FormatToken.h.

◆ ParameterIndex

unsigned clang::format::FormatToken::ParameterIndex = 0

The 0-based index of the parameter/argument.

For ObjC it is set for the selector name token. For now calculated only for ObjC.

Definition at line 529 of file FormatToken.h.

◆ ParentBracket

tok::TokenKind clang::format::FormatToken::ParentBracket = tok::unknown

If this is a bracket ("<", "(", "[" or "{"), contains the kind of the surrounding bracket.

Definition at line 485 of file FormatToken.h.

◆ PartOfMultiVariableDeclStmt

unsigned clang::format::FormatToken::PartOfMultiVariableDeclStmt

Is this token part of a DeclStmt defining multiple variables?

Only set if Type == TT_StartOfName.

Definition at line 352 of file FormatToken.h.

◆ Previous

FormatToken* clang::format::FormatToken::Previous = nullptr

◆ Role

std::shared_ptr<TokenRole> clang::format::FormatToken::Role

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

FIXME: Make FormatToken for parsing and AnnotatedToken two different classes and make this a unique_ptr in the AnnotatedToken class.

Definition at line 309 of file FormatToken.h.

◆ SpacesRequiredBefore

unsigned clang::format::FormatToken::SpacesRequiredBefore = 0

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

Definition at line 474 of file FormatToken.h.

◆ SplitPenalty

unsigned clang::format::FormatToken::SplitPenalty = 0

Penalty for inserting a line break before this token.

Definition at line 512 of file FormatToken.h.

◆ StartsBinaryExpression

unsigned clang::format::FormatToken::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.

Definition at line 345 of file FormatToken.h.

◆ StartsColumn

bool clang::format::FormatToken::StartsColumn = false

The first token in set of column elements.

Definition at line 558 of file FormatToken.h.

◆ Tok

Token clang::format::FormatToken::Tok

◆ TokenText

StringRef clang::format::FormatToken::TokenText

◆ TotalLength

unsigned clang::format::FormatToken::TotalLength = 0

◆ UnbreakableTailLength

unsigned clang::format::FormatToken::UnbreakableTailLength = 0

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

Definition at line 497 of file FormatToken.h.

◆ WhitespaceRange

SourceRange clang::format::FormatToken::WhitespaceRange

The range of the whitespace immediately preceding the Token.

Definition at line 312 of file FormatToken.h.

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


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