clang: lib/Format/FormatToken.h File Reference (original) (raw)

This file contains the declaration of the FormatToken, a wrapper around Token with additional information related to formatting. More...

#include "[clang/Basic/IdentifierTable.h](IdentifierTable%5F8h%5Fsource.html)"
#include "[clang/Basic/OperatorPrecedence.h](OperatorPrecedence%5F8h%5Fsource.html)"
#include "[clang/Format/Format.h](Format%5F8h%5Fsource.html)"
#include "[clang/Lex/Lexer.h](Lexer%5F8h%5Fsource.html)"
#include <unordered_set>
#include "clang/Basic/TransformTypeTraits.def"
#include "clang/Basic/TokenKinds.def"

Go to the source code of this file.

Classes
struct clang::format::MacroExpansion
Contains information on the token's role in a macro expansion. More...
struct clang::format::FormatToken
A wrapper around a Token storing information about the whitespace characters preceding it. More...
class clang::TokenRole
class clang::CommaSeparatedList
struct clang::AdditionalKeywords
Encapsulates keywords that are context sensitive or for languages not properly supported by Clang's lexer. More...
Namespaces
namespace clang
The JSON file list parser is used to communicate input to InstallAPI.
namespace clang::format
Macros
#define LIST_TOKEN_TYPES
#define TYPE(X)
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait)
#define KEYWORD(X, Y)
Enumerations
enum clang::format::TokenType : uint8_t { clang::format::NUM_TOKEN_TYPES }
Determines the semantic type of a syntactic token, e.g. More...
enum clang::format::BraceBlockKind { clang::format::BK_Unknown, clang::format::BK_Block, clang::format::BK_BracedInit }
enum clang::format::ParameterPackingKind { clang::format::PPK_BinPacked, clang::format::PPK_OnePerLine, clang::format::PPK_Inconclusive }
enum clang::format::FormatDecision { clang::format::FD_Unformatted, clang::format::FD_Continue, clang::format::FD_Break }
enum clang::format::MacroRole { clang::format::MR_ExpandedArg, clang::format::MR_UnexpandedArg, clang::format::MR_Hidden }
Roles a token can take in a configured macro expansion. More...
Functions
const char * clang::format::getTokenTypeName (TokenType Type)
Determines the name of a token type.
struct clang::format::FormatToken clang::format::getPreviousNonComment () const
Returns the previous token ignoring comments.
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 (tok::ObjCKeywordKind 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
bool isNot (T Kind) const
template<typename... Ts>
bool isNoneOf (Ts... Ks) const
bool isIf (bool AllowConstexprMacro=true) const
bool isLoop (const FormatStyle &Style) const
bool closesScopeAfterBlock () const
FormatToken * clang::format::getNextNonComment () const
Returns the next token ignoring comments.
bool clang::format::isBlockIndentedInitRBrace (const FormatStyle &Style) const
Returns true if this token ends a block indented initializer list.
bool clang::format::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.
bool clang::format::isCppStructuredBinding (bool IsCpp) const
Returns whether the token is the left square bracket of a C++ structured binding declaration.
bool clang::format::closesBlockOrBlockTypeList (const FormatStyle &Style) const
Same as opensBlockOrBlockTypeList, but for the closing token.
const FormatToken * clang::format::getNamespaceToken () const
Return the actual namespace token, if this token starts a namespace block.
void clang::format::copyFrom (const FormatToken &Tok)
bool clang::isLineComment (const FormatToken &FormatTok)
bool clang::continuesLineComment (const FormatToken &FormatTok, const FormatToken *Previous, const FormatToken *MinColumnToken)
bool clang::startsNextParameter (const FormatToken &Current, const FormatStyle &Style)
Variables
Token Tok
The Token.
StringRef TokenText
The raw text of the token.
std::shared_ptr< TokenRole > Role
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
Whether there is at least one unescaped newline before the Token.
unsigned IsMultiline
Whether the token text contains newlines (escaped or not).
unsigned IsFirst
Indicates that this is the first token of the file.
unsigned MustBreakBefore
Whether there must be a line break before this token.
unsigned MustBreakBeforeFinalized
Whether MustBreakBefore is finalized during parsing and must not be reset between runs.
unsigned IsUnterminatedLiteral
Set to true if this token is an unterminated literal.
unsigned CanBreakBefore
true if it is allowed to break before this token.
unsigned ClosesTemplateDeclaration
true if this is the ">" of "template<..>".
unsigned StartsBinaryExpression
true if this token starts a binary expression, i.e.
unsigned EndsBinaryExpression
true if this token ends a binary expression.
unsigned PartOfMultiVariableDeclStmt
Is this token part of a DeclStmt defining multiple variables?
unsigned ContinuesLineCommentSection
Does this line comment continue a line comment section?
unsigned Finalized
If true, this token has been fully formatted (indented and potentially re-formatted inside), and we do not allow further formatting changes.
unsigned ClosesRequiresClause
true if this is the last token within requires clause.
unsigned EndsCppAttributeGroup
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.
FormatToken * NextOperator = nullptr
If this is an operator (or "."/"->") in a sequence of operators with the same precedence, points to the next operator.
FormatToken * MatchingParen = nullptr
If this is a bracket, this points to the matching one.
FormatToken * Previous = nullptr
The previous token in the unwrapped line.
FormatToken * Next = 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.
bool MightBeFunctionDeclParen = false
Might be function declaration open/closing paren.
bool HasFormFeedBefore = false
Has "\n\f\n" or "\n\f\r\n" before TokenText.
bool FirstAfterPPLine = false
Is the first token after a preprocessor line.
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< MacroExpansion > MacroCtx
bool MacroParent = false
When macro expansion introduces nodes with children, those are marked as MacroParent.
true
true if this token starts a sequence with the given tokens in order, following the Next pointers, ignoring comments.

This file contains the declaration of the FormatToken, a wrapper around Token with additional information related to formatting.

Definition in file FormatToken.h.

KEYWORD

LIST_TOKEN_TYPES

TRANSFORM_TYPE_TRAIT_DEF

#define TRANSFORM_TYPE_TRAIT_DEF ( _,
Trait )

