clang 22.0.0git
FormatToken.h File Reference

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

#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/OperatorPrecedence.h"
#include "clang/Format/Format.h"
#include "clang/Lex/Lexer.h"
#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<typename T>
bool isNot (T Kind) const
template<typename... Ts>
bool isNoneOf (Ts... Ks) const
bool isIf (bool AllowConstexprMacro=true) const
bool closesScopeAfterBlock () const
FormatTokenclang::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 FormatTokenclang::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.
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.
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.

Detailed Description

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

Definition in file FormatToken.h.

Macro Definition Documentation

◆ KEYWORD

#define KEYWORD ( X,
Y )
Value:
case tok::kw_##X:
#define X(type, name)
Definition Value.h:97

◆ LIST_TOKEN_TYPES

#define LIST_TOKEN_TYPES

Definition at line 27 of file FormatToken.h.

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

◆ TRANSFORM_TYPE_TRAIT_DEF

#define TRANSFORM_TYPE_TRAIT_DEF ( _,
Trait )
Value:
tok::kw___##Trait,

◆ TYPE

#define TYPE ( X)
Value:
TT_##X,

Definition at line 222 of file FormatToken.h.

Function Documentation

◆ closesScopeAfterBlock()

bool getPreviousNonComment::closesScopeAfterBlock ( ) const

Definition at line 1194 of file FormatToken.h.

◆ FormatToken()

◆ getBlockKind()

BraceBlockKind getPreviousNonComment::getBlockKind ( ) const

Definition at line 936 of file FormatToken.h.

◆ getDecision()

FormatDecision getPreviousNonComment::getDecision ( ) const

Definition at line 949 of file FormatToken.h.

◆ getPackingKind()

ParameterPackingKind getPreviousNonComment::getPackingKind ( ) const

Definition at line 962 of file FormatToken.h.

◆ getType()

TokenType getPreviousNonComment::getType ( ) const

Returns the token's type, e.g.

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

Definition at line 977 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(), EmitX86CompressExpand(), EmitX86CompressStore(), EmitX86ExpandLoad(), EmitX86FMAExpr(), EmitX86MaskedCompare(), EmitX86MaskedStore(), 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(), handleCleanupAttr(), 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

Definition at line 1174 of file FormatToken.h.

◆ is() [2/7]

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

Definition at line 1167 of file FormatToken.h.

◆ is() [3/7]

bool getPreviousNonComment::is ( ParameterPackingKind PPK) const

Definition at line 1175 of file FormatToken.h.

◆ is() [4/7]

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

Definition at line 1163 of file FormatToken.h.

◆ is() [5/7]

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

Definition at line 1170 of file FormatToken.h.

◆ is() [6/7]

◆ is() [7/7]

bool getPreviousNonComment::is ( TokenType TT) const

Definition at line 1166 of file FormatToken.h.

◆ isIf()

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

Definition at line 1189 of file FormatToken.h.

◆ isNoneOf()

template<typename... Ts>
bool getPreviousNonComment::isNoneOf ( Ts... Ks) const

Definition at line 1185 of file FormatToken.h.

◆ isNot()

◆ isOneOf() [1/2]

template<typename A, typename B>
bool getPreviousNonComment::isOneOf ( A K1,
B K2 ) const

Definition at line 1177 of file FormatToken.h.

◆ isOneOf() [2/2]

template<typename A, typename B, typename... Ts>
bool getPreviousNonComment::isOneOf ( A K1,
B K2,
Ts... Ks ) const

Definition at line 1181 of file FormatToken.h.

◆ isTypeFinalized()

bool getPreviousNonComment::isTypeFinalized ( ) const

Definition at line 1004 of file FormatToken.h.

◆ overwriteFixedType()

void getPreviousNonComment::overwriteFixedType ( TokenType T)

Definition at line 998 of file FormatToken.h.

References FormatToken().

◆ setBlockKind()

void getPreviousNonComment::setBlockKind ( BraceBlockKind BBK)

Definition at line 939 of file FormatToken.h.

◆ setDecision()

void getPreviousNonComment::setDecision ( FormatDecision D)

Definition at line 952 of file FormatToken.h.

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

References FormatToken().

◆ setPackingKind()

void getPreviousNonComment::setPackingKind ( ParameterPackingKind K)

Definition at line 965 of file FormatToken.h.

◆ setType()

void getPreviousNonComment::setType ( TokenType T)

Definition at line 978 of file FormatToken.h.

Variable Documentation

◆ ArrayInitializerLineStart

bool ArrayInitializerLineStart = false

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

Definition at line 1122 of file FormatToken.h.

◆ BindingStrength

unsigned BindingStrength = 0

The binding strength of a token.

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

Definition at line 1063 of file FormatToken.h.

◆ BlockParameterCount

unsigned BlockParameterCount = 0

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

Definition at line 1042 of file FormatToken.h.

◆ BraceCount

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.

Definition at line 1143 of file FormatToken.h.

◆ CanBreakBefore

unsigned CanBreakBefore

true if it is allowed to break before this token.

Definition at line 899 of file FormatToken.h.

