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(AttributeLSquare) \
34 TYPE(AttributeMacro) \
35 TYPE(AttributeRParen) \
36 TYPE(AttributeRSquare) \
37 TYPE(BinaryOperator) \
42 TYPE(BracedListLBrace) \
43 TYPE(CaseLabelArrow) \
45 TYPE(CaseLabelColon) \
51 TYPE(CompoundRequirementLBrace) \
53 TYPE(ConditionalExpr) \
55 TYPE(ConditionLParen) \
56 TYPE(ConflictAlternative) \
60 TYPE(ControlStatementLBrace) \
61 TYPE(ControlStatementRBrace) \
63 TYPE(CSharpGenericTypeConstraint) \
64 TYPE(CSharpGenericTypeConstraintColon) \
65 TYPE(CSharpGenericTypeConstraintComma) \
66 TYPE(CSharpNamedArgumentColon) \
67 TYPE(CSharpNullable) \
68 TYPE(CSharpNullConditionalLSquare) \
69 TYPE(CSharpStringLiteral) \
70 TYPE(CtorInitializerColon) \
71 TYPE(CtorInitializerComma) \
72 TYPE(CtorDtorDeclName) \
73 TYPE(DesignatedInitializerLSquare) \
74 TYPE(DesignatedInitializerPeriod) \
82 TYPE(EnumUnderlyingTypeColon) \
86 TYPE(FunctionAnnotationRParen) \
87 TYPE(FunctionDeclarationName) \
88 TYPE(FunctionDeclarationLParen) \
89 TYPE(FunctionLBrace) \
90 TYPE(FunctionLikeMacro) \
91 TYPE(FunctionLikeOrFreestandingMacro) \
92 TYPE(FunctionTypeLParen) \
94 TYPE(GenericSelectionColon) \
96 TYPE(GotoLabelColon) \
98 TYPE(ImplicitStringLiteral) \
99 TYPE(InheritanceColon) \
100 TYPE(InheritanceComma) \
101 TYPE(InlineASMBrace) \
102 TYPE(InlineASMColon) \
103 TYPE(InlineASMParen) \
104 TYPE(InlineASMSymbolicNameLSquare) \
105 TYPE(JavaAnnotation) \
106 TYPE(JsAndAndEqual) \
107 TYPE(JsComputedPropertyName) \
108 TYPE(JsExponentiation) \
109 TYPE(JsExponentiationEqual) \
110 TYPE(JsPipePipeEqual) \
111 TYPE(JsPrivateIdentifier) \
113 TYPE(JsTypeOperator) \
114 TYPE(JsTypeOptionalQuestion) \
116 TYPE(LambdaDefinitionLParen) \
118 TYPE(LambdaLSquare) \
119 TYPE(LeadingJavaAnnotation) \
121 TYPE(MacroBlockBegin) \
122 TYPE(MacroBlockEnd) \
123 TYPE(ModulePartitionColon) \
124 TYPE(NamespaceLBrace) \
125 TYPE(NamespaceMacro) \
126 TYPE(NamespaceRBrace) \
127 TYPE(NonNullAssertion) \
128 TYPE(NullCoalescingEqual) \
129 TYPE(NullCoalescingOperator) \
130 TYPE(NullPropagatingOperator) \
131 TYPE(ObjCBlockLBrace) \
132 TYPE(ObjCBlockLParen) \
139 TYPE(ObjCMethodExpr) \
141 TYPE(ObjCMethodSpecifier) \
146 TYPE(ObjCStringLiteral) \
147 TYPE(OverloadedOperator) \
148 TYPE(OverloadedOperatorLParen) \
149 TYPE(PointerOrReference) \
150 TYPE(ProtoExtensionLSquare) \
151 TYPE(PureVirtualSpecifier) \
153 TYPE(RangeBasedForLoopColon) \
157 TYPE(RequiresClause) \
158 TYPE(RequiresClauseInARequiresExpression) \
159 TYPE(RequiresExpression) \
160 TYPE(RequiresExpressionLBrace) \
161 TYPE(RequiresExpressionLParen) \
167 TYPE(StatementAttributeLikeMacro) \
168 TYPE(StatementMacro) \
173 TYPE(StringInConcatenation) \
176 TYPE(StructuredBindingLSquare) \
177 TYPE(SwitchExpressionLabel) \
178 TYPE(SwitchExpressionLBrace) \
179 TYPE(TableGenBangOperator) \
180 TYPE(TableGenCondOperator) \
181 TYPE(TableGenCondOperatorColon) \
182 TYPE(TableGenCondOperatorComma) \
183 TYPE(TableGenDAGArgCloser) \
184 TYPE(TableGenDAGArgListColon) \
185 TYPE(TableGenDAGArgListColonToAlign) \
186 TYPE(TableGenDAGArgListComma) \
187 TYPE(TableGenDAGArgListCommaToBreak) \
188 TYPE(TableGenDAGArgOpener) \
189 TYPE(TableGenDAGArgOpenerToBreak) \
190 TYPE(TableGenDAGArgOperatorID) \
191 TYPE(TableGenDAGArgOperatorToBreak) \
192 TYPE(TableGenListCloser) \
193 TYPE(TableGenListOpener) \
194 TYPE(TableGenMultiLineString) \
195 TYPE(TableGenTrailingPasteOperator) \
196 TYPE(TableGenValueSuffix) \
197 TYPE(TemplateCloser) \
198 TYPE(TemplateOpener) \
199 TYPE(TemplateString) \
200 TYPE(TrailingAnnotation) \
201 TYPE(TrailingCommaVaOptRParen) \
202 TYPE(TrailingReturnArrow) \
203 TYPE(TrailingUnaryOperator) \
204 TYPE(TypeDeclarationParen) \
207 TYPE(TypenameMacro) \
208 TYPE(UnaryOperator) \
211 TYPE(UntouchableMacroFunc) \
212 TYPE(VariableTemplate) \
214 TYPE(VerilogAssignComma) \
216 TYPE(VerilogBlockLabelColon) \
220 TYPE(VerilogDimensionedTypeName) \
222 TYPE(VerilogInstancePortComma) \
223 TYPE(VerilogInstancePortLParen) \
226 TYPE(VerilogMultiLineListLParen) \
228 TYPE(VerilogNumberBase) \
231 TYPE(VerilogProtected) \
233 TYPE(VerilogStrength) \
235 TYPE(VerilogTableItem) \
237 TYPE(VerilogTypeComma) \
243#define TYPE(X) TT_##X,
338 TypeIsFinalized(
false), Type(TT_Unknown) {}
353 std::shared_ptr<TokenRole>
Role;
419 unsigned BlockKind : 2;
427 assert(
getBlockKind() == BBK &&
"BraceBlockKind overflow!");
432 unsigned Decision : 2;
440 assert(
getDecision() == D &&
"FormatDecision overflow!");
445 unsigned PackingKind : 2;
453 assert(
getPackingKind() == K &&
"ParameterPackingKind overflow!");
457 unsigned TypeIsFinalized : 1;
470 assert((!TypeIsFinalized ||
T == Type) &&
471 "Please use overwriteFixedType to change a fixed type.");
482 TypeIsFinalized =
true;
487 TypeIsFinalized =
false;
645 std::optional<MacroExpansion>
MacroCtx;
658 return Tok.getObjCKeywordID() == Kind;
662 return II && II ==
Tok.getIdentifierInfo();
665 return Tok.getIdentifierInfo() &&
666 Tok.getIdentifierInfo()->getPPKeywordID() == Kind;
671 template <
typename A,
typename B>
bool isOneOf(A K1, B K2)
const {
672 return is(K1) ||
is(K2);
674 template <
typename A,
typename B,
typename... Ts>
678 template <
typename T>
bool isNot(
T Kind)
const {
return !
is(Kind); }
679 template <
typename... Ts>
bool isNoneOf(Ts... Ks)
const {
683 bool isIf(
bool AllowConstexprMacro =
true)
const {
684 return is(tok::kw_if) || endsSequence(tok::kw_constexpr, tok::kw_if) ||
685 (endsSequence(tok::identifier, tok::kw_if) && AllowConstexprMacro);
689 return isOneOf(tok::kw_for, tok::kw_while) ||
698 return Previous->closesScopeAfterBlock();
704 template <
typename A,
typename... Ts>
705 bool startsSequence(A K1, Ts... Tokens)
const {
706 return startsSequenceInternal(K1, Tokens...);
715 template <
typename A,
typename... Ts>
716 bool endsSequence(A K1, Ts... Tokens)
const {
717 return endsSequenceInternal(K1, Tokens...);
722 bool isAttribute()
const {
723 return isOneOf(tok::kw___attribute, tok::kw___declspec, TT_AttributeMacro);
726 bool isAccessSpecifierKeyword()
const {
727 return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private);
730 bool isAccessSpecifier(
bool ColonRequired =
true)
const {
731 if (!isAccessSpecifierKeyword())
736 return NextNonComment && NextNonComment->is(tok::colon);
739 bool canBePointerOrReferenceQualifier()
const {
740 return isOneOf(tok::kw_const, tok::kw_restrict, tok::kw_volatile,
741 tok::kw__Nonnull, tok::kw__Nullable,
742 tok::kw__Null_unspecified, tok::kw___ptr32, tok::kw___ptr64,
743 tok::kw___funcref) ||
747 [[nodiscard]]
bool isQtProperty()
const;
748 [[nodiscard]]
bool isTypeName(
const LangOptions &LangOpts)
const;
749 [[nodiscard]]
bool isTypeOrIdentifier(
const LangOptions &LangOpts)
const;
751 bool isObjCAccessSpecifier()
const {
752 return is(tok::at) &&
Next &&
753 Next->isOneOf(tok::objc_public, tok::objc_protected,
754 tok::objc_package, tok::objc_private);
757 bool isObjCLifetimeQualifier(
const FormatStyle &Style)
const {
769 bool opensScope()
const {
770 if (
is(TT_TemplateString) &&
TokenText.ends_with(
"${"))
772 if (
is(TT_DictLiteral) &&
is(tok::less))
774 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
779 bool closesScope()
const {
780 if (
is(TT_TemplateString) &&
TokenText.starts_with(
"}"))
782 if (
is(TT_DictLiteral) &&
is(tok::greater))
784 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
789 bool isMemberAccess()
const {
790 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
791 isNoneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
792 TT_LambdaArrow, TT_LeadingJavaAnnotation);
795 bool isPointerOrReference()
const {
796 return isOneOf(tok::star, tok::amp, tok::ampamp);
799 bool isPlacementOperator()
const {
800 return isOneOf(tok::kw_new, tok::kw_delete);
803 bool isUnaryOperator()
const {
804 switch (
Tok.getKind()) {
808 case tok::minusminus:
812 case tok::kw_alignof:
819 bool isBinaryOperator()
const {
824 bool isTrailingComment()
const {
825 return is(tok::comment) &&
826 (
is(TT_LineComment) || !
Next ||
Next->NewlinesBefore > 0);
831 bool isFunctionLikeKeyword()
const {
835 return isOneOf(tok::kw_throw, tok::kw_typeid, tok::kw_return,
836 tok::kw_sizeof, tok::kw_alignof, tok::kw_alignas,
837 tok::kw_decltype, tok::kw_noexcept, tok::kw_static_assert,
840#include
"clang/Basic/BuiltinTraits.inc"
846 bool isLabelString()
const {
847 if (
isNot(tok::string_literal))
850 if (Content.starts_with(
"\"") || Content.starts_with(
"'"))
851 Content = Content.drop_front(1);
852 if (Content.ends_with(
"\"") || Content.ends_with(
"'"))
853 Content = Content.drop_back(1);
854 Content = Content.trim();
855 return Content.size() > 1 &&
856 (Content.back() ==
':' || Content.back() ==
'=');
870 bool hasWhitespaceBefore()
const {
883 while (
Tok &&
Tok->isNot(A1))
888 template <
typename... Ts>
891 while (
Tok && (
Tok->isNot(Ks) && ...))
899 while (
Tok &&
Tok->is(tok::comment))
928 if (Prev && Prev->is(tok::coloncolon))
930 if (!AllowFollowingColonColon) {
957 T = T->getPreviousNonComment();
958 }
while (
T &&
T->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
960 return T &&
T->is(tok::kw_auto);
965 if (
is(TT_TemplateString) && closesScope())
974 if (
is(tok::comment))
975 NamespaceTok = NamespaceTok->getNextNonComment();
977 if (NamespaceTok && NamespaceTok->
isOneOf(tok::kw_inline, tok::kw_export))
978 NamespaceTok = NamespaceTok->getNextNonComment();
979 return NamespaceTok &&
980 NamespaceTok->
isOneOf(tok::kw_namespace, TT_NamespaceMacro)
992 template <
typename A,
typename... Ts>
993 bool startsSequenceInternal(A K1, Ts... Tokens)
const {
994 if (
is(tok::comment) &&
Next)
995 return Next->startsSequenceInternal(K1, Tokens...);
996 return is(K1) &&
Next &&
Next->startsSequenceInternal(Tokens...);
999 template <
typename A>
bool startsSequenceInternal(A K1)
const {
1000 if (
is(tok::comment) &&
Next)
1001 return Next->startsSequenceInternal(K1);
1005 template <
typename A,
typename... Ts>
bool endsSequenceInternal(A K1)
const {
1007 return Previous->endsSequenceInternal(K1);
1011 template <
typename A,
typename... Ts>
1012 bool endsSequenceInternal(A K1, Ts... Tokens)
const {
1014 return Previous->endsSequenceInternal(K1, Tokens...);
1019class ContinuationIndenter;
1025 virtual ~TokenRole();
1029 virtual void precomputeFormattingInfos(
const FormatToken *Token);
1037 virtual unsigned formatFromToken(LineState &State,
1038 ContinuationIndenter *Indenter,
1046 ContinuationIndenter *Indenter,
1052 virtual void CommaFound(
const FormatToken *Token) {}
1054 virtual const FormatToken *lastComma() {
return nullptr; }
1060class CommaSeparatedList :
public TokenRole {
1063 : TokenRole(Style), HasNestedBracedList(
false) {}
1067 unsigned formatAfterToken(LineState &State, ContinuationIndenter *Indenter,
1068 bool DryRun)
override;
1070 unsigned formatFromToken(LineState &State, ContinuationIndenter *Indenter,
1071 bool DryRun)
override;
1074 void CommaFound(
const FormatToken *Token)
override {
1075 Commas.push_back(Token);
1081 return Commas.back();
1087 struct ColumnFormat {
1092 unsigned TotalWidth;
1103 const ColumnFormat *getColumnFormat(
unsigned RemainingCharacters)
const;
1115 bool HasNestedBracedList;
1120struct AdditionalKeywords {
1121 AdditionalKeywords(IdentifierTable &IdentTable) {
1122 kw_final = &IdentTable.get(
"final");
1123 kw_override = &IdentTable.get(
"override");
1124 kw_in = &IdentTable.get(
"in");
1125 kw_of = &IdentTable.get(
"of");
1126 kw_CF_CLOSED_ENUM = &IdentTable.get(
"CF_CLOSED_ENUM");
1127 kw_CF_ENUM = &IdentTable.get(
"CF_ENUM");
1128 kw_CF_OPTIONS = &IdentTable.get(
"CF_OPTIONS");
1129 kw_NS_CLOSED_ENUM = &IdentTable.get(
"NS_CLOSED_ENUM");
1130 kw_NS_ENUM = &IdentTable.get(
"NS_ENUM");
1131 kw_NS_ERROR_ENUM = &IdentTable.get(
"NS_ERROR_ENUM");
1132 kw_NS_OPTIONS = &IdentTable.get(
"NS_OPTIONS");
1134 kw_as = &IdentTable.get(
"as");
1135 kw_async = &IdentTable.get(
"async");
1136 kw_await = &IdentTable.get(
"await");
1137 kw_declare = &IdentTable.get(
"declare");
1138 kw_finally = &IdentTable.get(
"finally");
1139 kw_from = &IdentTable.get(
"from");
1140 kw_function = &IdentTable.get(
"function");
1141 kw_get = &IdentTable.get(
"get");
1142 kw_import = &IdentTable.get(
"import");
1143 kw_infer = &IdentTable.get(
"infer");
1144 kw_is = &IdentTable.get(
"is");
1145 kw_let = &IdentTable.get(
"let");
1146 kw_module = &IdentTable.get(
"module");
1147 kw_readonly = &IdentTable.get(
"readonly");
1148 kw_set = &IdentTable.get(
"set");
1149 kw_type = &IdentTable.get(
"type");
1150 kw_typeof = &IdentTable.get(
"typeof");
1151 kw_var = &IdentTable.get(
"var");
1152 kw_yield = &IdentTable.get(
"yield");
1154 kw_abstract = &IdentTable.get(
"abstract");
1155 kw_assert = &IdentTable.get(
"assert");
1156 kw_extends = &IdentTable.get(
"extends");
1157 kw_implements = &IdentTable.get(
"implements");
1158 kw_instanceof = &IdentTable.get(
"instanceof");
1159 kw_interface = &IdentTable.get(
"interface");
1160 kw_native = &IdentTable.get(
"native");
1161 kw_package = &IdentTable.get(
"package");
1162 kw_record = &IdentTable.get(
"record");
1163 kw_synchronized = &IdentTable.get(
"synchronized");
1164 kw_throws = &IdentTable.get(
"throws");
1165 kw___except = &IdentTable.get(
"__except");
1166 kw___has_include = &IdentTable.get(
"__has_include");
1167 kw___has_include_next = &IdentTable.get(
"__has_include_next");
1168 kw___VA_OPT__ = &IdentTable.get(
"__VA_OPT__");
1170 kw_mark = &IdentTable.get(
"mark");
1171 kw_region = &IdentTable.get(
"region");
1173 kw_extend = &IdentTable.get(
"extend");
1174 kw_option = &IdentTable.get(
"option");
1175 kw_optional = &IdentTable.get(
"optional");
1176 kw_repeated = &IdentTable.get(
"repeated");
1177 kw_required = &IdentTable.get(
"required");
1178 kw_returns = &IdentTable.get(
"returns");
1180 kw_signals = &IdentTable.get(
"signals");
1181 kw_qsignals = &IdentTable.get(
"Q_SIGNALS");
1182 kw_slots = &IdentTable.get(
"slots");
1183 kw_qslots = &IdentTable.get(
"Q_SLOTS");
1186 kw_internal_ident_after_define =
1187 &IdentTable.get(
"__CLANG_FORMAT_INTERNAL_IDENT_AFTER_DEFINE__");
1190 kw_dollar = &IdentTable.get(
"dollar");
1191 kw_base = &IdentTable.get(
"base");
1192 kw_byte = &IdentTable.get(
"byte");
1193 kw_checked = &IdentTable.get(
"checked");
1194 kw_decimal = &IdentTable.get(
"decimal");
1195 kw_delegate = &IdentTable.get(
"delegate");
1196 kw_event = &IdentTable.get(
"event");
1197 kw_fixed = &IdentTable.get(
"fixed");
1198 kw_foreach = &IdentTable.get(
"foreach");
1199 kw_init = &IdentTable.get(
"init");
1200 kw_implicit = &IdentTable.get(
"implicit");
1201 kw_internal = &IdentTable.get(
"internal");
1202 kw_lock = &IdentTable.get(
"lock");
1203 kw_null = &IdentTable.get(
"null");
1204 kw_object = &IdentTable.get(
"object");
1205 kw_out = &IdentTable.get(
"out");
1206 kw_params = &IdentTable.get(
"params");
1207 kw_ref = &IdentTable.get(
"ref");
1208 kw_string = &IdentTable.get(
"string");
1209 kw_stackalloc = &IdentTable.get(
"stackalloc");
1210 kw_sbyte = &IdentTable.get(
"sbyte");
1211 kw_sealed = &IdentTable.get(
"sealed");
1212 kw_uint = &IdentTable.get(
"uint");
1213 kw_ulong = &IdentTable.get(
"ulong");
1214 kw_unchecked = &IdentTable.get(
"unchecked");
1215 kw_unsafe = &IdentTable.get(
"unsafe");
1216 kw_ushort = &IdentTable.get(
"ushort");
1217 kw_when = &IdentTable.get(
"when");
1218 kw_where = &IdentTable.get(
"where");
1221 kw_always = &IdentTable.get(
"always");
1222 kw_always_comb = &IdentTable.get(
"always_comb");
1223 kw_always_ff = &IdentTable.get(
"always_ff");
1224 kw_always_latch = &IdentTable.get(
"always_latch");
1225 kw_assign = &IdentTable.get(
"assign");
1226 kw_assume = &IdentTable.get(
"assume");
1227 kw_automatic = &IdentTable.get(
"automatic");
1228 kw_before = &IdentTable.get(
"before");
1229 kw_begin = &IdentTable.get(
"begin");
1230 kw_begin_keywords = &IdentTable.get(
"begin_keywords");
1231 kw_bins = &IdentTable.get(
"bins");
1232 kw_binsof = &IdentTable.get(
"binsof");
1233 kw_casex = &IdentTable.get(
"casex");
1234 kw_casez = &IdentTable.get(
"casez");
1235 kw_celldefine = &IdentTable.get(
"celldefine");
1236 kw_checker = &IdentTable.get(
"checker");
1237 kw_clocking = &IdentTable.get(
"clocking");
1238 kw_constraint = &IdentTable.get(
"constraint");
1239 kw_context = &IdentTable.get(
"context");
1240 kw_cover = &IdentTable.get(
"cover");
1241 kw_covergroup = &IdentTable.get(
"covergroup");
1242 kw_coverpoint = &IdentTable.get(
"coverpoint");
1243 kw_data_block = &IdentTable.get(
"data_block");
1244 kw_data_decrypt_key = &IdentTable.get(
"data_decrypt_key");
1245 kw_data_public_key = &IdentTable.get(
"data_public_key");
1246 kw_default_decay_time = &IdentTable.get(
"default_decay_time");
1247 kw_default_nettype = &IdentTable.get(
"default_nettype");
1248 kw_default_trireg_strength = &IdentTable.get(
"default_trireg_strength");
1249 kw_delay_mode_distributed = &IdentTable.get(
"delay_mode_distributed");
1250 kw_delay_mode_path = &IdentTable.get(
"delay_mode_path");
1251 kw_delay_mode_unit = &IdentTable.get(
"delay_mode_unit");
1252 kw_delay_mode_zero = &IdentTable.get(
"delay_mode_zero");
1253 kw_digest_block = &IdentTable.get(
"digest_block");
1254 kw_digest_decrypt_key = &IdentTable.get(
"digest_decrypt_key");
1255 kw_digest_public_key = &IdentTable.get(
"digest_public_key");
1256 kw_disable = &IdentTable.get(
"disable");
1257 kw_dist = &IdentTable.get(
"dist");
1258 kw_edge = &IdentTable.get(
"edge");
1259 kw_elsif = &IdentTable.get(
"elsif");
1260 kw_end = &IdentTable.get(
"end");
1261 kw_end_keywords = &IdentTable.get(
"end_keywords");
1262 kw_endcase = &IdentTable.get(
"endcase");
1263 kw_endcelldefine = &IdentTable.get(
"endcelldefine");
1264 kw_endchecker = &IdentTable.get(
"endchecker");
1265 kw_endclass = &IdentTable.get(
"endclass");
1266 kw_endclocking = &IdentTable.get(
"endclocking");
1267 kw_endfunction = &IdentTable.get(
"endfunction");
1268 kw_endgenerate = &IdentTable.get(
"endgenerate");
1269 kw_endgroup = &IdentTable.get(
"endgroup");
1270 kw_endinterface = &IdentTable.get(
"endinterface");
1271 kw_endmodule = &IdentTable.get(
"endmodule");
1272 kw_endpackage = &IdentTable.get(
"endpackage");
1273 kw_endprimitive = &IdentTable.get(
"endprimitive");
1274 kw_endprogram = &IdentTable.get(
"endprogram");
1275 kw_endproperty = &IdentTable.get(
"endproperty");
1276 kw_endsequence = &IdentTable.get(
"endsequence");
1277 kw_endspecify = &IdentTable.get(
"endspecify");
1278 kw_endtable = &IdentTable.get(
"endtable");
1279 kw_endtask = &IdentTable.get(
"endtask");
1280 kw_forever = &IdentTable.get(
"forever");
1281 kw_fork = &IdentTable.get(
"fork");
1282 kw_generate = &IdentTable.get(
"generate");
1283 kw_highz0 = &IdentTable.get(
"highz0");
1284 kw_highz1 = &IdentTable.get(
"highz1");
1285 kw_iff = &IdentTable.get(
"iff");
1286 kw_ifnone = &IdentTable.get(
"ifnone");
1287 kw_ignore_bins = &IdentTable.get(
"ignore_bins");
1288 kw_illegal_bins = &IdentTable.get(
"illegal_bins");
1289 kw_initial = &IdentTable.get(
"initial");
1290 kw_inout = &IdentTable.get(
"inout");
1291 kw_input = &IdentTable.get(
"input");
1292 kw_inside = &IdentTable.get(
"inside");
1293 kw_interconnect = &IdentTable.get(
"interconnect");
1294 kw_intersect = &IdentTable.get(
"intersect");
1295 kw_join = &IdentTable.get(
"join");
1296 kw_join_any = &IdentTable.get(
"join_any");
1297 kw_join_none = &IdentTable.get(
"join_none");
1298 kw_key_block = &IdentTable.get(
"key_block");
1299 kw_key_public_key = &IdentTable.get(
"key_public_key");
1300 kw_large = &IdentTable.get(
"large");
1301 kw_local = &IdentTable.get(
"local");
1302 kw_localparam = &IdentTable.get(
"localparam");
1303 kw_macromodule = &IdentTable.get(
"macromodule");
1304 kw_matches = &IdentTable.get(
"matches");
1305 kw_medium = &IdentTable.get(
"medium");
1306 kw_negedge = &IdentTable.get(
"negedge");
1307 kw_nounconnected_drive = &IdentTable.get(
"nounconnected_drive");
1308 kw_output = &IdentTable.get(
"output");
1309 kw_packed = &IdentTable.get(
"packed");
1310 kw_parameter = &IdentTable.get(
"parameter");
1311 kw_posedge = &IdentTable.get(
"posedge");
1312 kw_primitive = &IdentTable.get(
"primitive");
1313 kw_priority = &IdentTable.get(
"priority");
1314 kw_program = &IdentTable.get(
"program");
1315 kw_property = &IdentTable.get(
"property");
1316 kw_protect = &IdentTable.get(
"protect");
1317 kw_pull0 = &IdentTable.get(
"pull0");
1318 kw_pull1 = &IdentTable.get(
"pull1");
1319 kw_pure = &IdentTable.get(
"pure");
1320 kw_rand = &IdentTable.get(
"rand");
1321 kw_randc = &IdentTable.get(
"randc");
1322 kw_randcase = &IdentTable.get(
"randcase");
1323 kw_randsequence = &IdentTable.get(
"randsequence");
1324 kw_repeat = &IdentTable.get(
"repeat");
1325 kw_resetall = &IdentTable.get(
"resetall");
1326 kw_sample = &IdentTable.get(
"sample");
1327 kw_scalared = &IdentTable.get(
"scalared");
1328 kw_sequence = &IdentTable.get(
"sequence");
1329 kw_small = &IdentTable.get(
"small");
1330 kw_soft = &IdentTable.get(
"soft");
1331 kw_solve = &IdentTable.get(
"solve");
1332 kw_specify = &IdentTable.get(
"specify");
1333 kw_specparam = &IdentTable.get(
"specparam");
1334 kw_strong0 = &IdentTable.get(
"strong0");
1335 kw_strong1 = &IdentTable.get(
"strong1");
1336 kw_supply0 = &IdentTable.get(
"supply0");
1337 kw_supply1 = &IdentTable.get(
"supply1");
1338 kw_table = &IdentTable.get(
"table");
1339 kw_tagged = &IdentTable.get(
"tagged");
1340 kw_task = &IdentTable.get(
"task");
1341 kw_timescale = &IdentTable.get(
"timescale");
1342 kw_tri = &IdentTable.get(
"tri");
1343 kw_tri0 = &IdentTable.get(
"tri0");
1344 kw_tri1 = &IdentTable.get(
"tri1");
1345 kw_triand = &IdentTable.get(
"triand");
1346 kw_trior = &IdentTable.get(
"trior");
1347 kw_trireg = &IdentTable.get(
"trireg");
1348 kw_unconnected_drive = &IdentTable.get(
"unconnected_drive");
1349 kw_undefineall = &IdentTable.get(
"undefineall");
1350 kw_unique = &IdentTable.get(
"unique");
1351 kw_unique0 = &IdentTable.get(
"unique0");
1352 kw_uwire = &IdentTable.get(
"uwire");
1353 kw_vectored = &IdentTable.get(
"vectored");
1354 kw_wait = &IdentTable.get(
"wait");
1355 kw_wand = &IdentTable.get(
"wand");
1356 kw_weak0 = &IdentTable.get(
"weak0");
1357 kw_weak1 = &IdentTable.get(
"weak1");
1358 kw_wildcard = &IdentTable.get(
"wildcard");
1359 kw_wire = &IdentTable.get(
"wire");
1360 kw_with = &IdentTable.get(
"with");
1361 kw_wor = &IdentTable.get(
"wor");
1364 kw_verilogHash = &IdentTable.get(
"#");
1365 kw_verilogHashHash = &IdentTable.get(
"##");
1366 kw_apostrophe = &IdentTable.get(
"\'");
1369 kw_bit = &IdentTable.get(
"bit");
1370 kw_bits = &IdentTable.get(
"bits");
1371 kw_code = &IdentTable.get(
"code");
1372 kw_dag = &IdentTable.get(
"dag");
1373 kw_def = &IdentTable.get(
"def");
1374 kw_defm = &IdentTable.get(
"defm");
1375 kw_defset = &IdentTable.get(
"defset");
1376 kw_defvar = &IdentTable.get(
"defvar");
1377 kw_dump = &IdentTable.get(
"dump");
1378 kw_include = &IdentTable.get(
"include");
1379 kw_list = &IdentTable.get(
"list");
1380 kw_multiclass = &IdentTable.get(
"multiclass");
1381 kw_then = &IdentTable.get(
"then");
1385 JsExtraKeywords = std::unordered_set<IdentifierInfo *>(
1386 {kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from,
1387 kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_override,
1388 kw_readonly, kw_set, kw_type, kw_typeof, kw_var, kw_yield,
1390 kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface});
1392 CSharpExtraKeywords = JsExtraKeywords;
1393 CSharpExtraKeywords.insert(
1394 {kw_base, kw_byte, kw_checked, kw_decimal, kw_delegate,
1395 kw_event, kw_fixed, kw_foreach, kw_implicit, kw_in,
1396 kw_init, kw_internal, kw_lock, kw_null, kw_object,
1397 kw_out, kw_params, kw_ref, kw_string, kw_stackalloc,
1398 kw_sbyte, kw_sealed, kw_uint, kw_ulong, kw_unchecked,
1399 kw_unsafe, kw_ushort, kw_when, kw_where});
1404 VerilogExtraKeywords =
1405 std::unordered_set<IdentifierInfo *>{kw_always,
1537 TableGenExtraKeywords = std::unordered_set<IdentifierInfo *>{
1817 return Tok.Tok.getIdentifierInfo() &&
1827 bool AcceptIdentifierName =
true)
const {
1830 if (
Tok.isAccessSpecifierKeyword())
1832 switch (
Tok.Tok.getKind()) {
1837 case tok::kw_continue:
1839 case tok::kw_default:
1840 case tok::kw_delete:
1844 case tok::kw_export:
1848 case tok::kw_import:
1849 case tok::kw_module:
1851 case tok::kw_return:
1852 case tok::kw_static:
1853 case tok::kw_switch:
1858 case tok::kw_typeof:
1863 case tok::identifier: {
1866 bool IsPseudoKeyword =
1867 JsExtraKeywords.find(
Tok.Tok.getIdentifierInfo()) !=
1868 JsExtraKeywords.end();
1869 return AcceptIdentifierName || !IsPseudoKeyword;
1877 switch (
Tok.Tok.getKind()) {
1879#define KEYWORD(X, Y) case tok::kw_##X:
1880#include "clang/Basic/TokenKinds.def"
1893 if (
Tok.isAccessSpecifierKeyword())
1895 switch (
Tok.Tok.getKind()) {
1903 case tok::kw_continue:
1904 case tok::kw_default:
1906 case tok::kw_double:
1909 case tok::kw_explicit:
1910 case tok::kw_extern:
1918 case tok::kw_namespace:
1920 case tok::kw_operator:
1921 case tok::kw_return:
1923 case tok::kw_sizeof:
1924 case tok::kw_static:
1925 case tok::kw_struct:
1926 case tok::kw_switch:
1931 case tok::kw_typeof:
1933 case tok::kw_virtual:
1935 case tok::kw_volatile:
1939 return Tok.is(tok::identifier) &&
1940 CSharpExtraKeywords.find(
Tok.Tok.getIdentifierInfo()) ==
1941 CSharpExtraKeywords.end();
1946 return Tok.isOneOf(kw_verilogHash, kw_verilogHashHash, kw_apostrophe);
1950 return Tok.isOneOf(kw_before, kw_intersect, kw_dist, kw_iff, kw_inside,
1955 switch (
Tok.Tok.getKind()) {
1959 case tok::kw_continue:
1960 case tok::kw_default:
1964 case tok::kw_export:
1965 case tok::kw_extern:
1968 case tok::kw_import:
1969 case tok::kw_protected:
1970 case tok::kw_restrict:
1971 case tok::kw_signed:
1972 case tok::kw_static:
1973 case tok::kw_struct:
1974 case tok::kw_typedef:
1976 case tok::kw_unsigned:
1977 case tok::kw_virtual:
1980 case tok::identifier:
1982 VerilogExtraKeywords.find(
Tok.Tok.getIdentifierInfo()) ==
1983 VerilogExtraKeywords.end();
1986 return Tok.Tok.getIdentifierInfo();
1994 auto Info =
Tok.Tok.getIdentifierInfo();
1997 switch (Info->getPPKeywordID()) {
1998 case tok::pp_define:
2002 case tok::pp_ifndef:
2003 case tok::pp_include:
2005 case tok::pp_pragma:
2026 const auto *Prev =
Tok.getPreviousNonComment();
2044 if (
Tok.endsSequence(kw_function, kw_with))
2051 return Tok.isOneOf(tok::kw_case, tok::kw_class, kw_function, kw_module,
2052 kw_interface, kw_package, kw_casex, kw_casez, kw_checker,
2053 kw_clocking, kw_covergroup, kw_macromodule, kw_primitive,
2054 kw_program, kw_property, kw_randcase, kw_randsequence,
2061 return Tok.is(TT_CaseLabelColon) ||
2062 (
Tok.is(tok::kw_default) &&
2069 bool isVerilogStructuredProcedure(
const FormatToken &
Tok)
const {
2070 return Tok.isOneOf(kw_always, kw_always_comb, kw_always_ff, kw_always_latch,
2071 kw_final, kw_forever, kw_initial);
2075 switch (
Tok.Tok.getKind()) {
2076 case tok::kw_extern:
2077 case tok::kw_signed:
2078 case tok::kw_static:
2079 case tok::kw_unsigned:
2080 case tok::kw_virtual:
2082 case tok::identifier:
2096 return Tok.isOneOf(kw_def, kw_defm, kw_defset, kw_defvar, kw_multiclass,
2097 kw_let, tok::kw_class);
2101 switch (
Tok.Tok.getKind()) {
2110 return Tok.is(tok::identifier) &&
2111 TableGenExtraKeywords.find(
Tok.Tok.getIdentifierInfo()) !=
2112 TableGenExtraKeywords.end();
2118 std::unordered_set<IdentifierInfo *> JsExtraKeywords;
2121 std::unordered_set<IdentifierInfo *> CSharpExtraKeywords;
2124 std::unordered_set<IdentifierInfo *> VerilogExtraKeywords;
2127 std::unordered_set<IdentifierInfo *> TableGenExtraKeywords;
2131 return FormatTok.is(tok::comment) && !FormatTok.TokenText.starts_with(
"/*");
2143 if (FormatTok.Finalized !=
Previous->Finalized)
2145 unsigned MinContinueColumn =
2146 MinColumnToken->OriginalColumn + (
isLineComment(*MinColumnToken) ? 0 : 1);
2147 return isLineComment(FormatTok) && FormatTok.NewlinesBefore == 1 &&
2149 FormatTok.OriginalColumn >= MinContinueColumn;
2158 return Tok.isOneOf(tok::kw_static, tok::kw_extern, tok::kw_inline,
2159 tok::kw_virtual, tok::kw_constexpr, tok::kw_consteval,
2160 tok::kw_friend, tok::kw_export, tok::kw__Noreturn,
2161 tok::kw___forceinline);
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Defines and computes precedence levels for binary/ternary operators.
static unsigned getPrecedence(tok::TokenKind Kind)
getPrecedence - Return the precedence of the specified binary operator token.
static constexpr bool isOneOf()
#define TRANSFORM_TYPE_TRAIT_DEF(Enum, _)
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...
void precomputeFormattingInfos(const FormatToken *Token) override
After the TokenAnnotator has finished annotating all the tokens, this function precomputes required i...
One of these records is kept for each identifier that is lexed.
Encodes a location in the source.
A trivial tuple used to represent a source range.
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...
TokenRole(const FormatStyle &Style)
const FormatStyle & Style
Token - This structure provides full information about a lexed token.
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.
Top level wrappers for InstallAPI frontend operations.
bool isLineComment(const FormatToken &FormatTok)
const FunctionProtoType * T
bool isReturnTypePrefixSpecifier(const FormatToken &Tok)
prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator, bool CPlusPlus11)
Return the precedence of the specified binary operator token.
bool continuesLineComment(const FormatToken &FormatTok, const FormatToken *Previous, const FormatToken *MinColumnToken)
int32_t uint32_t uint32_t __builtin_riscv_mhracc_i32 __builtin_riscv_mhraccu_u32 __builtin_riscv_mhraccsu_i32 __builtin_riscv_mhacc_h1_i32 __builtin_riscv_mhaccsu_h1_i32 __builtin_riscv_mulqr_i32 __builtin_riscv_mqrwacc_i64 int8_t
int32_t uint32_t uint32_t __builtin_riscv_mhracc_i32 __builtin_riscv_mhraccu_u32 __builtin_riscv_mhraccsu_i32 __builtin_riscv_mhacc_h1_i32 __builtin_riscv_mhaccsu_h1_i32 __builtin_riscv_mulqr_i32 __builtin_riscv_mqrwacc_i64 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
IdentifierInfo * kw_signals
IdentifierInfo * kw_celldefine
IdentifierInfo * kw_delay_mode_distributed
IdentifierInfo * kw_pull0
IdentifierInfo * kw_instanceof
IdentifierInfo * kw_readonly
IdentifierInfo * kw___has_include
IdentifierInfo * kw_supply1
IdentifierInfo * kw_sealed
IdentifierInfo * kw_implements
IdentifierInfo * kw_infer
IdentifierInfo * kw_output
IdentifierInfo * kw_sbyte
IdentifierInfo * kw_override
IdentifierInfo * kw_always
IdentifierInfo * kw_endchecker
IdentifierInfo * kw___except
IdentifierInfo * kw_unchecked
IdentifierInfo * kw_vectored
IdentifierInfo * kw_specparam
IdentifierInfo * kw_decimal
IdentifierInfo * kw_default_decay_time
IdentifierInfo * kw_binsof
IdentifierInfo * kw_extend
IdentifierInfo * kw_await
IdentifierInfo * kw_extends
IdentifierInfo * kw___VA_OPT__
IdentifierInfo * kw_coverpoint
IdentifierInfo * kw_begin_keywords
IdentifierInfo * kw_assert
IdentifierInfo * kw_async
IdentifierInfo * kw_CF_ENUM
IdentifierInfo * kw_qslots
IdentifierInfo * kw_nounconnected_drive
IdentifierInfo * kw_trireg
IdentifierInfo * kw_join_any
IdentifierInfo * kw_solve
IdentifierInfo * kw_abstract
IdentifierInfo * kw_default_nettype
IdentifierInfo * kw_ifnone
IdentifierInfo * kw_highz1
IdentifierInfo * kw_unique0
IdentifierInfo * kw_input
IdentifierInfo * kw_randc
IdentifierInfo * kw_always_ff
IdentifierInfo * kw_medium
IdentifierInfo * kw_weak0
IdentifierInfo * kw_protect
IdentifierInfo * kw_undefineall
IdentifierInfo * kw_sequence
IdentifierInfo * kw_event
IdentifierInfo * kw_foreach
IdentifierInfo * kw_apostrophe
IdentifierInfo * kw_weak1
IdentifierInfo * kw_program
IdentifierInfo * kw_required
IdentifierInfo * kw_fixed
IdentifierInfo * kw_assign
IdentifierInfo * kw_initial
IdentifierInfo * kw_macromodule
bool isVerilogKeywordSymbol(const FormatToken &Tok) const
IdentifierInfo * kw_property
bool isVerilogBegin(const FormatToken &Tok) const
Returns whether Tok is a Verilog keyword that opens a block.
IdentifierInfo * kw_CF_OPTIONS
IdentifierInfo * kw_tagged
IdentifierInfo * kw_interface
IdentifierInfo * kw_before
IdentifierInfo * kw_local
IdentifierInfo * kw___has_include_next
IdentifierInfo * kw_synchronized
IdentifierInfo * kw_params
IdentifierInfo * kw_endtable
IdentifierInfo * kw_endpackage
IdentifierInfo * kw_function
IdentifierInfo * kw_yield
IdentifierInfo * kw_automatic
IdentifierInfo * kw_declare
IdentifierInfo * kw_endcelldefine
IdentifierInfo * kw_checker
IdentifierInfo * kw_verilogHash
IdentifierInfo * kw_digest_decrypt_key
IdentifierInfo * kw_multiclass
IdentifierInfo * kw_internal
IdentifierInfo * kw_returns
IdentifierInfo * kw_supply0
IdentifierInfo * kw_large
IdentifierInfo * kw_endclocking
IdentifierInfo * kw_endfunction
IdentifierInfo * kw_endprimitive
IdentifierInfo * kw_implicit
IdentifierInfo * kw_where
IdentifierInfo * kw_randcase
IdentifierInfo * kw_NS_OPTIONS
IdentifierInfo * kw_triand
IdentifierInfo * kw_inside
IdentifierInfo * kw_native
IdentifierInfo * kw_clocking
IdentifierInfo * kw_typeof
IdentifierInfo * kw_join_none
IdentifierInfo * kw_endcase
IdentifierInfo * kw_intersect
IdentifierInfo * kw_include
IdentifierInfo * kw_primitive
IdentifierInfo * kw_record
IdentifierInfo * kw_string
IdentifierInfo * kw_begin
IdentifierInfo * kw_throws
IdentifierInfo * kw_slots
IdentifierInfo * kw_elsif
IdentifierInfo * kw_NS_ENUM
IdentifierInfo * kw_key_block
IdentifierInfo * kw_parameter
IdentifierInfo * kw_endtask
IdentifierInfo * kw_NS_CLOSED_ENUM
IdentifierInfo * kw_unconnected_drive
IdentifierInfo * kw_option
IdentifierInfo * kw_negedge
IdentifierInfo * kw_unique
IdentifierInfo * kw_timescale
IdentifierInfo * kw_package
IdentifierInfo * kw_generate
IdentifierInfo * kw_constraint
IdentifierInfo * kw_endprogram
IdentifierInfo * kw_delay_mode_unit
IdentifierInfo * kw_always_comb
IdentifierInfo * kw_module
IdentifierInfo * kw_stackalloc
IdentifierInfo * kw_delay_mode_path
bool isWordLike(const FormatToken &Tok, bool IsVerilog=true) const
Returns true if Tok is a keyword or an identifier.
IdentifierInfo * kw_trior
IdentifierInfo * kw_qsignals
IdentifierInfo * kw_specify
IdentifierInfo * kw_endproperty
IdentifierInfo * kw_endclass
IdentifierInfo * kw_digest_block
IdentifierInfo * kw_data_public_key
IdentifierInfo * kw_internal_ident_after_define
IdentifierInfo * kw_randsequence
IdentifierInfo * kw_data_block
IdentifierInfo * kw_checked
IdentifierInfo * kw_key_public_key
IdentifierInfo * kw_endmodule
IdentifierInfo * kw_ulong
IdentifierInfo * kw_casex
IdentifierInfo * kw_defvar
IdentifierInfo * kw_scalared
IdentifierInfo * kw_strong1
IdentifierInfo * kw_delegate
IdentifierInfo * kw_ignore_bins
IdentifierInfo * kw_small
IdentifierInfo * kw_cover
IdentifierInfo * kw_disable
IdentifierInfo * kw_always_latch
IdentifierInfo * kw_final
IdentifierInfo * kw_posedge
IdentifierInfo * kw_region
IdentifierInfo * kw_wildcard
IdentifierInfo * kw_forever
IdentifierInfo * kw_optional
IdentifierInfo * kw_default_trireg_strength
IdentifierInfo * kw_assume
IdentifierInfo * kw_dollar
IdentifierInfo * kw_verilogHashHash
IdentifierInfo * kw_casez
IdentifierInfo * kw_endgroup
IdentifierInfo * kw_delay_mode_zero
IdentifierInfo * kw_strong0
IdentifierInfo * kw_illegal_bins
IdentifierInfo * kw_priority
IdentifierInfo * kw_ushort
IdentifierInfo * kw_localparam
IdentifierInfo * kw_object
IdentifierInfo * kw_context
IdentifierInfo * kw_endsequence
IdentifierInfo * kw_inout
IdentifierInfo * kw_defset
IdentifierInfo * kw_end_keywords
IdentifierInfo * kw_matches
IdentifierInfo * kw_uwire
IdentifierInfo * kw_endspecify
IdentifierInfo * kw_data_decrypt_key
IdentifierInfo * kw_CF_CLOSED_ENUM
IdentifierInfo * kw_digest_public_key
IdentifierInfo * kw_sample
IdentifierInfo * kw_packed
IdentifierInfo * kw_unsafe
IdentifierInfo * kw_interconnect
IdentifierInfo * kw_pull1
IdentifierInfo * kw_NS_ERROR_ENUM
IdentifierInfo * kw_covergroup
IdentifierInfo * kw_repeat
bool isVerilogEnd(const FormatToken &Tok) const
Returns whether Tok is a Verilog keyword that closes a block.
IdentifierInfo * kw_endinterface
IdentifierInfo * kw_highz0
IdentifierInfo * kw_repeated
IdentifierInfo * kw_endgenerate
IdentifierInfo * kw_table
IdentifierInfo * kw_import
IdentifierInfo * kw_resetall
IdentifierInfo * kw_finally