-
Notifications
You must be signed in to change notification settings - Fork 380
/
StubImplementations.kt
2225 lines (1802 loc) · 89.2 KB
/
StubImplementations.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/
package org.rust.lang.core.stubs
import com.intellij.lang.*
import com.intellij.lang.parser.GeneratedParserUtilBase
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.StubBuilder
import com.intellij.psi.impl.source.tree.LazyParseableElement
import com.intellij.psi.impl.source.tree.RecursiveTreeElementWalkingVisitor
import com.intellij.psi.impl.source.tree.TreeElement
import com.intellij.psi.impl.source.tree.TreeUtil
import com.intellij.psi.stubs.*
import com.intellij.psi.tree.*
import com.intellij.util.BitUtil
import com.intellij.util.CharTable
import com.intellij.util.diff.FlyweightCapableTreeStructure
import com.intellij.util.io.DataInputOutputUtil.readNullable
import com.intellij.util.io.DataInputOutputUtil.writeNullable
import org.jetbrains.annotations.VisibleForTesting
import org.rust.lang.RsLanguage
import org.rust.lang.core.lexer.RsLexer
import org.rust.lang.core.parser.RustParser
import org.rust.lang.core.parser.RustParserDefinition
import org.rust.lang.core.psi.*
import org.rust.lang.core.psi.RsElementTypes.*
import org.rust.lang.core.psi.ext.*
import org.rust.lang.core.psi.impl.*
import org.rust.lang.core.stubs.BlockMayHaveStubsHeuristic.computeAndCache
import org.rust.lang.core.stubs.BlockMayHaveStubsHeuristic.getAndClearCached
import org.rust.lang.core.stubs.RsEmptyStmtType.shouldCreateStub
import org.rust.lang.core.stubs.common.RsMetaItemArgsPsiOrStub
import org.rust.lang.core.stubs.common.RsMetaItemPsiOrStub
import org.rust.lang.core.stubs.common.RsPathPsiOrStub
import org.rust.lang.core.types.ty.TyFloat
import org.rust.lang.core.types.ty.TyInteger
import org.rust.openapiext.ancestors
import org.rust.stdext.*
import org.rust.stdext.BitFlagsBuilder.Limit.BYTE
import org.rust.stdext.BitFlagsBuilder.Limit.INT
class RsFileStub(
file: RsFile?,
private val flags: Int,
) : PsiFileStubImpl<RsFile>(file), RsAttributeOwnerStub {
val mayHaveStdlibAttributes: Boolean
get() = BitUtil.isSet(flags, MAY_HAVE_STDLIB_ATTRIBUTES_MASK)
override val rawMetaItems: Sequence<RsMetaItemStub>
get() = RsInnerAttributeOwnerRegistry.rawMetaItems(this)
override val hasAttrs: Boolean
get() = BitUtil.isSet(flags, RsAttributeOwnerStub.ATTRS_MASK)
override val mayHaveCfg: Boolean
get() = BitUtil.isSet(flags, RsAttributeOwnerStub.CFG_MASK)
override val hasCfgAttr: Boolean
get() = BitUtil.isSet(flags, RsAttributeOwnerStub.CFG_ATTR_MASK)
override val mayHaveMacroUse: Boolean
get() = BitUtil.isSet(flags, RsAttributeOwnerStub.HAS_MACRO_USE_MASK)
override val mayHaveCustomDerive: Boolean
get() = false
override val mayHaveCustomAttrs: Boolean
get() = false
override fun getType() = Type
object Type : IStubFileElementType<RsFileStub>(RsLanguage) {
private const val STUB_VERSION = 225
// Bump this number if Stub structure changes
override fun getStubVersion(): Int = RustParserDefinition.PARSER_VERSION + STUB_VERSION
override fun getBuilder(): StubBuilder = object : DefaultStubBuilder() {
override fun createStubForFile(file: PsiFile): StubElement<*> {
TreeUtil.ensureParsed(file.node) // profiler hint
// for tests related to rust console
if (file is RsReplCodeFragment) {
return RsFileStub(null, flags = 0)
}
check(file is RsFile)
val rawAttributes = file.getTraversedRawAttributes(withCfgAttrAttribute = true)
var flags = RsAttributeOwnerStub.extractFlags(rawAttributes)
val mayHaveStdlibAttributes = rawAttributes.hasAnyOfAttributes("no_std", "no_core")
flags = BitUtil.set(flags, MAY_HAVE_STDLIB_ATTRIBUTES_MASK, mayHaveStdlibAttributes)
return RsFileStub(file, flags)
}
override fun skipChildProcessingWhenBuildingStubs(parent: ASTNode, child: ASTNode): Boolean {
val elementType = child.elementType
return elementType == MACRO_ARGUMENT || elementType == MACRO_BODY ||
elementType in RS_DOC_COMMENTS ||
elementType == BLOCK && parent.elementType == FUNCTION && skipChildForFunctionBody(child)
}
/** Note: if returns `true` then [RsBlockStubType.shouldCreateStub] MUST return `false` for the [child] */
private fun skipChildForFunctionBody(child: ASTNode): Boolean =
!BlockMayHaveStubsHeuristic.getAndClearCached(child)
}
override fun serialize(stub: RsFileStub, dataStream: StubOutputStream) {
dataStream.writeByte(stub.flags)
}
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?): RsFileStub =
RsFileStub(null, dataStream.readUnsignedByte())
override fun getExternalId(): String = "Rust.file"
// Uncomment to find out what causes switch to the AST
//
// private val PARESED = com.intellij.util.containers.ContainerUtil.newConcurrentSet<String>()
// override fun doParseContents(chameleon: ASTNode, psi: com.intellij.psi.PsiElement): ASTNode? {
// val path = psi.containingFile?.virtualFile?.path
// if (path != null && PARESED.add(path)) {
// println("Parsing (${PARESED.size}) $path")
// val trace = java.io.StringWriter().also { writer ->
// Exception().printStackTrace(java.io.PrintWriter(writer))
// writer.toString()
// }
// println(trace)
// println()
// }
// return super.doParseContents(chameleon, psi)
// }
}
companion object : BitFlagsBuilder(RsAttributeOwnerStub, BYTE) {
private val MAY_HAVE_STDLIB_ATTRIBUTES_MASK: Int = nextBitMask()
}
}
/**
* A utility used in the stub builder to detect that a code block [RsBlockStubType] should not be
* traversed in order to find child stubs. Avoiding code blocks traversing is important because they
* are lazy parseable and will not be parsed during indexing if not traversed.
* The utility is heuristic based, i.e. it can strictly say that a block does NOT have stubs, but can't
* strictly say that block has stubs.
*
* The value is used in two places, so there are some tricks with UserData (cache) to avoid double computation.
* There are two functions that do mostly the same but differs in how they use the cache.
* - [computeAndCache] computes the value and then puts it in the cache. Used in [RsFunctionStub.Type.createStub]
* - [getAndClearCached] retrieves and removes the value from the cache or compute the value if it does not
* present. Expected to be called after [computeAndCache] during indexing (because a function is a parent of a
* block, so it is processed earlier). The value is then removed from the cache because it is no longer needed
* and should be invalidated after each PSI change.
*
* See tests in `RsCodeBlockStubCreationTest`
*/
private object BlockMayHaveStubsHeuristic {
private val RS_HAS_ITEMS_OR_ATTRS: Key<Boolean> = Key.create("RS_HAS_ITEMS_OR_ATTRS")
// TODO remove `USE`
private val ITEM_DEF_KWS = tokenSetOf(STATIC, ENUM, IMPL, MACRO_KW, MOD, STRUCT, UNION, TRAIT, TYPE_KW, USE)
fun computeAndCache(node: ASTNode): Boolean {
assertIsBlock(node)
val hasItemsOrAttrs = computeBlockMayHaveStubs(node)
node.putUserData(RS_HAS_ITEMS_OR_ATTRS, hasItemsOrAttrs)
return hasItemsOrAttrs
}
/** The value can be already computed and cached by [computeAndCache] */
fun getAndClearCached(node: ASTNode): Boolean {
assertIsBlock(node)
val cachedHasItemsOrAttrs = node.getUserData(RS_HAS_ITEMS_OR_ATTRS)
if (cachedHasItemsOrAttrs != null) {
node.putUserData(RS_HAS_ITEMS_OR_ATTRS, null)
return cachedHasItemsOrAttrs
}
return computeBlockMayHaveStubs(node)
}
private fun assertIsBlock(node: ASTNode) {
check(node.elementType == BLOCK) { "Expected block, found: ${node.elementType}, text: `${node.text}`" }
}
private fun computeBlockMayHaveStubs(node: ASTNode): Boolean {
// Use PsiBuilder instead of RsLexer b/c PsiBuilder reuses already lexed tokens.
// See `RsBlockStubType.reuseCollapsedTokens`
val b = PsiBuilderFactory.getInstance().createBuilder(node.psi.project, node, null, RsLanguage, node.chars)
var prevToken: IElementType? = null
var prevTokenText: String? = null
while (true) {
val token = b.tokenType ?: break
val looksLikeStubElement = token in ITEM_DEF_KWS
// `const` but not `*const` and not `raw const`
|| token == CONST && !(prevToken == MUL || prevToken == IDENTIFIER && prevTokenText == "raw")
// `#!`
|| token == EXCL && prevToken == SHA
// `macro_rules!`
|| token == EXCL && prevToken == IDENTIFIER && prevTokenText == "macro_rules"
// `fn foo` (but not `fn()`)
|| token == IDENTIFIER && prevToken == FN
|| token == IDENTIFIER && b.tokenText == "union" && b.lookAhead(1) == IDENTIFIER
if (looksLikeStubElement) {
return true
}
prevToken = token
prevTokenText = if (token == IDENTIFIER) b.tokenText else null
b.advanceLexer()
}
return false
}
}
fun factory(name: String): RsStubElementType<*, *> = when (name) {
"EXTERN_CRATE_ITEM" -> RsExternCrateItemStub.Type
"USE_ITEM" -> RsUseItemStub.Type
"STRUCT_ITEM" -> RsStructItemStub.Type
"ENUM_ITEM" -> RsEnumItemStub.Type
"ENUM_BODY" -> RsPlaceholderStub.Type("ENUM_BODY", ::RsEnumBodyImpl)
"ENUM_VARIANT" -> RsEnumVariantStub.Type
"MOD_DECL_ITEM" -> RsModDeclItemStub.Type
"MOD_ITEM" -> RsModItemStub.Type
"TRAIT_ITEM" -> RsTraitItemStub.Type
"IMPL_ITEM" -> RsImplItemStub.Type
"MEMBERS" -> RsPlaceholderStub.Type("MEMBERS", ::RsMembersImpl)
"TRAIT_ALIAS" -> RsTraitAliasStub.Type
"TRAIT_ALIAS_BOUNDS" -> RsPlaceholderStub.Type("TRAIT_ALIAS_BOUNDS", ::RsTraitAliasBoundsImpl)
"FUNCTION" -> RsFunctionStub.Type
"CONSTANT" -> RsConstantStub.Type
"TYPE_ALIAS" -> RsTypeAliasStub.Type
"FOREIGN_MOD_ITEM" -> RsForeignModStub.Type
"BLOCK_FIELDS" -> RsPlaceholderStub.Type("BLOCK_FIELDS", ::RsBlockFieldsImpl)
"TUPLE_FIELDS" -> RsPlaceholderStub.Type("TUPLE_FIELDS", ::RsTupleFieldsImpl)
"TUPLE_FIELD_DECL" -> RsPlaceholderStub.Type("TUPLE_FIELD_DECL", ::RsTupleFieldDeclImpl)
"NAMED_FIELD_DECL" -> RsNamedFieldDeclStub.Type
"ALIAS" -> RsAliasStub.Type
"USE_SPECK" -> RsUseSpeckStub.Type
"USE_GROUP" -> RsPlaceholderStub.Type("USE_GROUP", ::RsUseGroupImpl)
"PATH" -> RsPathStub.Type
"TYPE_QUAL" -> RsPlaceholderStub.Type("TYPE_QUAL", ::RsTypeQualImpl)
"TRAIT_REF" -> RsPlaceholderStub.Type("TRAIT_REF", ::RsTraitRefImpl)
"TYPE_REFERENCE" -> RsPlaceholderStub.Type("TYPE_REFERENCE", ::RsTypeReferenceImpl)
"ARRAY_TYPE" -> RsArrayTypeStub.Type
"REF_LIKE_TYPE" -> RsRefLikeTypeStub.Type
"FN_POINTER_TYPE" -> RsFnPointerTypeStub.Type
"TUPLE_TYPE" -> RsPlaceholderStub.Type("TUPLE_TYPE", ::RsTupleTypeImpl)
"PAREN_TYPE" -> RsPlaceholderStub.Type("PAREN_TYPE", ::RsParenTypeImpl)
"BASE_TYPE" -> RsBaseTypeStub.Type
"FOR_IN_TYPE" -> RsPlaceholderStub.Type("FOR_IN_TYPE", ::RsForInTypeImpl)
"TRAIT_TYPE" -> RsTraitTypeStub.Type
"MACRO_TYPE" -> RsPlaceholderStub.Type("MACRO_TYPE", ::RsMacroTypeImpl)
"VALUE_PARAMETER_LIST" -> RsPlaceholderStub.Type("VALUE_PARAMETER_LIST", ::RsValueParameterListImpl)
"VALUE_PARAMETER" -> RsValueParameterStub.Type
"SELF_PARAMETER" -> RsSelfParameterStub.Type
"VARIADIC" -> RsPlaceholderStub.Type("VARIADIC", ::RsVariadicImpl)
"TYPE_PARAMETER_LIST" -> RsPlaceholderStub.Type("TYPE_PARAMETER_LIST", ::RsTypeParameterListImpl)
"TYPE_PARAMETER" -> RsTypeParameterStub.Type
"CONST_PARAMETER" -> RsConstParameterStub.Type
"LIFETIME" -> RsLifetimeStub.Type
"LIFETIME_PARAMETER" -> RsLifetimeParameterStub.Type
"FOR_LIFETIMES" -> RsPlaceholderStub.Type("FOR_LIFETIMES", ::RsForLifetimesImpl)
"TYPE_ARGUMENT_LIST" -> RsPlaceholderStub.Type("TYPE_ARGUMENT_LIST", ::RsTypeArgumentListImpl)
"ASSOC_TYPE_BINDING" -> RsPlaceholderStub.Type("ASSOC_TYPE_BINDING", ::RsAssocTypeBindingImpl)
"TYPE_PARAM_BOUNDS" -> RsPlaceholderStub.Type("TYPE_PARAM_BOUNDS", ::RsTypeParamBoundsImpl)
"POLYBOUND" -> RsPolyboundStub.Type
"BOUND" -> RsPlaceholderStub.Type("BOUND", ::RsBoundImpl)
"WHERE_CLAUSE" -> RsPlaceholderStub.Type("WHERE_CLAUSE", ::RsWhereClauseImpl)
"WHERE_PRED" -> RsPlaceholderStub.Type("WHERE_PRED", ::RsWherePredImpl)
"RET_TYPE" -> RsPlaceholderStub.Type("RET_TYPE", ::RsRetTypeImpl)
"MACRO" -> RsMacroStub.Type
"MACRO_2" -> RsMacro2Stub.Type
"MACRO_CALL" -> RsMacroCallStub.Type
"INCLUDE_MACRO_ARGUMENT" -> RsPlaceholderStub.Type("INCLUDE_MACRO_ARGUMENT", ::RsIncludeMacroArgumentImpl)
"CONCAT_MACRO_ARGUMENT" -> RsPlaceholderStub.Type("CONCAT_MACRO_ARGUMENT", ::RsConcatMacroArgumentImpl)
"ENV_MACRO_ARGUMENT" -> RsPlaceholderStub.Type("ENV_MACRO_ARGUMENT", ::RsEnvMacroArgumentImpl)
"INNER_ATTR" -> RsInnerAttrStub.Type
"OUTER_ATTR" -> RsPlaceholderStub.Type("OUTER_ATTR", ::RsOuterAttrImpl)
"META_ITEM" -> RsMetaItemStub.Type
"META_ITEM_ARGS" -> RsMetaItemArgsStub.Type
"BLOCK" -> RsBlockStubType
"BINARY_OP" -> RsBinaryOpStub.Type
"EXPR_STMT" -> RsExprStmtStub.Type
"LET_DECL" -> RsLetDeclStub.Type
"EMPTY_STMT" -> RsEmptyStmtType
"ARRAY_EXPR" -> RsExprStubType("ARRAY_EXPR", ::RsArrayExprImpl)
"BINARY_EXPR" -> RsExprStubType("BINARY_EXPR", ::RsBinaryExprImpl)
"BLOCK_EXPR" -> RsBlockExprStub.Type
"BREAK_EXPR" -> RsExprStubType("BREAK_EXPR", ::RsBreakExprImpl)
"CALL_EXPR" -> RsExprStubType("CALL_EXPR", ::RsCallExprImpl)
"CAST_EXPR" -> RsExprStubType("CAST_EXPR", ::RsCastExprImpl)
"CONT_EXPR" -> RsExprStubType("CONT_EXPR", ::RsContExprImpl)
"DOT_EXPR" -> RsExprStubType("DOT_EXPR", ::RsDotExprImpl)
"FOR_EXPR" -> RsExprStubType("FOR_EXPR", ::RsForExprImpl)
"IF_EXPR" -> RsExprStubType("IF_EXPR", ::RsIfExprImpl)
"INDEX_EXPR" -> RsExprStubType("INDEX_EXPR", ::RsIndexExprImpl)
"LAMBDA_EXPR" -> RsExprStubType("LAMBDA_EXPR", ::RsLambdaExprImpl)
"LIT_EXPR" -> RsLitExprStub.Type
"LOOP_EXPR" -> RsExprStubType("LOOP_EXPR", ::RsLoopExprImpl)
"MACRO_EXPR" -> RsExprStubType("MACRO_EXPR", ::RsMacroExprImpl)
"MATCH_EXPR" -> RsExprStubType("MATCH_EXPR", ::RsMatchExprImpl)
"PAREN_EXPR" -> RsExprStubType("PAREN_EXPR", ::RsParenExprImpl)
"PATH_EXPR" -> RsExprStubType("PATH_EXPR", ::RsPathExprImpl)
"RANGE_EXPR" -> RsExprStubType("RANGE_EXPR", ::RsRangeExprImpl)
"RET_EXPR" -> RsExprStubType("RET_EXPR", ::RsRetExprImpl)
"YIELD_EXPR" -> RsExprStubType("YIELD_EXPR", ::RsYieldExprImpl)
"STRUCT_LITERAL" -> RsExprStubType("STRUCT_LITERAL", ::RsStructLiteralImpl)
"TRY_EXPR" -> RsExprStubType("TRY_EXPR", ::RsTryExprImpl)
"TUPLE_EXPR" -> RsExprStubType("TUPLE_EXPR", ::RsTupleExprImpl)
"UNARY_EXPR" -> RsUnaryExprStub.Type
"UNIT_EXPR" -> RsExprStubType("UNIT_EXPR", ::RsUnitExprImpl)
"WHILE_EXPR" -> RsExprStubType("WHILE_EXPR", ::RsWhileExprImpl)
"VIS" -> RsVisStub.Type
"VIS_RESTRICTION" -> RsPlaceholderStub.Type("VIS_RESTRICTION", ::RsVisRestrictionImpl)
else -> error("Unknown element $name")
}
abstract class RsAttributeOwnerStubBase<T : RsElement>(
parent: StubElement<*>?,
elementType: IStubElementType<*, *>
) : StubBase<T>(parent, elementType),
RsAttributeOwnerStub {
override val rawMetaItems: Sequence<RsMetaItemStub>
get() = RsInnerAttributeOwnerRegistry.rawMetaItems(this)
override val rawOuterMetaItems: Sequence<RsMetaItemStub>
get() = RsInnerAttributeOwnerRegistry.rawOuterMetaItems(this)
override val hasAttrs: Boolean
get() = BitUtil.isSet(flags, RsAttributeOwnerStub.ATTRS_MASK)
override val mayHaveCfg: Boolean
get() = BitUtil.isSet(flags, RsAttributeOwnerStub.CFG_MASK)
override val hasCfgAttr: Boolean
get() = BitUtil.isSet(flags, RsAttributeOwnerStub.CFG_ATTR_MASK)
override val mayHaveMacroUse: Boolean
get() = BitUtil.isSet(flags, RsAttributeOwnerStub.HAS_MACRO_USE_MASK)
override val mayHaveCustomDerive: Boolean
get() = BitUtil.isSet(flags, RsAttributeOwnerStub.HAS_CUSTOM_DERIVE)
override val mayHaveCustomAttrs: Boolean
get() = BitUtil.isSet(flags, RsAttributeOwnerStub.HAS_CUSTOM_ATTRS)
protected abstract val flags: Int
}
abstract class RsAttrProcMacroOwnerStubBase<T : RsElement>(
parent: StubElement<*>?,
elementType: IStubElementType<*, *>
) : RsAttributeOwnerStubBase<T>(parent, elementType), RsAttrProcMacroOwnerStub {
override val stubbedText: String? get() = procMacroInfo?.stubbedText
override val stubbedTextHash: HashCode? get() = procMacroInfo?.stubbedTextHash
override val endOfAttrsOffset: Int get() = procMacroInfo?.endOfAttrsOffset ?: 0
override val startOffset: Int get() = procMacroInfo?.startOffset ?: 0
@get:VisibleForTesting
abstract val procMacroInfo: RsProcMacroStubInfo?
}
class RsExternCrateItemStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
override val name: String,
override val flags: Int,
override val procMacroInfo: RsProcMacroStubInfo?,
) : RsAttrProcMacroOwnerStubBase<RsExternCrateItem>(parent, elementType),
RsNamedStub {
val alias: RsAliasStub?
get() = findChildStubByType(RsAliasStub.Type)
object Type : RsStubElementType<RsExternCrateItemStub, RsExternCrateItem>("EXTERN_CRATE_ITEM") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?) =
RsExternCrateItemStub(
parentStub,
this,
dataStream.readNameAsString()!!,
dataStream.readUnsignedByte(),
RsProcMacroStubInfo.deserialize(dataStream),
)
override fun serialize(stub: RsExternCrateItemStub, dataStream: StubOutputStream) =
with(dataStream) {
writeName(stub.name)
writeByte(stub.flags)
RsProcMacroStubInfo.serialize(stub.procMacroInfo, dataStream)
}
override fun createPsi(stub: RsExternCrateItemStub) =
RsExternCrateItemImpl(stub, this)
override fun createStub(psi: RsExternCrateItem, parentStub: StubElement<*>?): RsExternCrateItemStub {
val flags = RsAttributeOwnerStub.extractFlags(psi)
val procMacroInfo = RsAttrProcMacroOwnerStub.extractTextAndOffset(flags, psi)
return RsExternCrateItemStub(parentStub, this, psi.referenceName, flags, procMacroInfo)
}
override fun indexStub(stub: RsExternCrateItemStub, sink: IndexSink) = sink.indexExternCrate(stub)
}
}
class RsUseItemStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
override val flags: Int,
override val procMacroInfo: RsProcMacroStubInfo?,
) : RsAttrProcMacroOwnerStubBase<RsUseItem>(parent, elementType) {
val useSpeck: RsUseSpeckStub?
get() = findChildStubByType(RsUseSpeckStub.Type)
// stored in stub as an optimization
val mayHavePreludeImport: Boolean
get() = BitUtil.isSet(flags, HAS_PRELUDE_IMPORT_MASK)
object Type : RsStubElementType<RsUseItemStub, RsUseItem>("USE_ITEM") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?) =
RsUseItemStub(
parentStub,
this,
dataStream.readUnsignedByte(),
RsProcMacroStubInfo.deserialize(dataStream),
)
override fun serialize(stub: RsUseItemStub, dataStream: StubOutputStream) =
with(dataStream) {
writeByte(stub.flags)
RsProcMacroStubInfo.serialize(stub.procMacroInfo, dataStream)
}
override fun createPsi(stub: RsUseItemStub) =
RsUseItemImpl(stub, this)
override fun createStub(psi: RsUseItem, parentStub: StubElement<*>?): RsUseItemStub {
var flags = RsAttributeOwnerStub.extractFlags(psi)
flags = BitUtil.set(flags, HAS_PRELUDE_IMPORT_MASK, HAS_PRELUDE_IMPORT_PROP.getDuringIndexing(psi))
val procMacroInfo = RsAttrProcMacroOwnerStub.extractTextAndOffset(flags, psi)
return RsUseItemStub(parentStub, this, flags, procMacroInfo)
}
}
companion object : BitFlagsBuilder(RsAttributeOwnerStub, BYTE) {
private val HAS_PRELUDE_IMPORT_MASK: Int = nextBitMask()
}
}
class RsUseSpeckStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
val isStarImport: Boolean,
/** Needed to distinguish `use {aaa, bbb};` and `use ::{aaa, bbb};` */
val hasColonColon: Boolean,
) : RsElementStub<RsUseSpeck>(parent, elementType) {
val path: RsPathStub?
get() = findChildStubByType(RsPathStub.Type)
val alias: RsAliasStub?
get() = findChildStubByType(RsAliasStub.Type)
val useGroup: StubElement<RsUseGroup>?
get() = findChildStubByType(RsStubElementTypes.USE_GROUP)
object Type : RsStubElementType<RsUseSpeckStub, RsUseSpeck>("USE_SPECK") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?): RsUseSpeckStub {
val flags = dataStream.readUnsignedByte()
return RsUseSpeckStub(
parentStub, this,
BitUtil.isSet(flags, IS_STAR_IMPORT_MASK),
BitUtil.isSet(flags, HAS_COLON_COLON_MASK),
)
}
override fun serialize(stub: RsUseSpeckStub, dataStream: StubOutputStream) {
var flags = 0
flags = BitUtil.set(flags, IS_STAR_IMPORT_MASK, stub.isStarImport)
flags = BitUtil.set(flags, HAS_COLON_COLON_MASK, stub.hasColonColon)
dataStream.writeByte(flags)
}
override fun createPsi(stub: RsUseSpeckStub) =
RsUseSpeckImpl(stub, this)
override fun createStub(psi: RsUseSpeck, parentStub: StubElement<*>?) =
RsUseSpeckStub(parentStub, this, psi.isStarImport, psi.hasColonColon)
override fun indexStub(stub: RsUseSpeckStub, sink: IndexSink) = sink.indexUseSpeck(stub)
}
companion object : BitFlagsBuilder(BYTE) {
private val IS_STAR_IMPORT_MASK: Int = nextBitMask()
private val HAS_COLON_COLON_MASK: Int = nextBitMask()
}
}
class RsStructItemStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
override val name: String?,
override val flags: Int,
override val procMacroInfo: RsProcMacroStubInfo?,
) : RsAttrProcMacroOwnerStubBase<RsStructItem>(parent, elementType),
RsNamedStub {
val blockFields: StubElement<RsBlockFields>?
get() = findChildStubByType(RsStubElementTypes.BLOCK_FIELDS)
val isUnion: Boolean
get() = BitUtil.isSet(flags, IS_UNION_MASK)
object Type : RsStubElementType<RsStructItemStub, RsStructItem>("STRUCT_ITEM") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?) =
RsStructItemStub(
parentStub,
this,
dataStream.readNameAsString(),
dataStream.readUnsignedByte(),
RsProcMacroStubInfo.deserialize(dataStream),
)
override fun serialize(stub: RsStructItemStub, dataStream: StubOutputStream) =
with(dataStream) {
writeName(stub.name)
writeByte(stub.flags)
RsProcMacroStubInfo.serialize(stub.procMacroInfo, dataStream)
}
override fun createPsi(stub: RsStructItemStub): RsStructItem =
RsStructItemImpl(stub, this)
override fun createStub(psi: RsStructItem, parentStub: StubElement<*>?): RsStructItemStub {
var flags = RsAttributeOwnerStub.extractFlags(psi)
flags = BitUtil.set(flags, IS_UNION_MASK, psi.kind == RsStructKind.UNION)
val procMacroInfo = RsAttrProcMacroOwnerStub.extractTextAndOffset(flags, psi)
return RsStructItemStub(parentStub, this, psi.name, flags, procMacroInfo)
}
override fun indexStub(stub: RsStructItemStub, sink: IndexSink) = sink.indexStructItem(stub)
}
companion object : BitFlagsBuilder(RsAttributeOwnerStub, BYTE) {
private val IS_UNION_MASK: Int = nextBitMask()
}
}
class RsEnumItemStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
override val name: String?,
override val flags: Int,
override val procMacroInfo: RsProcMacroStubInfo?,
) : RsAttrProcMacroOwnerStubBase<RsEnumItem>(parent, elementType),
RsNamedStub {
val enumBody: StubElement<RsEnumBody>?
get() = findChildStubByType(RsStubElementTypes.ENUM_BODY)
object Type : RsStubElementType<RsEnumItemStub, RsEnumItem>("ENUM_ITEM") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?): RsEnumItemStub =
RsEnumItemStub(
parentStub,
this,
dataStream.readNameAsString(),
dataStream.readUnsignedByte(),
RsProcMacroStubInfo.deserialize(dataStream),
)
override fun serialize(stub: RsEnumItemStub, dataStream: StubOutputStream) =
with(dataStream) {
writeName(stub.name)
writeByte(stub.flags)
RsProcMacroStubInfo.serialize(stub.procMacroInfo, dataStream)
}
override fun createPsi(stub: RsEnumItemStub) =
RsEnumItemImpl(stub, this)
override fun createStub(psi: RsEnumItem, parentStub: StubElement<*>?): RsEnumItemStub {
val flags = RsAttributeOwnerStub.extractFlags(psi)
val procMacroInfo = RsAttrProcMacroOwnerStub.extractTextAndOffset(flags, psi)
return RsEnumItemStub(parentStub, this, psi.name, flags, procMacroInfo)
}
override fun indexStub(stub: RsEnumItemStub, sink: IndexSink) = sink.indexEnumItem(stub)
}
}
class RsEnumVariantStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
override val name: String?,
override val flags: Int
) : RsAttributeOwnerStubBase<RsEnumVariant>(parent, elementType),
RsNamedStub {
val blockFields: StubElement<RsBlockFields>?
get() = findChildStubByType(RsStubElementTypes.BLOCK_FIELDS)
object Type : RsStubElementType<RsEnumVariantStub, RsEnumVariant>("ENUM_VARIANT") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?): RsEnumVariantStub =
RsEnumVariantStub(
parentStub,
this,
dataStream.readNameAsString(),
dataStream.readUnsignedByte()
)
override fun serialize(stub: RsEnumVariantStub, dataStream: StubOutputStream) =
with(dataStream) {
writeName(stub.name)
writeByte(stub.flags)
}
override fun createPsi(stub: RsEnumVariantStub) =
RsEnumVariantImpl(stub, this)
override fun createStub(psi: RsEnumVariant, parentStub: StubElement<*>?) =
RsEnumVariantStub(parentStub, this, psi.name, RsAttributeOwnerStub.extractFlags(psi))
override fun indexStub(stub: RsEnumVariantStub, sink: IndexSink) {
sink.indexEnumVariant(stub)
}
}
}
class RsModDeclItemStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
override val name: String?,
override val flags: Int
) : RsAttributeOwnerStubBase<RsModDeclItem>(parent, elementType),
RsNamedStub {
object Type : RsStubElementType<RsModDeclItemStub, RsModDeclItem>("MOD_DECL_ITEM") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?) =
RsModDeclItemStub(
parentStub,
this,
dataStream.readNameAsString(),
dataStream.readUnsignedByte()
)
override fun serialize(stub: RsModDeclItemStub, dataStream: StubOutputStream) =
with(dataStream) {
writeName(stub.name)
writeByte(stub.flags)
}
override fun createPsi(stub: RsModDeclItemStub) =
RsModDeclItemImpl(stub, this)
override fun createStub(psi: RsModDeclItem, parentStub: StubElement<*>?): RsModDeclItemStub =
RsModDeclItemStub(parentStub, this, psi.name, RsAttributeOwnerStub.extractFlags(psi))
override fun indexStub(stub: RsModDeclItemStub, sink: IndexSink) = sink.indexModDeclItem(stub)
}
}
class RsModItemStub(
parent: StubElement<*>?,
elementType: IStubElementType<*, *>,
override val name: String?,
override val flags: Int,
override val procMacroInfo: RsProcMacroStubInfo?,
) : RsAttrProcMacroOwnerStubBase<RsModItem>(parent, elementType),
RsNamedStub {
object Type : RsStubElementType<RsModItemStub, RsModItem>("MOD_ITEM") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?) =
RsModItemStub(
parentStub,
this,
dataStream.readNameAsString(),
dataStream.readUnsignedByte(),
RsProcMacroStubInfo.deserialize(dataStream),
)
override fun serialize(stub: RsModItemStub, dataStream: StubOutputStream) =
with(dataStream) {
writeName(stub.name)
writeByte(stub.flags)
RsProcMacroStubInfo.serialize(stub.procMacroInfo, dataStream)
}
override fun createPsi(stub: RsModItemStub): RsModItem =
RsModItemImpl(stub, this)
override fun createStub(psi: RsModItem, parentStub: StubElement<*>?): RsModItemStub {
val flags = RsAttributeOwnerStub.extractFlags(psi)
val procMacroInfo = RsAttrProcMacroOwnerStub.extractTextAndOffset(flags, psi)
return RsModItemStub(parentStub, this, psi.name, flags, procMacroInfo)
}
override fun indexStub(stub: RsModItemStub, sink: IndexSink) = sink.indexModItem(stub)
}
}
class RsTraitItemStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
override val name: String?,
override val flags: Int,
override val procMacroInfo: RsProcMacroStubInfo?,
) : RsAttrProcMacroOwnerStubBase<RsTraitItem>(parent, elementType),
RsNamedStub {
val isUnsafe: Boolean
get() = BitUtil.isSet(flags, UNSAFE_MASK)
val isAuto: Boolean
get() = BitUtil.isSet(flags, AUTO_MASK)
object Type : RsStubElementType<RsTraitItemStub, RsTraitItem>("TRAIT_ITEM") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?): RsTraitItemStub {
return RsTraitItemStub(
parentStub,
this,
dataStream.readNameAsString(),
dataStream.readUnsignedByte(),
RsProcMacroStubInfo.deserialize(dataStream),
)
}
override fun serialize(stub: RsTraitItemStub, dataStream: StubOutputStream) =
with(dataStream) {
writeName(stub.name)
writeByte(stub.flags)
RsProcMacroStubInfo.serialize(stub.procMacroInfo, dataStream)
}
override fun createPsi(stub: RsTraitItemStub): RsTraitItem =
RsTraitItemImpl(stub, this)
override fun createStub(psi: RsTraitItem, parentStub: StubElement<*>?): RsTraitItemStub {
var flags = RsAttributeOwnerStub.extractFlags(psi)
flags = BitUtil.set(flags, UNSAFE_MASK, psi.isUnsafe)
flags = BitUtil.set(flags, AUTO_MASK, psi.isAuto)
val procMacroInfo = RsAttrProcMacroOwnerStub.extractTextAndOffset(flags, psi)
return RsTraitItemStub(parentStub, this, psi.name, flags, procMacroInfo)
}
override fun indexStub(stub: RsTraitItemStub, sink: IndexSink) = sink.indexTraitItem(stub)
}
companion object : BitFlagsBuilder(RsAttributeOwnerStub, BYTE) {
private val UNSAFE_MASK: Int = nextBitMask()
private val AUTO_MASK: Int = nextBitMask()
}
}
class RsImplItemStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
override val flags: Int,
override val procMacroInfo: RsProcMacroStubInfo?,
) : RsAttrProcMacroOwnerStubBase<RsImplItem>(parent, elementType) {
val isNegativeImpl: Boolean
get() = BitUtil.isSet(flags, NEGATIVE_IMPL_MASK)
object Type : RsStubElementType<RsImplItemStub, RsImplItem>("IMPL_ITEM") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?) =
RsImplItemStub(parentStub, this,
dataStream.readUnsignedByte(),
RsProcMacroStubInfo.deserialize(dataStream),
)
override fun serialize(stub: RsImplItemStub, dataStream: StubOutputStream) =
with(dataStream) {
writeByte(stub.flags)
RsProcMacroStubInfo.serialize(stub.procMacroInfo, dataStream)
}
override fun createPsi(stub: RsImplItemStub): RsImplItem =
RsImplItemImpl(stub, this)
override fun createStub(psi: RsImplItem, parentStub: StubElement<*>?): RsImplItemStub {
var flags = RsAttributeOwnerStub.extractFlags(psi)
flags = BitUtil.set(flags, NEGATIVE_IMPL_MASK, psi.isNegativeImpl)
val procMacroInfo = RsAttrProcMacroOwnerStub.extractTextAndOffset(flags, psi)
return RsImplItemStub(parentStub, this, flags, procMacroInfo)
}
override fun indexStub(stub: RsImplItemStub, sink: IndexSink) = sink.indexImplItem(stub)
}
companion object : BitFlagsBuilder(RsAttributeOwnerStub, BYTE) {
private val NEGATIVE_IMPL_MASK: Int = nextBitMask()
}
}
class RsTraitAliasStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
override val name: String?,
override val flags: Int,
override val procMacroInfo: RsProcMacroStubInfo?,
) : RsAttrProcMacroOwnerStubBase<RsTraitAlias>(parent, elementType),
RsNamedStub {
object Type : RsStubElementType<RsTraitAliasStub, RsTraitAlias>("TRAIT_ALIAS") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?) =
RsTraitAliasStub(parentStub, this,
dataStream.readNameAsString(),
dataStream.readUnsignedByte(),
RsProcMacroStubInfo.deserialize(dataStream),
)
override fun serialize(stub: RsTraitAliasStub, dataStream: StubOutputStream) {
with(dataStream) {
writeName(stub.name)
writeByte(stub.flags)
RsProcMacroStubInfo.serialize(stub.procMacroInfo, dataStream)
}
}
override fun createPsi(stub: RsTraitAliasStub): RsTraitAlias =
RsTraitAliasImpl(stub, this)
override fun createStub(psi: RsTraitAlias, parentStub: StubElement<*>?): RsTraitAliasStub {
val flags = RsAttributeOwnerStub.extractFlags(psi)
val procMacroInfo = RsAttrProcMacroOwnerStub.extractTextAndOffset(flags, psi)
return RsTraitAliasStub(parentStub, this, psi.name, flags, procMacroInfo)
}
override fun indexStub(stub: RsTraitAliasStub, sink: IndexSink) = sink.indexTraitAlias(stub)
}
}
class RsFunctionStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
override val name: String?,
val abiName: String?,
override val flags: Int,
override val procMacroInfo: RsProcMacroStubInfo?,
) : RsAttrProcMacroOwnerStubBase<RsFunction>(parent, elementType),
RsNamedStub {
val isAbstract: Boolean get() = BitUtil.isSet(flags, ABSTRACT_MASK)
val isConst: Boolean get() = BitUtil.isSet(flags, CONST_MASK)
val isUnsafe: Boolean get() = BitUtil.isSet(flags, UNSAFE_MASK)
val isExtern: Boolean get() = BitUtil.isSet(flags, EXTERN_MASK)
val isVariadic: Boolean get() = BitUtil.isSet(flags, VARIADIC_MASK)
val isAsync: Boolean get() = BitUtil.isSet(flags, ASYNC_MASK)
// Method resolve optimization: stub field access is much faster than PSI traversing
val hasSelfParameters: Boolean get() = BitUtil.isSet(flags, HAS_SELF_PARAMETER_MASK)
val mayBeProcMacroDef: Boolean get() = BitUtil.isSet(flags, IS_PROC_MACRO_DEF)
object Type : RsStubElementType<RsFunctionStub, RsFunction>("FUNCTION") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?) =
RsFunctionStub(
parentStub,
this,
dataStream.readName()?.string,
dataStream.readUTFFastAsNullable(),
dataStream.readInt(),
RsProcMacroStubInfo.deserialize(dataStream),
)
override fun serialize(stub: RsFunctionStub, dataStream: StubOutputStream) =
with(dataStream) {
writeName(stub.name)
writeUTFFastAsNullable(stub.abiName)
writeInt(stub.flags)
RsProcMacroStubInfo.serialize(stub.procMacroInfo, dataStream)
}
override fun createPsi(stub: RsFunctionStub) =
RsFunctionImpl(stub, this)
override fun createStub(psi: RsFunction, parentStub: StubElement<*>?): RsFunctionStub {
val block = psi.block
val useInnerAttrs = block != null && ((block.node as LazyParseableElement).isParsed ||
BlockMayHaveStubsHeuristic.computeAndCache(block.node))
val attrs = if (useInnerAttrs && block != null) {
TreeUtil.ensureParsed(block.node) // profiler hint
psi.getTraversedRawAttributes(withCfgAttrAttribute = true)
} else {
QueryAttributes(
psi.outerAttrList.asSequence()
.map { it.metaItem }
.withFlattenCfgAttrsAttributes(withCfgAttrAttribute = true)
)
}
var flags = RsAttributeOwnerStub.extractFlags(attrs)
flags = BitUtil.set(flags, ABSTRACT_MASK, block == null)
flags = BitUtil.set(flags, CONST_MASK, psi.isConst)
flags = BitUtil.set(flags, UNSAFE_MASK, psi.isUnsafe)
flags = BitUtil.set(flags, EXTERN_MASK, psi.isExtern)
flags = BitUtil.set(flags, VARIADIC_MASK, psi.isVariadic)
flags = BitUtil.set(flags, ASYNC_MASK, psi.isAsync)
flags = BitUtil.set(flags, HAS_SELF_PARAMETER_MASK, psi.hasSelfParameters)
flags = BitUtil.set(flags, IS_PROC_MACRO_DEF, attrs.isProcMacroDef)
val procMacroInfo = RsAttrProcMacroOwnerStub.extractTextAndOffset(flags, psi)
return RsFunctionStub(
parentStub,
this,
name = psi.name,
abiName = psi.abiName,
flags = flags,
procMacroInfo = procMacroInfo,
)
}
override fun indexStub(stub: RsFunctionStub, sink: IndexSink) = sink.indexFunction(stub)
}
companion object : BitFlagsBuilder(RsAttributeOwnerStub, INT) {
private val ABSTRACT_MASK: Int = nextBitMask()
private val CONST_MASK: Int = nextBitMask()
private val UNSAFE_MASK: Int = nextBitMask()
private val EXTERN_MASK: Int = nextBitMask()
private val VARIADIC_MASK: Int = nextBitMask()
private val ASYNC_MASK: Int = nextBitMask()
private val HAS_SELF_PARAMETER_MASK: Int = nextBitMask()
private val IS_PROC_MACRO_DEF: Int = nextBitMask()
}
}
class RsConstantStub(
parent: StubElement<*>?, elementType: IStubElementType<*, *>,
override val name: String?,
override val flags: Int,
override val procMacroInfo: RsProcMacroStubInfo?,
) : RsAttrProcMacroOwnerStubBase<RsConstant>(parent, elementType),
RsNamedStub {
val isMut: Boolean
get() = BitUtil.isSet(flags, IS_MUT_MASK)
val isConst: Boolean
get() = BitUtil.isSet(flags, IS_CONST_MASK)
object Type : RsStubElementType<RsConstantStub, RsConstant>("CONSTANT") {
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?) =
RsConstantStub(
parentStub,
this,
dataStream.readNameAsString(),
dataStream.readUnsignedByte(),
RsProcMacroStubInfo.deserialize(dataStream),
)
override fun serialize(stub: RsConstantStub, dataStream: StubOutputStream) =
with(dataStream) {
writeName(stub.name)
writeByte(stub.flags)
RsProcMacroStubInfo.serialize(stub.procMacroInfo, dataStream)
}
override fun createPsi(stub: RsConstantStub) =
RsConstantImpl(stub, this)
override fun createStub(psi: RsConstant, parentStub: StubElement<*>?): RsConstantStub {
var flags = RsAttributeOwnerStub.extractFlags(psi)
flags = BitUtil.set(flags, IS_MUT_MASK, psi.isMut)
flags = BitUtil.set(flags, IS_CONST_MASK, psi.isConst)
val procMacroInfo = RsAttrProcMacroOwnerStub.extractTextAndOffset(flags, psi)
return RsConstantStub(parentStub, this, psi.name, flags, procMacroInfo)
}
override fun indexStub(stub: RsConstantStub, sink: IndexSink) = sink.indexConstant(stub)
}
companion object : BitFlagsBuilder(RsAttributeOwnerStub, BYTE) {
private val IS_MUT_MASK: Int = nextBitMask()