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) \
105 TYPE(LambdaDefinitionLParen) \
107 TYPE(LambdaLSquare) \
108 TYPE(LeadingJavaAnnotation) \
110 TYPE(MacroBlockBegin) \
111 TYPE(MacroBlockEnd) \
112 TYPE(ModulePartitionColon) \
113 TYPE(NamespaceLBrace) \
114 TYPE(NamespaceMacro) \
115 TYPE(NamespaceRBrace) \
116 TYPE(NonNullAssertion) \
117 TYPE(NullCoalescingEqual) \
118 TYPE(NullCoalescingOperator) \
119 TYPE(NullPropagatingOperator) \
120 TYPE(ObjCBlockLBrace) \
121 TYPE(ObjCBlockLParen) \
124 TYPE(ObjCMethodExpr) \
125 TYPE(ObjCMethodSpecifier) \
127 TYPE(ObjCStringLiteral) \
128 TYPE(OverloadedOperator) \
129 TYPE(OverloadedOperatorLParen) \
130 TYPE(PointerOrReference) \
131 TYPE(ProtoExtensionLSquare) \
132 TYPE(PureVirtualSpecifier) \
133 TYPE(RangeBasedForLoopColon) \
137 TYPE(RequiresClause) \
138 TYPE(RequiresClauseInARequiresExpression) \
139 TYPE(RequiresExpression) \
140 TYPE(RequiresExpressionLBrace) \
141 TYPE(RequiresExpressionLParen) \
144 TYPE(StatementAttributeLikeMacro) \
145 TYPE(StatementMacro) \
150 TYPE(StringInConcatenation) \
153 TYPE(StructuredBindingLSquare) \
154 TYPE(SwitchExpressionLabel) \
155 TYPE(SwitchExpressionLBrace) \
156 TYPE(TableGenBangOperator) \
157 TYPE(TableGenCondOperator) \
158 TYPE(TableGenCondOperatorColon) \
159 TYPE(TableGenCondOperatorComma) \
160 TYPE(TableGenDAGArgCloser) \
161 TYPE(TableGenDAGArgListColon) \
162 TYPE(TableGenDAGArgListColonToAlign) \
163 TYPE(TableGenDAGArgListComma) \
164 TYPE(TableGenDAGArgListCommaToBreak) \
165 TYPE(TableGenDAGArgOpener) \
166 TYPE(TableGenDAGArgOpenerToBreak) \
167 TYPE(TableGenDAGArgOperatorID) \
168 TYPE(TableGenDAGArgOperatorToBreak) \
169 TYPE(TableGenListCloser) \
170 TYPE(TableGenListOpener) \
171 TYPE(TableGenMultiLineString) \
172 TYPE(TableGenTrailingPasteOperator) \
173 TYPE(TableGenValueSuffix) \
174 TYPE(TemplateCloser) \
175 TYPE(TemplateOpener) \
176 TYPE(TemplateString) \
177 TYPE(TrailingAnnotation) \
178 TYPE(TrailingReturnArrow) \
179 TYPE(TrailingUnaryOperator) \
180 TYPE(TypeDeclarationParen) \
182 TYPE(TypenameMacro) \
183 TYPE(UnaryOperator) \
186 TYPE(UntouchableMacroFunc) \
188 TYPE(VerilogAssignComma) \
190 TYPE(VerilogBlockLabelColon) \
194 TYPE(VerilogDimensionedTypeName) \
196 TYPE(VerilogInstancePortComma) \
197 TYPE(VerilogInstancePortLParen) \
200 TYPE(VerilogMultiLineListLParen) \
202 TYPE(VerilogNumberBase) \
204 TYPE(VerilogStrength) \
206 TYPE(VerilogTableItem) \
208 TYPE(VerilogTypeComma) \
214#define TYPE(X) TT_##X,
324 std::shared_ptr<TokenRole>
Role;
387 unsigned BlockKind : 2;
395 assert(
getBlockKind() == BBK &&
"BraceBlockKind overflow!");
400 unsigned Decision : 2;
408 assert(
getDecision() ==
D &&
"FormatDecision overflow!");
413 unsigned PackingKind : 2;
421 assert(
getPackingKind() == K &&
"ParameterPackingKind overflow!");
425 unsigned TypeIsFinalized : 1;
438 assert((!TypeIsFinalized ||
T ==
Type) &&
439 "Please use overwriteFixedType to change a fixed type.");
450 TypeIsFinalized =
true;
455 TypeIsFinalized =
false;
599 std::optional<MacroExpansion>
MacroCtx;
622 template <
typename A,
typename B>
bool isOneOf(A K1, B K2)
const {
625 template <
typename A,
typename B,
typename... Ts>
626 bool isOneOf(A K1, B K2, Ts... Ks)
const {
631 bool isIf(
bool AllowConstexprMacro =
true)
const {
632 return is(tok::kw_if) ||
endsSequence(tok::kw_constexpr, tok::kw_if) ||
633 (
endsSequence(tok::identifier, tok::kw_if) && AllowConstexprMacro);
646 template <
typename A,
typename... Ts>
648 return startsSequenceInternal(K1, Tokens...);
657 template <
typename A,
typename... Ts>
659 return endsSequenceInternal(K1, Tokens...);
665 return isOneOf(tok::kw___attribute, tok::kw___declspec, TT_AttributeMacro);
673 return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private);
682 return NextNonComment && NextNonComment->is(tok::colon);
686 return isOneOf(tok::kw_const, tok::kw_restrict, tok::kw_volatile,
687 tok::kw__Nonnull, tok::kw__Nullable,
688 tok::kw__Null_unspecified, tok::kw___ptr32, tok::kw___ptr64,
689 tok::kw___funcref) ||
697 return is(tok::at) &&
Next &&
707 if (
is(TT_TemplateString) &&
TokenText.ends_with(
"${"))
709 if (
is(TT_DictLiteral) &&
is(tok::less))
711 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
717 if (
is(TT_TemplateString) &&
TokenText.starts_with(
"}"))
719 if (
is(TT_DictLiteral) &&
is(tok::greater))
721 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
727 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
728 !
isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
729 TT_LeadingJavaAnnotation);
733 return isOneOf(tok::star, tok::amp, tok::ampamp);
748 case tok::exclaimequal:
752 case tok::caretequal:
764 case tok::minusminus:
768 case tok::kw_alignof:
781 return is(tok::comment) &&
791 return isOneOf(tok::kw_throw, tok::kw_typeid, tok::kw_return,
792 tok::kw_sizeof, tok::kw_alignof, tok::kw_alignas,
793 tok::kw_decltype, tok::kw_noexcept, tok::kw_static_assert,
796#include
"clang/Basic/TransformTypeTraits.def"
803 if (
isNot(tok::string_literal))
806 if (Content.starts_with(
"\"") || Content.starts_with(
"'"))
807 Content = Content.drop_front(1);
808 if (Content.ends_with(
"\"") || Content.ends_with(
"'"))
809 Content = Content.drop_back(1);
810 Content = Content.trim();
811 return Content.size() > 1 &&
812 (Content.back() ==
':' || Content.back() ==
'=');
848 while (
Tok &&
Tok->
is(tok::comment))
863 if (!IsCpp ||
isNot(tok::l_square))
867 T =
T->getPreviousNonComment();
868 }
while (
T &&
T->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
870 return T &&
T->is(tok::kw_auto);
884 if (
is(tok::comment))
887 if (NamespaceTok && NamespaceTok->
isOneOf(tok::kw_inline, tok::kw_export))
889 return NamespaceTok &&
890 NamespaceTok->
isOneOf(tok::kw_namespace, TT_NamespaceMacro)
902 template <
typename A,
typename... Ts>
903 bool startsSequenceInternal(A K1, Ts... Tokens)
const {
904 if (
is(tok::comment) &&
Next)
905 return Next->startsSequenceInternal(K1, Tokens...);
906 return is(K1) &&
Next &&
Next->startsSequenceInternal(Tokens...);
909 template <
typename A>
bool startsSequenceInternal(A K1)
const {
910 if (
is(tok::comment) &&
Next)
911 return Next->startsSequenceInternal(K1);
915 template <
typename A,
typename... Ts>
bool endsSequenceInternal(A K1)
const {
917 return Previous->endsSequenceInternal(K1);
921 template <
typename A,
typename... Ts>
922 bool endsSequenceInternal(A K1, Ts... Tokens)
const {
924 return Previous->endsSequenceInternal(K1, Tokens...);
978 bool DryRun)
override;
981 bool DryRun)
override;
985 Commas.push_back(
Token);
991 return Commas.back();
997 struct ColumnFormat {
1002 unsigned TotalWidth;
1013 const ColumnFormat *getColumnFormat(
unsigned RemainingCharacters)
const;
1016 SmallVector<const FormatToken *, 8> Commas;
1020 SmallVector<unsigned, 8> ItemLengths;
1023 SmallVector<ColumnFormat, 4> Formats;
1025 bool HasNestedBracedList;
1095 &IdentTable.
get(
"__CLANG_FORMAT_INTERNAL_IDENT_AFTER_DEFINE__");
1283 JsExtraKeywords = std::unordered_set<IdentifierInfo *>(
1290 CSharpExtraKeywords = std::unordered_set<IdentifierInfo *>(
1307 VerilogExtraKeywords = std::unordered_set<IdentifierInfo *>(
1373 TableGenExtraKeywords = std::unordered_set<IdentifierInfo *>({
1666 bool AcceptIdentifierName =
true)
const {
1676 case tok::kw_continue:
1678 case tok::kw_default:
1679 case tok::kw_delete:
1683 case tok::kw_export:
1687 case tok::kw_import:
1688 case tok::kw_module:
1690 case tok::kw_return:
1691 case tok::kw_static:
1692 case tok::kw_switch:
1697 case tok::kw_typeof:
1702 case tok::identifier: {
1705 bool IsPseudoKeyword =
1707 JsExtraKeywords.end();
1708 return AcceptIdentifierName || !IsPseudoKeyword;
1718#define KEYWORD(X, Y) case tok::kw_##X:
1719#include "clang/Basic/TokenKinds.def"
1732 if (Tok.isAccessSpecifierKeyword())
1734 switch (Tok.Tok.getKind()) {
1742 case tok::kw_continue:
1743 case tok::kw_default:
1745 case tok::kw_double:
1748 case tok::kw_explicit:
1749 case tok::kw_extern:
1757 case tok::kw_namespace:
1759 case tok::kw_operator:
1760 case tok::kw_return:
1762 case tok::kw_sizeof:
1763 case tok::kw_static:
1764 case tok::kw_struct:
1765 case tok::kw_switch:
1770 case tok::kw_typeof:
1772 case tok::kw_virtual:
1774 case tok::kw_volatile:
1778 return Tok.is(tok::identifier) &&
1779 CSharpExtraKeywords.find(Tok.Tok.getIdentifierInfo()) ==
1780 CSharpExtraKeywords.end();
1798 case tok::kw_continue:
1799 case tok::kw_default:
1801 case tok::kw_extern:
1806 case tok::kw_restrict:
1807 case tok::kw_signed:
1808 case tok::kw_static:
1809 case tok::kw_struct:
1810 case tok::kw_typedef:
1812 case tok::kw_unsigned:
1813 case tok::kw_virtual:
1816 case tok::identifier:
1819 VerilogExtraKeywords.end();
1830 auto Info = Tok.Tok.getIdentifierInfo();
1833 switch (Info->getPPKeywordID()) {
1834 case tok::pp_define:
1838 case tok::pp_ifndef:
1839 case tok::pp_include:
1841 case tok::pp_pragma:
1893 return Tok.
is(TT_CaseLabelColon) ||
1894 (Tok.
is(tok::kw_default) &&
1908 case tok::kw_extern:
1909 case tok::kw_signed:
1910 case tok::kw_static:
1911 case tok::kw_unsigned:
1912 case tok::kw_virtual:
1914 case tok::identifier:
1942 return Tok.
is(tok::identifier) &&
1944 TableGenExtraKeywords.end();
1950 std::unordered_set<IdentifierInfo *> JsExtraKeywords;
1953 std::unordered_set<IdentifierInfo *> CSharpExtraKeywords;
1956 std::unordered_set<IdentifierInfo *> VerilogExtraKeywords;
1959 std::unordered_set<IdentifierInfo *> TableGenExtraKeywords;
1963 return FormatTok.is(tok::comment) && !FormatTok.TokenText.starts_with(
"/*");
1971 const FormatToken *MinColumnToken) {
1974 unsigned MinContinueColumn =
1975 MinColumnToken->OriginalColumn + (
isLineComment(*MinColumnToken) ? 0 : 1);
1976 return isLineComment(FormatTok) && FormatTok.NewlinesBefore == 1 &&
1978 FormatTok.OriginalColumn >= MinContinueColumn;
enum clang::sema::@1655::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