clang  14.0.0git
FormatToken.h
Go to the documentation of this file.
1 //===--- FormatToken.h - Format C++ code ------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file contains the declaration of the FormatToken, a wrapper
11 /// around Token with additional information related to formatting.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_LIB_FORMAT_FORMATTOKEN_H
16 #define LLVM_CLANG_LIB_FORMAT_FORMATTOKEN_H
17 
20 #include "clang/Format/Format.h"
21 #include "clang/Lex/Lexer.h"
22 #include <memory>
23 #include <unordered_set>
24 
25 namespace clang {
26 namespace format {
27 
28 #define LIST_TOKEN_TYPES \
29  TYPE(ArrayInitializerLSquare) \
30  TYPE(ArraySubscriptLSquare) \
31  TYPE(AttributeColon) \
32  TYPE(AttributeMacro) \
33  TYPE(AttributeParen) \
34  TYPE(AttributeSquare) \
35  TYPE(BinaryOperator) \
36  TYPE(BitFieldColon) \
37  TYPE(BlockComment) \
38  TYPE(CastRParen) \
39  TYPE(ConditionalExpr) \
40  TYPE(ConflictAlternative) \
41  TYPE(ConflictEnd) \
42  TYPE(ConflictStart) \
43  TYPE(ConstraintJunctions) \
44  TYPE(CtorInitializerColon) \
45  TYPE(CtorInitializerComma) \
46  TYPE(DesignatedInitializerLSquare) \
47  TYPE(DesignatedInitializerPeriod) \
48  TYPE(DictLiteral) \
49  TYPE(FatArrow) \
50  TYPE(ForEachMacro) \
51  TYPE(FunctionAnnotationRParen) \
52  TYPE(FunctionDeclarationName) \
53  TYPE(FunctionLBrace) \
54  TYPE(FunctionTypeLParen) \
55  TYPE(IfMacro) \
56  TYPE(ImplicitStringLiteral) \
57  TYPE(InheritanceColon) \
58  TYPE(InheritanceComma) \
59  TYPE(InlineASMBrace) \
60  TYPE(InlineASMColon) \
61  TYPE(InlineASMSymbolicNameLSquare) \
62  TYPE(JavaAnnotation) \
63  TYPE(JsComputedPropertyName) \
64  TYPE(JsExponentiation) \
65  TYPE(JsExponentiationEqual) \
66  TYPE(JsPipePipeEqual) \
67  TYPE(JsPrivateIdentifier) \
68  TYPE(JsTypeColon) \
69  TYPE(JsTypeOperator) \
70  TYPE(JsTypeOptionalQuestion) \
71  TYPE(JsAndAndEqual) \
72  TYPE(LambdaArrow) \
73  TYPE(LambdaLBrace) \
74  TYPE(LambdaLSquare) \
75  TYPE(LeadingJavaAnnotation) \
76  TYPE(LineComment) \
77  TYPE(MacroBlockBegin) \
78  TYPE(MacroBlockEnd) \
79  TYPE(ModulePartitionColon) \
80  TYPE(NamespaceMacro) \
81  TYPE(NonNullAssertion) \
82  TYPE(NullCoalescingEqual) \
83  TYPE(NullCoalescingOperator) \
84  TYPE(NullPropagatingOperator) \
85  TYPE(ObjCBlockLBrace) \
86  TYPE(ObjCBlockLParen) \
87  TYPE(ObjCDecl) \
88  TYPE(ObjCForIn) \
89  TYPE(ObjCMethodExpr) \
90  TYPE(ObjCMethodSpecifier) \
91  TYPE(ObjCProperty) \
92  TYPE(ObjCStringLiteral) \
93  TYPE(OverloadedOperator) \
94  TYPE(OverloadedOperatorLParen) \
95  TYPE(PointerOrReference) \
96  TYPE(PureVirtualSpecifier) \
97  TYPE(RangeBasedForLoopColon) \
98  TYPE(RegexLiteral) \
99  TYPE(SelectorName) \
100  TYPE(StartOfName) \
101  TYPE(StatementAttributeLikeMacro) \
102  TYPE(StatementMacro) \
103  TYPE(StructuredBindingLSquare) \
104  TYPE(TemplateCloser) \
105  TYPE(TemplateOpener) \
106  TYPE(TemplateString) \
107  TYPE(ProtoExtensionLSquare) \
108  TYPE(TrailingAnnotation) \
109  TYPE(TrailingReturnArrow) \
110  TYPE(TrailingUnaryOperator) \
111  TYPE(TypeDeclarationParen) \
112  TYPE(TypenameMacro) \
113  TYPE(UnaryOperator) \
114  TYPE(UntouchableMacroFunc) \
115  TYPE(CSharpStringLiteral) \
116  TYPE(CSharpNamedArgumentColon) \
117  TYPE(CSharpNullable) \
118  TYPE(CSharpNullConditionalLSquare) \
119  TYPE(CSharpGenericTypeConstraint) \
120  TYPE(CSharpGenericTypeConstraintColon) \
121  TYPE(CSharpGenericTypeConstraintComma) \
122  TYPE(Unknown)
123 
124 /// Determines the semantic type of a syntactic token, e.g. whether "<" is a
125 /// template opener or binary operator.
126 enum TokenType : uint8_t {
127 #define TYPE(X) TT_##X,
129 #undef TYPE
131 };
132 
133 /// Determines the name of a token type.
134 const char *getTokenTypeName(TokenType Type);
135 
136 // Represents what type of block a set of braces open.
138 
139 // The packing kind of a function's parameters.
141 
143 
144 /// Roles a token can take in a configured macro expansion.
145 enum MacroRole {
146  /// The token was expanded from a macro argument when formatting the expanded
147  /// token sequence.
149  /// The token is part of a macro argument that was previously formatted as
150  /// expansion when formatting the unexpanded macro call.
152  /// The token was expanded from a macro definition, and is not visible as part
153  /// of the macro call.
155 };
156 
157 struct FormatToken;
158 
159 /// Contains information on the token's role in a macro expansion.
160 ///
161 /// Given the following definitions:
162 /// A(X) = [ X ]
163 /// B(X) = < X >
164 /// C(X) = X
165 ///
166 /// Consider the macro call:
167 /// A({B(C(C(x)))}) -> [{<x>}]
168 ///
169 /// In this case, the tokens of the unexpanded macro call will have the
170 /// following relevant entries in their macro context (note that formatting
171 /// the unexpanded macro call happens *after* formatting the expanded macro
172 /// call):
173 /// A( { B( C( C(x) ) ) } )
174 /// Role: NN U NN NN NNUN N N U N (N=None, U=UnexpandedArg)
175 ///
176 /// [ { < x > } ]
177 /// Role: H E H E H E H (H=Hidden, E=ExpandedArg)
178 /// ExpandedFrom[0]: A A A A A A A
179 /// ExpandedFrom[1]: B B B
180 /// ExpandedFrom[2]: C
181 /// ExpandedFrom[3]: C
182 /// StartOfExpansion: 1 0 1 2 0 0 0
183 /// EndOfExpansion: 0 0 0 2 1 0 1
186 
187  /// The token's role in the macro expansion.
188  /// When formatting an expanded macro, all tokens that are part of macro
189  /// arguments will be MR_ExpandedArg, while all tokens that are not visible in
190  /// the macro call will be MR_Hidden.
191  /// When formatting an unexpanded macro call, all tokens that are part of
192  /// macro arguments will be MR_UnexpandedArg.
194 
195  /// The stack of macro call identifier tokens this token was expanded from.
197 
198  /// The number of expansions of which this macro is the first entry.
199  unsigned StartOfExpansion = 0;
200 
201  /// The number of currently open expansions in \c ExpandedFrom this macro is
202  /// the last token in.
203  unsigned EndOfExpansion = 0;
204 };
205 
206 class TokenRole;
207 class AnnotatedLine;
208 
209 /// A wrapper around a \c Token storing information about the
210 /// whitespace characters preceding it.
211 struct FormatToken {
218  Finalized(false), BlockKind(BK_Unknown), Decision(FD_Unformatted),
219  PackingKind(PPK_Inconclusive), Type(TT_Unknown) {}
220 
221  /// The \c Token.
223 
224  /// The raw text of the token.
225  ///
226  /// Contains the raw token text without leading whitespace and without leading
227  /// escaped newlines.
228  StringRef TokenText;
229 
230  /// A token can have a special role that can carry extra information
231  /// about the token's formatting.
232  /// FIXME: Make FormatToken for parsing and AnnotatedToken two different
233  /// classes and make this a unique_ptr in the AnnotatedToken class.
234  std::shared_ptr<TokenRole> Role;
235 
236  /// The range of the whitespace immediately preceding the \c Token.
238 
239  /// Whether there is at least one unescaped newline before the \c
240  /// Token.
241  unsigned HasUnescapedNewline : 1;
242 
243  /// Whether the token text contains newlines (escaped or not).
244  unsigned IsMultiline : 1;
245 
246  /// Indicates that this is the first token of the file.
247  unsigned IsFirst : 1;
248 
249  /// Whether there must be a line break before this token.
250  ///
251  /// This happens for example when a preprocessor directive ended directly
252  /// before the token.
253  unsigned MustBreakBefore : 1;
254 
255  /// Set to \c true if this token is an unterminated literal.
256  unsigned IsUnterminatedLiteral : 1;
257 
258  /// \c true if it is allowed to break before this token.
259  unsigned CanBreakBefore : 1;
260 
261  /// \c true if this is the ">" of "template<..>".
263 
264  /// \c true if this token starts a binary expression, i.e. has at least
265  /// one fake l_paren with a precedence greater than prec::Unknown.
267  /// \c true if this token ends a binary expression.
268  unsigned EndsBinaryExpression : 1;
269 
270  /// Is this token part of a \c DeclStmt defining multiple variables?
271  ///
272  /// Only set if \c Type == \c TT_StartOfName.
274 
275  /// Does this line comment continue a line comment section?
276  ///
277  /// Only set to true if \c Type == \c TT_LineComment.
279 
280  /// If \c true, this token has been fully formatted (indented and
281  /// potentially re-formatted inside), and we do not allow further formatting
282  /// changes.
283  unsigned Finalized : 1;
284 
285 private:
286  /// Contains the kind of block if this token is a brace.
287  unsigned BlockKind : 2;
288 
289 public:
291  return static_cast<BraceBlockKind>(BlockKind);
292  }
294  BlockKind = BBK;
295  assert(getBlockKind() == BBK && "BraceBlockKind overflow!");
296  }
297 
298 private:
299  /// Stores the formatting decision for the token once it was made.
300  unsigned Decision : 2;
301 
302 public:
304  return static_cast<FormatDecision>(Decision);
305  }
307  Decision = D;
308  assert(getDecision() == D && "FormatDecision overflow!");
309  }
310 
311 private:
312  /// If this is an opening parenthesis, how are the parameters packed?
313  unsigned PackingKind : 2;
314 
315 public:
317  return static_cast<ParameterPackingKind>(PackingKind);
318  }
320  PackingKind = K;
321  assert(getPackingKind() == K && "ParameterPackingKind overflow!");
322  }
323 
324 private:
325  TokenType Type;
326 
327 public:
328  /// Returns the token's type, e.g. whether "<" is a template opener or
329  /// binary operator.
330  TokenType getType() const { return Type; }
331  void setType(TokenType T) { Type = T; }
332 
333  /// The number of newlines immediately before the \c Token.
334  ///
335  /// This can be used to determine what the user wrote in the original code
336  /// and thereby e.g. leave an empty line between two function definitions.
337  unsigned NewlinesBefore = 0;
338 
339  /// The offset just past the last '\n' in this token's leading
340  /// whitespace (relative to \c WhiteSpaceStart). 0 if there is no '\n'.
341  unsigned LastNewlineOffset = 0;
342 
343  /// The width of the non-whitespace parts of the token (or its first
344  /// line for multi-line tokens) in columns.
345  /// We need this to correctly measure number of columns a token spans.
346  unsigned ColumnWidth = 0;
347 
348  /// Contains the width in columns of the last line of a multi-line
349  /// token.
350  unsigned LastLineColumnWidth = 0;
351 
352  /// The number of spaces that should be inserted before this token.
353  unsigned SpacesRequiredBefore = 0;
354 
355  /// Number of parameters, if this is "(", "[" or "<".
356  unsigned ParameterCount = 0;
357 
358  /// Number of parameters that are nested blocks,
359  /// if this is "(", "[" or "<".
360  unsigned BlockParameterCount = 0;
361 
362  /// If this is a bracket ("<", "(", "[" or "{"), contains the kind of
363  /// the surrounding bracket.
365 
366  /// The total length of the unwrapped line up to and including this
367  /// token.
368  unsigned TotalLength = 0;
369 
370  /// The original 0-based column of this token, including expanded tabs.
371  /// The configured TabWidth is used as tab width.
372  unsigned OriginalColumn = 0;
373 
374  /// The length of following tokens until the next natural split point,
375  /// or the next token that can be broken.
376  unsigned UnbreakableTailLength = 0;
377 
378  // FIXME: Come up with a 'cleaner' concept.
379  /// The binding strength of a token. This is a combined value of
380  /// operator precedence, parenthesis nesting, etc.
381  unsigned BindingStrength = 0;
382 
383  /// The nesting level of this token, i.e. the number of surrounding (),
384  /// [], {} or <>.
385  unsigned NestingLevel = 0;
386 
387  /// The indent level of this token. Copied from the surrounding line.
388  unsigned IndentLevel = 0;
389 
390  /// Penalty for inserting a line break before this token.
391  unsigned SplitPenalty = 0;
392 
393  /// If this is the first ObjC selector name in an ObjC method
394  /// definition or call, this contains the length of the longest name.
395  ///
396  /// This being set to 0 means that the selectors should not be colon-aligned,
397  /// e.g. because several of them are block-type.
399 
400  /// If this is the first ObjC selector name in an ObjC method
401  /// definition or call, this contains the number of parts that the whole
402  /// selector consist of.
403  unsigned ObjCSelectorNameParts = 0;
404 
405  /// The 0-based index of the parameter/argument. For ObjC it is set
406  /// for the selector name token.
407  /// For now calculated only for ObjC.
408  unsigned ParameterIndex = 0;
409 
410  /// Stores the number of required fake parentheses and the
411  /// corresponding operator precedence.
412  ///
413  /// If multiple fake parentheses start at a token, this vector stores them in
414  /// reverse order, i.e. inner fake parenthesis first.
416  /// Insert this many fake ) after this token for correct indentation.
417  unsigned FakeRParens = 0;
418 
419  /// If this is an operator (or "."/"->") in a sequence of operators
420  /// with the same precedence, contains the 0-based operator index.
421  unsigned OperatorIndex = 0;
422 
423  /// If this is an operator (or "."/"->") in a sequence of operators
424  /// with the same precedence, points to the next operator.
426 
427  /// If this is a bracket, this points to the matching one.
429 
430  /// The previous token in the unwrapped line.
431  FormatToken *Previous = nullptr;
432 
433  /// The next token in the unwrapped line.
434  FormatToken *Next = nullptr;
435 
436  /// The first token in set of column elements.
437  bool StartsColumn = false;
438 
439  /// This notes the start of the line of an array initializer.
441 
442  /// This starts an array initializer.
443  bool IsArrayInitializer = false;
444 
445  /// If this token starts a block, this contains all the unwrapped lines
446  /// in it.
448 
449  // Contains all attributes related to how this token takes part
450  // in a configured macro expansion.
452 
453  bool is(tok::TokenKind Kind) const { return Tok.is(Kind); }
454  bool is(TokenType TT) const { return getType() == TT; }
455  bool is(const IdentifierInfo *II) const {
456  return II && II == Tok.getIdentifierInfo();
457  }
458  bool is(tok::PPKeywordKind Kind) const {
459  return Tok.getIdentifierInfo() &&
461  }
462  bool is(BraceBlockKind BBK) const { return getBlockKind() == BBK; }
463  bool is(ParameterPackingKind PPK) const { return getPackingKind() == PPK; }
464 
465  template <typename A, typename B> bool isOneOf(A K1, B K2) const {
466  return is(K1) || is(K2);
467  }
468  template <typename A, typename B, typename... Ts>
469  bool isOneOf(A K1, B K2, Ts... Ks) const {
470  return is(K1) || isOneOf(K2, Ks...);
471  }
472  template <typename T> bool isNot(T Kind) const { return !is(Kind); }
473 
474  bool isIf(bool AllowConstexprMacro = true) const {
475  return is(tok::kw_if) || endsSequence(tok::kw_constexpr, tok::kw_if) ||
476  (endsSequence(tok::identifier, tok::kw_if) && AllowConstexprMacro);
477  }
478 
479  bool closesScopeAfterBlock() const {
480  if (getBlockKind() == BK_Block)
481  return true;
482  if (closesScope())
484  return false;
485  }
486 
487  /// \c true if this token starts a sequence with the given tokens in order,
488  /// following the ``Next`` pointers, ignoring comments.
489  template <typename A, typename... Ts>
490  bool startsSequence(A K1, Ts... Tokens) const {
491  return startsSequenceInternal(K1, Tokens...);
492  }
493 
494  /// \c true if this token ends a sequence with the given tokens in order,
495  /// following the ``Previous`` pointers, ignoring comments.
496  /// For example, given tokens [T1, T2, T3], the function returns true if
497  /// 3 tokens ending at this (ignoring comments) are [T3, T2, T1]. In other
498  /// words, the tokens passed to this function need to the reverse of the
499  /// order the tokens appear in code.
500  template <typename A, typename... Ts>
501  bool endsSequence(A K1, Ts... Tokens) const {
502  return endsSequenceInternal(K1, Tokens...);
503  }
504 
505  bool isStringLiteral() const { return tok::isStringLiteral(Tok.getKind()); }
506 
508  return Tok.isObjCAtKeyword(Kind);
509  }
510 
511  bool isAccessSpecifier(bool ColonRequired = true) const {
512  return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private) &&
513  (!ColonRequired || (Next && Next->is(tok::colon)));
514  }
515 
517  return isOneOf(tok::kw_const, tok::kw_restrict, tok::kw_volatile,
518  tok::kw___attribute, tok::kw__Nonnull, tok::kw__Nullable,
519  tok::kw__Null_unspecified, tok::kw___ptr32, tok::kw___ptr64,
520  TT_AttributeMacro);
521  }
522 
523  /// Determine whether the token is a simple-type-specifier.
524  bool isSimpleTypeSpecifier() const;
525 
526  bool isObjCAccessSpecifier() const {
527  return is(tok::at) && Next &&
528  (Next->isObjCAtKeyword(tok::objc_public) ||
529  Next->isObjCAtKeyword(tok::objc_protected) ||
530  Next->isObjCAtKeyword(tok::objc_package) ||
531  Next->isObjCAtKeyword(tok::objc_private));
532  }
533 
534  /// Returns whether \p Tok is ([{ or an opening < of a template or in
535  /// protos.
536  bool opensScope() const {
537  if (is(TT_TemplateString) && TokenText.endswith("${"))
538  return true;
539  if (is(TT_DictLiteral) && is(tok::less))
540  return true;
541  return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
542  TT_TemplateOpener);
543  }
544  /// Returns whether \p Tok is )]} or a closing > of a template or in
545  /// protos.
546  bool closesScope() const {
547  if (is(TT_TemplateString) && TokenText.startswith("}"))
548  return true;
549  if (is(TT_DictLiteral) && is(tok::greater))
550  return true;
551  return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
552  TT_TemplateCloser);
553  }
554 
555  /// Returns \c true if this is a "." or "->" accessing a member.
556  bool isMemberAccess() const {
557  return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
558  !isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
559  TT_LambdaArrow, TT_LeadingJavaAnnotation);
560  }
561 
562  bool isUnaryOperator() const {
563  switch (Tok.getKind()) {
564  case tok::plus:
565  case tok::plusplus:
566  case tok::minus:
567  case tok::minusminus:
568  case tok::exclaim:
569  case tok::tilde:
570  case tok::kw_sizeof:
571  case tok::kw_alignof:
572  return true;
573  default:
574  return false;
575  }
576  }
577 
578  bool isBinaryOperator() const {
579  // Comma is a binary operator, but does not behave as such wrt. formatting.
580  return getPrecedence() > prec::Comma;
581  }
582 
583  bool isTrailingComment() const {
584  return is(tok::comment) &&
585  (is(TT_LineComment) || !Next || Next->NewlinesBefore > 0);
586  }
587 
588  /// Returns \c true if this is a keyword that can be used
589  /// like a function call (e.g. sizeof, typeid, ...).
590  bool isFunctionLikeKeyword() const {
591  switch (Tok.getKind()) {
592  case tok::kw_throw:
593  case tok::kw_typeid:
594  case tok::kw_return:
595  case tok::kw_sizeof:
596  case tok::kw_alignof:
597  case tok::kw_alignas:
598  case tok::kw_decltype:
599  case tok::kw_noexcept:
600  case tok::kw_static_assert:
601  case tok::kw__Atomic:
602  case tok::kw___attribute:
603  case tok::kw___underlying_type:
604  case tok::kw_requires:
605  return true;
606  default:
607  return false;
608  }
609  }
610 
611  /// Returns \c true if this is a string literal that's like a label,
612  /// e.g. ends with "=" or ":".
613  bool isLabelString() const {
614  if (!is(tok::string_literal))
615  return false;
616  StringRef Content = TokenText;
617  if (Content.startswith("\"") || Content.startswith("'"))
618  Content = Content.drop_front(1);
619  if (Content.endswith("\"") || Content.endswith("'"))
620  Content = Content.drop_back(1);
621  Content = Content.trim();
622  return Content.size() > 1 &&
623  (Content.back() == ':' || Content.back() == '=');
624  }
625 
626  /// Returns actual token start location without leading escaped
627  /// newlines and whitespace.
628  ///
629  /// This can be different to Tok.getLocation(), which includes leading escaped
630  /// newlines.
632  return WhitespaceRange.getEnd();
633  }
634 
636  return getBinOpPrecedence(Tok.getKind(), /*GreaterThanIsOperator=*/true,
637  /*CPlusPlus11=*/true);
638  }
639 
640  /// Returns the previous token ignoring comments.
643  while (Tok && Tok->is(tok::comment))
644  Tok = Tok->Previous;
645  return Tok;
646  }
647 
648  /// Returns the next token ignoring comments.
650  const FormatToken *Tok = Next;
651  while (Tok && Tok->is(tok::comment))
652  Tok = Tok->Next;
653  return Tok;
654  }
655 
656  /// Returns \c true if this tokens starts a block-type list, i.e. a
657  /// list that should be indented with a block indent.
658  bool opensBlockOrBlockTypeList(const FormatStyle &Style) const {
659  // C# Does not indent object initialisers as continuations.
660  if (is(tok::l_brace) && getBlockKind() == BK_BracedInit && Style.isCSharp())
661  return true;
662  if (is(TT_TemplateString) && opensScope())
663  return true;
664  return is(TT_ArrayInitializerLSquare) || is(TT_ProtoExtensionLSquare) ||
665  (is(tok::l_brace) &&
666  (getBlockKind() == BK_Block || is(TT_DictLiteral) ||
667  (!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||
668  (is(tok::less) && (Style.Language == FormatStyle::LK_Proto ||
669  Style.Language == FormatStyle::LK_TextProto));
670  }
671 
672  /// Returns whether the token is the left square bracket of a C++
673  /// structured binding declaration.
674  bool isCppStructuredBinding(const FormatStyle &Style) const {
675  if (!Style.isCpp() || isNot(tok::l_square))
676  return false;
677  const FormatToken *T = this;
678  do {
679  T = T->getPreviousNonComment();
680  } while (T && T->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
681  tok::ampamp));
682  return T && T->is(tok::kw_auto);
683  }
684 
685  /// Same as opensBlockOrBlockTypeList, but for the closing token.
686  bool closesBlockOrBlockTypeList(const FormatStyle &Style) const {
687  if (is(TT_TemplateString) && closesScope())
688  return true;
690  }
691 
692  /// Return the actual namespace token, if this token starts a namespace
693  /// block.
695  const FormatToken *NamespaceTok = this;
696  if (is(tok::comment))
697  NamespaceTok = NamespaceTok->getNextNonComment();
698  // Detect "(inline|export)? namespace" in the beginning of a line.
699  if (NamespaceTok && NamespaceTok->isOneOf(tok::kw_inline, tok::kw_export))
700  NamespaceTok = NamespaceTok->getNextNonComment();
701  return NamespaceTok &&
702  NamespaceTok->isOneOf(tok::kw_namespace, TT_NamespaceMacro)
703  ? NamespaceTok
704  : nullptr;
705  }
706 
707  void copyFrom(const FormatToken &Tok) { *this = Tok; }
708 
709 private:
710  // Only allow copying via the explicit copyFrom method.
711  FormatToken(const FormatToken &) = delete;
712  FormatToken &operator=(const FormatToken &) = default;
713 
714  template <typename A, typename... Ts>
715  bool startsSequenceInternal(A K1, Ts... Tokens) const {
716  if (is(tok::comment) && Next)
717  return Next->startsSequenceInternal(K1, Tokens...);
718  return is(K1) && Next && Next->startsSequenceInternal(Tokens...);
719  }
720 
721  template <typename A> bool startsSequenceInternal(A K1) const {
722  if (is(tok::comment) && Next)
723  return Next->startsSequenceInternal(K1);
724  return is(K1);
725  }
726 
727  template <typename A, typename... Ts> bool endsSequenceInternal(A K1) const {
728  if (is(tok::comment) && Previous)
729  return Previous->endsSequenceInternal(K1);
730  return is(K1);
731  }
732 
733  template <typename A, typename... Ts>
734  bool endsSequenceInternal(A K1, Ts... Tokens) const {
735  if (is(tok::comment) && Previous)
736  return Previous->endsSequenceInternal(K1, Tokens...);
737  return is(K1) && Previous && Previous->endsSequenceInternal(Tokens...);
738  }
739 };
740 
741 class ContinuationIndenter;
742 struct LineState;
743 
744 class TokenRole {
745 public:
747  virtual ~TokenRole();
748 
749  /// After the \c TokenAnnotator has finished annotating all the tokens,
750  /// this function precomputes required information for formatting.
751  virtual void precomputeFormattingInfos(const FormatToken *Token);
752 
753  /// Apply the special formatting that the given role demands.
754  ///
755  /// Assumes that the token having this role is already formatted.
756  ///
757  /// Continues formatting from \p State leaving indentation to \p Indenter and
758  /// returns the total penalty that this formatting incurs.
759  virtual unsigned formatFromToken(LineState &State,
761  bool DryRun) {
762  return 0;
763  }
764 
765  /// Same as \c formatFromToken, but assumes that the first token has
766  /// already been set thereby deciding on the first line break.
767  virtual unsigned formatAfterToken(LineState &State,
769  bool DryRun) {
770  return 0;
771  }
772 
773  /// Notifies the \c Role that a comma was found.
774  virtual void CommaFound(const FormatToken *Token) {}
775 
776  virtual const FormatToken *lastComma() { return nullptr; }
777 
778 protected:
780 };
781 
783 public:
785  : TokenRole(Style), HasNestedBracedList(false) {}
786 
787  void precomputeFormattingInfos(const FormatToken *Token) override;
788 
790  bool DryRun) override;
791 
793  bool DryRun) override;
794 
795  /// Adds \p Token as the next comma to the \c CommaSeparated list.
796  void CommaFound(const FormatToken *Token) override {
797  Commas.push_back(Token);
798  }
799 
800  const FormatToken *lastComma() override {
801  if (Commas.empty())
802  return nullptr;
803  return Commas.back();
804  }
805 
806 private:
807  /// A struct that holds information on how to format a given list with
808  /// a specific number of columns.
809  struct ColumnFormat {
810  /// The number of columns to use.
811  unsigned Columns;
812 
813  /// The total width in characters.
814  unsigned TotalWidth;
815 
816  /// The number of lines required for this format.
817  unsigned LineCount;
818 
819  /// The size of each column in characters.
820  SmallVector<unsigned, 8> ColumnSizes;
821  };
822 
823  /// Calculate which \c ColumnFormat fits best into
824  /// \p RemainingCharacters.
825  const ColumnFormat *getColumnFormat(unsigned RemainingCharacters) const;
826 
827  /// The ordered \c FormatTokens making up the commas of this list.
829 
830  /// The length of each of the list's items in characters including the
831  /// trailing comma.
832  SmallVector<unsigned, 8> ItemLengths;
833 
834  /// Precomputed formats that can be used for this list.
836 
837  bool HasNestedBracedList;
838 };
839 
840 /// Encapsulates keywords that are context sensitive or for languages not
841 /// properly supported by Clang's lexer.
844  kw_final = &IdentTable.get("final");
845  kw_override = &IdentTable.get("override");
846  kw_in = &IdentTable.get("in");
847  kw_of = &IdentTable.get("of");
848  kw_CF_CLOSED_ENUM = &IdentTable.get("CF_CLOSED_ENUM");
849  kw_CF_ENUM = &IdentTable.get("CF_ENUM");
850  kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS");
851  kw_NS_CLOSED_ENUM = &IdentTable.get("NS_CLOSED_ENUM");
852  kw_NS_ENUM = &IdentTable.get("NS_ENUM");
853  kw_NS_OPTIONS = &IdentTable.get("NS_OPTIONS");
854 
855  kw_as = &IdentTable.get("as");
856  kw_async = &IdentTable.get("async");
857  kw_await = &IdentTable.get("await");
858  kw_declare = &IdentTable.get("declare");
859  kw_finally = &IdentTable.get("finally");
860  kw_from = &IdentTable.get("from");
861  kw_function = &IdentTable.get("function");
862  kw_get = &IdentTable.get("get");
863  kw_import = &IdentTable.get("import");
864  kw_infer = &IdentTable.get("infer");
865  kw_is = &IdentTable.get("is");
866  kw_let = &IdentTable.get("let");
867  kw_module = &IdentTable.get("module");
868  kw_readonly = &IdentTable.get("readonly");
869  kw_set = &IdentTable.get("set");
870  kw_type = &IdentTable.get("type");
871  kw_typeof = &IdentTable.get("typeof");
872  kw_var = &IdentTable.get("var");
873  kw_yield = &IdentTable.get("yield");
874 
875  kw_abstract = &IdentTable.get("abstract");
876  kw_assert = &IdentTable.get("assert");
877  kw_extends = &IdentTable.get("extends");
878  kw_implements = &IdentTable.get("implements");
879  kw_instanceof = &IdentTable.get("instanceof");
880  kw_interface = &IdentTable.get("interface");
881  kw_native = &IdentTable.get("native");
882  kw_package = &IdentTable.get("package");
883  kw_synchronized = &IdentTable.get("synchronized");
884  kw_throws = &IdentTable.get("throws");
885  kw___except = &IdentTable.get("__except");
886  kw___has_include = &IdentTable.get("__has_include");
887  kw___has_include_next = &IdentTable.get("__has_include_next");
888 
889  kw_mark = &IdentTable.get("mark");
890 
891  kw_extend = &IdentTable.get("extend");
892  kw_option = &IdentTable.get("option");
893  kw_optional = &IdentTable.get("optional");
894  kw_repeated = &IdentTable.get("repeated");
895  kw_required = &IdentTable.get("required");
896  kw_returns = &IdentTable.get("returns");
897 
898  kw_signals = &IdentTable.get("signals");
899  kw_qsignals = &IdentTable.get("Q_SIGNALS");
900  kw_slots = &IdentTable.get("slots");
901  kw_qslots = &IdentTable.get("Q_SLOTS");
902 
903  // C# keywords
904  kw_dollar = &IdentTable.get("dollar");
905  kw_base = &IdentTable.get("base");
906  kw_byte = &IdentTable.get("byte");
907  kw_checked = &IdentTable.get("checked");
908  kw_decimal = &IdentTable.get("decimal");
909  kw_delegate = &IdentTable.get("delegate");
910  kw_event = &IdentTable.get("event");
911  kw_fixed = &IdentTable.get("fixed");
912  kw_foreach = &IdentTable.get("foreach");
913  kw_implicit = &IdentTable.get("implicit");
914  kw_internal = &IdentTable.get("internal");
915  kw_lock = &IdentTable.get("lock");
916  kw_null = &IdentTable.get("null");
917  kw_object = &IdentTable.get("object");
918  kw_out = &IdentTable.get("out");
919  kw_params = &IdentTable.get("params");
920  kw_ref = &IdentTable.get("ref");
921  kw_string = &IdentTable.get("string");
922  kw_stackalloc = &IdentTable.get("stackalloc");
923  kw_sbyte = &IdentTable.get("sbyte");
924  kw_sealed = &IdentTable.get("sealed");
925  kw_uint = &IdentTable.get("uint");
926  kw_ulong = &IdentTable.get("ulong");
927  kw_unchecked = &IdentTable.get("unchecked");
928  kw_unsafe = &IdentTable.get("unsafe");
929  kw_ushort = &IdentTable.get("ushort");
930  kw_when = &IdentTable.get("when");
931  kw_where = &IdentTable.get("where");
932 
933  // Keep this at the end of the constructor to make sure everything here
934  // is
935  // already initialized.
936  JsExtraKeywords = std::unordered_set<IdentifierInfo *>(
940  // Keywords from the Java section.
942 
943  CSharpExtraKeywords = std::unordered_set<IdentifierInfo *>(
949  kw_where,
950  // Keywords from the JavaScript section.
954  // Keywords from the Java section.
956  }
957 
958  // Context sensitive keywords.
972 
973  // JavaScript keywords.
993 
994  // Java keywords.
1005 
1006  // Pragma keywords.
1008 
1009  // Proto keywords.
1016 
1017  // QT keywords.
1022 
1023  // C# keywords
1035 
1040 
1042 
1055 
1056  /// Returns \c true if \p Tok is a true JavaScript identifier, returns
1057  /// \c false if it is a keyword or a pseudo keyword.
1058  /// If \c AcceptIdentifierName is true, returns true not only for keywords,
1059  // but also for IdentifierName tokens (aka pseudo-keywords), such as
1060  // ``yield``.
1062  bool AcceptIdentifierName = true) const {
1063  // Based on the list of JavaScript & TypeScript keywords here:
1064  // https://github.com/microsoft/TypeScript/blob/main/src/compiler/scanner.ts#L74
1065  switch (Tok.Tok.getKind()) {
1066  case tok::kw_break:
1067  case tok::kw_case:
1068  case tok::kw_catch:
1069  case tok::kw_class:
1070  case tok::kw_continue:
1071  case tok::kw_const:
1072  case tok::kw_default:
1073  case tok::kw_delete:
1074  case tok::kw_do:
1075  case tok::kw_else:
1076  case tok::kw_enum:
1077  case tok::kw_export:
1078  case tok::kw_false:
1079  case tok::kw_for:
1080  case tok::kw_if:
1081  case tok::kw_import:
1082  case tok::kw_module:
1083  case tok::kw_new:
1084  case tok::kw_private:
1085  case tok::kw_protected:
1086  case tok::kw_public:
1087  case tok::kw_return:
1088  case tok::kw_static:
1089  case tok::kw_switch:
1090  case tok::kw_this:
1091  case tok::kw_throw:
1092  case tok::kw_true:
1093  case tok::kw_try:
1094  case tok::kw_typeof:
1095  case tok::kw_void:
1096  case tok::kw_while:
1097  // These are JS keywords that are lexed by LLVM/clang as keywords.
1098  return false;
1099  case tok::identifier: {
1100  // For identifiers, make sure they are true identifiers, excluding the
1101  // JavaScript pseudo-keywords (not lexed by LLVM/clang as keywords).
1102  bool IsPseudoKeyword =
1103  JsExtraKeywords.find(Tok.Tok.getIdentifierInfo()) !=
1104  JsExtraKeywords.end();
1105  return AcceptIdentifierName || !IsPseudoKeyword;
1106  }
1107  default:
1108  // Other keywords are handled in the switch below, to avoid problems due
1109  // to duplicate case labels when using the #include trick.
1110  break;
1111  }
1112 
1113  switch (Tok.Tok.getKind()) {
1114  // Handle C++ keywords not included above: these are all JS identifiers.
1115 #define KEYWORD(X, Y) case tok::kw_##X:
1116 #include "clang/Basic/TokenKinds.def"
1117  // #undef KEYWORD is not needed -- it's #undef-ed at the end of
1118  // TokenKinds.def
1119  return true;
1120  default:
1121  // All other tokens (punctuation etc) are not JS identifiers.
1122  return false;
1123  }
1124  }
1125 
1126  /// Returns \c true if \p Tok is a C# keyword, returns
1127  /// \c false if it is a anything else.
1128  bool isCSharpKeyword(const FormatToken &Tok) const {
1129  switch (Tok.Tok.getKind()) {
1130  case tok::kw_bool:
1131  case tok::kw_break:
1132  case tok::kw_case:
1133  case tok::kw_catch:
1134  case tok::kw_char:
1135  case tok::kw_class:
1136  case tok::kw_const:
1137  case tok::kw_continue:
1138  case tok::kw_default:
1139  case tok::kw_do:
1140  case tok::kw_double:
1141  case tok::kw_else:
1142  case tok::kw_enum:
1143  case tok::kw_explicit:
1144  case tok::kw_extern:
1145  case tok::kw_false:
1146  case tok::kw_float:
1147  case tok::kw_for:
1148  case tok::kw_goto:
1149  case tok::kw_if:
1150  case tok::kw_int:
1151  case tok::kw_long:
1152  case tok::kw_namespace:
1153  case tok::kw_new:
1154  case tok::kw_operator:
1155  case tok::kw_private:
1156  case tok::kw_protected:
1157  case tok::kw_public:
1158  case tok::kw_return:
1159  case tok::kw_short:
1160  case tok::kw_sizeof:
1161  case tok::kw_static:
1162  case tok::kw_struct:
1163  case tok::kw_switch:
1164  case tok::kw_this:
1165  case tok::kw_throw:
1166  case tok::kw_true:
1167  case tok::kw_try:
1168  case tok::kw_typeof:
1169  case tok::kw_using:
1170  case tok::kw_virtual:
1171  case tok::kw_void:
1172  case tok::kw_volatile:
1173  case tok::kw_while:
1174  return true;
1175  default:
1176  return Tok.is(tok::identifier) &&
1177  CSharpExtraKeywords.find(Tok.Tok.getIdentifierInfo()) ==
1178  CSharpExtraKeywords.end();
1179  }
1180  }
1181 
1182 private:
1183  /// The JavaScript keywords beyond the C++ keyword set.
1184  std::unordered_set<IdentifierInfo *> JsExtraKeywords;
1185 
1186  /// The C# keywords beyond the C++ keyword set
1187  std::unordered_set<IdentifierInfo *> CSharpExtraKeywords;
1188 };
1189 
1190 } // namespace format
1191 } // namespace clang
1192 
1193 #endif
clang::format::AdditionalKeywords::kw_object
IdentifierInfo * kw_object
Definition: FormatToken.h:1038
clang::format::FormatToken::LongestObjCSelectorName
unsigned LongestObjCSelectorName
If this is the first ObjC selector name in an ObjC method definition or call, this contains the lengt...
Definition: FormatToken.h:398
clang::format::FormatToken::getNextNonComment
const FormatToken * getNextNonComment() const
Returns the next token ignoring comments.
Definition: FormatToken.h:649
clang::format::FormatToken::MustBreakBefore
unsigned MustBreakBefore
Whether there must be a line break before this token.
Definition: FormatToken.h:253
clang::prec::Comma
@ Comma
Definition: OperatorPrecedence.h:28
clang::format::AdditionalKeywords::kw_implements
IdentifierInfo * kw_implements
Definition: FormatToken.h:998
clang::format::FormatToken::BindingStrength
unsigned BindingStrength
The binding strength of a token.
Definition: FormatToken.h:381
clang::format::AdditionalKeywords::AdditionalKeywords
AdditionalKeywords(IdentifierTable &IdentTable)
Definition: FormatToken.h:843
clang::format::MacroExpansion::EndOfExpansion
unsigned EndOfExpansion
The number of currently open expansions in ExpandedFrom this macro is the last token in.
Definition: FormatToken.h:203
clang::format::AdditionalKeywords::kw_NS_OPTIONS
IdentifierInfo * kw_NS_OPTIONS
Definition: FormatToken.h:968
clang::format::MacroExpansion::Role
MacroRole Role
The token's role in the macro expansion.
Definition: FormatToken.h:193
clang::format::AdditionalKeywords::kw_abstract
IdentifierInfo * kw_abstract
Definition: FormatToken.h:995
clang::format::AdditionalKeywords::kw_CF_ENUM
IdentifierInfo * kw_CF_ENUM
Definition: FormatToken.h:964
clang::Token::isObjCAtKeyword
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
Definition: Lexer.cpp:57
clang::format::MacroRole
MacroRole
Roles a token can take in a configured macro expansion.
Definition: FormatToken.h:145
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
clang::format::FormatToken::getNamespaceToken
const FormatToken * getNamespaceToken() const
Return the actual namespace token, if this token starts a namespace block.
Definition: FormatToken.h:694
clang::format::FormatToken::isObjCAtKeyword
bool isObjCAtKeyword(tok::ObjCKeywordKind Kind) const
Definition: FormatToken.h:507
clang::format::FormatToken::ClosesTemplateDeclaration
unsigned ClosesTemplateDeclaration
true if this is the ">" of "template<..>".
Definition: FormatToken.h:262
clang::format::FormatToken::SplitPenalty
unsigned SplitPenalty
Penalty for inserting a line break before this token.
Definition: FormatToken.h:391
clang::format::FormatToken::isBinaryOperator
bool isBinaryOperator() const
Definition: FormatToken.h:578
clang::format::FormatToken::isIf
bool isIf(bool AllowConstexprMacro=true) const
Definition: FormatToken.h:474
clang::format::AdditionalKeywords::kw_internal
IdentifierInfo * kw_internal
Definition: FormatToken.h:1034
clang::format::AdditionalKeywords::kw_instanceof
IdentifierInfo * kw_instanceof
Definition: FormatToken.h:999
llvm::SmallVector
Definition: LLVM.h:38
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:592
clang::format::BK_Unknown
@ BK_Unknown
Definition: FormatToken.h:137
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::format::FormatToken::getPrecedence
prec::Level getPrecedence() const
Definition: FormatToken.h:635
clang::format::AdditionalKeywords::kw_stackalloc
IdentifierInfo * kw_stackalloc
Definition: FormatToken.h:1045
clang::format::AdditionalKeywords::kw_from
IdentifierInfo * kw_from
Definition: FormatToken.h:979
clang::format::TokenRole::~TokenRole
virtual ~TokenRole()
Definition: FormatToken.cpp:73
clang::format::AdditionalKeywords::kw_final
IdentifierInfo * kw_final
Definition: FormatToken.h:959
clang::format::AdditionalKeywords::kw_readonly
IdentifierInfo * kw_readonly
Definition: FormatToken.h:987
clang::Token::getIdentifierInfo
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:179
clang::format::AdditionalKeywords::kw_optional
IdentifierInfo * kw_optional
Definition: FormatToken.h:1012
clang::format::FormatToken::IndentLevel
unsigned IndentLevel
The indent level of this token. Copied from the surrounding line.
Definition: FormatToken.h:388
clang::format::AdditionalKeywords::kw_is
IdentifierInfo * kw_is
Definition: FormatToken.h:984
clang::format::FormatStyle
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition: Format.h:59
clang::format::FormatToken::TokenText
StringRef TokenText
The raw text of the token.
Definition: FormatToken.h:228
clang::format::AdditionalKeywords::kw_CF_CLOSED_ENUM
IdentifierInfo * kw_CF_CLOSED_ENUM
Definition: FormatToken.h:963
clang::format::FormatToken::IsMultiline
unsigned IsMultiline
Whether the token text contains newlines (escaped or not).
Definition: FormatToken.h:244
clang::format::FormatToken
A wrapper around a Token storing information about the whitespace characters preceding it.
Definition: FormatToken.h:211
clang::format::AdditionalKeywords
Encapsulates keywords that are context sensitive or for languages not properly supported by Clang's l...
Definition: FormatToken.h:842
clang::format::FormatToken::StartsColumn
bool StartsColumn
The first token in set of column elements.
Definition: FormatToken.h:437
llvm::Optional
Definition: LLVM.h:40
clang::format::ParameterPackingKind
ParameterPackingKind
Definition: FormatToken.h:140
clang::format::FormatToken::isNot
bool isNot(T Kind) const
Definition: FormatToken.h:472
clang::format::TokenRole
Definition: FormatToken.h:744
clang::format::FormatToken::SpacesRequiredBefore
unsigned SpacesRequiredBefore
The number of spaces that should be inserted before this token.
Definition: FormatToken.h:353
clang::format::FormatToken::OriginalColumn
unsigned OriginalColumn
The original 0-based column of this token, including expanded tabs.
Definition: FormatToken.h:372
clang::format::FormatToken::OperatorIndex
unsigned OperatorIndex
If this is an operator (or "."/"->") in a sequence of operators with the same precedence,...
Definition: FormatToken.h:421
clang::format::CommaSeparatedList::lastComma
const FormatToken * lastComma() override
Definition: FormatToken.h:800
clang::format::FormatToken::BlockParameterCount
unsigned BlockParameterCount
Number of parameters that are nested blocks, if this is "(", "[" or "<".
Definition: FormatToken.h:360
clang::format::AdditionalKeywords::kw_as
IdentifierInfo * kw_as
Definition: FormatToken.h:974
clang::format::AdditionalKeywords::kw_native
IdentifierInfo * kw_native
Definition: FormatToken.h:1001
clang::format::FormatToken::closesBlockOrBlockTypeList
bool closesBlockOrBlockTypeList(const FormatStyle &Style) const
Same as opensBlockOrBlockTypeList, but for the closing token.
Definition: FormatToken.h:686
Format.h
clang::format::AdditionalKeywords::kw_signals
IdentifierInfo * kw_signals
Definition: FormatToken.h:1018
clang::format::FormatToken::setType
void setType(TokenType T)
Definition: FormatToken.h:331
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::tok::isStringLiteral
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token.
Definition: TokenKinds.h:78
clang::format::FormatToken::IsFirst
unsigned IsFirst
Indicates that this is the first token of the file.
Definition: FormatToken.h:247
clang::format::MacroExpansion::MacroExpansion
MacroExpansion(MacroRole Role)
Definition: FormatToken.h:185
clang::format::BK_BracedInit
@ BK_BracedInit
Definition: FormatToken.h:137
clang::format::AdditionalKeywords::kw_synchronized
IdentifierInfo * kw_synchronized
Definition: FormatToken.h:1003
clang::format::PPK_BinPacked
@ PPK_BinPacked
Definition: FormatToken.h:140
clang::format::FormatToken::FormatToken
FormatToken()
Definition: FormatToken.h:212
clang::format::FormatToken::NewlinesBefore
unsigned NewlinesBefore
The number of newlines immediately before the Token.
Definition: FormatToken.h:337
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
clang::format::AdditionalKeywords::kw_sbyte
IdentifierInfo * kw_sbyte
Definition: FormatToken.h:1046
clang::format::FormatToken::PartOfMultiVariableDeclStmt
unsigned PartOfMultiVariableDeclStmt
Is this token part of a DeclStmt defining multiple variables?
Definition: FormatToken.h:273
clang::format::FormatToken::getDecision
FormatDecision getDecision() const
Definition: FormatToken.h:303
clang::format::CommaSeparatedList::formatFromToken
unsigned formatFromToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun) override
Apply the special formatting that the given role demands.
Definition: FormatToken.cpp:136
clang::format::FormatToken::is
bool is(ParameterPackingKind PPK) const
Definition: FormatToken.h:463
clang::format::FormatToken::CanBreakBefore
unsigned CanBreakBefore
true if it is allowed to break before this token.
Definition: FormatToken.h:259
clang::format::AdditionalKeywords::kw_sealed
IdentifierInfo * kw_sealed
Definition: FormatToken.h:1047
clang::format::FormatToken::isCppStructuredBinding
bool isCppStructuredBinding(const FormatStyle &Style) const
Returns whether the token is the left square bracket of a C++ structured binding declaration.
Definition: FormatToken.h:674
clang::format::FormatToken::isAccessSpecifier
bool isAccessSpecifier(bool ColonRequired=true) const
Definition: FormatToken.h:511
clang::format::FormatToken::FakeRParens
unsigned FakeRParens
Insert this many fake ) after this token for correct indentation.
Definition: FormatToken.h:417
clang::format::FormatToken::isLabelString
bool isLabelString() const
Returns true if this is a string literal that's like a label, e.g.
Definition: FormatToken.h:613
clang::format::FormatToken::ArrayInitializerLineStart
bool ArrayInitializerLineStart
This notes the start of the line of an array initializer.
Definition: FormatToken.h:440
clang::format::CommaSeparatedList::CommaSeparatedList
CommaSeparatedList(const FormatStyle &Style)
Definition: FormatToken.h:784
clang::format::AdditionalKeywords::kw_import
IdentifierInfo * kw_import
Definition: FormatToken.h:982
clang::format::FormatStyle::LK_Proto
@ LK_Proto
Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).
Definition: Format.h:2662
clang::format::FormatToken::closesScope
bool closesScope() const
Returns whether Tok is )]} or a closing > of a template or in protos.
Definition: FormatToken.h:546
clang::format::AdditionalKeywords::kw_await
IdentifierInfo * kw_await
Definition: FormatToken.h:976
clang::format::FormatToken::NestingLevel
unsigned NestingLevel
The nesting level of this token, i.e.
Definition: FormatToken.h:385
clang::format::AdditionalKeywords::kw_extends
IdentifierInfo * kw_extends
Definition: FormatToken.h:997
LIST_TOKEN_TYPES
#define LIST_TOKEN_TYPES
Definition: FormatToken.h:28
clang::format::AdditionalKeywords::kw_foreach
IdentifierInfo * kw_foreach
Definition: FormatToken.h:1032
clang::format::AdditionalKeywords::kw_async
IdentifierInfo * kw_async
Definition: FormatToken.h:975
clang::format::FormatToken::Previous
FormatToken * Previous
The previous token in the unwrapped line.
Definition: FormatToken.h:431
clang::format::LineState
The current state when indenting a unwrapped line.
Definition: ContinuationIndenter.h:406
clang::format::TokenRole::formatAfterToken
virtual unsigned formatAfterToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun)
Same as formatFromToken, but assumes that the first token has already been set thereby deciding on th...
Definition: FormatToken.h:767
clang::format::FormatToken::EndsBinaryExpression
unsigned EndsBinaryExpression
true if this token ends a binary expression.
Definition: FormatToken.h:268
clang::format::FormatToken::getPackingKind
ParameterPackingKind getPackingKind() const
Definition: FormatToken.h:316
clang::format::AdditionalKeywords::kw_assert
IdentifierInfo * kw_assert
Definition: FormatToken.h:996
clang::format::AdditionalKeywords::kw_qslots
IdentifierInfo * kw_qslots
Definition: FormatToken.h:1021
clang::format::FormatToken::StartsBinaryExpression
unsigned StartsBinaryExpression
true if this token starts a binary expression, i.e.
Definition: FormatToken.h:266
clang::format::AdditionalKeywords::kw_NS_ENUM
IdentifierInfo * kw_NS_ENUM
Definition: FormatToken.h:967
clang::format::TokenRole::lastComma
virtual const FormatToken * lastComma()
Definition: FormatToken.h:776
clang::format::FormatToken::isMemberAccess
bool isMemberAccess() const
Returns true if this is a "." or "->" accessing a member.
Definition: FormatToken.h:556
clang::format::FormatToken::Tok
Token Tok
The Token.
Definition: FormatToken.h:222
clang::format::AdditionalKeywords::isCSharpKeyword
bool isCSharpKeyword(const FormatToken &Tok) const
Returns true if Tok is a C# keyword, returns false if it is a anything else.
Definition: FormatToken.h:1128
clang::format::AdditionalKeywords::kw_params
IdentifierInfo * kw_params
Definition: FormatToken.h:1041
clang::format::AdditionalKeywords::kw_required
IdentifierInfo * kw_required
Definition: FormatToken.h:1014
clang::format::AdditionalKeywords::kw_repeated
IdentifierInfo * kw_repeated
Definition: FormatToken.h:1013
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:220
clang::format::AdditionalKeywords::kw_throws
IdentifierInfo * kw_throws
Definition: FormatToken.h:1004
clang::Token::getKind
tok::TokenKind getKind() const
Definition: Token.h:92
clang::format::CommaSeparatedList::CommaFound
void CommaFound(const FormatToken *Token) override
Adds Token as the next comma to the CommaSeparated list.
Definition: FormatToken.h:796
clang::format::FormatStyle::LK_TextProto
@ LK_TextProto
Should be used for Protocol Buffer messages in text format (https://developers.google....
Definition: Format.h:2667
clang::format::FormatToken::isFunctionLikeKeyword
bool isFunctionLikeKeyword() const
Returns true if this is a keyword that can be used like a function call (e.g.
Definition: FormatToken.h:590
clang::format::AdditionalKeywords::kw_in
IdentifierInfo * kw_in
Definition: FormatToken.h:961
clang::format::AnnotatedLine
Definition: TokenAnnotator.h:38
clang::format::AdditionalKeywords::kw_ushort
IdentifierInfo * kw_ushort
Definition: FormatToken.h:1052
clang::format::AdditionalKeywords::kw_var
IdentifierInfo * kw_var
Definition: FormatToken.h:991
clang::format::FormatToken::is
bool is(const IdentifierInfo *II) const
Definition: FormatToken.h:455
clang::format::FormatToken::isObjCAccessSpecifier
bool isObjCAccessSpecifier() const
Definition: FormatToken.h:526
clang::Token::is
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
Definition: Token.h:97
clang::format::FormatToken::isTrailingComment
bool isTrailingComment() const
Definition: FormatToken.h:583
IdentifierTable.h
clang::format::FormatToken::isStringLiteral
bool isStringLiteral() const
Definition: FormatToken.h:505
clang::format::AdditionalKeywords::kw_of
IdentifierInfo * kw_of
Definition: FormatToken.h:962
clang::format::AdditionalKeywords::kw_lock
IdentifierInfo * kw_lock
Definition: FormatToken.h:1036
clang::format::AdditionalKeywords::kw_unsafe
IdentifierInfo * kw_unsafe
Definition: FormatToken.h:1051
clang::format::FD_Break
@ FD_Break
Definition: FormatToken.h:142
clang::format::TokenRole::formatFromToken
virtual unsigned formatFromToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun)
Apply the special formatting that the given role demands.
Definition: FormatToken.h:759
clang::format::AdditionalKeywords::kw_unchecked
IdentifierInfo * kw_unchecked
Definition: FormatToken.h:1050
clang::format::TokenRole::Style
const FormatStyle & Style
Definition: FormatToken.h:779
clang::format::AdditionalKeywords::kw_package
IdentifierInfo * kw_package
Definition: FormatToken.h:1002
clang::format::AdditionalKeywords::kw_finally
IdentifierInfo * kw_finally
Definition: FormatToken.h:978
clang::format::MacroExpansion
Contains information on the token's role in a macro expansion.
Definition: FormatToken.h:184
clang::format::AdditionalKeywords::kw_override
IdentifierInfo * kw_override
Definition: FormatToken.h:960
clang::tok::ObjCKeywordKind
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
Definition: TokenKinds.h:41
clang::format::BK_Block
@ BK_Block
Definition: FormatToken.h:137
clang::format::AdditionalKeywords::kw_null
IdentifierInfo * kw_null
Definition: FormatToken.h:1037
clang::format::CommaSeparatedList::precomputeFormattingInfos
void precomputeFormattingInfos(const FormatToken *Token) override
After the TokenAnnotator has finished annotating all the tokens, this function precomputes required i...
Definition: FormatToken.cpp:154
clang::format::MR_Hidden
@ MR_Hidden
The token was expanded from a macro definition, and is not visible as part of the macro call.
Definition: FormatToken.h:154
clang::format::AdditionalKeywords::kw___has_include
IdentifierInfo * kw___has_include
Definition: FormatToken.h:970
clang::format::MacroExpansion::ExpandedFrom
llvm::SmallVector< FormatToken *, 1 > ExpandedFrom
The stack of macro call identifier tokens this token was expanded from.
Definition: FormatToken.h:196
clang::format::FormatToken::getPreviousNonComment
FormatToken * getPreviousNonComment() const
Returns the previous token ignoring comments.
Definition: FormatToken.h:641
clang::format::FormatToken::is
bool is(tok::PPKeywordKind Kind) const
Definition: FormatToken.h:458
clang::format::PPK_OnePerLine
@ PPK_OnePerLine
Definition: FormatToken.h:140
clang::format::FormatToken::ParentBracket
tok::TokenKind ParentBracket
If this is a bracket ("<", "(", "[" or "{"), contains the kind of the surrounding bracket.
Definition: FormatToken.h:364
clang::format::getTokenTypeName
const char * getTokenTypeName(TokenType Type)
Determines the name of a token type.
Definition: FormatToken.cpp:24
clang::format::FormatToken::ContinuesLineCommentSection
unsigned ContinuesLineCommentSection
Does this line comment continue a line comment section?
Definition: FormatToken.h:278
clang::format::AdditionalKeywords::IsJavaScriptIdentifier
bool IsJavaScriptIdentifier(const FormatToken &Tok, bool AcceptIdentifierName=true) const
Returns true if Tok is a true JavaScript identifier, returns false if it is a keyword or a pseudo key...
Definition: FormatToken.h:1061
clang::format::AdditionalKeywords::kw_type
IdentifierInfo * kw_type
Definition: FormatToken.h:989
clang::format::FormatToken::canBePointerOrReferenceQualifier
bool canBePointerOrReferenceQualifier() const
Definition: FormatToken.h:516
clang::format::AdditionalKeywords::kw_decimal
IdentifierInfo * kw_decimal
Definition: FormatToken.h:1028
clang::format::FormatToken::isOneOf
bool isOneOf(A K1, B K2, Ts... Ks) const
Definition: FormatToken.h:469
clang::format::FormatToken::startsSequence
bool startsSequence(A K1, Ts... Tokens) const
true if this token starts a sequence with the given tokens in order, following the Next pointers,...
Definition: FormatToken.h:490
clang::format::NUM_TOKEN_TYPES
@ NUM_TOKEN_TYPES
Definition: FormatToken.h:130
clang::format::FormatToken::is
bool is(TokenType TT) const
Definition: FormatToken.h:454
clang::format::AdditionalKeywords::kw_mark
IdentifierInfo * kw_mark
Definition: FormatToken.h:1007
clang::format::FormatToken::isUnaryOperator
bool isUnaryOperator() const
Definition: FormatToken.h:562
clang::tok::TokenKind
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
clang::format::FormatToken::FakeLParens
SmallVector< prec::Level, 4 > FakeLParens
Stores the number of required fake parentheses and the corresponding operator precedence.
Definition: FormatToken.h:415
false
#define false
Definition: stdbool.h:17
clang::format::FD_Unformatted
@ FD_Unformatted
Definition: FormatToken.h:142
clang::format::FormatToken::Finalized
unsigned Finalized
If true, this token has been fully formatted (indented and potentially re-formatted inside),...
Definition: FormatToken.h:283
clang::format::CommaSeparatedList::formatAfterToken
unsigned formatAfterToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun) override
Same as formatFromToken, but assumes that the first token has already been set thereby deciding on th...
Definition: FormatToken.cpp:77
clang::format::FormatToken::getType
TokenType getType() const
Returns the token's type, e.g.
Definition: FormatToken.h:330
clang::format::AdditionalKeywords::kw_option
IdentifierInfo * kw_option
Definition: FormatToken.h:1011
clang::format::AdditionalKeywords::kw_let
IdentifierInfo * kw_let
Definition: FormatToken.h:985
Lexer.h
clang::format::FormatToken::getBlockKind
BraceBlockKind getBlockKind() const
Definition: FormatToken.h:290
clang::format::AdditionalKeywords::kw_byte
IdentifierInfo * kw_byte
Definition: FormatToken.h:1026
clang::tok::PPKeywordKind
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line.
Definition: TokenKinds.h:33
clang::format::AdditionalKeywords::kw_get
IdentifierInfo * kw_get
Definition: FormatToken.h:981
clang::format::AdditionalKeywords::kw_dollar
IdentifierInfo * kw_dollar
Definition: FormatToken.h:1024
clang::format::FormatToken::UnbreakableTailLength
unsigned UnbreakableTailLength
The length of following tokens until the next natural split point, or the next token that can be brok...
Definition: FormatToken.h:376
clang::format::FormatToken::is
bool is(tok::TokenKind Kind) const
Definition: FormatToken.h:453
clang::format::AdditionalKeywords::kw_set
IdentifierInfo * kw_set
Definition: FormatToken.h:988
clang::IdentifierInfo::getPPKeywordID
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.
Definition: IdentifierTable.cpp:312
clang::format::AdditionalKeywords::kw_declare
IdentifierInfo * kw_declare
Definition: FormatToken.h:977
State
LineState State
Definition: UnwrappedLineFormatter.cpp:987
clang::format::FormatToken::isOneOf
bool isOneOf(A K1, B K2) const
Definition: FormatToken.h:465
clang::format::FormatToken::getStartOfNonWhitespace
SourceLocation getStartOfNonWhitespace() const
Returns actual token start location without leading escaped newlines and whitespace.
Definition: FormatToken.h:631
clang::format::FormatToken::ParameterCount
unsigned ParameterCount
Number of parameters, if this is "(", "[" or "<".
Definition: FormatToken.h:356
clang::format::AdditionalKeywords::kw_fixed
IdentifierInfo * kw_fixed
Definition: FormatToken.h:1031
clang::format::FormatToken::LastLineColumnWidth
unsigned LastLineColumnWidth
Contains the width in columns of the last line of a multi-line token.
Definition: FormatToken.h:350
clang::format::AdditionalKeywords::kw_base
IdentifierInfo * kw_base
Definition: FormatToken.h:1025
clang::format::AdditionalKeywords::kw_function
IdentifierInfo * kw_function
Definition: FormatToken.h:980
clang::format::FD_Continue
@ FD_Continue
Definition: FormatToken.h:142
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
clang::format::ContinuationIndenter
Definition: ContinuationIndenter.h:50
clang::format::AdditionalKeywords::kw_module
IdentifierInfo * kw_module
Definition: FormatToken.h:986
clang::format::AdditionalKeywords::kw_typeof
IdentifierInfo * kw_typeof
Definition: FormatToken.h:990
clang::format::AdditionalKeywords::kw_delegate
IdentifierInfo * kw_delegate
Definition: FormatToken.h:1029
clang::format::AdditionalKeywords::kw_event
IdentifierInfo * kw_event
Definition: FormatToken.h:1030
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::format::FormatToken::endsSequence
bool endsSequence(A K1, Ts... Tokens) const
true if this token ends a sequence with the given tokens in order, following the Previous pointers,...
Definition: FormatToken.h:501
clang::format::AdditionalKeywords::kw_extend
IdentifierInfo * kw_extend
Definition: FormatToken.h:1010
clang::format::FormatToken::Role
std::shared_ptr< TokenRole > Role
A token can have a special role that can carry extra information about the token's formatting.
Definition: FormatToken.h:234
clang::format::FormatToken::NextOperator
FormatToken * NextOperator
If this is an operator (or "."/"->") in a sequence of operators with the same precedence,...
Definition: FormatToken.h:425
clang::format::FormatToken::MacroCtx
llvm::Optional< MacroExpansion > MacroCtx
Definition: FormatToken.h:451
clang::format::AdditionalKeywords::kw_interface
IdentifierInfo * kw_interface
Definition: FormatToken.h:1000
clang::format::FormatToken::setBlockKind
void setBlockKind(BraceBlockKind BBK)
Definition: FormatToken.h:293
clang::format::MR_UnexpandedArg
@ MR_UnexpandedArg
The token is part of a macro argument that was previously formatted as expansion when formatting the ...
Definition: FormatToken.h:151
clang::format::FormatToken::setPackingKind
void setPackingKind(ParameterPackingKind K)
Definition: FormatToken.h:319
clang::format::AdditionalKeywords::kw_returns
IdentifierInfo * kw_returns
Definition: FormatToken.h:1015
clang
Definition: CalledOnceCheck.h:17
clang::format::FormatToken::Children
SmallVector< AnnotatedLine *, 1 > Children
If this token starts a block, this contains all the unwrapped lines in it.
Definition: FormatToken.h:447
clang::format::FormatToken::isSimpleTypeSpecifier
bool isSimpleTypeSpecifier() const
Determine whether the token is a simple-type-specifier.
Definition: FormatToken.cpp:39
clang::format::AdditionalKeywords::kw_string
IdentifierInfo * kw_string
Definition: FormatToken.h:1044
clang::format::AdditionalKeywords::kw_yield
IdentifierInfo * kw_yield
Definition: FormatToken.h:992
clang::format::AdditionalKeywords::kw___except
IdentifierInfo * kw___except
Definition: FormatToken.h:969
clang::format::FormatToken::opensBlockOrBlockTypeList
bool opensBlockOrBlockTypeList(const FormatStyle &Style) const
Returns true if this tokens starts a block-type list, i.e.
Definition: FormatToken.h:658
clang::format::FormatDecision
FormatDecision
Definition: FormatToken.h:142
clang::prec::Level
Level
Definition: OperatorPrecedence.h:26
clang::format::TokenRole::precomputeFormattingInfos
virtual void precomputeFormattingInfos(const FormatToken *Token)
After the TokenAnnotator has finished annotating all the tokens, this function precomputes required i...
Definition: FormatToken.cpp:75
clang::format::AdditionalKeywords::kw_ulong
IdentifierInfo * kw_ulong
Definition: FormatToken.h:1049
clang::IdentifierTable
Implements an efficient mapping from strings to IdentifierInfo nodes.
Definition: IdentifierTable.h:559
clang::format::FormatToken::IsUnterminatedLiteral
unsigned IsUnterminatedLiteral
Set to true if this token is an unterminated literal.
Definition: FormatToken.h:256
clang::getBinOpPrecedence
prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator, bool CPlusPlus11)
Return the precedence of the specified binary operator token.
Definition: OperatorPrecedence.cpp:17
clang::format::AdditionalKeywords::kw_NS_CLOSED_ENUM
IdentifierInfo * kw_NS_CLOSED_ENUM
Definition: FormatToken.h:966
clang::format::FormatToken::LastNewlineOffset
unsigned LastNewlineOffset
The offset just past the last ' ' in this token's leading whitespace (relative to WhiteSpaceStart).
Definition: FormatToken.h:341
clang::format::AdditionalKeywords::kw_uint
IdentifierInfo * kw_uint
Definition: FormatToken.h:1048
clang::format::FormatToken::ColumnWidth
unsigned ColumnWidth
The width of the non-whitespace parts of the token (or its first line for multi-line tokens) in colum...
Definition: FormatToken.h:346
clang::format::AdditionalKeywords::kw_CF_OPTIONS
IdentifierInfo * kw_CF_OPTIONS
Definition: FormatToken.h:965
clang::format::BraceBlockKind
BraceBlockKind
Definition: FormatToken.h:137
clang::format::FormatToken::ObjCSelectorNameParts
unsigned ObjCSelectorNameParts
If this is the first ObjC selector name in an ObjC method definition or call, this contains the numbe...
Definition: FormatToken.h:403
clang::format::CommaSeparatedList
Definition: FormatToken.h:782
clang::format::TokenRole::CommaFound
virtual void CommaFound(const FormatToken *Token)
Notifies the Role that a comma was found.
Definition: FormatToken.h:774
clang::format::AdditionalKeywords::kw_implicit
IdentifierInfo * kw_implicit
Definition: FormatToken.h:1033
clang::format::AdditionalKeywords::kw_qsignals
IdentifierInfo * kw_qsignals
Definition: FormatToken.h:1019
OperatorPrecedence.h
clang::format::AdditionalKeywords::kw_where
IdentifierInfo * kw_where
Definition: FormatToken.h:1054
clang::format::FormatToken::closesScopeAfterBlock
bool closesScopeAfterBlock() const
Definition: FormatToken.h:479
clang::format::AdditionalKeywords::kw_infer
IdentifierInfo * kw_infer
Definition: FormatToken.h:983
Indenter
ContinuationIndenter * Indenter
Definition: UnwrappedLineFormatter.cpp:884
clang::format::FormatToken::TotalLength
unsigned TotalLength
The total length of the unwrapped line up to and including this token.
Definition: FormatToken.h:368
clang::format::FormatToken::ParameterIndex
unsigned ParameterIndex
The 0-based index of the parameter/argument.
Definition: FormatToken.h:408
clang::format::PPK_Inconclusive
@ PPK_Inconclusive
Definition: FormatToken.h:140
clang::format::FormatToken::Next
FormatToken * Next
The next token in the unwrapped line.
Definition: FormatToken.h:434
clang::format::AdditionalKeywords::kw_when
IdentifierInfo * kw_when
Definition: FormatToken.h:1053
clang::format::MR_ExpandedArg
@ MR_ExpandedArg
The token was expanded from a macro argument when formatting the expanded token sequence.
Definition: FormatToken.h:148
clang::format::FormatToken::HasUnescapedNewline
unsigned HasUnescapedNewline
Whether there is at least one unescaped newline before the Token.
Definition: FormatToken.h:241
clang::format::TokenType
TokenType
Determines the semantic type of a syntactic token, e.g.
Definition: FormatToken.h:126
clang::format::FormatToken::WhitespaceRange
SourceRange WhitespaceRange
The range of the whitespace immediately preceding the Token.
Definition: FormatToken.h:237
clang::format::AdditionalKeywords::kw_checked
IdentifierInfo * kw_checked
Definition: FormatToken.h:1027
clang::format::AdditionalKeywords::kw_slots
IdentifierInfo * kw_slots
Definition: FormatToken.h:1020
clang::format::MacroExpansion::StartOfExpansion
unsigned StartOfExpansion
The number of expansions of which this macro is the first entry.
Definition: FormatToken.h:199
clang::format::AdditionalKeywords::kw___has_include_next
IdentifierInfo * kw___has_include_next
Definition: FormatToken.h:971
clang::format::FormatToken::MatchingParen
FormatToken * MatchingParen
If this is a bracket, this points to the matching one.
Definition: FormatToken.h:428
clang::format::AdditionalKeywords::kw_ref
IdentifierInfo * kw_ref
Definition: FormatToken.h:1043
clang::format::FormatToken::copyFrom
void copyFrom(const FormatToken &Tok)
Definition: FormatToken.h:707
clang::format::TokenRole::TokenRole
TokenRole(const FormatStyle &Style)
Definition: FormatToken.h:746
clang::format::FormatToken::setDecision
void setDecision(FormatDecision D)
Definition: FormatToken.h:306
clang::format::FormatToken::opensScope
bool opensScope() const
Returns whether Tok is ([{ or an opening < of a template or in protos.
Definition: FormatToken.h:536
clang::format::FormatToken::IsArrayInitializer
bool IsArrayInitializer
This starts an array initializer.
Definition: FormatToken.h:443
clang::format::AdditionalKeywords::kw_out
IdentifierInfo * kw_out
Definition: FormatToken.h:1039
clang::format::FormatToken::is
bool is(BraceBlockKind BBK) const
Definition: FormatToken.h:462