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(ArrayInitializerLSquare) \
29 TYPE(ArraySubscriptLSquare) \
30 TYPE(AttributeColon) \
31 TYPE(AttributeLParen) \
32 TYPE(AttributeMacro) \
33 TYPE(AttributeRParen) \
34 TYPE(AttributeSquare) \
35 TYPE(BinaryOperator) \
40 TYPE(BracedListLBrace) \
41 TYPE(CaseLabelArrow) \
43 TYPE(CaseLabelColon) \
48 TYPE(ConditionalExpr) \
50 TYPE(ConditionLParen) \
51 TYPE(ConflictAlternative) \
55 TYPE(ControlStatementLBrace) \
56 TYPE(ControlStatementRBrace) \
58 TYPE(CSharpGenericTypeConstraint) \
59 TYPE(CSharpGenericTypeConstraintColon) \
60 TYPE(CSharpGenericTypeConstraintComma) \
61 TYPE(CSharpNamedArgumentColon) \
62 TYPE(CSharpNullable) \
63 TYPE(CSharpNullConditionalLSquare) \
64 TYPE(CSharpStringLiteral) \
65 TYPE(CtorInitializerColon) \
66 TYPE(CtorInitializerComma) \
67 TYPE(CtorDtorDeclName) \
68 TYPE(DesignatedInitializerLSquare) \
69 TYPE(DesignatedInitializerPeriod) \
78 TYPE(FunctionAnnotationRParen) \
79 TYPE(FunctionDeclarationName) \
80 TYPE(FunctionDeclarationLParen) \
81 TYPE(FunctionLBrace) \
82 TYPE(FunctionLikeOrFreestandingMacro) \
83 TYPE(FunctionTypeLParen) \
85 TYPE(GenericSelectionColon) \
87 TYPE(GotoLabelColon) \
89 TYPE(ImplicitStringLiteral) \
90 TYPE(InheritanceColon) \
91 TYPE(InheritanceComma) \
92 TYPE(InlineASMBrace) \
93 TYPE(InlineASMColon) \
94 TYPE(InlineASMSymbolicNameLSquare) \
95 TYPE(JavaAnnotation) \
97 TYPE(JsComputedPropertyName) \
98 TYPE(JsExponentiation) \
99 TYPE(JsExponentiationEqual) \
100 TYPE(JsPipePipeEqual) \
101 TYPE(JsPrivateIdentifier) \
103 TYPE(JsTypeOperator) \
104 TYPE(JsTypeOptionalQuestion) \
106 TYPE(LambdaDefinitionLParen) \
108 TYPE(LambdaLSquare) \
109 TYPE(LeadingJavaAnnotation) \
111 TYPE(MacroBlockBegin) \
112 TYPE(MacroBlockEnd) \
113 TYPE(ModulePartitionColon) \
114 TYPE(NamespaceLBrace) \
115 TYPE(NamespaceMacro) \
116 TYPE(NamespaceRBrace) \
117 TYPE(NonNullAssertion) \
118 TYPE(NullCoalescingEqual) \
119 TYPE(NullCoalescingOperator) \
120 TYPE(NullPropagatingOperator) \
121 TYPE(ObjCBlockLBrace) \
122 TYPE(ObjCBlockLParen) \
125 TYPE(ObjCMethodExpr) \
126 TYPE(ObjCMethodSpecifier) \
128 TYPE(ObjCStringLiteral) \
129 TYPE(OverloadedOperator) \
130 TYPE(OverloadedOperatorLParen) \
131 TYPE(PointerOrReference) \
132 TYPE(ProtoExtensionLSquare) \
133 TYPE(PureVirtualSpecifier) \
134 TYPE(RangeBasedForLoopColon) \
138 TYPE(RequiresClause) \
139 TYPE(RequiresClauseInARequiresExpression) \
140 TYPE(RequiresExpression) \
141 TYPE(RequiresExpressionLBrace) \
142 TYPE(RequiresExpressionLParen) \
145 TYPE(StatementAttributeLikeMacro) \
146 TYPE(StatementMacro) \
151 TYPE(StringInConcatenation) \
154 TYPE(StructuredBindingLSquare) \
155 TYPE(SwitchExpressionLabel) \
156 TYPE(SwitchExpressionLBrace) \
157 TYPE(TableGenBangOperator) \
158 TYPE(TableGenCondOperator) \
159 TYPE(TableGenCondOperatorColon) \
160 TYPE(TableGenCondOperatorComma) \
161 TYPE(TableGenDAGArgCloser) \
162 TYPE(TableGenDAGArgListColon) \
163 TYPE(TableGenDAGArgListColonToAlign) \
164 TYPE(TableGenDAGArgListComma) \
165 TYPE(TableGenDAGArgListCommaToBreak) \
166 TYPE(TableGenDAGArgOpener) \
167 TYPE(TableGenDAGArgOpenerToBreak) \
168 TYPE(TableGenDAGArgOperatorID) \
169 TYPE(TableGenDAGArgOperatorToBreak) \
170 TYPE(TableGenListCloser) \
171 TYPE(TableGenListOpener) \
172 TYPE(TableGenMultiLineString) \
173 TYPE(TableGenTrailingPasteOperator) \
174 TYPE(TableGenValueSuffix) \
175 TYPE(TemplateCloser) \
176 TYPE(TemplateOpener) \
177 TYPE(TemplateString) \
178 TYPE(TrailingAnnotation) \
179 TYPE(TrailingReturnArrow) \
180 TYPE(TrailingUnaryOperator) \
181 TYPE(TypeDeclarationParen) \
184 TYPE(TypenameMacro) \
185 TYPE(UnaryOperator) \
188 TYPE(UntouchableMacroFunc) \
190 TYPE(VerilogAssignComma) \
192 TYPE(VerilogBlockLabelColon) \
196 TYPE(VerilogDimensionedTypeName) \
198 TYPE(VerilogInstancePortComma) \
199 TYPE(VerilogInstancePortLParen) \
202 TYPE(VerilogMultiLineListLParen) \
204 TYPE(VerilogNumberBase) \
206 TYPE(VerilogStrength) \
208 TYPE(VerilogTableItem) \
210 TYPE(VerilogTypeComma) \
216#define TYPE(X) TT_##X,
326 std::shared_ptr<TokenRole>
Role;
389 unsigned BlockKind : 2;
397 assert(
getBlockKind() == BBK &&
"BraceBlockKind overflow!");
402 unsigned Decision : 2;
410 assert(
getDecision() ==
D &&
"FormatDecision overflow!");
415 unsigned PackingKind : 2;
423 assert(
getPackingKind() == K &&
"ParameterPackingKind overflow!");
427 unsigned TypeIsFinalized : 1;
440 assert((!TypeIsFinalized ||
T ==
Type) &&
441 "Please use overwriteFixedType to change a fixed type.");
452 TypeIsFinalized =
true;
457 TypeIsFinalized =
false;
604 std::optional<MacroExpansion>
MacroCtx;
627 template <
typename A,
typename B>
bool isOneOf(A K1, B K2)
const {
630 template <
typename A,
typename B,
typename... Ts>
631 bool isOneOf(A K1, B K2, Ts... Ks)
const {
636 bool isIf(
bool AllowConstexprMacro =
true)
const {
637 return is(tok::kw_if) ||
endsSequence(tok::kw_constexpr, tok::kw_if) ||
638 (
endsSequence(tok::identifier, tok::kw_if) && AllowConstexprMacro);
651 template <
typename A,
typename... Ts>
653 return startsSequenceInternal(K1, Tokens...);
662 template <
typename A,
typename... Ts>
664 return endsSequenceInternal(K1, Tokens...);
670 return isOneOf(tok::kw___attribute, tok::kw___declspec, TT_AttributeMacro);
678 return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private);
687 return NextNonComment && NextNonComment->is(tok::colon);
691 return isOneOf(tok::kw_const, tok::kw_restrict, tok::kw_volatile,
692 tok::kw__Nonnull, tok::kw__Nullable,
693 tok::kw__Null_unspecified, tok::kw___ptr32, tok::kw___ptr64,
694 tok::kw___funcref) ||
702 return is(tok::at) &&
Next &&
712 if (
is(TT_TemplateString) &&
TokenText.ends_with(
"${"))
714 if (
is(TT_DictLiteral) &&
is(tok::less))
716 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
722 if (
is(TT_TemplateString) &&
TokenText.starts_with(
"}"))
724 if (
is(TT_DictLiteral) &&
is(tok::greater))
726 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
732 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
733 !
isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
734 TT_LambdaArrow, TT_LeadingJavaAnnotation);
738 return isOneOf(tok::star, tok::amp, tok::ampamp);
753 case tok::exclaimequal:
757 case tok::caretequal:
769 case tok::minusminus:
773 case tok::kw_alignof:
786 return is(tok::comment) &&
796 return isOneOf(tok::kw_throw, tok::kw_typeid, tok::kw_return,
797 tok::kw_sizeof, tok::kw_alignof, tok::kw_alignas,
798 tok::kw_decltype, tok::kw_noexcept, tok::kw_static_assert,
801#include
"clang/Basic/TransformTypeTraits.def"
808 if (
isNot(tok::string_literal))
811 if (Content.starts_with(
"\"") || Content.starts_with(
"'"))
812 Content = Content.drop_front(1);
813 if (Content.ends_with(
"\"") || Content.ends_with(
"'"))
814 Content = Content.drop_back(1);
815 Content = Content.trim();
816 return Content.size() > 1 &&
817 (Content.back() ==
':' || Content.back() ==
'=');
853 while (
Tok &&
Tok->
is(tok::comment))
868 if (!IsCpp ||
isNot(tok::l_square))
872 T =
T->getPreviousNonComment();
873 }
while (
T &&
T->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
875 return T &&
T->is(tok::kw_auto);
889 if (
is(tok::comment))
892 if (NamespaceTok && NamespaceTok->
isOneOf(tok::kw_inline, tok::kw_export))
894 return NamespaceTok &&
895 NamespaceTok->
isOneOf(tok::kw_namespace, TT_NamespaceMacro)
907 template <
typename A,
typename... Ts>
908 bool startsSequenceInternal(A K1, Ts... Tokens)
const {
909 if (
is(tok::comment) &&
Next)
910 return Next->startsSequenceInternal(K1, Tokens...);
911 return is(K1) &&
Next &&
Next->startsSequenceInternal(Tokens...);
914 template <
typename A>
bool startsSequenceInternal(A K1)
const {
915 if (
is(tok::comment) &&
Next)
916 return Next->startsSequenceInternal(K1);
920 template <
typename A,
typename... Ts>
bool endsSequenceInternal(A K1)
const {
922 return Previous->endsSequenceInternal(K1);
926 template <
typename A,
typename... Ts>
927 bool endsSequenceInternal(A K1, Ts... Tokens)
const {
929 return Previous->endsSequenceInternal(K1, Tokens...);
983 bool DryRun)
override;
986 bool DryRun)
override;
990 Commas.push_back(
Token);
996 return Commas.back();
1002 struct ColumnFormat {
1007 unsigned TotalWidth;
1018 const ColumnFormat *getColumnFormat(
unsigned RemainingCharacters)
const;
1021 SmallVector<const FormatToken *, 8> Commas;
1025 SmallVector<unsigned, 8> ItemLengths;
1028 SmallVector<ColumnFormat, 4> Formats;
1030 bool HasNestedBracedList;
1100 &IdentTable.
get(
"__CLANG_FORMAT_INTERNAL_IDENT_AFTER_DEFINE__");
1288 JsExtraKeywords = std::unordered_set<IdentifierInfo *>(
1295 CSharpExtraKeywords = std::unordered_set<IdentifierInfo *>(
1312 VerilogExtraKeywords = std::unordered_set<IdentifierInfo *>(
1378 TableGenExtraKeywords = std::unordered_set<IdentifierInfo *>({
1671 bool AcceptIdentifierName =
true)
const {
1681 case tok::kw_continue:
1683 case tok::kw_default:
1684 case tok::kw_delete:
1688 case tok::kw_export:
1692 case tok::kw_import:
1693 case tok::kw_module:
1695 case tok::kw_return:
1696 case tok::kw_static:
1697 case tok::kw_switch:
1702 case tok::kw_typeof:
1707 case tok::identifier: {
1710 bool IsPseudoKeyword =
1712 JsExtraKeywords.end();
1713 return AcceptIdentifierName || !IsPseudoKeyword;
1723#define KEYWORD(X, Y) case tok::kw_##X:
1724#include "clang/Basic/TokenKinds.def"
1737 if (Tok.isAccessSpecifierKeyword())
1739 switch (Tok.Tok.getKind()) {
1747 case tok::kw_continue:
1748 case tok::kw_default:
1750 case tok::kw_double:
1753 case tok::kw_explicit:
1754 case tok::kw_extern:
1762 case tok::kw_namespace:
1764 case tok::kw_operator:
1765 case tok::kw_return:
1767 case tok::kw_sizeof:
1768 case tok::kw_static:
1769 case tok::kw_struct:
1770 case tok::kw_switch:
1775 case tok::kw_typeof:
1777 case tok::kw_virtual:
1779 case tok::kw_volatile:
1783 return Tok.is(tok::identifier) &&
1784 CSharpExtraKeywords.find(Tok.Tok.getIdentifierInfo()) ==
1785 CSharpExtraKeywords.end();
1803 case tok::kw_continue:
1804 case tok::kw_default:
1806 case tok::kw_extern:
1811 case tok::kw_restrict:
1812 case tok::kw_signed:
1813 case tok::kw_static:
1814 case tok::kw_struct:
1815 case tok::kw_typedef:
1817 case tok::kw_unsigned:
1818 case tok::kw_virtual:
1821 case tok::identifier:
1824 VerilogExtraKeywords.end();
1835 auto Info = Tok.Tok.getIdentifierInfo();
1838 switch (Info->getPPKeywordID()) {
1839 case tok::pp_define:
1843 case tok::pp_ifndef:
1844 case tok::pp_include:
1846 case tok::pp_pragma:
1898 return Tok.
is(TT_CaseLabelColon) ||
1899 (Tok.
is(tok::kw_default) &&
1913 case tok::kw_extern:
1914 case tok::kw_signed:
1915 case tok::kw_static:
1916 case tok::kw_unsigned:
1917 case tok::kw_virtual:
1919 case tok::identifier:
1947 return Tok.
is(tok::identifier) &&
1949 TableGenExtraKeywords.end();
1955 std::unordered_set<IdentifierInfo *> JsExtraKeywords;
1958 std::unordered_set<IdentifierInfo *> CSharpExtraKeywords;
1961 std::unordered_set<IdentifierInfo *> VerilogExtraKeywords;
1964 std::unordered_set<IdentifierInfo *> TableGenExtraKeywords;
1968 return FormatTok.is(tok::comment) && !FormatTok.TokenText.starts_with(
"/*");
1976 const FormatToken *MinColumnToken) {
1979 unsigned MinContinueColumn =
1980 MinColumnToken->OriginalColumn + (
isLineComment(*MinColumnToken) ? 0 : 1);
1981 return isLineComment(FormatTok) && FormatTok.NewlinesBefore == 1 &&
1983 FormatTok.OriginalColumn >= MinContinueColumn;
enum clang::sema::@1718::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