TYPE

closesScopeAfterBlock()

bool getPreviousNonComment::closesScopeAfterBlock ( ) const
getPreviousNonComment::FormatToken ( )

Definition at line 852 of file FormatToken.h.

References WhitespaceRange.

Referenced by clang::CommaSeparatedList::CommaSeparatedList(), clang::CommaSeparatedList::formatAfterToken(), clang::TokenRole::formatFromToken(), clang::AdditionalKeywords::isJavaScriptIdentifier(), clang::AdditionalKeywords::isVerilogEnd(), clang::AdditionalKeywords::isVerilogEndOfLabel(), clang::AdditionalKeywords::isVerilogHierarchy(), clang::AdditionalKeywords::isVerilogStructuredProcedure(), overwriteFixedType(), clang::CommaSeparatedList::precomputeFormattingInfos(), clang::TokenRole::precomputeFormattingInfos(), setFinalizedType(), and clang::startsNextParameter().

getBlockKind()

BraceBlockKind getPreviousNonComment::getBlockKind ( ) const

getDecision()

FormatDecision getPreviousNonComment::getDecision ( ) const

getPackingKind()

ParameterPackingKind getPreviousNonComment::getPackingKind ( ) const

getType()

TokenType getPreviousNonComment::getType ( ) const

Returns the token's type, e.g.

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

Definition at line 984 of file FormatToken.h.

Referenced by clang::SemaObjC::ActOnObjCForCollectionStmt(), clang::Sema::AddBuiltinOperatorCandidates(), clang::Sema::AddOverloadCandidate(), clang::AnyCall::AnyCall(), clang::Sema::AttachBaseSpecifiers(), clang::Sema::BuildCallExpr(), clang::Sema::BuildInitList(), clang::Sema::BuildResolvedCallExpr(), clang::Sema::BuildTypeTrait(), clang::CodeGen::CodeGenFunction::BuildVector(), clang::Sema::BuiltinElementwiseTernaryMath(), clang::Sema::canThrow(), clang::Sema::CheckArgsForPlaceholders(), CheckLValueConstantExpression(), clang::Sema::CheckNonDependentConversions(), ClassifyInternal(), CompleteNonViableCandidate(), clang::driver::tools::Clang::ConstructJob(), clang::CoroutineStmtBuilder::CoroutineStmtBuilder(), clang::Sema::CreateGenericSelectionExpr(), clang::Sema::CreateOverloadedArraySubscriptExpr(), clang::Sema::CreateOverloadedBinOp(), clang::Sema::DeduceTemplateArguments(), clang::CodeGen::CodeGenFunction::EmitAArch64BuiltinExpr(), clang::CodeGen::CodeGenFunction::EmitAArch64SVEBuiltinExpr(), clang::CodeGen::CodeGenFunction::EmitAMDGPUBuiltinExpr(), clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(), emitBuiltinWithOneOverloadedType(), clang::CodeGen::CodeGenFunction::EmitCall(), clang::CIRGen::CIRGenFunction::emitCall(), EmitCommonNeonSISDBuiltinExpr(), clang::CodeGen::CodeGenModule::EmitGlobalAnnotations(), emitOutlinedFunctionPrologue(), clang::CodeGen::CodeGenFunction::EmitRISCVBuiltinExpr(), emitRVVCreateBuiltin(), emitRVVGetBuiltin(), emitRVVPseudoVWCVTBuiltin(), emitRVVReinterpretBuiltin(), emitRVVSetBuiltin(), EmitScalarFMAExpr(), clang::CodeGen::CodeGenFunction::EmitSVEGatherLoad(), clang::CodeGen::CodeGenFunction::EmitSVEGatherPrefetch(), clang::CodeGen::CodeGenFunction::EmitSVEPMull(), clang::CodeGen::CodeGenFunction::EmitSVEScatterStore(), clang::CodeGen::CodeGenFunction::EmitX86BuiltinExpr(), clang::CIRGen::CIRGenFunction::emitX86BuiltinExpr(), EmitX86CompressExpand(), EmitX86CompressStore(), EmitX86ExpandLoad(), EmitX86FMAExpr(), emitX86MaskAddLogic(), EmitX86MaskedCompare(), EmitX86MaskedStore(), emitX86MaskLogic(), emitX86MaskTest(), emitX86MaskUnpack(), clang::Expr::EvaluateAsConstantExpr(), clang::Expr::EvaluateAsFloat(), EvaluateComparisonBinaryOperator(), clang::VarDecl::evaluateDestruction(), findCompleteObject(), clang::Sema::FindInstantiatedDecl(), clang::CodeGen::CodeGenFunction::GetAddressOfBaseClass(), clang::TypedefNameDecl::getAnonDeclWithTypedefName(), clang::CIRGen::CIRGenBuilderTy::getAnonRecordTy(), clang::CIRGen::CIRGenBuilderTy::getCompleteNamedRecordType(), clang::CXXMethodDecl::getFunctionObjectParameterReferenceType(), clang::CIRGen::CIRGenBuilderTy::getIncompleteRecordTy(), clang::CXXMethodDecl::getThisType(), clang::diff::Node::getTypeLabel(), handlePassObjectSizeAttr(), clang::ASTNodeImporter::ImportAPValue(), clang::InitializationSequence::InitializeFrom(), clang::interp::interp__builtin_object_size(), isDesignatorAtObjectEnd(), isOnePastTheEndOfCompleteObject(), clang::CXXMethodDecl::isUsualDeallocationFunction(), lifetimeStartedInEvaluation(), packTBLDVectorList(), clang::FoldingSetPlaceholder< T >::Profile(), clang::TreeTransform< AdjustConstraintDepth >::RebuildMemberExpr(), clang::dataflow::RecordInitListHelper::RecordInitListHelper(), clang::dataflow::RecordInitListHelper::RecordInitListHelper(), clang::CodeGen::ConstantEmitter::tryEmitPrivate(), clang::Expr::tryEvaluateObjectSize(), clang::TypeOfExprType::TypeOfExprType(), and clang::ento::ExprEngine::Visit().