◆ Children

SmallVector<AnnotatedLine *, 1> Children

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

Definition at line 1147 of file FormatToken.h.

Referenced by clang::format::TokenAnnotator::calculateFormattingInformation(), clang::CXXConstructExpr::children(), clang::DeclStmt::children(), clang::MSPropertyRefExpr::children(), clang::ObjCArrayLiteral::children(), clang::ObjCDictionaryLiteral::children(), clang::ObjCMessageExpr::children(), clang::ObjCPropertyRefExpr::children(), clang::OMPAffinityClause::children(), clang::OMPAlignedClause::children(), clang::OMPAllocateClause::children(), clang::OMPClause::children(), clang::OMPCopyinClause::children(), clang::OMPCopyprivateClause::children(), clang::OMPDependClause::children(), clang::OMPDepobjClause::children(), clang::OMPDistScheduleClause::children(), clang::OMPDoacrossClause::children(), clang::OMPExclusiveClause::children(), clang::OMPFirstprivateClause::children(), clang::OMPFlushClause::children(), clang::OMPFromClause::children(), clang::OMPHasDeviceAddrClause::children(), clang::OMPInclusiveClause::children(), clang::OMPInitClause::children(), clang::OMPInReductionClause::children(), clang::OMPIsDevicePtrClause::children(), clang::OMPLastprivateClause::children(), clang::OMPLinearClause::children(), clang::OMPMapClause::children(), clang::OMPNontemporalClause::children(), clang::OMPNumTeamsClause::children(), clang::OMPPrivateClause::children(), clang::OMPReductionClause::children(), clang::OMPScheduleClause::children(), clang::OMPSharedClause::children(), clang::OMPTaskReductionClause::children(), clang::OMPThreadLimitClause::children(), clang::OMPToClause::children(), clang::OMPUseDeviceAddrClause::children(), clang::OMPUseDevicePtrClause::children(), clang::OpenACCClause::children(), clang::OpenACCClauseWithExprs::children(), clang::OpenACCSelfClause::children(), clang::Stmt::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(), clang::OMPNontemporalClause::private_refs(), clang::OMPChildren::setChildren(), clang::OMPClause::used_children(), clang::OMPFinalClause::used_children(), clang::OMPFirstprivateClause::used_children(), clang::OMPGrainsizeClause::used_children(), clang::OMPIfClause::used_children(), clang::OMPLinearClause::used_children(), clang::OMPMapClause::used_children(), clang::OMPNocontextClause::used_children(), clang::OMPNovariantsClause::used_children(), clang::OMPNowaitClause::used_children(), clang::OMPNumTasksClause::used_children(), clang::OMPPriorityClause::used_children(), and clang::OMPReductionClause::used_children().

◆ ClosesRequiresClause

unsigned ClosesRequiresClause

true if this is the last token within requires clause.

Definition at line 926 of file FormatToken.h.

◆ ClosesTemplateDeclaration

unsigned ClosesTemplateDeclaration

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

Definition at line 902 of file FormatToken.h.

◆ ColumnWidth

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

◆ ContinuesLineCommentSection

unsigned ContinuesLineCommentSection

Does this line comment continue a line comment section?

Only set to true if Type == TT_LineComment.

Definition at line 918 of file FormatToken.h.

◆ EndsBinaryExpression

unsigned EndsBinaryExpression

true if this token ends a binary expression.

Definition at line 908 of file FormatToken.h.

◆ EndsCppAttributeGroup

unsigned EndsCppAttributeGroup

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

Definition at line 929 of file FormatToken.h.

◆ FakeLParens

SmallVector<prec::Level, 4> 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 1097 of file FormatToken.h.

◆ FakeRParens

unsigned FakeRParens = 0

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

Definition at line 1099 of file FormatToken.h.

◆ Finalized

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

◆ FirstAfterPPLine

bool FirstAfterPPLine = false

Is the first token after a preprocessor line.

Definition at line 1137 of file FormatToken.h.

◆ ForcedPrecedence

prec::Level ForcedPrecedence = prec::Unknown

Used to set an operator precedence explicitly.

Definition at line 1007 of file FormatToken.h.

◆ HasFormFeedBefore

bool HasFormFeedBefore = false

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

Definition at line 1134 of file FormatToken.h.

◆ HasUnescapedNewline

unsigned HasUnescapedNewline

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

Definition at line 877 of file FormatToken.h.

◆ IndentLevel

unsigned IndentLevel = 0

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

Definition at line 1070 of file FormatToken.h.

Referenced by clang::format::TokenAnnotator::calculateFormattingInformation(), DumpRecordLayout(), PrintBitFieldOffset(), printCoverage(), PrintIndentNoOffset(), and PrintOffset().

◆ IsArrayInitializer

bool IsArrayInitializer = false

This starts an array initializer.

Definition at line 1125 of file FormatToken.h.

◆ IsFirst

unsigned IsFirst

Indicates that this is the first token of the file.

Definition at line 883 of file FormatToken.h.

