15#ifndef LLVM_CLANG_LIB_FORMAT_FORMATTOKEN_H
16#define LLVM_CLANG_LIB_FORMAT_FORMATTOKEN_H
22#include <unordered_set>
27#define LIST_TOKEN_TYPES \
28 TYPE(AfterPPDirective) \
29 TYPE(ArrayInitializerLSquare) \
30 TYPE(ArraySubscriptLSquare) \
31 TYPE(AttributeColon) \
32 TYPE(AttributeLParen) \
33 TYPE(AttributeMacro) \
34 TYPE(AttributeRParen) \
35 TYPE(AttributeSquare) \
36 TYPE(BinaryOperator) \
41 TYPE(BracedListLBrace) \
42 TYPE(CaseLabelArrow) \
44 TYPE(CaseLabelColon) \
50 TYPE(CompoundRequirementLBrace) \
52 TYPE(ConditionalExpr) \
54 TYPE(ConditionLParen) \
55 TYPE(ConflictAlternative) \
59 TYPE(ControlStatementLBrace) \
60 TYPE(ControlStatementRBrace) \
62 TYPE(CSharpGenericTypeConstraint) \
63 TYPE(CSharpGenericTypeConstraintColon) \
64 TYPE(CSharpGenericTypeConstraintComma) \
65 TYPE(CSharpNamedArgumentColon) \
66 TYPE(CSharpNullable) \
67 TYPE(CSharpNullConditionalLSquare) \
68 TYPE(CSharpStringLiteral) \
69 TYPE(CtorInitializerColon) \
70 TYPE(CtorInitializerComma) \
71 TYPE(CtorDtorDeclName) \
72 TYPE(DesignatedInitializerLSquare) \
73 TYPE(DesignatedInitializerPeriod) \
82 TYPE(FunctionAnnotationRParen) \
83 TYPE(FunctionDeclarationName) \
84 TYPE(FunctionDeclarationLParen) \
85 TYPE(FunctionLBrace) \
86 TYPE(FunctionLikeOrFreestandingMacro) \
87 TYPE(FunctionTypeLParen) \
89 TYPE(GenericSelectionColon) \
91 TYPE(GotoLabelColon) \
93 TYPE(ImplicitStringLiteral) \
94 TYPE(InheritanceColon) \
95 TYPE(InheritanceComma) \
96 TYPE(InlineASMBrace) \
97 TYPE(InlineASMColon) \
98 TYPE(InlineASMSymbolicNameLSquare) \
99 TYPE(JavaAnnotation) \
100 TYPE(JsAndAndEqual) \
101 TYPE(JsComputedPropertyName) \
102 TYPE(JsExponentiation) \
103 TYPE(JsExponentiationEqual) \
104 TYPE(JsPipePipeEqual) \
105 TYPE(JsPrivateIdentifier) \
107 TYPE(JsTypeOperator) \
108 TYPE(JsTypeOptionalQuestion) \
110 TYPE(LambdaDefinitionLParen) \
112 TYPE(LambdaLSquare) \
113 TYPE(LeadingJavaAnnotation) \
115 TYPE(MacroBlockBegin) \
116 TYPE(MacroBlockEnd) \
117 TYPE(ModulePartitionColon) \
118 TYPE(NamespaceLBrace) \
119 TYPE(NamespaceMacro) \
120 TYPE(NamespaceRBrace) \
121 TYPE(NonNullAssertion) \
122 TYPE(NullCoalescingEqual) \
123 TYPE(NullCoalescingOperator) \
124 TYPE(NullPropagatingOperator) \
125 TYPE(ObjCBlockLBrace) \
126 TYPE(ObjCBlockLParen) \
129 TYPE(ObjCMethodExpr) \
130 TYPE(ObjCMethodSpecifier) \
132 TYPE(ObjCStringLiteral) \
133 TYPE(OverloadedOperator) \
134 TYPE(OverloadedOperatorLParen) \
135 TYPE(PointerOrReference) \
136 TYPE(ProtoExtensionLSquare) \
137 TYPE(PureVirtualSpecifier) \
138 TYPE(RangeBasedForLoopColon) \
142 TYPE(RequiresClause) \
143 TYPE(RequiresClauseInARequiresExpression) \
144 TYPE(RequiresExpression) \
145 TYPE(RequiresExpressionLBrace) \
146 TYPE(RequiresExpressionLParen) \
149 TYPE(StatementAttributeLikeMacro) \
150 TYPE(StatementMacro) \
155 TYPE(StringInConcatenation) \
158 TYPE(StructuredBindingLSquare) \
159 TYPE(SwitchExpressionLabel) \
160 TYPE(SwitchExpressionLBrace) \
161 TYPE(TableGenBangOperator) \
162 TYPE(TableGenCondOperator) \
163 TYPE(TableGenCondOperatorColon) \
164 TYPE(TableGenCondOperatorComma) \
165 TYPE(TableGenDAGArgCloser) \
166 TYPE(TableGenDAGArgListColon) \
167 TYPE(TableGenDAGArgListColonToAlign) \
168 TYPE(TableGenDAGArgListComma) \
169 TYPE(TableGenDAGArgListCommaToBreak) \
170 TYPE(TableGenDAGArgOpener) \
171 TYPE(TableGenDAGArgOpenerToBreak) \
172 TYPE(TableGenDAGArgOperatorID) \
173 TYPE(TableGenDAGArgOperatorToBreak) \
174 TYPE(TableGenListCloser) \
175 TYPE(TableGenListOpener) \
176 TYPE(TableGenMultiLineString) \
177 TYPE(TableGenTrailingPasteOperator) \
178 TYPE(TableGenValueSuffix) \
179 TYPE(TemplateCloser) \
180 TYPE(TemplateOpener) \
181 TYPE(TemplateString) \
182 TYPE(TrailingAnnotation) \
183 TYPE(TrailingReturnArrow) \
184 TYPE(TrailingUnaryOperator) \
185 TYPE(TypeDeclarationParen) \
188 TYPE(TypenameMacro) \
189 TYPE(UnaryOperator) \
192 TYPE(UntouchableMacroFunc) \
193 TYPE(VariableTemplate) \
195 TYPE(VerilogAssignComma) \
197 TYPE(VerilogBlockLabelColon) \
201 TYPE(VerilogDimensionedTypeName) \
203 TYPE(VerilogInstancePortComma) \
204 TYPE(VerilogInstancePortLParen) \
207 TYPE(VerilogMultiLineListLParen) \
209 TYPE(VerilogNumberBase) \
211 TYPE(VerilogStrength) \
213 TYPE(VerilogTableItem) \
215 TYPE(VerilogTypeComma) \
221#define TYPE(X) TT_##X,
331 std::shared_ptr<TokenRole>
Role;
394 unsigned BlockKind : 2;
402 assert(
getBlockKind() == BBK &&
"BraceBlockKind overflow!");
407 unsigned Decision : 2;
415 assert(
getDecision() ==
D &&
"FormatDecision overflow!");
420 unsigned PackingKind : 2;
428 assert(
getPackingKind() == K &&
"ParameterPackingKind overflow!");
432 unsigned TypeIsFinalized : 1;
445 assert((!TypeIsFinalized ||
T ==
Type) &&
446 "Please use overwriteFixedType to change a fixed type.");
457 TypeIsFinalized =
true;
462 TypeIsFinalized =
false;
609 std::optional<MacroExpansion>
MacroCtx;
632 template <
typename A,
typename B>
bool isOneOf(A K1, B K2)
const {
635 template <
typename A,
typename B,
typename... Ts>
636 bool isOneOf(A K1, B K2, Ts... Ks)
const {
641 bool isIf(
bool AllowConstexprMacro =
true)
const {
642 return is(tok::kw_if) ||
endsSequence(tok::kw_constexpr, tok::kw_if) ||
643 (
endsSequence(tok::identifier, tok::kw_if) && AllowConstexprMacro);
656 template <
typename A,
typename... Ts>
658 return startsSequenceInternal(K1, Tokens...);
667 template <
typename A,
typename... Ts>
669 return endsSequenceInternal(K1, Tokens...);
675 return isOneOf(tok::kw___attribute, tok::kw___declspec, TT_AttributeMacro);
683 return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private);
692 return NextNonComment && NextNonComment->is(tok::colon);
696 return isOneOf(tok::kw_const, tok::kw_restrict, tok::kw_volatile,
697 tok::kw__Nonnull, tok::kw__Nullable,
698 tok::kw__Null_unspecified, tok::kw___ptr32, tok::kw___ptr64,
699 tok::kw___funcref) ||
707 return is(tok::at) &&
Next &&
717 if (
is(TT_TemplateString) &&
TokenText.ends_with(
"${"))
719 if (
is(TT_DictLiteral) &&
is(tok::less))
721 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
727 if (
is(TT_TemplateString) &&
TokenText.starts_with(
"}"))
729 if (
is(TT_DictLiteral) &&
is(tok::greater))
731 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
737 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
738 !
isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
739 TT_LambdaArrow, TT_LeadingJavaAnnotation);
743 return isOneOf(tok::star, tok::amp, tok::ampamp);
758 case tok::exclaimequal:
762 case tok::caretequal:
774 case tok::minusminus:
778 case tok::kw_alignof:
791 return is(tok::comment) &&
801 return isOneOf(tok::kw_throw, tok::kw_typeid, tok::kw_return,
802 tok::kw_sizeof, tok::kw_alignof, tok::kw_alignas,
803 tok::kw_decltype, tok::kw_noexcept, tok::kw_static_assert,
806#include
"clang/Basic/TransformTypeTraits.def"
813 if (
isNot(tok::string_literal))
816 if (Content.starts_with(
"\"") || Content.starts_with(
"'"))
817 Content = Content.drop_front(1);
818 if (Content.ends_with(
"\"") || Content.ends_with(
"'"))
819 Content = Content.drop_back(1);
820 Content = Content.trim();
821 return Content.size() > 1 &&
822 (Content.back() ==
':' || Content.back() ==
'=');
858 while (
Tok &&
Tok->
is(tok::comment))
873 if (!IsCpp ||
isNot(tok::l_square))
877 T =
T->getPreviousNonComment();
878 }
while (
T &&
T->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
880 return T &&
T->is(tok::kw_auto);
894 if (
is(tok::comment))
897 if (NamespaceTok && NamespaceTok->
isOneOf(tok::kw_inline, tok::kw_export))
899 return NamespaceTok &&
900 NamespaceTok->
isOneOf(tok::kw_namespace, TT_NamespaceMacro)
912 template <
typename A,
typename... Ts>
913 bool startsSequenceInternal(A K1, Ts... Tokens)
const {
914 if (
is(tok::comment) &&
Next)
915 return Next->startsSequenceInternal(K1, Tokens...);
916 return is(K1) &&
Next &&
Next->startsSequenceInternal(Tokens...);
919 template <
typename A>
bool startsSequenceInternal(A K1)
const {
920 if (
is(tok::comment) &&
Next)
921 return Next->startsSequenceInternal(K1);
925 template <
typename A,
typename... Ts>
bool endsSequenceInternal(A K1)
const {
927 return Previous->endsSequenceInternal(K1);
931 template <
typename A,
typename... Ts>
932 bool endsSequenceInternal(A K1, Ts... Tokens)
const {
934 return Previous->endsSequenceInternal(K1, Tokens...);
988 bool DryRun)
override;
991 bool DryRun)
override;
995 Commas.push_back(
Token);
1001 return Commas.back();
1007 struct ColumnFormat {
1012 unsigned TotalWidth;
1023 const ColumnFormat *getColumnFormat(
unsigned RemainingCharacters)
const;
1026 SmallVector<const FormatToken *, 8> Commas;
1030 SmallVector<unsigned, 8> ItemLengths;
1033 SmallVector<ColumnFormat, 4> Formats;
1035 bool HasNestedBracedList;
1105 &IdentTable.
get(
"__CLANG_FORMAT_INTERNAL_IDENT_AFTER_DEFINE__");
1293 JsExtraKeywords = std::unordered_set<IdentifierInfo *>(
1300 CSharpExtraKeywords = std::unordered_set<IdentifierInfo *>(
1317 VerilogExtraKeywords = std::unordered_set<IdentifierInfo *>(
1383 TableGenExtraKeywords = std::unordered_set<IdentifierInfo *>({
1676 bool AcceptIdentifierName =
true)
const {
1686 case tok::kw_continue:
1688 case tok::kw_default:
1689 case tok::kw_delete:
1693 case tok::kw_export:
1697 case tok::kw_import:
1698 case tok::kw_module:
1700 case tok::kw_return:
1701 case tok::kw_static:
1702 case tok::kw_switch:
1707 case tok::kw_typeof:
1712 case tok::identifier: {
1715 bool IsPseudoKeyword =
1717 JsExtraKeywords.end();
1718 return AcceptIdentifierName || !IsPseudoKeyword;
1728#define KEYWORD(X, Y) case tok::kw_##X:
1729#include "clang/Basic/TokenKinds.def"
1742 if (Tok.isAccessSpecifierKeyword())
1744 switch (Tok.Tok.getKind()) {
1752 case tok::kw_continue:
1753 case tok::kw_default:
1755 case tok::kw_double:
1758 case tok::kw_explicit:
1759 case tok::kw_extern:
1767 case tok::kw_namespace:
1769 case tok::kw_operator:
1770 case tok::kw_return:
1772 case tok::kw_sizeof:
1773 case tok::kw_static:
1774 case tok::kw_struct:
1775 case tok::kw_switch:
1780 case tok::kw_typeof:
1782 case tok::kw_virtual:
1784 case tok::kw_volatile:
1788 return Tok.is(tok::identifier) &&
1789 CSharpExtraKeywords.find(Tok.Tok.getIdentifierInfo()) ==
1790 CSharpExtraKeywords.end();
1808 case tok::kw_continue:
1809 case tok::kw_default:
1811 case tok::kw_extern:
1816 case tok::kw_restrict:
1817 case tok::kw_signed:
1818 case tok::kw_static:
1819 case tok::kw_struct:
1820 case tok::kw_typedef:
1822 case tok::kw_unsigned:
1823 case tok::kw_virtual:
1826 case tok::identifier:
1829 VerilogExtraKeywords.end();
1840 auto Info = Tok.Tok.getIdentifierInfo();
1843 switch (Info->getPPKeywordID()) {
1844 case tok::pp_define:
1848 case tok::pp_ifndef:
1849 case tok::pp_include:
1851 case tok::pp_pragma:
1903 return Tok.
is(TT_CaseLabelColon) ||
1904 (Tok.
is(tok::kw_default) &&
1918 case tok::kw_extern:
1919 case tok::kw_signed:
1920 case tok::kw_static:
1921 case tok::kw_unsigned:
1922 case tok::kw_virtual:
1924 case tok::identifier:
1952 return Tok.
is(tok::identifier) &&
1954 TableGenExtraKeywords.end();
1960 std::unordered_set<IdentifierInfo *> JsExtraKeywords;
1963 std::unordered_set<IdentifierInfo *> CSharpExtraKeywords;
1966 std::unordered_set<IdentifierInfo *> VerilogExtraKeywords;
1969 std::unordered_set<IdentifierInfo *> TableGenExtraKeywords;
1973 return FormatTok.is(tok::comment) && !FormatTok.TokenText.starts_with(
"/*");
1981 const FormatToken *MinColumnToken) {
1984 unsigned MinContinueColumn =
1985 MinColumnToken->OriginalColumn + (
isLineComment(*MinColumnToken) ? 0 : 1);
1986 return isLineComment(FormatTok) && FormatTok.NewlinesBefore == 1 &&
1988 FormatTok.OriginalColumn >= MinContinueColumn;
enum clang::sema::@1704::IndirectLocalPathEntry::EntryKind Kind
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Defines and computes precedence levels for binary/ternary operators.
static constexpr bool isOneOf()
#define TRANSFORM_TYPE_TRAIT_DEF(Enum, _)
One of these records is kept for each identifier that is lexed.
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.
Implements an efficient mapping from strings to IdentifierInfo nodes.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
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)) {....
tok::TokenKind getKind() const
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
The base class of the type hierarchy.
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token.
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line.
The JSON file list parser is used to communicate input to InstallAPI.
prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator, bool CPlusPlus11)
Return the precedence of the specified binary operator token.
const FunctionProtoType * T