is() [1/7]

bool getPreviousNonComment::is ( BraceBlockKind BBK ) const

is() [2/7]

bool getPreviousNonComment::is ( const IdentifierInfo * II ) const

is() [3/7]

bool getPreviousNonComment::is ( ParameterPackingKind PPK ) const

is() [4/7]

bool getPreviousNonComment::is ( tok::ObjCKeywordKind Kind ) const

is() [5/7]

bool getPreviousNonComment::is ( tok::PPKeywordKind Kind ) const

is() [6/7]

bool getPreviousNonComment::is ( tok::TokenKind Kind ) const

Examples

/work/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/StaticAnalyzer/Core/RegionStore.cpp.

Definition at line 1169 of file FormatToken.h.

Referenced by GetNextRawTok(), getStorage(), clang::TokenLexer::Init(), clang::TokenLexer::Lex(), clang::Parser::MightBeCXXScopeToken(), clang::Parser::ParseConstraintLogicalAndExpression(), clang::Parser::parseMapTypeModifiers(), clang::Parser::ParseOpenMPVarList(), clang::Parser::ParseUnqualifiedId(), clang::format::IndexedTokenSource::peekNextToken(), clang::RewriteMacrosInInput(), clang::Parser::SkipMalformedDecl(), clang::Parser::TryAnnotateTypeOrScopeToken(), clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(), and clang::ento::tryExpandAsInteger().

is() [7/7]

bool getPreviousNonComment::is ( TokenType TT ) const

isIf()

bool getPreviousNonComment::isIf ( bool AllowConstexprMacro = true ) const

isLoop()

bool getPreviousNonComment::isLoop ( const FormatStyle & Style ) const

isNoneOf()

template<typename... Ts>

bool getPreviousNonComment::isNoneOf ( Ts... Ks ) const

isNot()

template

bool getPreviousNonComment::isNot ( T Kind ) const

isOneOf() [1/2]

template<typename A, typename B>

bool getPreviousNonComment::isOneOf ( A K1,
B K2 ) const

isOneOf() [2/2]

template<typename A, typename B, typename... Ts>

bool getPreviousNonComment::isOneOf ( A K1,
B K2,
Ts... Ks ) const

isTypeFinalized()

bool getPreviousNonComment::isTypeFinalized ( ) const

overwriteFixedType()

void getPreviousNonComment::overwriteFixedType ( TokenType T )

setBlockKind()

void getPreviousNonComment::setBlockKind ( BraceBlockKind BBK )

setDecision()

void getPreviousNonComment::setDecision ( FormatDecision D )

setFinalizedType()

void getPreviousNonComment::setFinalizedType ( TokenType T )

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

References FormatToken().

setPackingKind()

void getPreviousNonComment::setPackingKind ( ParameterPackingKind K )

setType()

void getPreviousNonComment::setType ( TokenType T )

ArrayInitializerLineStart

BindingStrength

The binding strength of a token.

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

Definition at line 1070 of file FormatToken.h.

BlockParameterCount

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

