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) \
48 TYPE(CompoundRequirementLBrace) \
50 TYPE(ConditionalExpr) \
52 TYPE(ConditionLParen) \
53 TYPE(ConflictAlternative) \
57 TYPE(ControlStatementLBrace) \
58 TYPE(ControlStatementRBrace) \
60 TYPE(CSharpGenericTypeConstraint) \
61 TYPE(CSharpGenericTypeConstraintColon) \
62 TYPE(CSharpGenericTypeConstraintComma) \
63 TYPE(CSharpNamedArgumentColon) \
64 TYPE(CSharpNullable) \
65 TYPE(CSharpNullConditionalLSquare) \
66 TYPE(CSharpStringLiteral) \
67 TYPE(CtorInitializerColon) \
68 TYPE(CtorInitializerComma) \
69 TYPE(CtorDtorDeclName) \
70 TYPE(DesignatedInitializerLSquare) \
71 TYPE(DesignatedInitializerPeriod) \
80 TYPE(FunctionAnnotationRParen) \
81 TYPE(FunctionDeclarationName) \
82 TYPE(FunctionDeclarationLParen) \
83 TYPE(FunctionLBrace) \
84 TYPE(FunctionLikeOrFreestandingMacro) \
85 TYPE(FunctionTypeLParen) \
87 TYPE(GenericSelectionColon) \
89 TYPE(GotoLabelColon) \
91 TYPE(ImplicitStringLiteral) \
92 TYPE(InheritanceColon) \
93 TYPE(InheritanceComma) \
94 TYPE(InlineASMBrace) \
95 TYPE(InlineASMColon) \
96 TYPE(InlineASMSymbolicNameLSquare) \
97 TYPE(JavaAnnotation) \
99 TYPE(JsComputedPropertyName) \
100 TYPE(JsExponentiation) \
101 TYPE(JsExponentiationEqual) \
102 TYPE(JsPipePipeEqual) \
103 TYPE(JsPrivateIdentifier) \
105 TYPE(JsTypeOperator) \
106 TYPE(JsTypeOptionalQuestion) \
108 TYPE(LambdaDefinitionLParen) \
110 TYPE(LambdaLSquare) \
111 TYPE(LeadingJavaAnnotation) \
113 TYPE(MacroBlockBegin) \
114 TYPE(MacroBlockEnd) \
115 TYPE(ModulePartitionColon) \
116 TYPE(NamespaceLBrace) \
117 TYPE(NamespaceMacro) \
118 TYPE(NamespaceRBrace) \
119 TYPE(NonNullAssertion) \
120 TYPE(NullCoalescingEqual) \
121 TYPE(NullCoalescingOperator) \
122 TYPE(NullPropagatingOperator) \
123 TYPE(ObjCBlockLBrace) \
124 TYPE(ObjCBlockLParen) \
127 TYPE(ObjCMethodExpr) \
128 TYPE(ObjCMethodSpecifier) \
130 TYPE(ObjCStringLiteral) \
131 TYPE(OverloadedOperator) \
132 TYPE(OverloadedOperatorLParen) \
133 TYPE(PointerOrReference) \
134 TYPE(ProtoExtensionLSquare) \
135 TYPE(PureVirtualSpecifier) \
136 TYPE(RangeBasedForLoopColon) \
140 TYPE(RequiresClause) \
141 TYPE(RequiresClauseInARequiresExpression) \
142 TYPE(RequiresExpression) \
143 TYPE(RequiresExpressionLBrace) \
144 TYPE(RequiresExpressionLParen) \
147 TYPE(StatementAttributeLikeMacro) \
148 TYPE(StatementMacro) \
153 TYPE(StringInConcatenation) \
156 TYPE(StructuredBindingLSquare) \
157 TYPE(SwitchExpressionLabel) \
158 TYPE(SwitchExpressionLBrace) \
159 TYPE(TableGenBangOperator) \
160 TYPE(TableGenCondOperator) \
161 TYPE(TableGenCondOperatorColon) \
162 TYPE(TableGenCondOperatorComma) \
163 TYPE(TableGenDAGArgCloser) \
164 TYPE(TableGenDAGArgListColon) \
165 TYPE(TableGenDAGArgListColonToAlign) \
166 TYPE(TableGenDAGArgListComma) \
167 TYPE(TableGenDAGArgListCommaToBreak) \
168 TYPE(TableGenDAGArgOpener) \
169 TYPE(TableGenDAGArgOpenerToBreak) \
170 TYPE(TableGenDAGArgOperatorID) \
171 TYPE(TableGenDAGArgOperatorToBreak) \
172 TYPE(TableGenListCloser) \
173 TYPE(TableGenListOpener) \
174 TYPE(TableGenMultiLineString) \
175 TYPE(TableGenTrailingPasteOperator) \
176 TYPE(TableGenValueSuffix) \
177 TYPE(TemplateCloser) \
178 TYPE(TemplateOpener) \
179 TYPE(TemplateString) \
180 TYPE(TrailingAnnotation) \
181 TYPE(TrailingReturnArrow) \
182 TYPE(TrailingUnaryOperator) \
183 TYPE(TypeDeclarationParen) \
186 TYPE(TypenameMacro) \
187 TYPE(UnaryOperator) \
190 TYPE(UntouchableMacroFunc) \
191 TYPE(VariableTemplate) \
193 TYPE(VerilogAssignComma) \
195 TYPE(VerilogBlockLabelColon) \
199 TYPE(VerilogDimensionedTypeName) \
201 TYPE(VerilogInstancePortComma) \
202 TYPE(VerilogInstancePortLParen) \
205 TYPE(VerilogMultiLineListLParen) \
207 TYPE(VerilogNumberBase) \
209 TYPE(VerilogStrength) \
211 TYPE(VerilogTableItem) \
213 TYPE(VerilogTypeComma) \
219#define TYPE(X) TT_##X,
329 std::shared_ptr<TokenRole>
Role;
392 unsigned BlockKind : 2;
400 assert(
getBlockKind() == BBK &&
"BraceBlockKind overflow!");
405 unsigned Decision : 2;
413 assert(
getDecision() ==
D &&
"FormatDecision overflow!");
418 unsigned PackingKind : 2;
426 assert(
getPackingKind() == K &&
"ParameterPackingKind overflow!");
430 unsigned TypeIsFinalized : 1;
443 assert((!TypeIsFinalized ||
T ==
Type) &&
444 "Please use overwriteFixedType to change a fixed type.");
455 TypeIsFinalized =
true;
460 TypeIsFinalized =
false;
607 std::optional<MacroExpansion>
MacroCtx;
630 template <
typename A,
typename B>
bool isOneOf(A K1, B K2)
const {
633 template <
typename A,
typename B,
typename... Ts>
634 bool isOneOf(A K1, B K2, Ts... Ks)
const {
639 bool isIf(
bool AllowConstexprMacro =
true)
const {
640 return is(tok::kw_if) ||
endsSequence(tok::kw_constexpr, tok::kw_if) ||
641 (
endsSequence(tok::identifier, tok::kw_if) && AllowConstexprMacro);
654 template <
typename A,
typename... Ts>
656 return startsSequenceInternal(K1, Tokens...);
665 template <
typename A,
typename... Ts>
667 return endsSequenceInternal(K1, Tokens...);
673 return isOneOf(tok::kw___attribute, tok::kw___declspec, TT_AttributeMacro);
681 return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private);
690 return NextNonComment && NextNonComment->is(tok::colon);
694 return isOneOf(tok::kw_const, tok::kw_restrict, tok::kw_volatile,
695 tok::kw__Nonnull, tok::kw__Nullable,
696 tok::kw__Null_unspecified, tok::kw___ptr32, tok::kw___ptr64,
697 tok::kw___funcref) ||
705 return is(tok::at) &&
Next &&
715 if (
is(TT_TemplateString) &&
TokenText.ends_with(
"${"))
717 if (
is(TT_DictLiteral) &&
is(tok::less))
719 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
725 if (
is(TT_TemplateString) &&
TokenText.starts_with(
"}"))
727 if (
is(TT_DictLiteral) &&
is(tok::greater))
729 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
735 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
736 !
isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
737 TT_LambdaArrow, TT_LeadingJavaAnnotation);
741 return isOneOf(tok::star, tok::amp, tok::ampamp);
756 case tok::exclaimequal:
760 case tok::caretequal:
772 case tok::minusminus:
776 case tok::kw_alignof:
789 return is(tok::comment) &&
799 return isOneOf(tok::kw_throw, tok::kw_typeid, tok::kw_return,
800 tok::kw_sizeof, tok::kw_alignof, tok::kw_alignas,
801 tok::kw_decltype, tok::kw_noexcept, tok::kw_static_assert,
804#include
"clang/Basic/TransformTypeTraits.def"
811 if (
isNot(tok::string_literal))
814 if (Content.starts_with(
"\"") || Content.starts_with(
"'"))
815 Content = Content.drop_front(1);
816 if (Content.ends_with(
"\"") || Content.ends_with(
"'"))
817 Content = Content.drop_back(1);
818 Content = Content.trim();
819 return Content.size() > 1 &&
820 (Content.back() ==
':' || Content.back() ==
'=');
856 while (
Tok &&
Tok->
is(tok::comment))
871 if (!IsCpp ||
isNot(tok::l_square))
875 T =
T->getPreviousNonComment();
876 }
while (
T &&
T->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
878 return T &&
T->is(tok::kw_auto);
892 if (
is(tok::comment))
895 if (NamespaceTok && NamespaceTok->
isOneOf(tok::kw_inline, tok::kw_export))
897 return NamespaceTok &&
898 NamespaceTok->
isOneOf(tok::kw_namespace, TT_NamespaceMacro)
910 template <
typename A,
typename... Ts>
911 bool startsSequenceInternal(A K1, Ts... Tokens)
const {
912 if (
is(tok::comment) &&
Next)
913 return Next->startsSequenceInternal(K1, Tokens...);
914 return is(K1) &&
Next &&
Next->startsSequenceInternal(Tokens...);
917 template <
typename A>
bool startsSequenceInternal(A K1)
const {
918 if (
is(tok::comment) &&
Next)
919 return Next->startsSequenceInternal(K1);
923 template <
typename A,
typename... Ts>
bool endsSequenceInternal(A K1)
const {
925 return Previous->endsSequenceInternal(K1);
929 template <
typename A,
typename... Ts>
930 bool endsSequenceInternal(A K1, Ts... Tokens)
const {
932 return Previous->endsSequenceInternal(K1, Tokens...);
986 bool DryRun)
override;
989 bool DryRun)
override;
993 Commas.push_back(
Token);
999 return Commas.back();
1005 struct ColumnFormat {
1010 unsigned TotalWidth;
1021 const ColumnFormat *getColumnFormat(
unsigned RemainingCharacters)
const;
1024 SmallVector<const FormatToken *, 8> Commas;
1028 SmallVector<unsigned, 8> ItemLengths;
1031 SmallVector<ColumnFormat, 4> Formats;
1033 bool HasNestedBracedList;
1103 &IdentTable.
get(
"__CLANG_FORMAT_INTERNAL_IDENT_AFTER_DEFINE__");
1291 JsExtraKeywords = std::unordered_set<IdentifierInfo *>(
1298 CSharpExtraKeywords = std::unordered_set<IdentifierInfo *>(
1315 VerilogExtraKeywords = std::unordered_set<IdentifierInfo *>(
1381 TableGenExtraKeywords = std::unordered_set<IdentifierInfo *>({
1674 bool AcceptIdentifierName =
true)
const {
1684 case tok::kw_continue:
1686 case tok::kw_default:
1687 case tok::kw_delete:
1691 case tok::kw_export:
1695 case tok::kw_import:
1696 case tok::kw_module:
1698 case tok::kw_return:
1699 case tok::kw_static:
1700 case tok::kw_switch:
1705 case tok::kw_typeof:
1710 case tok::identifier: {
1713 bool IsPseudoKeyword =
1715 JsExtraKeywords.end();
1716 return AcceptIdentifierName || !IsPseudoKeyword;
1726#define KEYWORD(X, Y) case tok::kw_##X:
1727#include "clang/Basic/TokenKinds.def"
1740 if (Tok.isAccessSpecifierKeyword())
1742 switch (Tok.Tok.getKind()) {
1750 case tok::kw_continue:
1751 case tok::kw_default:
1753 case tok::kw_double:
1756 case tok::kw_explicit:
1757 case tok::kw_extern:
1765 case tok::kw_namespace:
1767 case tok::kw_operator:
1768 case tok::kw_return:
1770 case tok::kw_sizeof:
1771 case tok::kw_static:
1772 case tok::kw_struct:
1773 case tok::kw_switch:
1778 case tok::kw_typeof:
1780 case tok::kw_virtual:
1782 case tok::kw_volatile:
1786 return Tok.is(tok::identifier) &&
1787 CSharpExtraKeywords.find(Tok.Tok.getIdentifierInfo()) ==
1788 CSharpExtraKeywords.end();
1806 case tok::kw_continue:
1807 case tok::kw_default:
1809 case tok::kw_extern:
1814 case tok::kw_restrict:
1815 case tok::kw_signed:
1816 case tok::kw_static:
1817 case tok::kw_struct:
1818 case tok::kw_typedef:
1820 case tok::kw_unsigned:
1821 case tok::kw_virtual:
1824 case tok::identifier:
1827 VerilogExtraKeywords.end();
1838 auto Info = Tok.Tok.getIdentifierInfo();
1841 switch (Info->getPPKeywordID()) {
1842 case tok::pp_define:
1846 case tok::pp_ifndef:
1847 case tok::pp_include:
1849 case tok::pp_pragma:
1901 return Tok.
is(TT_CaseLabelColon) ||
1902 (Tok.
is(tok::kw_default) &&
1916 case tok::kw_extern:
1917 case tok::kw_signed:
1918 case tok::kw_static:
1919 case tok::kw_unsigned:
1920 case tok::kw_virtual:
1922 case tok::identifier:
1950 return Tok.
is(tok::identifier) &&
1952 TableGenExtraKeywords.end();
1958 std::unordered_set<IdentifierInfo *> JsExtraKeywords;
1961 std::unordered_set<IdentifierInfo *> CSharpExtraKeywords;
1964 std::unordered_set<IdentifierInfo *> VerilogExtraKeywords;
1967 std::unordered_set<IdentifierInfo *> TableGenExtraKeywords;
1971 return FormatTok.is(tok::comment) && !FormatTok.TokenText.starts_with(
"/*");
1979 const FormatToken *MinColumnToken) {
1982 unsigned MinContinueColumn =
1983 MinColumnToken->OriginalColumn + (
isLineComment(*MinColumnToken) ? 0 : 1);
1984 return isLineComment(FormatTok) && FormatTok.NewlinesBefore == 1 &&
1986 FormatTok.OriginalColumn >= MinContinueColumn;
enum clang::sema::@1724::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