|
clang 22.0.0git
|
A wrapper around a Token storing information about the whitespace characters preceding it.
More...
#include "/work/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/Format/FormatToken.h"
Public Member Functions | |
| FormatToken () | |
| BraceBlockKind | getBlockKind () const |
| void | setBlockKind (BraceBlockKind BBK) |
| FormatDecision | getDecision () const |
| void | setDecision (FormatDecision D) |
| ParameterPackingKind | getPackingKind () const |
| void | setPackingKind (ParameterPackingKind K) |
| TokenType | getType () const |
| Returns the token's type, e.g. | |
| void | setType (TokenType T) |
| void | setFinalizedType (TokenType T) |
| Sets the type and also the finalized flag. | |
| void | overwriteFixedType (TokenType T) |
| bool | isTypeFinalized () const |
| bool | is (tok::TokenKind Kind) const |
| bool | is (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 | isLoop (const FormatStyle &Style) const |
| bool | closesScopeAfterBlock () const |
Public Attributes | |
| 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: 1 |
Whether there is at least one unescaped newline before the Token. | |
| unsigned | IsMultiline: 1 |
| Whether the token text contains newlines (escaped or not). | |
| unsigned | IsFirst: 1 |
| Indicates that this is the first token of the file. | |
| unsigned | MustBreakBefore: 1 |
| Whether there must be a line break before this token. | |
| unsigned | MustBreakBeforeFinalized: 1 |
| Whether MustBreakBefore is finalized during parsing and must not be reset between runs. | |
| unsigned | IsUnterminatedLiteral: 1 |
Set to true if this token is an unterminated literal. | |
| unsigned | CanBreakBefore: 1 |
true if it is allowed to break before this token. | |
| unsigned | ClosesTemplateDeclaration: 1 |
true if this is the ">" of "template<..>". | |
| unsigned | StartsBinaryExpression: 1 |
true if this token starts a binary expression, i.e. | |
| unsigned | EndsBinaryExpression: 1 |
true if this token ends a binary expression. | |
| unsigned | PartOfMultiVariableDeclStmt: 1 |
Is this token part of a DeclStmt defining multiple variables? | |
| unsigned | ContinuesLineCommentSection: 1 |
| Does this line comment continue a line comment section? | |
| unsigned | Finalized: 1 |
If true, this token has been fully formatted (indented and potentially re-formatted inside), and we do not allow further formatting changes. | |
| unsigned | ClosesRequiresClause: 1 |
true if this is the last token within requires clause. | |
| unsigned | EndsCppAttributeGroup: 1 |
true if this token ends a group of C++ attributes. | |
| prec::Level | ForcedPrecedence = prec::Unknown |
| Used to set an operator precedence explicitly. | |
| unsigned | NewlinesBefore = 0 |
The number of newlines immediately before the Token. | |
| int | Newlines = -1 |
The number of newlines immediately before the Token after formatting. | |
| unsigned | LastNewlineOffset = 0 |
| The offset just past the last ' ' in this token's leading whitespace (relative to WhiteSpaceStart). | |
| unsigned | ColumnWidth = 0 |
| The width of the non-whitespace parts of the token (or its first line for multi-line tokens) in columns. | |
| unsigned | LastLineColumnWidth = 0 |
| Contains the width in columns of the last line of a multi-line token. | |
| unsigned | SpacesRequiredBefore = 0 |
| The number of spaces that should be inserted before this token. | |
| unsigned | ParameterCount = 0 |
| Number of parameters, if this is "(", "[" or "<". | |
| unsigned | BlockParameterCount = 0 |
| Number of parameters that are nested blocks, if this is "(", "[" or "<". | |
| tok::TokenKind | ParentBracket = tok::unknown |
| If this is a bracket ("<", "(", "[" or "{"), contains the kind of the surrounding bracket. | |
| unsigned | TotalLength = 0 |
| The total length of the unwrapped line up to and including this token. | |
| unsigned | OriginalColumn = 0 |
| The original 0-based column of this token, including expanded tabs. | |
| unsigned | UnbreakableTailLength = 0 |
| The length of following tokens until the next natural split point, or the next token that can be broken. | |
| unsigned | BindingStrength = 0 |
| The binding strength of a token. | |
| unsigned | NestingLevel = 0 |
| The nesting level of this token, i.e. | |
| unsigned | IndentLevel = 0 |
| The indent level of this token. Copied from the surrounding line. | |
| unsigned | SplitPenalty = 0 |
| Penalty for inserting a line break before this token. | |
| unsigned | LongestObjCSelectorName = 0 |
| If this is the first ObjC selector name in an ObjC method definition or call, this contains the length of the longest name. | |
| unsigned | ObjCSelectorNameParts = 0 |
| If this is the first ObjC selector name in an ObjC method definition or call, this contains the number of parts that the whole selector consist of. | |
| unsigned | ParameterIndex = 0 |
| The 0-based index of the parameter/argument. | |
| SmallVector< prec::Level, 4 > | FakeLParens |
| Stores the number of required fake parentheses and the corresponding operator precedence. | |
| unsigned | FakeRParens = 0 |
| Insert this many fake ) after this token for correct indentation. | |
| unsigned | OperatorIndex = 0 |
| If this is an operator (or "."/"->") in a sequence of operators with the same precedence, contains the 0-based operator index. | |
| 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. | |
A wrapper around a Token storing information about the whitespace characters preceding it.
Definition at line 307 of file FormatToken.h.
|
inline |
Definition at line 308 of file FormatToken.h.
|
inline |
Definition at line 663 of file FormatToken.h.
References is().
|
inline |
Definition at line 399 of file FormatToken.h.
References ClosesRequiresClause.
Referenced by clang::format::opensBlockOrBlockTypeList().
|
inline |
Definition at line 412 of file FormatToken.h.
|
inline |
Definition at line 425 of file FormatToken.h.
|
inline |
Returns the token's type, e.g.
whether "<" is a template opener or binary operator.
Definition at line 440 of file FormatToken.h.
|
inline |
Definition at line 637 of file FormatToken.h.
References Tok.
|
inline |
Definition at line 630 of file FormatToken.h.
|
inline |
Definition at line 638 of file FormatToken.h.
References Tok.
|
inline |
Definition at line 626 of file FormatToken.h.
References MacroCtx.
|
inline |
Definition at line 633 of file FormatToken.h.
References MacroParent.
|
inline |
Definition at line 625 of file FormatToken.h.
Referenced by clang::format::ContinuationIndenter::addTokenToState(), clang::format::JavaScriptImportSorter::analyze(), clang::format::NamespaceEndCommentsFixer::analyze(), clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), clang::format::LeftRightQualifierAlignmentFixer::analyzeRight(), clang::format::TokenAnnotator::calculateFormattingInformation(), clang::format::ContinuationIndenter::canBreak(), closesScopeAfterBlock(), clang::format::computeNewlines(), clang::format::continuesLineCommentSection(), clang::format::UnwrappedLineFormatter::format(), clang::format::getNamespaceToken(), clang::format::hasNestedBlockInlined(), clang::format::isBlockIndentedInitRBrace(), clang::format::isFunctionDeclarationName(), isIf(), clang::format::markOptionalBraces(), clang::format::mustBeJSIdent(), clang::format::ContinuationIndenter::mustBreak(), clang::format::opensBlockOrBlockTypeList(), clang::format::opensProtoMessageField(), clang::format::ShouldBreakBeforeBrace(), clang::format::startsNextParameter(), and clang::TokenRole::TokenRole().
Definition at line 629 of file FormatToken.h.
Definition at line 652 of file FormatToken.h.
References is().
|
inline |
Definition at line 657 of file FormatToken.h.
|
inline |
Definition at line 648 of file FormatToken.h.
Referenced by clang::format::ContinuationIndenter::canBreak(), clang::format::isFunctionDeclarationName(), clang::format::mustBeJSIdent(), and clang::format::ContinuationIndenter::mustBreak().
Definition at line 647 of file FormatToken.h.
References Tok.
Referenced by clang::format::NamespaceEndCommentsFixer::analyze(), clang::format::ContinuationIndenter::canBreak(), clang::format::closesBlockOrBlockTypeList(), clang::format::computeNewlines(), clang::format::isC78ParameterDecl(), clang::format::isFunctionDeclarationName(), clang::format::ContinuationIndenter::mustBreak(), and clang::format::opensProtoMessageField().
|
inline |
Definition at line 640 of file FormatToken.h.
Referenced by clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), clang::format::LeftRightQualifierAlignmentFixer::analyzeRight(), clang::format::computeNewlines(), clang::format::getLengthToMatchingParen(), clang::format::isJSDeclOrStmt(), and clang::format::mustBeJSIdentOrValue().
|
inline |
Definition at line 644 of file FormatToken.h.
|
inline |
Definition at line 467 of file FormatToken.h.
References MacroCtx, clang::format::MR_UnexpandedArg, and clang::T.
|
inline |
Definition at line 461 of file FormatToken.h.
References clang::T.
|
inline |
Definition at line 402 of file FormatToken.h.
References EndsCppAttributeGroup.
|
inline |
Definition at line 415 of file FormatToken.h.
|
inline |
Sets the type and also the finalized flag.
This prevents the type to be reset in TokenAnnotator::resetTokenMetadata(). If the type needs to be set to another one please use overwriteFixedType, or even better remove the need to reassign the type.
Definition at line 455 of file FormatToken.h.
References MacroCtx, clang::format::MR_UnexpandedArg, and clang::T.
Referenced by clang::format::TokenAnnotator::annotate().
|
inline |
Definition at line 428 of file FormatToken.h.
|
inline |
Definition at line 441 of file FormatToken.h.
This notes the start of the line of an array initializer.
Definition at line 585 of file FormatToken.h.
| unsigned clang::format::FormatToken::BindingStrength = 0 |
The binding strength of a token.
This is a combined value of operator precedence, parenthesis nesting, etc.
Definition at line 526 of file FormatToken.h.
| unsigned clang::format::FormatToken::BlockParameterCount = 0 |
Number of parameters that are nested blocks, if this is "(", "[" or "<".
Definition at line 505 of file FormatToken.h.
| int8_t clang::format::FormatToken::BraceCount = 0 |
Number of optional braces to be inserted after this token: -1: a single left brace 0: no braces >0: number of right braces.
Definition at line 606 of file FormatToken.h.
| unsigned clang::format::FormatToken::CanBreakBefore |
true if it is allowed to break before this token.
Definition at line 362 of file FormatToken.h.
Referenced by clang::format::ContinuationIndenter::canBreak(), clang::format::getLengthToMatchingParen(), clang::format::ContinuationIndenter::mustBreak(), and clang::format::mustBreakBinaryOperation().
| SmallVector<AnnotatedLine *, 1> clang::format::FormatToken::Children |
If this token starts a block, this contains all the unwrapped lines in it.
Definition at line 610 of file FormatToken.h.
Referenced by clang::format::AnnotatedLine::addChildren(), clang::format::TokenAnnotator::calculateFormattingInformation(), and clang::format::AnnotatedLine::~AnnotatedLine().
| unsigned clang::format::FormatToken::ClosesRequiresClause |
true if this is the last token within requires clause.
Definition at line 389 of file FormatToken.h.
Referenced by clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), clang::format::LeftRightQualifierAlignmentFixer::analyzeRight(), and getBlockKind().
| unsigned clang::format::FormatToken::ClosesTemplateDeclaration |
true if this is the ">" of "template<..>".
Definition at line 365 of file FormatToken.h.
Referenced by clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), and clang::format::LeftRightQualifierAlignmentFixer::analyzeRight().
| unsigned clang::format::FormatToken::ColumnWidth = 0 |
The width of the non-whitespace parts of the token (or its first line for multi-line tokens) in columns.
We need this to correctly measure number of columns a token spans.
Definition at line 491 of file FormatToken.h.
Referenced by clang::format::CodePointsBetween().
| unsigned clang::format::FormatToken::ContinuesLineCommentSection |
Does this line comment continue a line comment section?
Only set to true if Type == TT_LineComment.
Definition at line 381 of file FormatToken.h.
| unsigned clang::format::FormatToken::EndsBinaryExpression |
true if this token ends a binary expression.
Definition at line 371 of file FormatToken.h.
| unsigned clang::format::FormatToken::EndsCppAttributeGroup |
true if this token ends a group of C++ attributes.
Definition at line 392 of file FormatToken.h.
Referenced by setBlockKind().
| SmallVector<prec::Level, 4> clang::format::FormatToken::FakeLParens |
Stores the number of required fake parentheses and the corresponding operator precedence.
If multiple fake parentheses start at a token, this vector stores them in reverse order, i.e. inner fake parenthesis first.
Definition at line 560 of file FormatToken.h.
| unsigned clang::format::FormatToken::FakeRParens = 0 |
Insert this many fake ) after this token for correct indentation.
Definition at line 562 of file FormatToken.h.
| unsigned clang::format::FormatToken::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 386 of file FormatToken.h.
Referenced by clang::format::NamespaceEndCommentsFixer::analyze().
Is the first token after a preprocessor line.
Definition at line 600 of file FormatToken.h.
| prec::Level clang::format::FormatToken::ForcedPrecedence = prec::Unknown |
Used to set an operator precedence explicitly.
Definition at line 470 of file FormatToken.h.
Has "\n\f\n" or "\n\f\r\n" before TokenText.
Definition at line 597 of file FormatToken.h.
| unsigned clang::format::FormatToken::HasUnescapedNewline |
Whether there is at least one unescaped newline before the Token.
Definition at line 340 of file FormatToken.h.
| unsigned clang::format::FormatToken::IndentLevel = 0 |
The indent level of this token. Copied from the surrounding line.
Definition at line 533 of file FormatToken.h.
This starts an array initializer.
Definition at line 588 of file FormatToken.h.
| unsigned clang::format::FormatToken::IsFirst |
Indicates that this is the first token of the file.
Definition at line 346 of file FormatToken.h.
Referenced by clang::format::UnwrappedLineFormatter::format().
| unsigned clang::format::FormatToken::IsMultiline |
Whether the token text contains newlines (escaped or not).
Definition at line 343 of file FormatToken.h.
| unsigned clang::format::FormatToken::IsUnterminatedLiteral |
Set to true if this token is an unterminated literal.
Definition at line 359 of file FormatToken.h.
| unsigned clang::format::FormatToken::LastLineColumnWidth = 0 |
Contains the width in columns of the last line of a multi-line token.
Definition at line 495 of file FormatToken.h.
| unsigned clang::format::FormatToken::LastNewlineOffset = 0 |
The offset just past the last '
' in this token's leading whitespace (relative to WhiteSpaceStart).
0 if there is no '
'.
Definition at line 486 of file FormatToken.h.
Referenced by clang::format::ContinuationIndenter::addTokenToState().
| unsigned clang::format::FormatToken::LongestObjCSelectorName = 0 |
If this is the first ObjC selector name in an ObjC method definition or call, this contains the length of the longest name.
This being set to 0 means that the selectors should not be colon-aligned, e.g. because several of them are block-type.
Definition at line 543 of file FormatToken.h.
| std::optional<MacroExpansion> clang::format::FormatToken::MacroCtx |
Definition at line 614 of file FormatToken.h.
Referenced by is(), isTypeFinalized(), and setFinalizedType().
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 623 of file FormatToken.h.
Referenced by is().
| FormatToken* clang::format::FormatToken::MatchingParen = nullptr |
If this is a bracket, this points to the matching one.
Definition at line 573 of file FormatToken.h.
Referenced by clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), clang::format::TokenAnnotator::calculateFormattingInformation(), clang::format::ContinuationIndenter::canBreak(), clang::format::getLengthToMatchingParen(), clang::format::markOptionalBraces(), and clang::format::ContinuationIndenter::mustBreak().
Might be function declaration open/closing paren.
Definition at line 594 of file FormatToken.h.
| unsigned clang::format::FormatToken::MustBreakBefore |
Whether there must be a line break before this token.
This happens for example when a preprocessor directive ended directly before the token.
Definition at line 352 of file FormatToken.h.
Referenced by clang::format::TokenAnnotator::calculateFormattingInformation(), clang::format::ContinuationIndenter::canBreak(), and clang::format::ContinuationIndenter::mustBreak().
| unsigned clang::format::FormatToken::MustBreakBeforeFinalized |
Whether MustBreakBefore is finalized during parsing and must not be reset between runs.
Definition at line 356 of file FormatToken.h.
| unsigned clang::format::FormatToken::NestingLevel = 0 |
The nesting level of this token, i.e.
the number of surrounding (), [], {} or <>.
Definition at line 530 of file FormatToken.h.
Referenced by clang::format::ContinuationIndenter::canBreak(), clang::format::isFunctionDeclarationName(), clang::format::ContinuationIndenter::mustBreak(), and clang::format::opensProtoMessageField().
| int clang::format::FormatToken::Newlines = -1 |
The number of newlines immediately before the Token after formatting.
This is used to avoid overlapping whitespace replacements when Newlines is recomputed for a finalized preprocessor branching directive.
Definition at line 482 of file FormatToken.h.
| unsigned clang::format::FormatToken::NewlinesBefore = 0 |
The number of newlines immediately before the Token.
This can be used to determine what the user wrote in the original code and thereby e.g. leave an empty line between two function definitions.
Definition at line 476 of file FormatToken.h.
Referenced by clang::format::JavaScriptImportSorter::analyze(), clang::format::NamespaceEndCommentsFixer::analyze(), clang::format::continuesLineCommentSection(), clang::format::UnwrappedLineFormatter::format(), clang::format::ContinuationIndenter::mustBreak(), and clang::format::TokenAnnotator::setCommentLineLevels().
| FormatToken* clang::format::FormatToken::Next = nullptr |
The next token in the unwrapped line.
Definition at line 579 of file FormatToken.h.
Referenced by clang::format::NamespaceEndCommentsFixer::analyze(), clang::format::AnnotatedLine::AnnotatedLine(), clang::format::BreakableLineCommentSection::BreakableLineCommentSection(), clang::format::TokenAnnotator::calculateFormattingInformation(), clang::format::UnwrappedLineFormatter::format(), clang::format::getLengthToMatchingParen(), clang::format::isFunctionDeclarationName(), and clang::format::AnnotatedLine::~AnnotatedLine().
| FormatToken* clang::format::FormatToken::NextOperator = nullptr |
If this is an operator (or "."/"->") in a sequence of operators with the same precedence, points to the next operator.
Definition at line 570 of file FormatToken.h.
| unsigned clang::format::FormatToken::ObjCSelectorNameParts = 0 |
If this is the first ObjC selector name in an ObjC method definition or call, this contains the number of parts that the whole selector consist of.
Definition at line 548 of file FormatToken.h.
Referenced by clang::format::ContinuationIndenter::mustBreak().
| unsigned clang::format::FormatToken::OperatorIndex = 0 |
If this is an operator (or "."/"->") in a sequence of operators with the same precedence, contains the 0-based operator index.
Definition at line 566 of file FormatToken.h.
Is optional and can be removed.
Definition at line 591 of file FormatToken.h.
Referenced by clang::format::markOptionalBraces().
| unsigned clang::format::FormatToken::OriginalColumn = 0 |
The original 0-based column of this token, including expanded tabs.
The configured TabWidth is used as tab width.
Definition at line 517 of file FormatToken.h.
Referenced by clang::format::UnwrappedLineFormatter::format(), and clang::format::TokenAnnotator::setCommentLineLevels().
| unsigned clang::format::FormatToken::ParameterCount = 0 |
Number of parameters, if this is "(", "[" or "<".
Definition at line 501 of file FormatToken.h.
| unsigned clang::format::FormatToken::ParameterIndex = 0 |
The 0-based index of the parameter/argument.
For ObjC it is set for the selector name token. For now calculated only for ObjC.
Definition at line 553 of file FormatToken.h.
| tok::TokenKind clang::format::FormatToken::ParentBracket = tok::unknown |
If this is a bracket ("<", "(", "[" or "{"), contains the kind of the surrounding bracket.
Definition at line 509 of file FormatToken.h.
| unsigned clang::format::FormatToken::PartOfMultiVariableDeclStmt |
Is this token part of a DeclStmt defining multiple variables?
Only set if Type == TT_StartOfName.
Definition at line 376 of file FormatToken.h.
| FormatToken* clang::format::FormatToken::Previous = nullptr |
The previous token in the unwrapped line.
Definition at line 576 of file FormatToken.h.
Referenced by clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft(), clang::format::TokenAnnotator::calculateFormattingInformation(), clang::format::ContinuationIndenter::canBreak(), clang::format::isC78ParameterDecl(), clang::format::ContinuationIndenter::mustBreak(), clang::format::opensProtoMessageField(), clang::format::startsNextOperand(), and clang::format::startsNextParameter().
| std::shared_ptr<TokenRole> clang::format::FormatToken::Role |
A token can have a special role that can carry extra information about the token's formatting.
FIXME: Make FormatToken for parsing and AnnotatedToken two different classes and make this a unique_ptr in the AnnotatedToken class.
Definition at line 333 of file FormatToken.h.
Referenced by clang::format::AnnotatedLine::~AnnotatedLine().
| unsigned clang::format::FormatToken::SpacesRequiredBefore = 0 |
The number of spaces that should be inserted before this token.
Definition at line 498 of file FormatToken.h.
| unsigned clang::format::FormatToken::SplitPenalty = 0 |
Penalty for inserting a line break before this token.
Definition at line 536 of file FormatToken.h.
| unsigned clang::format::FormatToken::StartsBinaryExpression |
true if this token starts a binary expression, i.e.
has at least one fake l_paren with a precedence greater than prec::Unknown.
Definition at line 369 of file FormatToken.h.
The first token in set of column elements.
Definition at line 582 of file FormatToken.h.
| Token clang::format::FormatToken::Tok |
The Token.
Definition at line 321 of file FormatToken.h.
Referenced by clang::format::AnnotatedLine::AnnotatedLine(), clang::format::UnwrappedLineFormatter::format(), is(), is(), isNot(), clang::format::mustBeJSIdent(), clang::format::mustBeJSIdentOrValue(), and clang::format::ShouldBreakBeforeBrace().
| StringRef clang::format::FormatToken::TokenText |
The raw text of the token.
Contains the raw token text without leading whitespace and without leading escaped newlines.
Definition at line 327 of file FormatToken.h.
Referenced by clang::format::BreakableBlockComment::adaptStartOfLine(), clang::format::JavaScriptImportSorter::analyze(), clang::format::NamespaceEndCommentsFixer::analyze(), clang::format::BreakableComment::compressWhitespace(), clang::format::continuesLineCommentSection(), clang::format::getNamespaceTokenText(), clang::format::BreakableBlockComment::insertBreak(), clang::format::BreakableLineCommentSection::insertBreak(), clang::format::ContinuationIndenter::mustBreak(), clang::format::BreakableBlockComment::reflow(), and clang::format::BreakableLineCommentSection::reflow().
| unsigned clang::format::FormatToken::TotalLength = 0 |
The total length of the unwrapped line up to and including this token.
Definition at line 513 of file FormatToken.h.
Referenced by clang::format::TokenAnnotator::calculateFormattingInformation(), clang::format::CodePointsBetween(), clang::format::UnwrappedLineFormatter::format(), and clang::format::getLengthToMatchingParen().
| clang::format::FormatToken::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 846 of file FormatToken.h.
| unsigned clang::format::FormatToken::UnbreakableTailLength = 0 |
The length of following tokens until the next natural split point, or the next token that can be broken.
Definition at line 521 of file FormatToken.h.
| SourceRange clang::format::FormatToken::WhitespaceRange |
The range of the whitespace immediately preceding the Token.
Definition at line 336 of file FormatToken.h.
Referenced by clang::format::ContinuationIndenter::addTokenToState().