Definition at line 1049 of file FormatToken.h.

BraceCount

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

CanBreakBefore

true if it is allowed to break before this token.

Definition at line 906 of file FormatToken.h.

Children

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

Definition at line 1154 of file FormatToken.h.

Referenced by clang::format::TokenAnnotator::calculateFormattingInformation(), clang::DeclStmt::children(), clang::syntax::createTree(), clang::syntax::deepCopyExpandingMacros(), llvm::IDFCalculatorDetail::ChildrenGetterTy< clang::CFGBlock, IsPostDom >::get(), clang::syntax::CallArguments::getArguments(), clang::syntax::CallArguments::getArgumentsAndCommas(), clang::syntax::DeclaratorList::getDeclarators(), clang::syntax::SimpleDeclaration::getDeclarators(), clang::syntax::DeclaratorList::getDeclaratorsAndCommas(), clang::syntax::List::getElementsAsNodes(), clang::syntax::List::getElementsAsNodesAndDelimiters(), clang::syntax::ParameterDeclarationList::getParameterDeclarations(), clang::syntax::ParameterDeclarationList::getParametersAndCommas(), clang::syntax::NestedNameSpecifier::getSpecifiers(), clang::syntax::NestedNameSpecifier::getSpecifiersAndDoubleColons(), clang::syntax::CompoundStatement::getStatements(), clang::LexicallyOrderedRecursiveASTVisitor< Derived >::getStmtChildren(), print_elem(), and clang::OMPChildren::setChildren().

ClosesRequiresClause

true if this is the last token within requires clause.

Definition at line 933 of file FormatToken.h.

ClosesTemplateDeclaration

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

Definition at line 909 of file FormatToken.h.

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.

Definition at line 1035 of file FormatToken.h.

ContinuesLineCommentSection

Does this line comment continue a line comment section?

Only set to true if Type == TT_LineComment.

Definition at line 925 of file FormatToken.h.

EndsBinaryExpression

true if this token ends a binary expression.

Definition at line 915 of file FormatToken.h.

EndsCppAttributeGroup

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

Definition at line 936 of file FormatToken.h.

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

FakeRParens

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

Definition at line 1106 of file FormatToken.h.

Finalized

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

FirstAfterPPLine

Is the first token after a preprocessor line.

Definition at line 1144 of file FormatToken.h.

ForcedPrecedence

Used to set an operator precedence explicitly.

Definition at line 1014 of file FormatToken.h.

HasFormFeedBefore

Has "\n\f\n" or "\n\f\r\n" before TokenText.

Definition at line 1141 of file FormatToken.h.

HasUnescapedNewline

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

Definition at line 884 of file FormatToken.h.

IndentLevel

IsArrayInitializer

IsFirst

IsMultiline

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

Definition at line 887 of file FormatToken.h.

IsUnterminatedLiteral

Set to true if this token is an unterminated literal.

Definition at line 903 of file FormatToken.h.

LastLineColumnWidth

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

Definition at line 1039 of file FormatToken.h.

LastNewlineOffset

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

0 if there is no '
'.

Definition at line 1030 of file FormatToken.h.

LongestObjCSelectorName

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

MacroCtx

std::optional MacroCtx

MacroParent

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

MatchingParen

FormatToken* MatchingParen = nullptr

MightBeFunctionDeclParen

Might be function declaration open/closing paren.

Definition at line 1138 of file FormatToken.h.

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

MustBreakBeforeFinalized

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

Definition at line 900 of file FormatToken.h.

NestingLevel

Newlines

NewlinesBefore

Next

FormatToken* Next = nullptr

The next token in the unwrapped line.

Definition at line 1123 of file FormatToken.h.