Referenced by addTocDataOptions(), checkFormatStringExpr(), diagnoseInvalidUnicodeCodepointInIdentifier(), EnumToString(), and maybeDiagnoseIDCharCompat().

◆ IsMultiline

unsigned IsMultiline

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

Definition at line 880 of file FormatToken.h.

◆ IsUnterminatedLiteral

unsigned IsUnterminatedLiteral

Set to true if this token is an unterminated literal.

Definition at line 896 of file FormatToken.h.

◆ LastLineColumnWidth

unsigned LastLineColumnWidth = 0

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

Definition at line 1032 of file FormatToken.h.

◆ LastNewlineOffset

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

◆ LongestObjCSelectorName

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.

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

◆ MacroCtx

std::optional<MacroExpansion> MacroCtx

Definition at line 1151 of file FormatToken.h.

◆ MacroParent

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

◆ MatchingParen

FormatToken* MatchingParen = nullptr

If this is a bracket, this points to the matching one.

Definition at line 1110 of file FormatToken.h.

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

◆ MightBeFunctionDeclParen

bool MightBeFunctionDeclParen = false

Might be function declaration open/closing paren.

Definition at line 1131 of file FormatToken.h.

◆ MustBreakBefore

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

◆ MustBreakBeforeFinalized

unsigned MustBreakBeforeFinalized

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

Definition at line 893 of file FormatToken.h.

◆ NestingLevel

unsigned NestingLevel = 0

The nesting level of this token, i.e.

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

Definition at line 1067 of file FormatToken.h.

Referenced by clang::Preprocessor::HandlePragmaModuleBuild(), and clang::format::opensBlockOrBlockTypeList().

◆ Newlines

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

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

◆ NewlinesBefore

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

Referenced by clang::format::AlignMatchingTokenSequence(), clang::format::AlignTokenSequence(), and clang::format::FormatTokenLexer::lex().

◆ Next

FormatToken* Next = nullptr

The next token in the unwrapped line.

Definition at line 1116 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(), 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 1107 of file FormatToken.h.

◆ ObjCSelectorNameParts

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.

Definition at line 1085 of file FormatToken.h.

◆ OperatorIndex

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

◆ Optional

bool Optional = false

Is optional and can be removed.

Definition at line 1128 of file FormatToken.h.

Referenced by createTemplateSignatureString(), and formatTemplateParameterPlaceholder().

◆ OriginalColumn

unsigned OriginalColumn = 0

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

The configured TabWidth is used as tab width.

Definition at line 1054 of file FormatToken.h.

◆ ParameterCount

unsigned ParameterCount = 0

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

Definition at line 1038 of file FormatToken.h.

◆ ParameterIndex

unsigned 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 1090 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 1046 of file FormatToken.h.

◆ PartOfMultiVariableDeclStmt

unsigned PartOfMultiVariableDeclStmt

Is this token part of a DeclStmt defining multiple variables?

Only set if Type == TT_StartOfName.

Definition at line 913 of file FormatToken.h.

◆ Previous

FormatToken* Previous = nullptr

The previous token in the unwrapped line.

Definition at line 1113 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<TokenRole> 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 870 of file FormatToken.h.

Referenced by clang::syntax::MutationsImpl::addAfter(), clang::ModuleMap::addHeader(), clang::ModuleMap::headerRoleToKind(), indexPreprocessorMacro(), clang::ModuleMap::isModular(), clang::ModuleMap::KnownHeader::KnownHeader(), clang::HeaderSearch::MarkFileModuleHeader(), clang::HeaderFileInfo::mergeModuleMembership(), moduleMembershipNeedsMerge(), and clang::index::printSymbolRoles().

◆ SpacesRequiredBefore

unsigned SpacesRequiredBefore = 0

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

Definition at line 1035 of file FormatToken.h.

◆ SplitPenalty

unsigned SplitPenalty = 0

Penalty for inserting a line break before this token.

Definition at line 1073 of file FormatToken.h.

◆ StartsBinaryExpression

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

◆ StartsColumn

bool StartsColumn = false

The first token in set of column elements.

Definition at line 1119 of file FormatToken.h.

◆ Tok

Token Tok

The Token.

Definition at line 858 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::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

StringRef TokenText

The raw text of the token.

Contains the raw token text without leading whitespace and without leading escaped newlines.

Definition at line 864 of file FormatToken.h.

Referenced by clang::format::BreakableBlockComment::BreakableBlockComment(), clang::format::BreakableLineCommentSection::BreakableLineCommentSection(), clang::format::getRawStringDelimiter(), and clang::ast_matchers::internal::isTokenAtLoc().

◆ TotalLength

unsigned TotalLength = 0

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

Definition at line 1050 of file FormatToken.h.

◆ true

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::plus: case tok::plusplus: case tok::minus: 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 1377 of file FormatToken.h.

◆ UnbreakableTailLength

unsigned UnbreakableTailLength = 0

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

Definition at line 1058 of file FormatToken.h.

◆ WhitespaceRange

SourceRange WhitespaceRange

The range of the whitespace immediately preceding the Token.

Definition at line 873 of file FormatToken.h.

Referenced by FormatToken().