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