Referenced by clang::ASTContext::adjustDeducedFunctionResultType(), clang::format::LeftRightQualifierAlignmentFixer::analyzeRight(), clang::syntax::Node::assertInvariants(), clang::format::TokenAnnotator::calculateFormattingInformation(), checkIsValidOpenCLKernelParameter(), clang::interp::DynamicAllocator::cleanup(), clang::MacroArgs::deallocate(), clang::SemaSYCL::deepTypeCheckForDevice(), clang::StoredDeclsMap::DestroyAll(), clang::interp::Block::dump(), clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(), emitScanBasedDirective(), clang::interp::Pointer::expand(), clang::FileEntryRef::FileMgr::MapEntryOptionalStorage< FileEntryRef >, FindBestPath(), clang::ast_matchers::dynamic::formatErrorString(), clang::tooling::getExtendedRange(), clang::tooling::getExtendedText(), clang::format::getFunctionName(), handleAPINotedRetainCountAttribute(), HandleVirtualDispatch(), clang::format::IndexedTokenSource::insertTokens(), clang::format::isC78ParameterDecl(), clang::format::isFunctionDeclarationName(), clang::format::isPossibleMacro(), clang::AdditionalKeywords::isVerilogQualifier(), clang::AdditionalKeywords::isVerilogStructuredProcedure(), clang::Sema::LookupQualifiedName(), MarkUsedTemplateParameters(), clang::tooling::maybeExtendRange(), clang::Decl::redecl_iterator::operator++(), clang::Redeclarable< decl_type >::redecl_iterator::operator++(), clang::format::IndexedTokenSource::peekNextToken(), clang::api_notes::APINotesReader::Implementation::readContextBlock(), clang::api_notes::APINotesReader::Implementation::readControlBlock(), clang::api_notes::APINotesReader::Implementation::readCXXMethodBlock(), clang::api_notes::APINotesReader::Implementation::readEnumConstantBlock(), clang::api_notes::APINotesReader::Implementation::readFieldBlock(), clang::api_notes::APINotesReader::Implementation::readGlobalFunctionBlock(), clang::api_notes::APINotesReader::Implementation::readGlobalVariableBlock(), clang::api_notes::APINotesReader::Implementation::readIdentifierBlock(), clang::api_notes::APINotesReader::Implementation::readObjCMethodBlock(), clang::api_notes::APINotesReader::Implementation::readObjCPropertyBlock(), clang::api_notes::APINotesReader::Implementation::readObjCSelectorBlock(), clang::api_notes::APINotesReader::Implementation::readTagBlock(), clang::api_notes::APINotesReader::Implementation::readTypedefBlock(), removeEdgesToDefaultInitializers(), clang::ASTDeclReader::setNextObjCCategory(), clang::syntax::TokenBuffer::spelledForExpanded(), clang::ento::ExprEngine::Visit(), and clang::interp::InterpState::~InterpState().

NextOperator

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

ObjCSelectorNameParts

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

OperatorIndex

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

Definition at line 1110 of file FormatToken.h.

Optional

OriginalColumn

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

The configured TabWidth is used as tab width.

Definition at line 1061 of file FormatToken.h.

ParameterCount

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

Definition at line 1045 of file FormatToken.h.

ParameterIndex

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

ParentBracket

tok::TokenKind ParentBracket = tok::unknown

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

Definition at line 1053 of file FormatToken.h.

PartOfMultiVariableDeclStmt

Is this token part of a DeclStmt defining multiple variables?

Only set if Type == TT_StartOfName.

Definition at line 920 of file FormatToken.h.

Previous

FormatToken* Previous = nullptr

The previous token in the unwrapped line.

Definition at line 1120 of file FormatToken.h.

Referenced by clang::Sema::ActOnAliasDeclaration(), clang::Sema::ActOnDecompositionDeclarator(), clang::Sema::ActOnDuplicateODRHashDefinition(), clang::Sema::ActOnExplicitInstantiation(), clang::Sema::ActOnFinishConceptDefinition(), clang::Sema::ActOnFriendFunctionDecl(), clang::Sema::ActOnFunctionDeclarator(), clang::SemaOpenMP::ActOnOMPIteratorExpr(), clang::SemaObjC::ActOnStartCategoryInterface(), clang::Sema::ActOnStartConceptDefinition(), clang::Sema::ActOnTag(), clang::Sema::ActOnTypedefDeclarator(), clang::Sema::ActOnTypedefNameDecl(), clang::Sema::ActOnVariableDeclarator(), clang::Sema::ActOnVarTemplateSpecialization(), AddInitializerToDiag(), clang::SemaObjC::addMethodToGlobalList(), clang::format::ContinuationIndenter::addTokenToState(), clang::format::AlignTokenSequence(), AllowOverloadingOfFunction(), clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), clang::ASTReader::AssignedLambdaNumbering(), clang::ASTDeclReader::attachPreviousDecl(), clang::ASTDeclReader::attachPreviousDeclImpl(), clang::ASTDeclReader::attachPreviousDeclImpl(), clang::ASTDeclReader::attachPreviousDeclImpl(), clang::driver::Driver::BuildInputs(), clang::Sema::BuildUsingDeclaration(), clang::Sema::BuildUsingEnumDeclaration(), clang::Sema::BuildVariableInstantiation(), clang::format::ContinuationIndenter::canBreak(), clang::Sema::CheckClassTemplate(), clang::Sema::CheckConceptRedefinition(), CheckDeclarationCausesMultiVersioning(), clang::Sema::CheckDependentFunctionTemplateSpecialization(), checkForConflictWithNonVisibleExternC(), clang::Sema::CheckFunctionDeclaration(), clang::Sema::CheckFunctionTemplateSpecialization(), checkGlobalOrExternCConflict(), clang::Sema::CheckMemberSpecialization(), clang::ASTDeclReader::checkMultipleDefinitionInNamedModules(), CheckMultiVersionAdditionalDecl(), CheckMultiVersionFunction(), clang::SemaCUDA::checkTargetOverload(), clang::Sema::CheckUsingShadowDecl(), clang::Sema::CheckVariableDeclaration(), clang::Sema::CompleteMemberSpecialization(), DiagnoseInvalidRedeclaration(), clang::CodeGen::CodeGenFunction::EmitBinaryOperatorLValue(), clang::CodeGen::CodeGenFunction::EmitWithOriginalRHSBitfieldAssignment(), filterNonConflictingPreviousTypedefDecls(), clang::Sema::FilterUsingLookup(), clang::Sema::HandleDeclarator(), clang::Sema::HandleField(), clang::Sema::HandleMSProperty(), clang::format::hasNestedBlockInlined(), clang::Sema::isAcceptableTagRedeclaration(), clang::format::isFunctionDeclarationName(), clang::SemaCUDA::maybeAddHostDeviceAttrs(), mergeTypeWithPrevious(), clang::Sema::MergeVarDecl(), clang::format::ContinuationIndenter::mustBreak(), PrintDifference(), clang::Redeclarable< decl_type >::DeclLink::setPrevious(), clang::format::shouldUnindentNextOperator(), clang::format::startsNextOperand(), clang::format::startsNextParameter(), clang::startsNextParameter(), clang::TokenRole::TokenRole(), clang::TemplateDeclInstantiator::VisitCXXMethodDecl(), clang::TemplateDeclInstantiator::VisitFunctionDecl(), clang::dataflow::DataflowAnalysis< Derived, LatticeT >::widenTypeErased(), and clang::dataflow::TypeErasedDataflowAnalysis::widenTypeErased().

