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