clang  17.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 <optional>
24 #include <unordered_set>
25 
26 namespace clang {
27 namespace format {
28 
29 #define LIST_TOKEN_TYPES \
30  TYPE(ArrayInitializerLSquare) \
31  TYPE(ArraySubscriptLSquare) \
32  TYPE(AttributeColon) \
33  TYPE(AttributeMacro) \
34  TYPE(AttributeParen) \
35  TYPE(AttributeSquare) \
36  TYPE(BinaryOperator) \
37  TYPE(BitFieldColon) \
38  TYPE(BlockComment) \
39  TYPE(BracedListLBrace) \
40  TYPE(CastRParen) \
41  TYPE(ClassLBrace) \
42  TYPE(CompoundRequirementLBrace) \
43  /* ternary ?: expression */ \
44  TYPE(ConditionalExpr) \
45  /* the condition in an if statement */ \
46  TYPE(ConditionLParen) \
47  TYPE(ConflictAlternative) \
48  TYPE(ConflictEnd) \
49  TYPE(ConflictStart) \
50  /* l_brace of if/for/while */ \
51  TYPE(ControlStatementLBrace) \
52  TYPE(CppCastLParen) \
53  TYPE(CSharpGenericTypeConstraint) \
54  TYPE(CSharpGenericTypeConstraintColon) \
55  TYPE(CSharpGenericTypeConstraintComma) \
56  TYPE(CSharpNamedArgumentColon) \
57  TYPE(CSharpNullable) \
58  TYPE(CSharpNullConditionalLSquare) \
59  TYPE(CSharpStringLiteral) \
60  TYPE(CtorInitializerColon) \
61  TYPE(CtorInitializerComma) \
62  TYPE(DesignatedInitializerLSquare) \
63  TYPE(DesignatedInitializerPeriod) \
64  TYPE(DictLiteral) \
65  TYPE(ElseLBrace) \
66  TYPE(EnumLBrace) \
67  TYPE(FatArrow) \
68  TYPE(ForEachMacro) \
69  TYPE(FunctionAnnotationRParen) \
70  TYPE(FunctionDeclarationName) \
71  TYPE(FunctionLBrace) \
72  TYPE(FunctionLikeOrFreestandingMacro) \
73  TYPE(FunctionTypeLParen) \
74  /* The colons as part of a C11 _Generic selection */ \
75  TYPE(GenericSelectionColon) \
76  /* The colon at the end of a goto label or a case label. Currently only used \
77  * for Verilog. */ \
78  TYPE(GotoLabelColon) \
79  TYPE(IfMacro) \
80  TYPE(ImplicitStringLiteral) \
81  TYPE(InheritanceColon) \
82  TYPE(InheritanceComma) \
83  TYPE(InlineASMBrace) \
84  TYPE(InlineASMColon) \
85  TYPE(InlineASMSymbolicNameLSquare) \
86  TYPE(JavaAnnotation) \
87  TYPE(JsAndAndEqual) \
88  TYPE(JsComputedPropertyName) \
89  TYPE(JsExponentiation) \
90  TYPE(JsExponentiationEqual) \
91  TYPE(JsPipePipeEqual) \
92  TYPE(JsPrivateIdentifier) \
93  TYPE(JsTypeColon) \
94  TYPE(JsTypeOperator) \
95  TYPE(JsTypeOptionalQuestion) \
96  TYPE(LambdaArrow) \
97  TYPE(LambdaLBrace) \
98  TYPE(LambdaLSquare) \
99  TYPE(LeadingJavaAnnotation) \
100  TYPE(LineComment) \
101  TYPE(MacroBlockBegin) \
102  TYPE(MacroBlockEnd) \
103  TYPE(ModulePartitionColon) \
104  TYPE(NamespaceMacro) \
105  TYPE(NonNullAssertion) \
106  TYPE(NullCoalescingEqual) \
107  TYPE(NullCoalescingOperator) \
108  TYPE(NullPropagatingOperator) \
109  TYPE(ObjCBlockLBrace) \
110  TYPE(ObjCBlockLParen) \
111  TYPE(ObjCDecl) \
112  TYPE(ObjCForIn) \
113  TYPE(ObjCMethodExpr) \
114  TYPE(ObjCMethodSpecifier) \
115  TYPE(ObjCProperty) \
116  TYPE(ObjCStringLiteral) \
117  TYPE(OverloadedOperator) \
118  TYPE(OverloadedOperatorLParen) \
119  TYPE(PointerOrReference) \
120  TYPE(ProtoExtensionLSquare) \
121  TYPE(PureVirtualSpecifier) \
122  TYPE(RangeBasedForLoopColon) \
123  TYPE(RecordLBrace) \
124  TYPE(RegexLiteral) \
125  TYPE(RequiresClause) \
126  TYPE(RequiresClauseInARequiresExpression) \
127  TYPE(RequiresExpression) \
128  TYPE(RequiresExpressionLBrace) \
129  TYPE(RequiresExpressionLParen) \
130  TYPE(SelectorName) \
131  TYPE(StartOfName) \
132  TYPE(StatementAttributeLikeMacro) \
133  TYPE(StatementMacro) \
134  TYPE(StructLBrace) \
135  TYPE(StructuredBindingLSquare) \
136  TYPE(TemplateCloser) \
137  TYPE(TemplateOpener) \
138  TYPE(TemplateString) \
139  TYPE(TrailingAnnotation) \
140  TYPE(TrailingReturnArrow) \
141  TYPE(TrailingUnaryOperator) \
142  TYPE(TypeDeclarationParen) \
143  TYPE(TypenameMacro) \
144  TYPE(UnaryOperator) \
145  TYPE(UnionLBrace) \
146  TYPE(UntouchableMacroFunc) \
147  /* like in begin : block */ \
148  TYPE(VerilogBlockLabelColon) \
149  /* The square bracket for the dimension part of the type name. \
150  * In 'logic [1:0] x[1:0]', only the first '['. This way we can have space \
151  * before the first bracket but not the second. */ \
152  TYPE(VerilogDimensionedTypeName) \
153  /* for the base in a number literal, not including the quote */ \
154  TYPE(VerilogNumberBase) \
155  /* Things inside the table in user-defined primitives. */ \
156  TYPE(VerilogTableItem) \
157  TYPE(Unknown)
158 
159 /// Determines the semantic type of a syntactic token, e.g. whether "<" is a
160 /// template opener or binary operator.
161 enum TokenType : uint8_t {
162 #define TYPE(X) TT_##X,
164 #undef TYPE
166 };
167 
168 /// Determines the name of a token type.
170 
171 // Represents what type of block a set of braces open.
173 
174 // The packing kind of a function's parameters.
176 
178 
179 /// Roles a token can take in a configured macro expansion.
180 enum MacroRole {
181  /// The token was expanded from a macro argument when formatting the expanded
182  /// token sequence.
184  /// The token is part of a macro argument that was previously formatted as
185  /// expansion when formatting the unexpanded macro call.
187  /// The token was expanded from a macro definition, and is not visible as part
188  /// of the macro call.
189  MR_Hidden,
190 };
191 
192 struct FormatToken;
193 
194 /// Contains information on the token's role in a macro expansion.
195 ///
196 /// Given the following definitions:
197 /// A(X) = [ X ]
198 /// B(X) = < X >
199 /// C(X) = X
200 ///
201 /// Consider the macro call:
202 /// A({B(C(C(x)))}) -> [{<x>}]
203 ///
204 /// In this case, the tokens of the unexpanded macro call will have the
205 /// following relevant entries in their macro context (note that formatting
206 /// the unexpanded macro call happens *after* formatting the expanded macro
207 /// call):
208 /// A( { B( C( C(x) ) ) } )
209 /// Role: NN U NN NN NNUN N N U N (N=None, U=UnexpandedArg)
210 ///
211 /// [ { < x > } ]
212 /// Role: H E H E H E H (H=Hidden, E=ExpandedArg)
213 /// ExpandedFrom[0]: A A A A A A A
214 /// ExpandedFrom[1]: B B B
215 /// ExpandedFrom[2]: C
216 /// ExpandedFrom[3]: C
217 /// StartOfExpansion: 1 0 1 2 0 0 0
218 /// EndOfExpansion: 0 0 0 2 1 0 1
219 struct MacroExpansion {
221 
222  /// The token's role in the macro expansion.
223  /// When formatting an expanded macro, all tokens that are part of macro
224  /// arguments will be MR_ExpandedArg, while all tokens that are not visible in
225  /// the macro call will be MR_Hidden.
226  /// When formatting an unexpanded macro call, all tokens that are part of
227  /// macro arguments will be MR_UnexpandedArg.
229 
230  /// The stack of macro call identifier tokens this token was expanded from.
232 
233  /// The number of expansions of which this macro is the first entry.
234  unsigned StartOfExpansion = 0;
235 
236  /// The number of currently open expansions in \c ExpandedFrom this macro is
237  /// the last token in.
238  unsigned EndOfExpansion = 0;
239 };
240 
241 class TokenRole;
242 class AnnotatedLine;
243 
244 /// A wrapper around a \c Token storing information about the
245 /// whitespace characters preceding it.
246 struct FormatToken {
247  FormatToken()
248  : HasUnescapedNewline(false), IsMultiline(false), IsFirst(false),
249  MustBreakBefore(false), IsUnterminatedLiteral(false),
253  Finalized(false), ClosesRequiresClause(false),
254  EndsCppAttributeGroup(false), BlockKind(BK_Unknown),
255  Decision(FD_Unformatted), PackingKind(PPK_Inconclusive),
256  TypeIsFinalized(false), Type(TT_Unknown) {}
257 
258  /// The \c Token.
259  Token Tok;
260 
261  /// The raw text of the token.
262  ///
263  /// Contains the raw token text without leading whitespace and without leading
264  /// escaped newlines.
265  StringRef TokenText;
266 
267  /// A token can have a special role that can carry extra information
268  /// about the token's formatting.
269  /// FIXME: Make FormatToken for parsing and AnnotatedToken two different
270  /// classes and make this a unique_ptr in the AnnotatedToken class.
271  std::shared_ptr<TokenRole> Role;
272 
273  /// The range of the whitespace immediately preceding the \c Token.
275 
276  /// Whether there is at least one unescaped newline before the \c
277  /// Token.
278  unsigned HasUnescapedNewline : 1;
279 
280  /// Whether the token text contains newlines (escaped or not).
281  unsigned IsMultiline : 1;
282 
283  /// Indicates that this is the first token of the file.
284  unsigned IsFirst : 1;
285 
286  /// Whether there must be a line break before this token.
287  ///
288  /// This happens for example when a preprocessor directive ended directly
289  /// before the token.
290  unsigned MustBreakBefore : 1;
291 
292  /// Set to \c true if this token is an unterminated literal.
293  unsigned IsUnterminatedLiteral : 1;
294 
295  /// \c true if it is allowed to break before this token.
296  unsigned CanBreakBefore : 1;
297 
298  /// \c true if this is the ">" of "template<..>".
299  unsigned ClosesTemplateDeclaration : 1;
300 
301  /// \c true if this token starts a binary expression, i.e. has at least
302  /// one fake l_paren with a precedence greater than prec::Unknown.
303  unsigned StartsBinaryExpression : 1;
304  /// \c true if this token ends a binary expression.
305  unsigned EndsBinaryExpression : 1;
306 
307  /// Is this token part of a \c DeclStmt defining multiple variables?
308  ///
309  /// Only set if \c Type == \c TT_StartOfName.
310  unsigned PartOfMultiVariableDeclStmt : 1;
311 
312  /// Does this line comment continue a line comment section?
313  ///
314  /// Only set to true if \c Type == \c TT_LineComment.
315  unsigned ContinuesLineCommentSection : 1;
316 
317  /// If \c true, this token has been fully formatted (indented and
318  /// potentially re-formatted inside), and we do not allow further formatting
319  /// changes.
320  unsigned Finalized : 1;
321 
322  /// \c true if this is the last token within requires clause.
323  unsigned ClosesRequiresClause : 1;
324 
325  /// \c true if this token ends a group of C++ attributes.
326  unsigned EndsCppAttributeGroup : 1;
327 
328 private:
329  /// Contains the kind of block if this token is a brace.
330  unsigned BlockKind : 2;
331 
332 public:
334  return static_cast<BraceBlockKind>(BlockKind);
335  }
336  void setBlockKind(BraceBlockKind BBK) {
337  BlockKind = BBK;
338  assert(getBlockKind() == BBK && "BraceBlockKind overflow!");
339  }
340 
341 private:
342  /// Stores the formatting decision for the token once it was made.
343  unsigned Decision : 2;
344 
345 public:
347  return static_cast<FormatDecision>(Decision);
348  }
349  void setDecision(FormatDecision D) {
350  Decision = D;
351  assert(getDecision() == D && "FormatDecision overflow!");
352  }
353 
354 private:
355  /// If this is an opening parenthesis, how are the parameters packed?
356  unsigned PackingKind : 2;
357 
358 public:
360  return static_cast<ParameterPackingKind>(PackingKind);
361  }
363  PackingKind = K;
364  assert(getPackingKind() == K && "ParameterPackingKind overflow!");
365  }
366 
367 private:
368  unsigned TypeIsFinalized : 1;
369  TokenType Type;
370 
371 public:
372  /// Returns the token's type, e.g. whether "<" is a template opener or
373  /// binary operator.
374  TokenType getType() const { return Type; }
375  void setType(TokenType T) {
376  assert((!TypeIsFinalized || T == Type) &&
377  "Please use overwriteFixedType to change a fixed type.");
378  Type = T;
379  }
380  /// Sets the type and also the finalized flag. This prevents the type to be
381  /// reset in TokenAnnotator::resetTokenMetadata(). If the type needs to be set
382  /// to another one please use overwriteFixedType, or even better remove the
383  /// need to reassign the type.
384  void setFinalizedType(TokenType T) {
385  Type = T;
386  TypeIsFinalized = true;
387  }
388  void overwriteFixedType(TokenType T) {
389  TypeIsFinalized = false;
390  setType(T);
391  }
392  bool isTypeFinalized() const { return TypeIsFinalized; }
393 
394  /// Used to set an operator precedence explicitly.
396 
397  /// The number of newlines immediately before the \c Token.
398  ///
399  /// This can be used to determine what the user wrote in the original code
400  /// and thereby e.g. leave an empty line between two function definitions.
401  unsigned NewlinesBefore = 0;
402 
403  /// The offset just past the last '\n' in this token's leading
404  /// whitespace (relative to \c WhiteSpaceStart). 0 if there is no '\n'.
405  unsigned LastNewlineOffset = 0;
406 
407  /// The width of the non-whitespace parts of the token (or its first
408  /// line for multi-line tokens) in columns.
409  /// We need this to correctly measure number of columns a token spans.
410  unsigned ColumnWidth = 0;
411 
412  /// Contains the width in columns of the last line of a multi-line
413  /// token.
414  unsigned LastLineColumnWidth = 0;
415 
416  /// The number of spaces that should be inserted before this token.
417  unsigned SpacesRequiredBefore = 0;
418 
419  /// Number of parameters, if this is "(", "[" or "<".
420  unsigned ParameterCount = 0;
421 
422  /// Number of parameters that are nested blocks,
423  /// if this is "(", "[" or "<".
424  unsigned BlockParameterCount = 0;
425 
426  /// If this is a bracket ("<", "(", "[" or "{"), contains the kind of
427  /// the surrounding bracket.
428  tok::TokenKind ParentBracket = tok::unknown;
429 
430  /// The total length of the unwrapped line up to and including this
431  /// token.
432  unsigned TotalLength = 0;
433 
434  /// The original 0-based column of this token, including expanded tabs.
435  /// The configured TabWidth is used as tab width.
436  unsigned OriginalColumn = 0;
437 
438  /// The length of following tokens until the next natural split point,
439  /// or the next token that can be broken.
440  unsigned UnbreakableTailLength = 0;
441 
442  // FIXME: Come up with a 'cleaner' concept.
443  /// The binding strength of a token. This is a combined value of
444  /// operator precedence, parenthesis nesting, etc.
445  unsigned BindingStrength = 0;
446 
447  /// The nesting level of this token, i.e. the number of surrounding (),
448  /// [], {} or <>.
449  unsigned NestingLevel = 0;
450 
451  /// The indent level of this token. Copied from the surrounding line.
452  unsigned IndentLevel = 0;
453 
454  /// Penalty for inserting a line break before this token.
455  unsigned SplitPenalty = 0;
456 
457  /// If this is the first ObjC selector name in an ObjC method
458  /// definition or call, this contains the length of the longest name.
459  ///
460  /// This being set to 0 means that the selectors should not be colon-aligned,
461  /// e.g. because several of them are block-type.
462  unsigned LongestObjCSelectorName = 0;
463 
464  /// If this is the first ObjC selector name in an ObjC method
465  /// definition or call, this contains the number of parts that the whole
466  /// selector consist of.
467  unsigned ObjCSelectorNameParts = 0;
468 
469  /// The 0-based index of the parameter/argument. For ObjC it is set
470  /// for the selector name token.
471  /// For now calculated only for ObjC.
472  unsigned ParameterIndex = 0;
473 
474  /// Stores the number of required fake parentheses and the
475  /// corresponding operator precedence.
476  ///
477  /// If multiple fake parentheses start at a token, this vector stores them in
478  /// reverse order, i.e. inner fake parenthesis first.
480  /// Insert this many fake ) after this token for correct indentation.
481  unsigned FakeRParens = 0;
482 
483  /// If this is an operator (or "."/"->") in a sequence of operators
484  /// with the same precedence, contains the 0-based operator index.
485  unsigned OperatorIndex = 0;
486 
487  /// If this is an operator (or "."/"->") in a sequence of operators
488  /// with the same precedence, points to the next operator.
490 
491  /// If this is a bracket, this points to the matching one.
493 
494  /// The previous token in the unwrapped line.
495  FormatToken *Previous = nullptr;
496 
497  /// The next token in the unwrapped line.
498  FormatToken *Next = nullptr;
499 
500  /// The first token in set of column elements.
501  bool StartsColumn = false;
502 
503  /// This notes the start of the line of an array initializer.
505 
506  /// This starts an array initializer.
507  bool IsArrayInitializer = false;
508 
509  /// Is optional and can be removed.
510  bool Optional = false;
511 
512  /// Number of optional braces to be inserted after this token:
513  /// -1: a single left brace
514  /// 0: no braces
515  /// >0: number of right braces
516  int8_t BraceCount = 0;
517 
518  /// If this token starts a block, this contains all the unwrapped lines
519  /// in it.
521 
522  // Contains all attributes related to how this token takes part
523  // in a configured macro expansion.
524  std::optional<MacroExpansion> MacroCtx;
525 
526  /// When macro expansion introduces nodes with children, those are marked as
527  /// \c MacroParent.
528  /// FIXME: The formatting code currently hard-codes the assumption that
529  /// child nodes are introduced by blocks following an opening brace.
530  /// This is deeply baked into the code and disentangling this will require
531  /// signficant refactorings. \c MacroParent allows us to special-case the
532  /// cases in which we treat parents as block-openers for now.
533  bool MacroParent = false;
534 
535  bool is(tok::TokenKind Kind) const { return Tok.is(Kind); }
536  bool is(TokenType TT) const { return getType() == TT; }
537  bool is(const IdentifierInfo *II) const {
538  return II && II == Tok.getIdentifierInfo();
539  }
540  bool is(tok::PPKeywordKind Kind) const {
541  return Tok.getIdentifierInfo() &&
543  }
544  bool is(BraceBlockKind BBK) const { return getBlockKind() == BBK; }
545  bool is(ParameterPackingKind PPK) const { return getPackingKind() == PPK; }
546 
547  template <typename A, typename B> bool isOneOf(A K1, B K2) const {
548  return is(K1) || is(K2);
549  }
550  template <typename A, typename B, typename... Ts>
551  bool isOneOf(A K1, B K2, Ts... Ks) const {
552  return is(K1) || isOneOf(K2, Ks...);
553  }
554  template <typename T> bool isNot(T Kind) const { return !is(Kind); }
555 
556  bool isIf(bool AllowConstexprMacro = true) const {
557  return is(tok::kw_if) || endsSequence(tok::kw_constexpr, tok::kw_if) ||
558  (endsSequence(tok::identifier, tok::kw_if) && AllowConstexprMacro);
559  }
560 
561  bool closesScopeAfterBlock() const {
562  if (getBlockKind() == BK_Block)
563  return true;
564  if (closesScope())
566  return false;
567  }
568 
569  /// \c true if this token starts a sequence with the given tokens in order,
570  /// following the ``Next`` pointers, ignoring comments.
571  template <typename A, typename... Ts>
572  bool startsSequence(A K1, Ts... Tokens) const {
573  return startsSequenceInternal(K1, Tokens...);
574  }
575 
576  /// \c true if this token ends a sequence with the given tokens in order,
577  /// following the ``Previous`` pointers, ignoring comments.
578  /// For example, given tokens [T1, T2, T3], the function returns true if
579  /// 3 tokens ending at this (ignoring comments) are [T3, T2, T1]. In other
580  /// words, the tokens passed to this function need to the reverse of the
581  /// order the tokens appear in code.
582  template <typename A, typename... Ts>
583  bool endsSequence(A K1, Ts... Tokens) const {
584  return endsSequenceInternal(K1, Tokens...);
585  }
586 
587  bool isStringLiteral() const { return tok::isStringLiteral(Tok.getKind()); }
588 
591  }
592 
593  bool isAccessSpecifier(bool ColonRequired = true) const {
594  if (!isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private))
595  return false;
596  if (!ColonRequired)
597  return true;
598  const auto NextNonComment = getNextNonComment();
599  return NextNonComment && NextNonComment->is(tok::colon);
600  }
601 
602  bool canBePointerOrReferenceQualifier() const {
603  return isOneOf(tok::kw_const, tok::kw_restrict, tok::kw_volatile,
604  tok::kw___attribute, tok::kw__Nonnull, tok::kw__Nullable,
605  tok::kw__Null_unspecified, tok::kw___ptr32, tok::kw___ptr64,
606  TT_AttributeMacro);
607  }
608 
609  /// Determine whether the token is a simple-type-specifier.
610  [[nodiscard]] bool isSimpleTypeSpecifier() const;
611 
612  [[nodiscard]] bool isTypeOrIdentifier() const;
613 
614  bool isObjCAccessSpecifier() const {
615  return is(tok::at) && Next &&
616  (Next->isObjCAtKeyword(tok::objc_public) ||
617  Next->isObjCAtKeyword(tok::objc_protected) ||
618  Next->isObjCAtKeyword(tok::objc_package) ||
619  Next->isObjCAtKeyword(tok::objc_private));
620  }
621 
622  /// Returns whether \p Tok is ([{ or an opening < of a template or in
623  /// protos.
624  bool opensScope() const {
625  if (is(TT_TemplateString) && TokenText.endswith("${"))
626  return true;
627  if (is(TT_DictLiteral) && is(tok::less))
628  return true;
629  return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
630  TT_TemplateOpener);
631  }
632  /// Returns whether \p Tok is )]} or a closing > of a template or in
633  /// protos.
634  bool closesScope() const {
635  if (is(TT_TemplateString) && TokenText.startswith("}"))
636  return true;
637  if (is(TT_DictLiteral) && is(tok::greater))
638  return true;
639  return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
640  TT_TemplateCloser);
641  }
642 
643  /// Returns \c true if this is a "." or "->" accessing a member.
644  bool isMemberAccess() const {
645  return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
646  !isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
647  TT_LambdaArrow, TT_LeadingJavaAnnotation);
648  }
649 
650  bool isUnaryOperator() const {
651  switch (Tok.getKind()) {
652  case tok::plus:
653  case tok::plusplus:
654  case tok::minus:
655  case tok::minusminus:
656  case tok::exclaim:
657  case tok::tilde:
658  case tok::kw_sizeof:
659  case tok::kw_alignof:
660  return true;
661  default:
662  return false;
663  }
664  }
665 
666  bool isBinaryOperator() const {
667  // Comma is a binary operator, but does not behave as such wrt. formatting.
669  }
670 
671  bool isTrailingComment() const {
672  return is(tok::comment) &&
673  (is(TT_LineComment) || !Next || Next->NewlinesBefore > 0);
674  }
675 
676  /// Returns \c true if this is a keyword that can be used
677  /// like a function call (e.g. sizeof, typeid, ...).
678  bool isFunctionLikeKeyword() const {
679  switch (Tok.getKind()) {
680  case tok::kw_throw:
681  case tok::kw_typeid:
682  case tok::kw_return:
683  case tok::kw_sizeof:
684  case tok::kw_alignof:
685  case tok::kw_alignas:
686  case tok::kw_decltype:
687  case tok::kw_noexcept:
688  case tok::kw_static_assert:
689  case tok::kw__Atomic:
690  case tok::kw___attribute:
691 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
692 #include "clang/Basic/TransformTypeTraits.def"
693  case tok::kw_requires:
694  return true;
695  default:
696  return false;
697  }
698  }
699 
700  /// Returns \c true if this is a string literal that's like a label,
701  /// e.g. ends with "=" or ":".
702  bool isLabelString() const {
703  if (!is(tok::string_literal))
704  return false;
705  StringRef Content = TokenText;
706  if (Content.startswith("\"") || Content.startswith("'"))
707  Content = Content.drop_front(1);
708  if (Content.endswith("\"") || Content.endswith("'"))
709  Content = Content.drop_back(1);
710  Content = Content.trim();
711  return Content.size() > 1 &&
712  (Content.back() == ':' || Content.back() == '=');
713  }
714 
715  /// Returns actual token start location without leading escaped
716  /// newlines and whitespace.
717  ///
718  /// This can be different to Tok.getLocation(), which includes leading escaped
719  /// newlines.
721  return WhitespaceRange.getEnd();
722  }
723 
724  /// Returns \c true if the range of whitespace immediately preceding the \c
725  /// Token is not empty.
726  bool hasWhitespaceBefore() const {
728  }
729 
730  prec::Level getPrecedence() const {
732  return ForcedPrecedence;
733  return getBinOpPrecedence(Tok.getKind(), /*GreaterThanIsOperator=*/true,
734  /*CPlusPlus11=*/true);
735  }
736 
737  /// Returns the previous token ignoring comments.
738  [[nodiscard]] FormatToken *getPreviousNonComment() const {
740  while (Tok && Tok->is(tok::comment))
741  Tok = Tok->Previous;
742  return Tok;
743  }
744 
745  /// Returns the next token ignoring comments.
746  [[nodiscard]] const FormatToken *getNextNonComment() const {
747  const FormatToken *Tok = Next;
748  while (Tok && Tok->is(tok::comment))
749  Tok = Tok->Next;
750  return Tok;
751  }
752 
753  /// Returns \c true if this tokens starts a block-type list, i.e. a
754  /// list that should be indented with a block indent.
755  [[nodiscard]] bool opensBlockOrBlockTypeList(const FormatStyle &Style) const;
756 
757  /// Returns whether the token is the left square bracket of a C++
758  /// structured binding declaration.
759  bool isCppStructuredBinding(const FormatStyle &Style) const {
760  if (!Style.isCpp() || isNot(tok::l_square))
761  return false;
762  const FormatToken *T = this;
763  do {
764  T = T->getPreviousNonComment();
765  } while (T && T->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
766  tok::ampamp));
767  return T && T->is(tok::kw_auto);
768  }
769 
770  /// Same as opensBlockOrBlockTypeList, but for the closing token.
771  bool closesBlockOrBlockTypeList(const FormatStyle &Style) const {
772  if (is(TT_TemplateString) && closesScope())
773  return true;
775  }
776 
777  /// Return the actual namespace token, if this token starts a namespace
778  /// block.
779  const FormatToken *getNamespaceToken() const {
780  const FormatToken *NamespaceTok = this;
781  if (is(tok::comment))
782  NamespaceTok = NamespaceTok->getNextNonComment();
783  // Detect "(inline|export)? namespace" in the beginning of a line.
784  if (NamespaceTok && NamespaceTok->isOneOf(tok::kw_inline, tok::kw_export))
785  NamespaceTok = NamespaceTok->getNextNonComment();
786  return NamespaceTok &&
787  NamespaceTok->isOneOf(tok::kw_namespace, TT_NamespaceMacro)
788  ? NamespaceTok
789  : nullptr;
790  }
791 
792  void copyFrom(const FormatToken &Tok) { *this = Tok; }
793 
794 private:
795  // Only allow copying via the explicit copyFrom method.
796  FormatToken(const FormatToken &) = delete;
797  FormatToken &operator=(const FormatToken &) = default;
798 
799  template <typename A, typename... Ts>
800  bool startsSequenceInternal(A K1, Ts... Tokens) const {
801  if (is(tok::comment) && Next)
802  return Next->startsSequenceInternal(K1, Tokens...);
803  return is(K1) && Next && Next->startsSequenceInternal(Tokens...);
804  }
805 
806  template <typename A> bool startsSequenceInternal(A K1) const {
807  if (is(tok::comment) && Next)
808  return Next->startsSequenceInternal(K1);
809  return is(K1);
810  }
811 
812  template <typename A, typename... Ts> bool endsSequenceInternal(A K1) const {
813  if (is(tok::comment) && Previous)
814  return Previous->endsSequenceInternal(K1);
815  return is(K1);
816  }
817 
818  template <typename A, typename... Ts>
819  bool endsSequenceInternal(A K1, Ts... Tokens) const {
820  if (is(tok::comment) && Previous)
821  return Previous->endsSequenceInternal(K1, Tokens...);
822  return is(K1) && Previous && Previous->endsSequenceInternal(Tokens...);
823  }
824 };
825 
827 struct LineState;
828 
829 class TokenRole {
830 public:
831  TokenRole(const FormatStyle &Style) : Style(Style) {}
832  virtual ~TokenRole();
833 
834  /// After the \c TokenAnnotator has finished annotating all the tokens,
835  /// this function precomputes required information for formatting.
836  virtual void precomputeFormattingInfos(const FormatToken *Token);
837 
838  /// Apply the special formatting that the given role demands.
839  ///
840  /// Assumes that the token having this role is already formatted.
841  ///
842  /// Continues formatting from \p State leaving indentation to \p Indenter and
843  /// returns the total penalty that this formatting incurs.
844  virtual unsigned formatFromToken(LineState &State,
846  bool DryRun) {
847  return 0;
848  }
849 
850  /// Same as \c formatFromToken, but assumes that the first token has
851  /// already been set thereby deciding on the first line break.
852  virtual unsigned formatAfterToken(LineState &State,
854  bool DryRun) {
855  return 0;
856  }
857 
858  /// Notifies the \c Role that a comma was found.
859  virtual void CommaFound(const FormatToken *Token) {}
860 
861  virtual const FormatToken *lastComma() { return nullptr; }
862 
863 protected:
865 };
866 
867 class CommaSeparatedList : public TokenRole {
868 public:
870  : TokenRole(Style), HasNestedBracedList(false) {}
871 
872  void precomputeFormattingInfos(const FormatToken *Token) override;
873 
875  bool DryRun) override;
876 
878  bool DryRun) override;
879 
880  /// Adds \p Token as the next comma to the \c CommaSeparated list.
881  void CommaFound(const FormatToken *Token) override {
882  Commas.push_back(Token);
883  }
884 
885  const FormatToken *lastComma() override {
886  if (Commas.empty())
887  return nullptr;
888  return Commas.back();
889  }
890 
891 private:
892  /// A struct that holds information on how to format a given list with
893  /// a specific number of columns.
894  struct ColumnFormat {
895  /// The number of columns to use.
896  unsigned Columns;
897 
898  /// The total width in characters.
899  unsigned TotalWidth;
900 
901  /// The number of lines required for this format.
902  unsigned LineCount;
903 
904  /// The size of each column in characters.
905  SmallVector<unsigned, 8> ColumnSizes;
906  };
907 
908  /// Calculate which \c ColumnFormat fits best into
909  /// \p RemainingCharacters.
910  const ColumnFormat *getColumnFormat(unsigned RemainingCharacters) const;
911 
912  /// The ordered \c FormatTokens making up the commas of this list.
913  SmallVector<const FormatToken *, 8> Commas;
914 
915  /// The length of each of the list's items in characters including the
916  /// trailing comma.
917  SmallVector<unsigned, 8> ItemLengths;
918 
919  /// Precomputed formats that can be used for this list.
920  SmallVector<ColumnFormat, 4> Formats;
921 
922  bool HasNestedBracedList;
923 };
924 
925 /// Encapsulates keywords that are context sensitive or for languages not
926 /// properly supported by Clang's lexer.
927 struct AdditionalKeywords {
928  AdditionalKeywords(IdentifierTable &IdentTable) {
929  kw_final = &IdentTable.get("final");
930  kw_override = &IdentTable.get("override");
931  kw_in = &IdentTable.get("in");
932  kw_of = &IdentTable.get("of");
933  kw_CF_CLOSED_ENUM = &IdentTable.get("CF_CLOSED_ENUM");
934  kw_CF_ENUM = &IdentTable.get("CF_ENUM");
935  kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS");
936  kw_NS_CLOSED_ENUM = &IdentTable.get("NS_CLOSED_ENUM");
937  kw_NS_ENUM = &IdentTable.get("NS_ENUM");
938  kw_NS_OPTIONS = &IdentTable.get("NS_OPTIONS");
939 
940  kw_as = &IdentTable.get("as");
941  kw_async = &IdentTable.get("async");
942  kw_await = &IdentTable.get("await");
943  kw_declare = &IdentTable.get("declare");
944  kw_finally = &IdentTable.get("finally");
945  kw_from = &IdentTable.get("from");
946  kw_function = &IdentTable.get("function");
947  kw_get = &IdentTable.get("get");
948  kw_import = &IdentTable.get("import");
949  kw_infer = &IdentTable.get("infer");
950  kw_is = &IdentTable.get("is");
951  kw_let = &IdentTable.get("let");
952  kw_module = &IdentTable.get("module");
953  kw_readonly = &IdentTable.get("readonly");
954  kw_set = &IdentTable.get("set");
955  kw_type = &IdentTable.get("type");
956  kw_typeof = &IdentTable.get("typeof");
957  kw_var = &IdentTable.get("var");
958  kw_yield = &IdentTable.get("yield");
959 
960  kw_abstract = &IdentTable.get("abstract");
961  kw_assert = &IdentTable.get("assert");
962  kw_extends = &IdentTable.get("extends");
963  kw_implements = &IdentTable.get("implements");
964  kw_instanceof = &IdentTable.get("instanceof");
965  kw_interface = &IdentTable.get("interface");
966  kw_native = &IdentTable.get("native");
967  kw_package = &IdentTable.get("package");
968  kw_synchronized = &IdentTable.get("synchronized");
969  kw_throws = &IdentTable.get("throws");
970  kw___except = &IdentTable.get("__except");
971  kw___has_include = &IdentTable.get("__has_include");
972  kw___has_include_next = &IdentTable.get("__has_include_next");
973 
974  kw_mark = &IdentTable.get("mark");
975  kw_region = &IdentTable.get("region");
976 
977  kw_extend = &IdentTable.get("extend");
978  kw_option = &IdentTable.get("option");
979  kw_optional = &IdentTable.get("optional");
980  kw_repeated = &IdentTable.get("repeated");
981  kw_required = &IdentTable.get("required");
982  kw_returns = &IdentTable.get("returns");
983 
984  kw_signals = &IdentTable.get("signals");
985  kw_qsignals = &IdentTable.get("Q_SIGNALS");
986  kw_slots = &IdentTable.get("slots");
987  kw_qslots = &IdentTable.get("Q_SLOTS");
988 
989  // For internal clang-format use.
991  &IdentTable.get("__CLANG_FORMAT_INTERNAL_IDENT_AFTER_DEFINE__");
992 
993  // C# keywords
994  kw_dollar = &IdentTable.get("dollar");
995  kw_base = &IdentTable.get("base");
996  kw_byte = &IdentTable.get("byte");
997  kw_checked = &IdentTable.get("checked");
998  kw_decimal = &IdentTable.get("decimal");
999  kw_delegate = &IdentTable.get("delegate");
1000  kw_event = &IdentTable.get("event");
1001  kw_fixed = &IdentTable.get("fixed");
1002  kw_foreach = &IdentTable.get("foreach");
1003  kw_init = &IdentTable.get("init");
1004  kw_implicit = &IdentTable.get("implicit");
1005  kw_internal = &IdentTable.get("internal");
1006  kw_lock = &IdentTable.get("lock");
1007  kw_null = &IdentTable.get("null");
1008  kw_object = &IdentTable.get("object");
1009  kw_out = &IdentTable.get("out");
1010  kw_params = &IdentTable.get("params");
1011  kw_ref = &IdentTable.get("ref");
1012  kw_string = &IdentTable.get("string");
1013  kw_stackalloc = &IdentTable.get("stackalloc");
1014  kw_sbyte = &IdentTable.get("sbyte");
1015  kw_sealed = &IdentTable.get("sealed");
1016  kw_uint = &IdentTable.get("uint");
1017  kw_ulong = &IdentTable.get("ulong");
1018  kw_unchecked = &IdentTable.get("unchecked");
1019  kw_unsafe = &IdentTable.get("unsafe");
1020  kw_ushort = &IdentTable.get("ushort");
1021  kw_when = &IdentTable.get("when");
1022  kw_where = &IdentTable.get("where");
1023 
1024  // Verilog keywords
1025  kw_always = &IdentTable.get("always");
1026  kw_always_comb = &IdentTable.get("always_comb");
1027  kw_always_ff = &IdentTable.get("always_ff");
1028  kw_always_latch = &IdentTable.get("always_latch");
1029  kw_assign = &IdentTable.get("assign");
1030  kw_assume = &IdentTable.get("assume");
1031  kw_automatic = &IdentTable.get("automatic");
1032  kw_before = &IdentTable.get("before");
1033  kw_begin = &IdentTable.get("begin");
1034  kw_begin_keywords = &IdentTable.get("begin_keywords");
1035  kw_bins = &IdentTable.get("bins");
1036  kw_binsof = &IdentTable.get("binsof");
1037  kw_casex = &IdentTable.get("casex");
1038  kw_casez = &IdentTable.get("casez");
1039  kw_celldefine = &IdentTable.get("celldefine");
1040  kw_checker = &IdentTable.get("checker");
1041  kw_clocking = &IdentTable.get("clocking");
1042  kw_constraint = &IdentTable.get("constraint");
1043  kw_cover = &IdentTable.get("cover");
1044  kw_covergroup = &IdentTable.get("covergroup");
1045  kw_coverpoint = &IdentTable.get("coverpoint");
1046  kw_default_decay_time = &IdentTable.get("default_decay_time");
1047  kw_default_nettype = &IdentTable.get("default_nettype");
1048  kw_default_trireg_strength = &IdentTable.get("default_trireg_strength");
1049  kw_delay_mode_distributed = &IdentTable.get("delay_mode_distributed");
1050  kw_delay_mode_path = &IdentTable.get("delay_mode_path");
1051  kw_delay_mode_unit = &IdentTable.get("delay_mode_unit");
1052  kw_delay_mode_zero = &IdentTable.get("delay_mode_zero");
1053  kw_disable = &IdentTable.get("disable");
1054  kw_dist = &IdentTable.get("dist");
1055  kw_elsif = &IdentTable.get("elsif");
1056  kw_end = &IdentTable.get("end");
1057  kw_end_keywords = &IdentTable.get("end_keywords");
1058  kw_endcase = &IdentTable.get("endcase");
1059  kw_endcelldefine = &IdentTable.get("endcelldefine");
1060  kw_endchecker = &IdentTable.get("endchecker");
1061  kw_endclass = &IdentTable.get("endclass");
1062  kw_endclocking = &IdentTable.get("endclocking");
1063  kw_endfunction = &IdentTable.get("endfunction");
1064  kw_endgenerate = &IdentTable.get("endgenerate");
1065  kw_endgroup = &IdentTable.get("endgroup");
1066  kw_endinterface = &IdentTable.get("endinterface");
1067  kw_endmodule = &IdentTable.get("endmodule");
1068  kw_endpackage = &IdentTable.get("endpackage");
1069  kw_endprimitive = &IdentTable.get("endprimitive");
1070  kw_endprogram = &IdentTable.get("endprogram");
1071  kw_endproperty = &IdentTable.get("endproperty");
1072  kw_endsequence = &IdentTable.get("endsequence");
1073  kw_endspecify = &IdentTable.get("endspecify");
1074  kw_endtable = &IdentTable.get("endtable");
1075  kw_endtask = &IdentTable.get("endtask");
1076  kw_forever = &IdentTable.get("forever");
1077  kw_fork = &IdentTable.get("fork");
1078  kw_generate = &IdentTable.get("generate");
1079  kw_highz0 = &IdentTable.get("highz0");
1080  kw_highz1 = &IdentTable.get("highz1");
1081  kw_iff = &IdentTable.get("iff");
1082  kw_ifnone = &IdentTable.get("ifnone");
1083  kw_ignore_bins = &IdentTable.get("ignore_bins");
1084  kw_illegal_bins = &IdentTable.get("illegal_bins");
1085  kw_initial = &IdentTable.get("initial");
1086  kw_inout = &IdentTable.get("inout");
1087  kw_input = &IdentTable.get("input");
1088  kw_inside = &IdentTable.get("inside");
1089  kw_interconnect = &IdentTable.get("interconnect");
1090  kw_intersect = &IdentTable.get("intersect");
1091  kw_join = &IdentTable.get("join");
1092  kw_join_any = &IdentTable.get("join_any");
1093  kw_join_none = &IdentTable.get("join_none");
1094  kw_large = &IdentTable.get("large");
1095  kw_local = &IdentTable.get("local");
1096  kw_localparam = &IdentTable.get("localparam");
1097  kw_macromodule = &IdentTable.get("macromodule");
1098  kw_matches = &IdentTable.get("matches");
1099  kw_medium = &IdentTable.get("medium");
1100  kw_nounconnected_drive = &IdentTable.get("nounconnected_drive");
1101  kw_output = &IdentTable.get("output");
1102  kw_packed = &IdentTable.get("packed");
1103  kw_parameter = &IdentTable.get("parameter");
1104  kw_primitive = &IdentTable.get("primitive");
1105  kw_priority = &IdentTable.get("priority");
1106  kw_program = &IdentTable.get("program");
1107  kw_property = &IdentTable.get("property");
1108  kw_pull0 = &IdentTable.get("pull0");
1109  kw_pull1 = &IdentTable.get("pull1");
1110  kw_pure = &IdentTable.get("pure");
1111  kw_rand = &IdentTable.get("rand");
1112  kw_randc = &IdentTable.get("randc");
1113  kw_randcase = &IdentTable.get("randcase");
1114  kw_randsequence = &IdentTable.get("randsequence");
1115  kw_repeat = &IdentTable.get("repeat");
1116  kw_resetall = &IdentTable.get("resetall");
1117  kw_sample = &IdentTable.get("sample");
1118  kw_scalared = &IdentTable.get("scalared");
1119  kw_sequence = &IdentTable.get("sequence");
1120  kw_small = &IdentTable.get("small");
1121  kw_soft = &IdentTable.get("soft");
1122  kw_solve = &IdentTable.get("solve");
1123  kw_specify = &IdentTable.get("specify");
1124  kw_specparam = &IdentTable.get("specparam");
1125  kw_strong0 = &IdentTable.get("strong0");
1126  kw_strong1 = &IdentTable.get("strong1");
1127  kw_supply0 = &IdentTable.get("supply0");
1128  kw_supply1 = &IdentTable.get("supply1");
1129  kw_table = &IdentTable.get("table");
1130  kw_tagged = &IdentTable.get("tagged");
1131  kw_task = &IdentTable.get("task");
1132  kw_timescale = &IdentTable.get("timescale");
1133  kw_tri = &IdentTable.get("tri");
1134  kw_tri0 = &IdentTable.get("tri0");
1135  kw_tri1 = &IdentTable.get("tri1");
1136  kw_triand = &IdentTable.get("triand");
1137  kw_trior = &IdentTable.get("trior");
1138  kw_trireg = &IdentTable.get("trireg");
1139  kw_unconnected_drive = &IdentTable.get("unconnected_drive");
1140  kw_undefineall = &IdentTable.get("undefineall");
1141  kw_unique = &IdentTable.get("unique");
1142  kw_unique0 = &IdentTable.get("unique0");
1143  kw_uwire = &IdentTable.get("uwire");
1144  kw_vectored = &IdentTable.get("vectored");
1145  kw_wand = &IdentTable.get("wand");
1146  kw_weak0 = &IdentTable.get("weak0");
1147  kw_weak1 = &IdentTable.get("weak1");
1148  kw_wildcard = &IdentTable.get("wildcard");
1149  kw_wire = &IdentTable.get("wire");
1150  kw_with = &IdentTable.get("with");
1151  kw_wor = &IdentTable.get("wor");
1152 
1153  // Symbols that are treated as keywords.
1154  kw_verilogHash = &IdentTable.get("#");
1155  kw_verilogHashHash = &IdentTable.get("##");
1156  kw_apostrophe = &IdentTable.get("\'");
1157 
1158  // Keep this at the end of the constructor to make sure everything here
1159  // is
1160  // already initialized.
1161  JsExtraKeywords = std::unordered_set<IdentifierInfo *>(
1165  // Keywords from the Java section.
1167 
1168  CSharpExtraKeywords = std::unordered_set<IdentifierInfo *>(
1174  kw_when, kw_where,
1175  // Keywords from the JavaScript section.
1179  // Keywords from the Java section.
1181 
1182  // Some keywords are not included here because they don't need special
1183  // treatment like `showcancelled` or they should be treated as identifiers
1184  // like `int` and `logic`.
1185  VerilogExtraKeywords =
1186  std::unordered_set<IdentifierInfo *>({kw_always,
1188  kw_always_ff,
1190  kw_assert,
1191  kw_assign,
1192  kw_assume,
1193  kw_automatic,
1194  kw_before,
1195  kw_begin,
1196  kw_bins,
1197  kw_binsof,
1198  kw_casex,
1199  kw_casez,
1200  kw_celldefine,
1201  kw_checker,
1202  kw_clocking,
1203  kw_constraint,
1204  kw_cover,
1205  kw_covergroup,
1206  kw_coverpoint,
1207  kw_disable,
1208  kw_dist,
1209  kw_end,
1210  kw_endcase,
1211  kw_endchecker,
1212  kw_endclass,
1216  kw_endgroup,
1218  kw_endmodule,
1219  kw_endpackage,
1221  kw_endprogram,
1224  kw_endspecify,
1225  kw_endtable,
1226  kw_endtask,
1227  kw_extends,
1228  kw_final,
1229  kw_foreach,
1230  kw_forever,
1231  kw_fork,
1232  kw_function,
1233  kw_generate,
1234  kw_highz0,
1235  kw_highz1,
1236  kw_iff,
1237  kw_ifnone,
1240  kw_implements,
1241  kw_import,
1242  kw_initial,
1243  kw_inout,
1244  kw_input,
1245  kw_inside,
1247  kw_interface,
1248  kw_intersect,
1249  kw_join,
1250  kw_join_any,
1251  kw_join_none,
1252  kw_large,
1253  kw_let,
1254  kw_local,
1255  kw_localparam,
1257  kw_matches,
1258  kw_medium,
1259  kw_output,
1260  kw_package,
1261  kw_packed,
1262  kw_parameter,
1263  kw_primitive,
1264  kw_priority,
1265  kw_program,
1266  kw_property,
1267  kw_pull0,
1268  kw_pull1,
1269  kw_pure,
1270  kw_rand,
1271  kw_randc,
1272  kw_randcase,
1274  kw_ref,
1275  kw_repeat,
1276  kw_sample,
1277  kw_scalared,
1278  kw_sequence,
1279  kw_small,
1280  kw_soft,
1281  kw_solve,
1282  kw_specify,
1283  kw_specparam,
1284  kw_strong0,
1285  kw_strong1,
1286  kw_supply0,
1287  kw_supply1,
1288  kw_table,
1289  kw_tagged,
1290  kw_task,
1291  kw_tri,
1292  kw_tri0,
1293  kw_tri1,
1294  kw_triand,
1295  kw_trior,
1296  kw_trireg,
1297  kw_unique,
1298  kw_unique0,
1299  kw_uwire,
1300  kw_var,
1301  kw_vectored,
1302  kw_wand,
1303  kw_weak0,
1304  kw_weak1,
1305  kw_wildcard,
1306  kw_wire,
1307  kw_with,
1308  kw_wor,
1311  }
1313  // Context sensitive keywords.
1328  // JavaScript keywords.
1349  // Java keywords.
1361  // Pragma keywords.
1365  // Proto keywords.
1373  // QT keywords.
1378 
1379  // For internal use by clang-format.
1382  // C# keywords
1416  // Verilog keywords
1545  // Workaround for hashes and backticks in Verilog.
1548 
1549  // Symbols in Verilog that don't exist in C++.
1551 
1552  /// Returns \c true if \p Tok is a keyword or an identifier.
1553  bool isWordLike(const FormatToken &Tok) const {
1554  // getIdentifierinfo returns non-null for keywords as well as identifiers.
1555  return Tok.Tok.getIdentifierInfo() != nullptr &&
1557  }
1558 
1559  /// Returns \c true if \p Tok is a true JavaScript identifier, returns
1560  /// \c false if it is a keyword or a pseudo keyword.
1561  /// If \c AcceptIdentifierName is true, returns true not only for keywords,
1562  // but also for IdentifierName tokens (aka pseudo-keywords), such as
1563  // ``yield``.
1564  bool IsJavaScriptIdentifier(const FormatToken &Tok,
1565  bool AcceptIdentifierName = true) const {
1566  // Based on the list of JavaScript & TypeScript keywords here:
1567  // https://github.com/microsoft/TypeScript/blob/main/src/compiler/scanner.ts#L74
1568  switch (Tok.Tok.getKind()) {
1569  case tok::kw_break:
1570  case tok::kw_case:
1571  case tok::kw_catch:
1572  case tok::kw_class:
1573  case tok::kw_continue:
1574  case tok::kw_const:
1575  case tok::kw_default:
1576  case tok::kw_delete:
1577  case tok::kw_do:
1578  case tok::kw_else:
1579  case tok::kw_enum:
1580  case tok::kw_export:
1581  case tok::kw_false:
1582  case tok::kw_for:
1583  case tok::kw_if:
1584  case tok::kw_import:
1585  case tok::kw_module:
1586  case tok::kw_new:
1587  case tok::kw_private:
1588  case tok::kw_protected:
1589  case tok::kw_public:
1590  case tok::kw_return:
1591  case tok::kw_static:
1592  case tok::kw_switch:
1593  case tok::kw_this:
1594  case tok::kw_throw:
1595  case tok::kw_true:
1596  case tok::kw_try:
1597  case tok::kw_typeof:
1598  case tok::kw_void:
1599  case tok::kw_while:
1600  // These are JS keywords that are lexed by LLVM/clang as keywords.
1601  return false;
1602  case tok::identifier: {
1603  // For identifiers, make sure they are true identifiers, excluding the
1604  // JavaScript pseudo-keywords (not lexed by LLVM/clang as keywords).
1605  bool IsPseudoKeyword =
1606  JsExtraKeywords.find(Tok.Tok.getIdentifierInfo()) !=
1607  JsExtraKeywords.end();
1608  return AcceptIdentifierName || !IsPseudoKeyword;
1609  }
1610  default:
1611  // Other keywords are handled in the switch below, to avoid problems due
1612  // to duplicate case labels when using the #include trick.
1613  break;
1614  }
1615 
1616  switch (Tok.Tok.getKind()) {
1617  // Handle C++ keywords not included above: these are all JS identifiers.
1618 #define KEYWORD(X, Y) case tok::kw_##X:
1619 #include "clang/Basic/TokenKinds.def"
1620  // #undef KEYWORD is not needed -- it's #undef-ed at the end of
1621  // TokenKinds.def
1622  return true;
1623  default:
1624  // All other tokens (punctuation etc) are not JS identifiers.
1625  return false;
1626  }
1627  }
1629  /// Returns \c true if \p Tok is a C# keyword, returns
1630  /// \c false if it is a anything else.
1631  bool isCSharpKeyword(const FormatToken &Tok) const {
1632  switch (Tok.Tok.getKind()) {
1633  case tok::kw_bool:
1634  case tok::kw_break:
1635  case tok::kw_case:
1636  case tok::kw_catch:
1637  case tok::kw_char:
1638  case tok::kw_class:
1639  case tok::kw_const:
1640  case tok::kw_continue:
1641  case tok::kw_default:
1642  case tok::kw_do:
1643  case tok::kw_double:
1644  case tok::kw_else:
1645  case tok::kw_enum:
1646  case tok::kw_explicit:
1647  case tok::kw_extern:
1648  case tok::kw_false:
1649  case tok::kw_float:
1650  case tok::kw_for:
1651  case tok::kw_goto:
1652  case tok::kw_if:
1653  case tok::kw_int:
1654  case tok::kw_long:
1655  case tok::kw_namespace:
1656  case tok::kw_new:
1657  case tok::kw_operator:
1658  case tok::kw_private:
1659  case tok::kw_protected:
1660  case tok::kw_public:
1661  case tok::kw_return:
1662  case tok::kw_short:
1663  case tok::kw_sizeof:
1664  case tok::kw_static:
1665  case tok::kw_struct:
1666  case tok::kw_switch:
1667  case tok::kw_this:
1668  case tok::kw_throw:
1669  case tok::kw_true:
1670  case tok::kw_try:
1671  case tok::kw_typeof:
1672  case tok::kw_using:
1673  case tok::kw_virtual:
1674  case tok::kw_void:
1675  case tok::kw_volatile:
1676  case tok::kw_while:
1677  return true;
1678  default:
1679  return Tok.is(tok::identifier) &&
1680  CSharpExtraKeywords.find(Tok.Tok.getIdentifierInfo()) ==
1681  CSharpExtraKeywords.end();
1682  }
1683  }
1684 
1685  bool isVerilogWordOperator(const FormatToken &Tok) const {
1686  return Tok.isOneOf(kw_before, kw_intersect, kw_dist, kw_iff, kw_inside,
1688  }
1689 
1690  bool isVerilogIdentifier(const FormatToken &Tok) const {
1691  switch (Tok.Tok.getKind()) {
1692  case tok::kw_case:
1693  case tok::kw_class:
1694  case tok::kw_const:
1695  case tok::kw_continue:
1696  case tok::kw_default:
1697  case tok::kw_do:
1698  case tok::kw_extern:
1699  case tok::kw_else:
1700  case tok::kw_enum:
1701  case tok::kw_for:
1702  case tok::kw_if:
1703  case tok::kw_restrict:
1704  case tok::kw_signed:
1705  case tok::kw_static:
1706  case tok::kw_struct:
1707  case tok::kw_typedef:
1708  case tok::kw_union:
1709  case tok::kw_unsigned:
1710  case tok::kw_virtual:
1711  case tok::kw_while:
1712  return false;
1713  case tok::identifier:
1714  return VerilogExtraKeywords.find(Tok.Tok.getIdentifierInfo()) ==
1715  VerilogExtraKeywords.end();
1716  default:
1717  // getIdentifierInfo returns non-null for both identifiers and keywords.
1718  return Tok.Tok.getIdentifierInfo() != nullptr;
1719  }
1720  }
1721 
1722  /// Returns whether \p Tok is a Verilog preprocessor directive. This is
1723  /// needed because macro expansions start with a backtick as well and they
1724  /// need to be treated differently.
1725  bool isVerilogPPDirective(const FormatToken &Tok) const {
1726  auto Info = Tok.Tok.getIdentifierInfo();
1727  if (!Info)
1728  return false;
1729  switch (Info->getPPKeywordID()) {
1730  case tok::pp_define:
1731  case tok::pp_else:
1732  case tok::pp_endif:
1733  case tok::pp_ifdef:
1734  case tok::pp_ifndef:
1735  case tok::pp_include:
1736  case tok::pp_line:
1737  case tok::pp_pragma:
1738  case tok::pp_undef:
1739  return true;
1740  default:
1748  }
1749  }
1750 
1751  /// Returns whether \p Tok is a Verilog keyword that opens a block.
1752  bool isVerilogBegin(const FormatToken &Tok) const {
1753  // `table` is not included since it needs to be treated specially.
1754  return !Tok.endsSequence(kw_fork, kw_disable) &&
1756  }
1757 
1758  /// Returns whether \p Tok is a Verilog keyword that closes a block.
1759  bool isVerilogEnd(const FormatToken &Tok) const {
1760  return !Tok.endsSequence(kw_join, kw_rand) &&
1761  Tok.isOneOf(TT_MacroBlockEnd, kw_end, kw_endcase, kw_endclass,
1768  }
1769 
1770  /// Returns whether \p Tok is a Verilog keyword that opens a module, etc.
1771  bool isVerilogHierarchy(const FormatToken &Tok) const {
1772  if (Tok.endsSequence(kw_function, kw_with))
1773  return false;
1774  if (Tok.is(kw_property)) {
1775  const FormatToken *Prev = Tok.getPreviousNonComment();
1776  return !(Prev &&
1777  Prev->isOneOf(tok::kw_restrict, kw_assert, kw_assume, kw_cover));
1778  }
1779  return Tok.isOneOf(tok::kw_case, tok::kw_class, kw_function, kw_module,
1784  }
1785 
1786  bool isVerilogEndOfLabel(const FormatToken &Tok) const {
1787  const FormatToken *Next = Tok.getNextNonComment();
1788  // In Verilog the colon in a default label is optional.
1789  return Tok.is(TT_GotoLabelColon) ||
1790  (Tok.is(tok::kw_default) &&
1791  !(Next && Next->isOneOf(tok::colon, tok::semi, kw_clocking, kw_iff,
1793  }
1794 
1795 private:
1796  /// The JavaScript keywords beyond the C++ keyword set.
1797  std::unordered_set<IdentifierInfo *> JsExtraKeywords;
1798 
1799  /// The C# keywords beyond the C++ keyword set
1800  std::unordered_set<IdentifierInfo *> CSharpExtraKeywords;
1801 
1802  /// The Verilog keywords beyond the C++ keyword set.
1803  std::unordered_set<IdentifierInfo *> VerilogExtraKeywords;
1804 };
1805 
1806 } // namespace format
1807 } // namespace clang
1808 
1809 #endif
clang::format::AdditionalKeywords::kw_object
IdentifierInfo * kw_object
Definition: FormatToken.h:1395
clang::format::AdditionalKeywords::kw_internal_ident_after_define
IdentifierInfo * kw_internal_ident_after_define
Definition: FormatToken.h:1377
clang::format::AdditionalKeywords::kw_tri0
IdentifierInfo * kw_tri0
Definition: FormatToken.h:1522
clang::format::AdditionalKeywords::kw_end_keywords
IdentifierInfo * kw_end_keywords
Definition: FormatToken.h:1446
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:459
clang::format::FormatToken::getNextNonComment
const FormatToken * getNextNonComment() const
Returns the next token ignoring comments.
Definition: FormatToken.h:743
clang::format::AdditionalKeywords::kw_casex
IdentifierInfo * kw_casex
Definition: FormatToken.h:1426
clang::format::FormatToken::MustBreakBefore
unsigned MustBreakBefore
Whether there must be a line break before this token.
Definition: FormatToken.h:287
clang::prec::Comma
@ Comma
Definition: OperatorPrecedence.h:28
clang::format::AdditionalKeywords::kw_inout
IdentifierInfo * kw_inout
Definition: FormatToken.h:1475
clang::format::AdditionalKeywords::kw_implements
IdentifierInfo * kw_implements
Definition: FormatToken.h:1350
clang::dependency_directives_scan::pp_undef
@ pp_undef
Definition: DependencyDirectivesScanner.h:64
clang::format::FormatToken::BindingStrength
unsigned BindingStrength
The binding strength of a token.
Definition: FormatToken.h:442
clang::format::AdditionalKeywords::isWordLike
bool isWordLike(const FormatToken &Tok) const
Returns true if Tok is a keyword or an identifier.
Definition: FormatToken.h:1550
clang::format::AdditionalKeywords::kw_table
IdentifierInfo * kw_table
Definition: FormatToken.h:1518
clang::format::AdditionalKeywords::AdditionalKeywords
AdditionalKeywords(IdentifierTable &IdentTable)
Definition: FormatToken.h:925
clang::format::MacroExpansion::EndOfExpansion
unsigned EndOfExpansion
The number of currently open expansions in ExpandedFrom this macro is the last token in.
Definition: FormatToken.h:235
clang::format::AdditionalKeywords::kw_NS_OPTIONS
IdentifierInfo * kw_NS_OPTIONS
Definition: FormatToken.h:1320
clang::format::MacroExpansion::Role
MacroRole Role
The token's role in the macro expansion.
Definition: FormatToken.h:225
clang::format::AdditionalKeywords::kw_binsof
IdentifierInfo * kw_binsof
Definition: FormatToken.h:1425
clang::format::AdditionalKeywords::kw_specparam
IdentifierInfo * kw_specparam
Definition: FormatToken.h:1513
clang::format::AdditionalKeywords::kw_abstract
IdentifierInfo * kw_abstract
Definition: FormatToken.h:1347
clang::format::AdditionalKeywords::kw_strong0
IdentifierInfo * kw_strong0
Definition: FormatToken.h:1514
clang::format::AdditionalKeywords::kw_randc
IdentifierInfo * kw_randc
Definition: FormatToken.h:1501
clang::format::AdditionalKeywords::kw_CF_ENUM
IdentifierInfo * kw_CF_ENUM
Definition: FormatToken.h:1316
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:177
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:776
clang::format::AdditionalKeywords::kw_endcase
IdentifierInfo * kw_endcase
Definition: FormatToken.h:1447
clang::format::FormatToken::isObjCAtKeyword
bool isObjCAtKeyword(tok::ObjCKeywordKind Kind) const
Definition: FormatToken.h:586
clang::format::AdditionalKeywords::kw_sequence
IdentifierInfo * kw_sequence
Definition: FormatToken.h:1508
clang::format::FormatToken::ClosesTemplateDeclaration
unsigned ClosesTemplateDeclaration
true if this is the ">" of "template<..>".
Definition: FormatToken.h:296
clang::format::AdditionalKeywords::kw_trireg
IdentifierInfo * kw_trireg
Definition: FormatToken.h:1527
clang::format::FormatToken::SplitPenalty
unsigned SplitPenalty
Penalty for inserting a line break before this token.
Definition: FormatToken.h:452
clang::format::AdditionalKeywords::kw_uwire
IdentifierInfo * kw_uwire
Definition: FormatToken.h:1532
clang::format::FormatToken::isBinaryOperator
bool isBinaryOperator() const
Definition: FormatToken.h:663
clang::format::FormatToken::isIf
bool isIf(bool AllowConstexprMacro=true) const
Definition: FormatToken.h:553
clang::format::AdditionalKeywords::kw_delay_mode_zero
IdentifierInfo * kw_delay_mode_zero
Definition: FormatToken.h:1441
clang::format::AdditionalKeywords::kw_internal
IdentifierInfo * kw_internal
Definition: FormatToken.h:1391
clang::format::AdditionalKeywords::kw_instanceof
IdentifierInfo * kw_instanceof
Definition: FormatToken.h:1351
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:597
clang::format::BK_Unknown
@ BK_Unknown
Definition: FormatToken.h:169
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::dependency_directives_scan::pp_ifndef
@ pp_ifndef
Definition: DependencyDirectivesScanner.h:74
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:219
clang::format::FormatToken::getPrecedence
prec::Level getPrecedence() const
Definition: FormatToken.h:727
clang::format::AdditionalKeywords::kw_endmodule
IdentifierInfo * kw_endmodule
Definition: FormatToken.h:1456
clang::format::AdditionalKeywords::kw_stackalloc
IdentifierInfo * kw_stackalloc
Definition: FormatToken.h:1402
clang::format::AdditionalKeywords::kw_from
IdentifierInfo * kw_from
Definition: FormatToken.h:1331
clang::format::TokenRole::~TokenRole
virtual ~TokenRole()
Definition: FormatToken.cpp:92
clang::format::AdditionalKeywords::kw_final
IdentifierInfo * kw_final
Definition: FormatToken.h:1311
clang::format::AdditionalKeywords::isVerilogBegin
bool isVerilogBegin(const FormatToken &Tok) const
Returns whether Tok is a Verilog keyword that opens a block.
Definition: FormatToken.h:1749
clang::format::AdditionalKeywords::kw_default_trireg_strength
IdentifierInfo * kw_default_trireg_strength
Definition: FormatToken.h:1437
clang::format::AdditionalKeywords::kw_readonly
IdentifierInfo * kw_readonly
Definition: FormatToken.h:1339
clang::Token::getIdentifierInfo
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:181
clang::format::AdditionalKeywords::kw_delay_mode_distributed
IdentifierInfo * kw_delay_mode_distributed
Definition: FormatToken.h:1438
clang::format::AdditionalKeywords::kw_join_any
IdentifierInfo * kw_join_any
Definition: FormatToken.h:1481
clang::format::AdditionalKeywords::kw_soft
IdentifierInfo * kw_soft
Definition: FormatToken.h:1510
clang::format::AdditionalKeywords::kw_program
IdentifierInfo * kw_program
Definition: FormatToken.h:1495
clang::format::AdditionalKeywords::kw_matches
IdentifierInfo * kw_matches
Definition: FormatToken.h:1487
clang::format::AdditionalKeywords::kw_optional
IdentifierInfo * kw_optional
Definition: FormatToken.h:1365
clang::format::FormatToken::IndentLevel
unsigned IndentLevel
The indent level of this token. Copied from the surrounding line.
Definition: FormatToken.h:449
clang::format::AdditionalKeywords::kw_is
IdentifierInfo * kw_is
Definition: FormatToken.h:1336
clang::format::FormatStyle
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition: Format.h:55
clang::format::FormatToken::TokenText
StringRef TokenText
The raw text of the token.
Definition: FormatToken.h:262
clang::format::AdditionalKeywords::kw_region
IdentifierInfo * kw_region
Definition: FormatToken.h:1360
clang::format::AdditionalKeywords::kw_CF_CLOSED_ENUM
IdentifierInfo * kw_CF_CLOSED_ENUM
Definition: FormatToken.h:1315
clang::format::FormatToken::IsMultiline
unsigned IsMultiline
Whether the token text contains newlines (escaped or not).
Definition: FormatToken.h:278
clang::format::FormatToken
A wrapper around a Token storing information about the whitespace characters preceding it.
Definition: FormatToken.h:243
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:513
clang::format::AdditionalKeywords
Encapsulates keywords that are context sensitive or for languages not properly supported by Clang's l...
Definition: FormatToken.h:924
clang::format::FormatToken::StartsColumn
bool StartsColumn
The first token in set of column elements.
Definition: FormatToken.h:498
clang::format::ParameterPackingKind
ParameterPackingKind
Definition: FormatToken.h:172
clang::format::AdditionalKeywords::kw_unique
IdentifierInfo * kw_unique
Definition: FormatToken.h:1530
clang::format::FormatToken::isNot
bool isNot(T Kind) const
Definition: FormatToken.h:551
clang::format::TokenRole
Definition: FormatToken.h:826
clang::format::FormatToken::SpacesRequiredBefore
unsigned SpacesRequiredBefore
The number of spaces that should be inserted before this token.
Definition: FormatToken.h:414
clang::format::AdditionalKeywords::kw_output
IdentifierInfo * kw_output
Definition: FormatToken.h:1490
clang::format::AdditionalKeywords::kw_endspecify
IdentifierInfo * kw_endspecify
Definition: FormatToken.h:1462
clang::format::FormatToken::OriginalColumn
unsigned OriginalColumn
The original 0-based column of this token, including expanded tabs.
Definition: FormatToken.h:433
clang::format::FormatToken::OperatorIndex
unsigned OperatorIndex
If this is an operator (or "."/"->") in a sequence of operators with the same precedence,...
Definition: FormatToken.h:482
clang::format::CommaSeparatedList::lastComma
const FormatToken * lastComma() override
Definition: FormatToken.h:882
clang::format::AdditionalKeywords::kw_illegal_bins
IdentifierInfo * kw_illegal_bins
Definition: FormatToken.h:1473
clang::format::FormatToken::BlockParameterCount
unsigned BlockParameterCount
Number of parameters that are nested blocks, if this is "(", "[" or "<".
Definition: FormatToken.h:421
clang::format::AdditionalKeywords::kw_as
IdentifierInfo * kw_as
Definition: FormatToken.h:1326
clang::format::AdditionalKeywords::kw_native
IdentifierInfo * kw_native
Definition: FormatToken.h:1353
clang::format::AdditionalKeywords::kw_unconnected_drive
IdentifierInfo * kw_unconnected_drive
Definition: FormatToken.h:1528
clang::format::FormatToken::closesBlockOrBlockTypeList
bool closesBlockOrBlockTypeList(const FormatStyle &Style) const
Same as opensBlockOrBlockTypeList, but for the closing token.
Definition: FormatToken.h:768
clang::format::AdditionalKeywords::kw_assume
IdentifierInfo * kw_assume
Definition: FormatToken.h:1419
clang::format::AdditionalKeywords::kw_default_nettype
IdentifierInfo * kw_default_nettype
Definition: FormatToken.h:1436
clang::format::AdditionalKeywords::kw_disable
IdentifierInfo * kw_disable
Definition: FormatToken.h:1442
Format.h
clang::format::AdditionalKeywords::kw_signals
IdentifierInfo * kw_signals
Definition: FormatToken.h:1371
clang::format::FormatToken::setType
void setType(TokenType T)
Definition: FormatToken.h:372
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
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:281
clang::format::MacroExpansion::MacroExpansion
MacroExpansion(MacroRole Role)
Definition: FormatToken.h:217
clang::format::AdditionalKeywords::kw_endtask
IdentifierInfo * kw_endtask
Definition: FormatToken.h:1464
clang::format::FormatToken::ForcedPrecedence
prec::Level ForcedPrecedence
Used to set an operator precedence explicitly.
Definition: FormatToken.h:392
clang::format::BK_BracedInit
@ BK_BracedInit
Definition: FormatToken.h:169
clang::format::AdditionalKeywords::kw_clocking
IdentifierInfo * kw_clocking
Definition: FormatToken.h:1430
clang::format::AdditionalKeywords::kw_unique0
IdentifierInfo * kw_unique0
Definition: FormatToken.h:1531
clang::format::AdditionalKeywords::kw_synchronized
IdentifierInfo * kw_synchronized
Definition: FormatToken.h:1355
clang::format::PPK_BinPacked
@ PPK_BinPacked
Definition: FormatToken.h:172
clang::format::FormatToken::FormatToken
FormatToken()
Definition: FormatToken.h:244
clang::format::AdditionalKeywords::kw_before
IdentifierInfo * kw_before
Definition: FormatToken.h:1421
clang::format::FormatToken::NewlinesBefore
unsigned NewlinesBefore
The number of newlines immediately before the Token.
Definition: FormatToken.h:398
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1566
clang::format::AdditionalKeywords::kw_sbyte
IdentifierInfo * kw_sbyte
Definition: FormatToken.h:1403
clang::format::FormatToken::PartOfMultiVariableDeclStmt
unsigned PartOfMultiVariableDeclStmt
Is this token part of a DeclStmt defining multiple variables?
Definition: FormatToken.h:307
clang::format::FormatToken::getDecision
FormatDecision getDecision() const
Definition: FormatToken.h:343
clang::format::AdditionalKeywords::kw_wire
IdentifierInfo * kw_wire
Definition: FormatToken.h:1538
clang::format::AdditionalKeywords::isVerilogIdentifier
bool isVerilogIdentifier(const FormatToken &Tok) const
Definition: FormatToken.h:1687
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:156
clang::format::FormatToken::CanBreakBefore
unsigned CanBreakBefore
true if it is allowed to break before this token.
Definition: FormatToken.h:293
clang::format::AdditionalKeywords::kw_sealed
IdentifierInfo * kw_sealed
Definition: FormatToken.h:1404
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:756
clang::format::FormatToken::isAccessSpecifier
bool isAccessSpecifier(bool ColonRequired=true) const
Definition: FormatToken.h:590
clang::format::FormatToken::FakeRParens
unsigned FakeRParens
Insert this many fake ) after this token for correct indentation.
Definition: FormatToken.h:478
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:699
clang::format::FormatToken::ArrayInitializerLineStart
bool ArrayInitializerLineStart
This notes the start of the line of an array initializer.
Definition: FormatToken.h:501
clang::format::AdditionalKeywords::kw_undefineall
IdentifierInfo * kw_undefineall
Definition: FormatToken.h:1529
clang::format::CommaSeparatedList::CommaSeparatedList
CommaSeparatedList(const FormatStyle &Style)
Definition: FormatToken.h:866
clang::format::AdditionalKeywords::kw_import
IdentifierInfo * kw_import
Definition: FormatToken.h:1334
clang::format::AdditionalKeywords::kw_supply0
IdentifierInfo * kw_supply0
Definition: FormatToken.h:1516
clang::format::FormatToken::closesScope
bool closesScope() const
Returns whether Tok is )]} or a closing > of a template or in protos.
Definition: FormatToken.h:631
clang::format::AdditionalKeywords::kw_await
IdentifierInfo * kw_await
Definition: FormatToken.h:1328
clang::format::FormatToken::NestingLevel
unsigned NestingLevel
The nesting level of this token, i.e.
Definition: FormatToken.h:446
clang::format::AdditionalKeywords::kw_extends
IdentifierInfo * kw_extends
Definition: FormatToken.h:1349
LIST_TOKEN_TYPES
#define LIST_TOKEN_TYPES
Definition: FormatToken.h:29
clang::format::AdditionalKeywords::kw_foreach
IdentifierInfo * kw_foreach
Definition: FormatToken.h:1388
clang::format::AdditionalKeywords::kw_async
IdentifierInfo * kw_async
Definition: FormatToken.h:1327
clang::format::FormatToken::Previous
FormatToken * Previous
The previous token in the unwrapped line.
Definition: FormatToken.h:492
clang::format::AdditionalKeywords::isVerilogEndOfLabel
bool isVerilogEndOfLabel(const FormatToken &Tok) const
Definition: FormatToken.h:1783
clang::dependency_directives_scan::pp_endif
@ pp_endif
Definition: DependencyDirectivesScanner.h:79
clang::format::LineState
The current state when indenting a unwrapped line.
Definition: ContinuationIndenter.h:416
clang::format::AdditionalKeywords::kw_apostrophe
IdentifierInfo * kw_apostrophe
Definition: FormatToken.h:1547
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:849
clang::prec::Unknown
@ Unknown
Definition: OperatorPrecedence.h:27
clang::format::FormatToken::EndsBinaryExpression
unsigned EndsBinaryExpression
true if this token ends a binary expression.
Definition: FormatToken.h:302
clang::format::FormatToken::getPackingKind
ParameterPackingKind getPackingKind() const
Definition: FormatToken.h:356
clang::format::AdditionalKeywords::kw_assert
IdentifierInfo * kw_assert
Definition: FormatToken.h:1348
clang::format::AdditionalKeywords::kw_qslots
IdentifierInfo * kw_qslots
Definition: FormatToken.h:1374
clang::format::FormatToken::StartsBinaryExpression
unsigned StartsBinaryExpression
true if this token starts a binary expression, i.e.
Definition: FormatToken.h:300
clang::format::AdditionalKeywords::kw_NS_ENUM
IdentifierInfo * kw_NS_ENUM
Definition: FormatToken.h:1319
clang::format::TokenRole::lastComma
virtual const FormatToken * lastComma()
Definition: FormatToken.h:858
clang::format::AdditionalKeywords::kw_endprimitive
IdentifierInfo * kw_endprimitive
Definition: FormatToken.h:1458
clang::format::AdditionalKeywords::kw_forever
IdentifierInfo * kw_forever
Definition: FormatToken.h:1465
clang::format::FormatToken::MacroParent
bool MacroParent
When macro expansion introduces nodes with children, those are marked as MacroParent.
Definition: FormatToken.h:530
clang::format::FormatToken::isMemberAccess
bool isMemberAccess() const
Returns true if this is a "." or "->" accessing a member.
Definition: FormatToken.h:641
clang::format::FormatToken::Tok
Token Tok
The Token.
Definition: FormatToken.h:256
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:1628
clang::format::AdditionalKeywords::kw_params
IdentifierInfo * kw_params
Definition: FormatToken.h:1398
clang::format::AdditionalKeywords::kw_required
IdentifierInfo * kw_required
Definition: FormatToken.h:1367
llvm::Optional
std::optional< T > Optional
Definition: LLVM.h:40
clang::format::AdditionalKeywords::kw_repeated
IdentifierInfo * kw_repeated
Definition: FormatToken.h:1366
clang::format::AdditionalKeywords::kw_strong1
IdentifierInfo * kw_strong1
Definition: FormatToken.h:1515
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:220
clang::format::AdditionalKeywords::kw_throws
IdentifierInfo * kw_throws
Definition: FormatToken.h:1356
clang::format::AdditionalKeywords::kw_pure
IdentifierInfo * kw_pure
Definition: FormatToken.h:1499
clang::format::AdditionalKeywords::kw_large
IdentifierInfo * kw_large
Definition: FormatToken.h:1483
clang::Token::getKind
tok::TokenKind getKind() const
Definition: Token.h:93
clang::format::CommaSeparatedList::CommaFound
void CommaFound(const FormatToken *Token) override
Adds Token as the next comma to the CommaSeparated list.
Definition: FormatToken.h:878
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:675
clang::dependency_directives_scan::pp_define
@ pp_define
Definition: DependencyDirectivesScanner.h:63
clang::format::AdditionalKeywords::kw_in
IdentifierInfo * kw_in
Definition: FormatToken.h:1313
clang::format::AnnotatedLine
Definition: TokenAnnotator.h:37
clang::format::AdditionalKeywords::kw_ushort
IdentifierInfo * kw_ushort
Definition: FormatToken.h:1409
clang::format::AdditionalKeywords::isVerilogEnd
bool isVerilogEnd(const FormatToken &Tok) const
Returns whether Tok is a Verilog keyword that closes a block.
Definition: FormatToken.h:1756
clang::format::AdditionalKeywords::kw_endchecker
IdentifierInfo * kw_endchecker
Definition: FormatToken.h:1449
clang::format::AdditionalKeywords::kw_delay_mode_unit
IdentifierInfo * kw_delay_mode_unit
Definition: FormatToken.h:1440
clang::format::AdditionalKeywords::kw_var
IdentifierInfo * kw_var
Definition: FormatToken.h:1343
clang::format::AdditionalKeywords::kw_medium
IdentifierInfo * kw_medium
Definition: FormatToken.h:1488
clang::format::FormatToken::isObjCAccessSpecifier
bool isObjCAccessSpecifier() const
Definition: FormatToken.h:611
clang::format::AdditionalKeywords::kw_fork
IdentifierInfo * kw_fork
Definition: FormatToken.h:1466
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:98
clang::format::FormatToken::isTrailingComment
bool isTrailingComment() const
Definition: FormatToken.h:668
clang::format::AdditionalKeywords::kw_randcase
IdentifierInfo * kw_randcase
Definition: FormatToken.h:1502
clang::format::AdditionalKeywords::kw_casez
IdentifierInfo * kw_casez
Definition: FormatToken.h:1427
IdentifierTable.h
clang::format::FormatToken::isStringLiteral
bool isStringLiteral() const
Definition: FormatToken.h:584
clang::format::AdditionalKeywords::kw_of
IdentifierInfo * kw_of
Definition: FormatToken.h:1314
clang::format::AdditionalKeywords::kw_lock
IdentifierInfo * kw_lock
Definition: FormatToken.h:1393
clang::format::AdditionalKeywords::kw_unsafe
IdentifierInfo * kw_unsafe
Definition: FormatToken.h:1408
clang::format::AdditionalKeywords::kw_init
IdentifierInfo * kw_init
Definition: FormatToken.h:1390
clang::format::FD_Break
@ FD_Break
Definition: FormatToken.h:174
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:841
clang::format::AdditionalKeywords::kw_unchecked
IdentifierInfo * kw_unchecked
Definition: FormatToken.h:1407
clang::format::AdditionalKeywords::kw_interconnect
IdentifierInfo * kw_interconnect
Definition: FormatToken.h:1478
clang::format::AdditionalKeywords::kw_randsequence
IdentifierInfo * kw_randsequence
Definition: FormatToken.h:1503
clang::format::FormatToken::EndsCppAttributeGroup
unsigned EndsCppAttributeGroup
true if this token ends a group of C++ attributes.
Definition: FormatToken.h:323
clang::format::TokenRole::Style
const FormatStyle & Style
Definition: FormatToken.h:861
clang::format::AdditionalKeywords::kw_package
IdentifierInfo * kw_package
Definition: FormatToken.h:1354
clang::format::AdditionalKeywords::kw_timescale
IdentifierInfo * kw_timescale
Definition: FormatToken.h:1521
clang::format::AdditionalKeywords::kw_endproperty
IdentifierInfo * kw_endproperty
Definition: FormatToken.h:1460
clang::format::FormatToken::hasWhitespaceBefore
bool hasWhitespaceBefore() const
Returns true if the range of whitespace immediately preceding the Token is not empty.
Definition: FormatToken.h:723
clang::format::AdditionalKeywords::kw_verilogHash
IdentifierInfo * kw_verilogHash
Definition: FormatToken.h:1543
clang::format::AdditionalKeywords::kw_endtable
IdentifierInfo * kw_endtable
Definition: FormatToken.h:1463
clang::format::AdditionalKeywords::kw_finally
IdentifierInfo * kw_finally
Definition: FormatToken.h:1330
clang::format::MacroExpansion
Contains information on the token's role in a macro expansion.
Definition: FormatToken.h:216
clang::format::AdditionalKeywords::kw_override
IdentifierInfo * kw_override
Definition: FormatToken.h:1312
clang::tok::ObjCKeywordKind
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
Definition: TokenKinds.h:41
clang::format::AdditionalKeywords::kw_property
IdentifierInfo * kw_property
Definition: FormatToken.h:1496
clang::format::BK_Block
@ BK_Block
Definition: FormatToken.h:169
clang::format::AdditionalKeywords::kw_assign
IdentifierInfo * kw_assign
Definition: FormatToken.h:1418
clang::format::AdditionalKeywords::kw_always_ff
IdentifierInfo * kw_always_ff
Definition: FormatToken.h:1416
clang::format::AdditionalKeywords::kw_null
IdentifierInfo * kw_null
Definition: FormatToken.h:1394
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:174
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:186
clang::format::AdditionalKeywords::kw___has_include
IdentifierInfo * kw___has_include
Definition: FormatToken.h:1322
clang::format::MacroExpansion::ExpandedFrom
llvm::SmallVector< FormatToken *, 1 > ExpandedFrom
The stack of macro call identifier tokens this token was expanded from.
Definition: FormatToken.h:228
clang::format::FormatToken::getPreviousNonComment
FormatToken * getPreviousNonComment() const
Returns the previous token ignoring comments.
Definition: FormatToken.h:735
clang::format::AdditionalKeywords::kw_endclass
IdentifierInfo * kw_endclass
Definition: FormatToken.h:1450
clang::format::FormatToken::is
bool is(tok::PPKeywordKind Kind) const
Definition: FormatToken.h:537
clang::format::AdditionalKeywords::kw_rand
IdentifierInfo * kw_rand
Definition: FormatToken.h:1500
clang::format::AdditionalKeywords::kw_weak1
IdentifierInfo * kw_weak1
Definition: FormatToken.h:1536
clang::format::AdditionalKeywords::kw_coverpoint
IdentifierInfo * kw_coverpoint
Definition: FormatToken.h:1434
clang::format::PPK_OnePerLine
@ PPK_OnePerLine
Definition: FormatToken.h:172
clang::format::AdditionalKeywords::kw_delay_mode_path
IdentifierInfo * kw_delay_mode_path
Definition: FormatToken.h:1439
clang::format::AdditionalKeywords::kw_dist
IdentifierInfo * kw_dist
Definition: FormatToken.h:1443
clang::format::FormatToken::ParentBracket
tok::TokenKind ParentBracket
If this is a bracket ("<", "(", "[" or "{"), contains the kind of the surrounding bracket.
Definition: FormatToken.h:425
clang::format::AdditionalKeywords::kw_elsif
IdentifierInfo * kw_elsif
Definition: FormatToken.h:1444
clang::format::getTokenTypeName
const char * getTokenTypeName(TokenType Type)
Determines the name of a token type.
Definition: FormatToken.cpp:24
clang::format::AdditionalKeywords::kw_tri1
IdentifierInfo * kw_tri1
Definition: FormatToken.h:1523
clang::format::FormatToken::ContinuesLineCommentSection
unsigned ContinuesLineCommentSection
Does this line comment continue a line comment section?
Definition: FormatToken.h:312
clang::format::AdditionalKeywords::kw_specify
IdentifierInfo * kw_specify
Definition: FormatToken.h:1512
clang::format::AdditionalKeywords::kw_intersect
IdentifierInfo * kw_intersect
Definition: FormatToken.h:1479
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:1561
clang::format::AdditionalKeywords::kw_type
IdentifierInfo * kw_type
Definition: FormatToken.h:1341
clang::format::FormatToken::canBePointerOrReferenceQualifier
bool canBePointerOrReferenceQualifier() const
Definition: FormatToken.h:599
clang::format::AdditionalKeywords::kw_priority
IdentifierInfo * kw_priority
Definition: FormatToken.h:1494
clang::format::AdditionalKeywords::kw_decimal
IdentifierInfo * kw_decimal
Definition: FormatToken.h:1384
clang::format::AdditionalKeywords::kw_verilogHashHash
IdentifierInfo * kw_verilogHashHash
Definition: FormatToken.h:1544
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:569
clang::format::AdditionalKeywords::kw_supply1
IdentifierInfo * kw_supply1
Definition: FormatToken.h:1517
clang::format::AdditionalKeywords::kw_bins
IdentifierInfo * kw_bins
Definition: FormatToken.h:1424
clang::format::AdditionalKeywords::kw_endclocking
IdentifierInfo * kw_endclocking
Definition: FormatToken.h:1451
clang::format::NUM_TOKEN_TYPES
@ NUM_TOKEN_TYPES
Definition: FormatToken.h:162
clang::format::AdditionalKeywords::kw_mark
IdentifierInfo * kw_mark
Definition: FormatToken.h:1359
clang::format::FormatToken::isUnaryOperator
bool isUnaryOperator() const
Definition: FormatToken.h:647
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:476
clang::format::FormatToken::overwriteFixedType
void overwriteFixedType(TokenType T)
Definition: FormatToken.h:385
clang::format::AdditionalKeywords::kw_wildcard
IdentifierInfo * kw_wildcard
Definition: FormatToken.h:1537
clang::format::FD_Unformatted
@ FD_Unformatted
Definition: FormatToken.h:174
clang::format::FormatToken::Finalized
unsigned Finalized
If true, this token has been fully formatted (indented and potentially re-formatted inside),...
Definition: FormatToken.h:317
clang::format::AdditionalKeywords::kw_endprogram
IdentifierInfo * kw_endprogram
Definition: FormatToken.h:1459
clang::format::AdditionalKeywords::kw_trior
IdentifierInfo * kw_trior
Definition: FormatToken.h:1526
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:96
clang::format::AdditionalKeywords::kw_highz1
IdentifierInfo * kw_highz1
Definition: FormatToken.h:1469
clang::format::FormatToken::getType
TokenType getType() const
Returns the token's type, e.g.
Definition: FormatToken.h:371
clang::dependency_directives_scan::pp_else
@ pp_else
Definition: DependencyDirectivesScanner.h:78
clang::format::AdditionalKeywords::kw_endpackage
IdentifierInfo * kw_endpackage
Definition: FormatToken.h:1457
clang::format::AdditionalKeywords::kw_option
IdentifierInfo * kw_option
Definition: FormatToken.h:1364
clang::format::AdditionalKeywords::kw_triand
IdentifierInfo * kw_triand
Definition: FormatToken.h:1525
clang::format::AdditionalKeywords::kw_let
IdentifierInfo * kw_let
Definition: FormatToken.h:1337
clang::format::AdditionalKeywords::kw_endgroup
IdentifierInfo * kw_endgroup
Definition: FormatToken.h:1454
clang::format::AdditionalKeywords::isVerilogWordOperator
bool isVerilogWordOperator(const FormatToken &Tok) const
Definition: FormatToken.h:1682
Lexer.h
clang::format::AdditionalKeywords::kw_join
IdentifierInfo * kw_join
Definition: FormatToken.h:1480
clang::format::FormatToken::isTypeFinalized
bool isTypeFinalized() const
Definition: FormatToken.h:389
clang::format::FormatToken::getBlockKind
BraceBlockKind getBlockKind() const
Definition: FormatToken.h:330
clang::format::AdditionalKeywords::kw_byte
IdentifierInfo * kw_byte
Definition: FormatToken.h:1382
clang::format::FormatToken::setFinalizedType
void setFinalizedType(TokenType T)
Sets the type and also the finalized flag.
Definition: FormatToken.h:381
clang::format::FormatToken::ClosesRequiresClause
unsigned ClosesRequiresClause
true if this is the last token within requires clause.
Definition: FormatToken.h:320
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_ifnone
IdentifierInfo * kw_ifnone
Definition: FormatToken.h:1471
clang::format::AdditionalKeywords::kw_get
IdentifierInfo * kw_get
Definition: FormatToken.h:1333
clang::format::AdditionalKeywords::kw_parameter
IdentifierInfo * kw_parameter
Definition: FormatToken.h:1492
clang::format::AdditionalKeywords::kw_cover
IdentifierInfo * kw_cover
Definition: FormatToken.h:1432
clang::format::AdditionalKeywords::kw_dollar
IdentifierInfo * kw_dollar
Definition: FormatToken.h:1380
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:437
clang::format::FormatToken::is
bool is(tok::TokenKind Kind) const
Definition: FormatToken.h:532
clang::format::AdditionalKeywords::kw_checker
IdentifierInfo * kw_checker
Definition: FormatToken.h:1429
clang::format::AdditionalKeywords::kw_set
IdentifierInfo * kw_set
Definition: FormatToken.h:1340
clang::IdentifierInfo::getPPKeywordID
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.
Definition: IdentifierTable.cpp:395
clang::format::AdditionalKeywords::kw_declare
IdentifierInfo * kw_declare
Definition: FormatToken.h:1329
State
LineState State
Definition: UnwrappedLineFormatter.cpp:1147
clang::format::FormatToken::isOneOf
bool isOneOf(A K1, B K2) const
Definition: FormatToken.h:544
clang::format::FormatToken::getStartOfNonWhitespace
SourceLocation getStartOfNonWhitespace() const
Returns actual token start location without leading escaped newlines and whitespace.
Definition: FormatToken.h:717
clang::dependency_directives_scan::pp_include
@ pp_include
Definition: DependencyDirectivesScanner.h:61
clang::format::FormatToken::ParameterCount
unsigned ParameterCount
Number of parameters, if this is "(", "[" or "<".
Definition: FormatToken.h:417
clang::format::AdditionalKeywords::kw_fixed
IdentifierInfo * kw_fixed
Definition: FormatToken.h:1387
clang::format::AdditionalKeywords::kw_wor
IdentifierInfo * kw_wor
Definition: FormatToken.h:1540
clang::format::AdditionalKeywords::kw_wand
IdentifierInfo * kw_wand
Definition: FormatToken.h:1534
clang::format::FormatToken::LastLineColumnWidth
unsigned LastLineColumnWidth
Contains the width in columns of the last line of a multi-line token.
Definition: FormatToken.h:411
clang::format::AdditionalKeywords::kw_base
IdentifierInfo * kw_base
Definition: FormatToken.h:1381
clang::format::AdditionalKeywords::kw_covergroup
IdentifierInfo * kw_covergroup
Definition: FormatToken.h:1433
clang::format::AdditionalKeywords::kw_function
IdentifierInfo * kw_function
Definition: FormatToken.h:1332
clang::format::FD_Continue
@ FD_Continue
Definition: FormatToken.h:174
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:85
clang::format::ContinuationIndenter
Definition: ContinuationIndenter.h:51
clang::format::AdditionalKeywords::kw_module
IdentifierInfo * kw_module
Definition: FormatToken.h:1338
clang::format::AdditionalKeywords::kw_typeof
IdentifierInfo * kw_typeof
Definition: FormatToken.h:1342
clang::format::AdditionalKeywords::kw_delegate
IdentifierInfo * kw_delegate
Definition: FormatToken.h:1385
clang::format::AdditionalKeywords::kw_event
IdentifierInfo * kw_event
Definition: FormatToken.h:1386
clang::format::AdditionalKeywords::kw_endsequence
IdentifierInfo * kw_endsequence
Definition: FormatToken.h:1461
clang::format::AdditionalKeywords::kw_resetall
IdentifierInfo * kw_resetall
Definition: FormatToken.h:1505
clang::format::AdditionalKeywords::kw_task
IdentifierInfo * kw_task
Definition: FormatToken.h:1520
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::format::AdditionalKeywords::kw_macromodule
IdentifierInfo * kw_macromodule
Definition: FormatToken.h:1486
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:580
clang::format::AdditionalKeywords::kw_extend
IdentifierInfo * kw_extend
Definition: FormatToken.h:1363
clang::format::AdditionalKeywords::kw_localparam
IdentifierInfo * kw_localparam
Definition: FormatToken.h:1485
clang::format::AdditionalKeywords::kw_automatic
IdentifierInfo * kw_automatic
Definition: FormatToken.h:1420
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:268
clang::format::FormatToken::NextOperator
FormatToken * NextOperator
If this is an operator (or "."/"->") in a sequence of operators with the same precedence,...
Definition: FormatToken.h:486
clang::format::AdditionalKeywords::kw_endgenerate
IdentifierInfo * kw_endgenerate
Definition: FormatToken.h:1453
clang::format::AdditionalKeywords::kw_interface
IdentifierInfo * kw_interface
Definition: FormatToken.h:1352
clang::format::FormatToken::setBlockKind
void setBlockKind(BraceBlockKind BBK)
Definition: FormatToken.h:333
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:183
clang::format::AdditionalKeywords::kw_always_latch
IdentifierInfo * kw_always_latch
Definition: FormatToken.h:1417
clang::format::AdditionalKeywords::kw_always_comb
IdentifierInfo * kw_always_comb
Definition: FormatToken.h:1415
clang::format::AdditionalKeywords::isVerilogHierarchy
bool isVerilogHierarchy(const FormatToken &Tok) const
Returns whether Tok is a Verilog keyword that opens a module, etc.
Definition: FormatToken.h:1768
clang::format::AdditionalKeywords::kw_nounconnected_drive
IdentifierInfo * kw_nounconnected_drive
Definition: FormatToken.h:1489
clang::format::AdditionalKeywords::kw_vectored
IdentifierInfo * kw_vectored
Definition: FormatToken.h:1533
clang::format::FormatToken::setPackingKind
void setPackingKind(ParameterPackingKind K)
Definition: FormatToken.h:359
clang::format::AdditionalKeywords::kw_endcelldefine
IdentifierInfo * kw_endcelldefine
Definition: FormatToken.h:1448
clang::format::AdditionalKeywords::kw_returns
IdentifierInfo * kw_returns
Definition: FormatToken.h:1368
clang
Definition: CalledOnceCheck.h:17
clang::format::FormatToken::isTypeOrIdentifier
bool isTypeOrIdentifier() const
Definition: FormatToken.cpp:74
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:517
clang::format::AdditionalKeywords::kw_always
IdentifierInfo * kw_always
Definition: FormatToken.h:1414
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:1401
clang::format::AdditionalKeywords::kw_with
IdentifierInfo * kw_with
Definition: FormatToken.h:1539
clang::format::AdditionalKeywords::kw_yield
IdentifierInfo * kw_yield
Definition: FormatToken.h:1344
clang::format::AdditionalKeywords::kw_ignore_bins
IdentifierInfo * kw_ignore_bins
Definition: FormatToken.h:1472
clang::format::AdditionalKeywords::kw_packed
IdentifierInfo * kw_packed
Definition: FormatToken.h:1491
clang::format::AdditionalKeywords::kw___except
IdentifierInfo * kw___except
Definition: FormatToken.h:1321
clang::dependency_directives_scan::pp_ifdef
@ pp_ifdef
Definition: DependencyDirectivesScanner.h:73
clang::format::FormatToken::opensBlockOrBlockTypeList
bool opensBlockOrBlockTypeList(const FormatStyle &Style) const
Returns true if this tokens starts a block-type list, i.e.
Definition: FormatToken.cpp:78
clang::format::AdditionalKeywords::kw_endfunction
IdentifierInfo * kw_endfunction
Definition: FormatToken.h:1452
clang::format::FormatDecision
FormatDecision
Definition: FormatToken.h:174
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:94
clang::format::AdditionalKeywords::kw_begin_keywords
IdentifierInfo * kw_begin_keywords
Definition: FormatToken.h:1423
clang::format::AdditionalKeywords::kw_ulong
IdentifierInfo * kw_ulong
Definition: FormatToken.h:1406
clang::IdentifierTable
Implements an efficient mapping from strings to IdentifierInfo nodes.
Definition: IdentifierTable.h:564
clang::format::FormatToken::IsUnterminatedLiteral
unsigned IsUnterminatedLiteral
Set to true if this token is an unterminated literal.
Definition: FormatToken.h:290
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:1318
clang::format::FormatToken::LastNewlineOffset
unsigned LastNewlineOffset
The offset just past the last ' ' in this token's leading whitespace (relative to WhiteSpaceStart).
Definition: FormatToken.h:402
clang::format::AdditionalKeywords::kw_uint
IdentifierInfo * kw_uint
Definition: FormatToken.h:1405
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:407
clang::format::AdditionalKeywords::kw_iff
IdentifierInfo * kw_iff
Definition: FormatToken.h:1470
clang::format::AdditionalKeywords::kw_tri
IdentifierInfo * kw_tri
Definition: FormatToken.h:1524
clang::format::AdditionalKeywords::kw_primitive
IdentifierInfo * kw_primitive
Definition: FormatToken.h:1493
clang::format::AdditionalKeywords::kw_weak0
IdentifierInfo * kw_weak0
Definition: FormatToken.h:1535
clang::format::AdditionalKeywords::kw_CF_OPTIONS
IdentifierInfo * kw_CF_OPTIONS
Definition: FormatToken.h:1317
clang::format::BraceBlockKind
BraceBlockKind
Definition: FormatToken.h:169
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:464
clang::format::CommaSeparatedList
Definition: FormatToken.h:864
clang::format::AdditionalKeywords::kw_repeat
IdentifierInfo * kw_repeat
Definition: FormatToken.h:1504
clang::format::TokenRole::CommaFound
virtual void CommaFound(const FormatToken *Token)
Notifies the Role that a comma was found.
Definition: FormatToken.h:856
clang::format::AdditionalKeywords::kw_implicit
IdentifierInfo * kw_implicit
Definition: FormatToken.h:1389
clang::format::AdditionalKeywords::kw_celldefine
IdentifierInfo * kw_celldefine
Definition: FormatToken.h:1428
clang::format::AdditionalKeywords::kw_small
IdentifierInfo * kw_small
Definition: FormatToken.h:1509
clang::format::AdditionalKeywords::kw_constraint
IdentifierInfo * kw_constraint
Definition: FormatToken.h:1431
clang::format::AdditionalKeywords::kw_qsignals
IdentifierInfo * kw_qsignals
Definition: FormatToken.h:1372
OperatorPrecedence.h
clang::format::AdditionalKeywords::isVerilogPPDirective
bool isVerilogPPDirective(const FormatToken &Tok) const
Returns whether Tok is a Verilog preprocessor directive.
Definition: FormatToken.h:1722
clang::format::AdditionalKeywords::kw_where
IdentifierInfo * kw_where
Definition: FormatToken.h:1411
clang::format::FormatToken::closesScopeAfterBlock
bool closesScopeAfterBlock() const
Definition: FormatToken.h:558
clang::format::AdditionalKeywords::kw_infer
IdentifierInfo * kw_infer
Definition: FormatToken.h:1335
Indenter
ContinuationIndenter * Indenter
Definition: UnwrappedLineFormatter.cpp:1044
clang::format::FormatToken::TotalLength
unsigned TotalLength
The total length of the unwrapped line up to and including this token.
Definition: FormatToken.h:429
clang::format::FormatToken::ParameterIndex
unsigned ParameterIndex
The 0-based index of the parameter/argument.
Definition: FormatToken.h:469
clang::format::AdditionalKeywords::kw_pull1
IdentifierInfo * kw_pull1
Definition: FormatToken.h:1498
clang::format::PPK_Inconclusive
@ PPK_Inconclusive
Definition: FormatToken.h:172
clang::format::FormatToken::Next
FormatToken * Next
The next token in the unwrapped line.
Definition: FormatToken.h:495
clang::format::AdditionalKeywords::kw_when
IdentifierInfo * kw_when
Definition: FormatToken.h:1410
clang::format::MR_ExpandedArg
@ MR_ExpandedArg
The token was expanded from a macro argument when formatting the expanded token sequence.
Definition: FormatToken.h:180
clang::format::FormatToken::HasUnescapedNewline
unsigned HasUnescapedNewline
Whether there is at least one unescaped newline before the Token.
Definition: FormatToken.h:275
clang::format::AdditionalKeywords::kw_join_none
IdentifierInfo * kw_join_none
Definition: FormatToken.h:1482
clang::format::AdditionalKeywords::kw_endinterface
IdentifierInfo * kw_endinterface
Definition: FormatToken.h:1455
clang::format::TokenType
TokenType
Determines the semantic type of a syntactic token, e.g.
Definition: FormatToken.h:158
clang::format::FormatToken::WhitespaceRange
SourceRange WhitespaceRange
The range of the whitespace immediately preceding the Token.
Definition: FormatToken.h:271
clang::format::AdditionalKeywords::kw_checked
IdentifierInfo * kw_checked
Definition: FormatToken.h:1383
clang::format::AdditionalKeywords::kw_generate
IdentifierInfo * kw_generate
Definition: FormatToken.h:1467
clang::format::AdditionalKeywords::kw_initial
IdentifierInfo * kw_initial
Definition: FormatToken.h:1474
clang::format::AdditionalKeywords::kw_slots
IdentifierInfo * kw_slots
Definition: FormatToken.h:1373
clang::format::MacroExpansion::StartOfExpansion
unsigned StartOfExpansion
The number of expansions of which this macro is the first entry.
Definition: FormatToken.h:231
clang::format::AdditionalKeywords::kw___has_include_next
IdentifierInfo * kw___has_include_next
Definition: FormatToken.h:1323
clang::format::AdditionalKeywords::kw_default_decay_time
IdentifierInfo * kw_default_decay_time
Definition: FormatToken.h:1435
clang::format::AdditionalKeywords::kw_tagged
IdentifierInfo * kw_tagged
Definition: FormatToken.h:1519
clang::format::AdditionalKeywords::kw_inside
IdentifierInfo * kw_inside
Definition: FormatToken.h:1477
clang::format::AdditionalKeywords::kw_input
IdentifierInfo * kw_input
Definition: FormatToken.h:1476
clang::format::FormatToken::MatchingParen
FormatToken * MatchingParen
If this is a bracket, this points to the matching one.
Definition: FormatToken.h:489
clang::format::AdditionalKeywords::kw_highz0
IdentifierInfo * kw_highz0
Definition: FormatToken.h:1468
clang::format::AdditionalKeywords::kw_sample
IdentifierInfo * kw_sample
Definition: FormatToken.h:1506
clang::format::AdditionalKeywords::kw_scalared
IdentifierInfo * kw_scalared
Definition: FormatToken.h:1507
clang::format::AdditionalKeywords::kw_ref
IdentifierInfo * kw_ref
Definition: FormatToken.h:1400
clang::format::AdditionalKeywords::kw_solve
IdentifierInfo * kw_solve
Definition: FormatToken.h:1511
clang::format::FormatToken::copyFrom
void copyFrom(const FormatToken &Tok)
Definition: FormatToken.h:789
clang::format::AdditionalKeywords::kw_begin
IdentifierInfo * kw_begin
Definition: FormatToken.h:1422
clang::format::AdditionalKeywords::kw_local
IdentifierInfo * kw_local
Definition: FormatToken.h:1484
clang::format::AdditionalKeywords::kw_end
IdentifierInfo * kw_end
Definition: FormatToken.h:1445
clang::format::TokenRole::TokenRole
TokenRole(const FormatStyle &Style)
Definition: FormatToken.h:828
clang::format::FormatToken::MacroCtx
std::optional< MacroExpansion > MacroCtx
Definition: FormatToken.h:521
clang::format::AdditionalKeywords::kw_pull0
IdentifierInfo * kw_pull0
Definition: FormatToken.h:1497
clang::format::FormatToken::setDecision
void setDecision(FormatDecision D)
Definition: FormatToken.h:346
clang::format::FormatToken::opensScope
bool opensScope() const
Returns whether Tok is ([{ or an opening < of a template or in protos.
Definition: FormatToken.h:621
clang::format::FormatToken::IsArrayInitializer
bool IsArrayInitializer
This starts an array initializer.
Definition: FormatToken.h:504
clang::format::AdditionalKeywords::kw_out
IdentifierInfo * kw_out
Definition: FormatToken.h:1396