Role

std::shared_ptr Role

SpacesRequiredBefore

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

Definition at line 1042 of file FormatToken.h.

SplitPenalty

Penalty for inserting a line break before this token.

Definition at line 1080 of file FormatToken.h.

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

StartsColumn

The first token in set of column elements.

Definition at line 1126 of file FormatToken.h.

Tok

The Token.

Definition at line 865 of file FormatToken.h.

Referenced by clang::Sema::ActOnCharacterConstant(), clang::Sema::ActOnNumericConstant(), clang::Sema::ActOnStringLiteral(), clang::Sema::ActOnUnevaluatedStringLiteral(), clang::ASTWriter::AddToken(), clang::TokenRewriter::AddTokenBefore(), clang::format::WhitespaceManager::addUntouchableToken(), clang::format::AlignTokenSequence(), clang::format::NamespaceEndCommentsFixer::analyze(), clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), clang::format::LeftRightQualifierAlignmentFixer::analyzeRight(), clang::format::TokenAnnotator::annotate(), clang::Preprocessor::AnnotateCachedTokens(), clang::format::AnnotatedLine::AnnotatedLine(), atOrBeforeSeparation(), clang::TokenConcatenation::AvoidConcat(), buildMSAsmString(), clang::format::TokenAnnotator::calculateFormattingInformation(), contains(), clang::Preprocessor::CreateString(), clang::MacroExpansionContext::detail::MacroExpansionRangeRecorder, clang::Preprocessor::Diag(), diagnoseUnexpectedOperator(), clang::DoPrintPreprocessedInput(), clang::MacroInfo::dump(), clang::Preprocessor::DumpToken(), dumpTokenInto(), dumpTokenInto(), clang::Preprocessor::EnterAnnotationToken(), clang::PreferredTypeBuilder::enterBinary(), clang::PreferredTypeBuilder::enterCondition(), clang::PreferredTypeBuilder::enterDesignatedInitializer(), clang::PreferredTypeBuilder::enterFunctionArgument(), clang::Preprocessor::EnterMacro(), clang::PreferredTypeBuilder::enterMemAccess(), clang::PreferredTypeBuilder::enterParenExpr(), clang::PreferredTypeBuilder::enterReturn(), clang::PreferredTypeBuilder::enterSubscript(), clang::Preprocessor::EnterToken(), clang::PreferredTypeBuilder::enterTypeCast(), clang::PreferredTypeBuilder::enterUnary(), clang::PreferredTypeBuilder::enterVariableInit(), EvaluateFeatureLikeBuiltinMacro(), EvaluateHasIncludeCommon(), clang::DumpTokensAction::ExecuteAction(), clang::PreprocessOnlyAction::ExecuteAction(), clang::PrintDependencyDirectivesSourceMinimizerAction::ExecuteAction(), clang::format::MacroExpander::expand(), clang::Sema::ExpandFunctionLocalPredefinedMacros(), ExpectFeatureIdentifierInfo(), findDirectives(), clang::Lexer::findLocationAfterToken(), clang::Lexer::findNextToken(), clang::Lexer::findPreviousToken(), clang::format::LeftRightQualifierAlignmentFixer::fixQualifierAlignment(), fixSeparateAttrArgAndNumber(), clang::AttributeCommonInfo::Form::Form(), clang::format::UnwrappedLineFormatter::format(), clang::PreferredTypeBuilder::get(), clang::format::getEnclosingFunctionName(), getEntityEndLoc(), GetFirstChar(), clang::RawComment::getFormattedLines(), clang::format::getFunctionName(), getIdentifier(), clang::format::getLanguageByComment(), clang::format::getLengthToMatchingParen(), clang::format::getLengthToNextOperator(), clang::format::FormatTokenSource::getNextNonComment(), clang::StringLiteralParser::getOffsetOfStringByte(), clang::MacroArgs::getPreExpArgument(), clang::MacroInfo::getReplacementToken(), clang::comments::Lexer::getSpelling(), clang::Lexer::getSpelling(), clang::Lexer::getSpelling(), clang::Preprocessor::getSpelling(), clang::Preprocessor::getSpelling(), clang::Preprocessor::getSpelling(), clang::Preprocessor::getSpellingOfSingleCharacterNumericConstant(), getSpellingSlow(), clang::Preprocessor::HandleMicrosoftCommentPaste(), clang::PragmaNamespace::HandlePragma(), clang::Preprocessor::HandlePragmaHdrstop(), clang::Preprocessor::HandlePragmaIncludeAlias(), clang::Preprocessor::HandlePragmaModuleBuild(), clang::Preprocessor::HandlePragmaPoison(), clang::html::HighlightMacros(), clang::TokenLexer::Init(), clang::format::isAllmanBrace(), clang::format::isAllmanLambdaBrace(), IsBuiltinTrait(), clang::format::isC78ParameterDecl(), clang::format::isC78Type(), IsCommonTypo(), clang::format::isConfiguredQualifier(), clang::format::isConfiguredQualifierOrType(), clang::format::isCppStructuredBinding(), clang::format::isCtorOrDtorName(), clang::format::isEmptyLambdaAllowed(), isEndOfTemplateArgument(), clang::format::IsFunctionArgument(), clang::format::isFunctionDeclarationName(), clang::AdditionalKeywords::isJavaScriptIdentifier(), isMapModifier(), isMapType(), clang::format::isPossibleMacro(), clang::Preprocessor::IsPreviousCachedToken(), clang::format::isQualifier(), clang::format::isQualifierOrType(), clang::AdditionalKeywords::isTableGenDefinition(), clang::AdditionalKeywords::isVerilogBegin(), clang::AdditionalKeywords::isVerilogEnd(), clang::AdditionalKeywords::isVerilogEndOfLabel(), clang::AdditionalKeywords::isVerilogHierarchy(), clang::AdditionalKeywords::isVerilogPPDirective(), clang::AdditionalKeywords::isVerilogQualifier(), clang::AdditionalKeywords::isVerilogStructuredProcedure(), clang::AdditionalKeywords::isVerilogWordOperator(), clang::TokenLexer::Lex(), clang::format::FormatTokenLexer::lex(), clang::comments::TextTokenRetokenizer::lexDelimitedSeq(), LexModuleName(), LexModuleNameComponent(), clang::Preprocessor::LexOnOffSwitch(), clang::comments::TextTokenRetokenizer::lexParHeading(), clang::Preprocessor::LexTokensUntilEOF(), clang::comments::TextTokenRetokenizer::lexType(), clang::comments::TextTokenRetokenizer::lexWord(), LocPropertyAttribute(), clang::format::maxNestingDepth(), clang::tooling::maybeExtendRange(), clang::format::ContinuationIndenter::mustBreak(), clang::format::mustBreakAfterAttributes(), clang::TokenValue::operator==(), clang::IncrementalParser::Parse(), ParseAlignPragma(), parseDeclareSimdClauses(), ParseLoopHintValue(), parseMapType(), parseOpenMPAllocateClauseModifiers(), parseOpenMPDirectiveKind(), parseOpenMPReductionId(), parseOpenMPSimpleClause(), clang::Preprocessor::ParsePragmaPushOrPopMacro(), clang::Preprocessor::parseSimpleIntegerLiteral(), clang::printDependencyDirectivesAsSource(), PrintPreprocessedTokens(), clang::format::IntegerLiteralSeparatorFixer::process(), clang::format::NumericLiteralCaseFixer::process(), clang::ASTReader::ReadToken(), clang::MacroExpansionContext::registerForPreprocessor(), clang::Preprocessor::ReplaceLastTokenWithAnnotation(), clang::format::WhitespaceManager::replaceWhitespace(), clang::format::WhitespaceManager::replaceWhitespaceInToken(), clang::RewriteIncludesInInput(), clang::format::rotateTokens(), clang::CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks(), clang::format::shouldUnindentNextOperator(), clang::format::skipNameQualifier(), clang::Preprocessor::SkipTokensWhileUsingPCH(), clang::syntax::spelledIdentifierTouching(), clang::syntax::TokenBuffer::spelledTokenContaining(), clang::syntax::spelledTokensTouching(), clang::format::startsSegmentOfBuilderTypeCall(), startsWithNewline(), clang::MacroArgs::StringifyArgument(), clang::format::tokenCanStartNewLine(), clang::tokenIsLikeStringLiteral(), clang::TokenLexer::TokenLexer(), clang::TokenRewriter::TokenRewriter(), and clang::Preprocessor::TypoCorrectToken().

TokenText

TotalLength

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

Definition at line 1057 of file FormatToken.h.

true

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 startsSequence(A K1, Ts... Tokens) const { return startsSequenceInternal(K1, Tokens...); }

/ 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. template <typename A, typename... Ts> bool endsSequence(A K1, Ts... Tokens) const { return endsSequenceInternal(K1, Tokens...); }

bool isStringLiteral() const { return tok::isStringLiteral(Tok.getKind()); }

bool isAttribute() const { return isOneOf(tok::kw___attribute, tok::kw___declspec, TT_AttributeMacro); }

bool isAccessSpecifierKeyword() const { return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private); }

bool isAccessSpecifier(bool ColonRequired = true) const { if (!isAccessSpecifierKeyword()) return false; if (!ColonRequired) return true; const auto *NextNonComment = getNextNonComment(); return NextNonComment && NextNonComment->is(tok::colon); }

bool canBePointerOrReferenceQualifier() const { return isOneOf(tok::kw_const, tok::kw_restrict, tok::kw_volatile, tok::kw__Nonnull, tok::kw__Nullable, tok::kw__Null_unspecified, tok::kw___ptr32, tok::kw___ptr64, tok::kw___funcref) || isAttribute(); }

[[nodiscard]] bool isQtProperty() const; [[nodiscard]] bool isTypeName(const LangOptions &LangOpts) const; [[nodiscard]] bool isTypeOrIdentifier(const LangOptions &LangOpts) const;

bool isObjCAccessSpecifier() const { return is(tok::at) && Next && Next->isOneOf(tok::objc_public, tok::objc_protected, tok::objc_package, tok::objc_private); }

bool isObjCLifetimeQualifier(const FormatStyle &Style) const { if (Style.Language != FormatStyle::LK_ObjC || isNot(tok::identifier) || !TokenText.starts_with("__")) { return false; } const auto Qualifier = TokenText.substr(2); return Qualifier == "autoreleasing" || Qualifier == "strong" || Qualifier == "weak" || Qualifier == "unsafe_unretained"; }

/ Returns whether Tok is ([{ or an opening < of a template or in / protos. bool opensScope() const { if (is(TT_TemplateString) && TokenText.ends_with("${")) return true; if (is(TT_DictLiteral) && is(tok::less)) return true; return isOneOf(tok::l_paren, tok::l_brace, tok::l_square, TT_TemplateOpener); } / Returns whether Tok is )]} or a closing > of a template or in / protos. bool closesScope() const { if (is(TT_TemplateString) && TokenText.starts_with("}")) return true; if (is(TT_DictLiteral) && is(tok::greater)) return true; return isOneOf(tok::r_paren, tok::r_brace, tok::r_square, TT_TemplateCloser); }

/ Returns true if this is a "." or "->" accessing a member. bool isMemberAccess() const { return isOneOf(tok::arrow, tok::period, tok::arrowstar) && isNoneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow, TT_LambdaArrow, TT_LeadingJavaAnnotation); }

bool isPointerOrReference() const { return isOneOf(tok::star, tok::amp, tok::ampamp); }

bool isPlacementOperator() const { return isOneOf(tok::kw_new, tok::kw_delete); }

bool isUnaryOperator() const { switch (Tok.getKind()) { case tok:➕ case tok::plusplus: case tok:➖ case tok::minusminus: case tok::exclaim: case tok::tilde: case tok::kw_sizeof: case tok::kw_alignof: return true; default: return false; } }

bool isBinaryOperator() const { Comma is a binary operator, but does not behave as such wrt. formatting. return getPrecedence() > prec::Comma; }

bool isTrailingComment() const { return is(tok::comment) && (is(TT_LineComment) || !Next || Next->NewlinesBefore > 0); }

/ Returns true if this is a keyword that can be used / like a function call (e.g. sizeof, typeid, ...). bool isFunctionLikeKeyword() const { if (isAttribute()) return true;

return isOneOf(tok::kw_throw, tok::kw_typeid, tok::kw_return, tok::kw_sizeof, tok::kw_alignof, tok::kw_alignas, tok::kw_decltype, tok::kw_noexcept, tok::kw_static_assert, tok::kw__Atomic, #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait)

           tok::kw_requires);

}

/ Returns true if this is a string literal that's like a label, / e.g. ends with "=" or ":". bool isLabelString() const { if (isNot(tok::string_literal)) return false; StringRef Content = TokenText; if (Content.starts_with("\"") || Content.starts_with("'")) Content = Content.drop_front(1); if (Content.ends_with("\"") || Content.ends_with("'")) Content = Content.drop_back(1); Content = Content.trim(); return Content.size() > 1 && (Content.back() == ':' || Content.back() == '='); }

/ Returns actual token start location without leading escaped / newlines and whitespace. / / This can be different to Tok.getLocation(), which includes leading escaped / newlines. SourceLocation getStartOfNonWhitespace() const { return WhitespaceRange.getEnd(); }

/ Returns true if the range of whitespace immediately preceding the / Token is not empty. bool hasWhitespaceBefore() const { return WhitespaceRange.getBegin() != WhitespaceRange.getEnd(); }

prec::Level getPrecedence() const { if (ForcedPrecedence != prec::Unknown) return ForcedPrecedence; return getBinOpPrecedence(Tok.getKind(), /*GreaterThanIsOperator=

Definition at line 1390 of file FormatToken.h.

UnbreakableTailLength

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

Definition at line 1065 of file FormatToken.h.

WhitespaceRange

SourceRange WhitespaceRange