1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
+ using System . Text ;
4
5
using org . jetbrains . kotlin . metadata . jvm ;
5
6
using Type = org . jetbrains . kotlin . metadata . jvm . Type ;
6
7
@@ -48,23 +49,34 @@ internal static KotlinClass FromProtobuf (Class c, JvmNameResolver resolver)
48
49
}
49
50
}
50
51
51
- public class KotlinConstructor
52
+ public class KotlinMethodBase
52
53
{
53
- public int Flags { get ; set ; }
54
- public List < KotlinValueParameter > ValueParameters { get ; set ; }
55
54
public int [ ] VersionRequirements { get ; set ; }
56
55
56
+ public virtual string GetSignature ( ) => string . Empty ;
57
+ }
58
+
59
+ public class KotlinConstructor : KotlinMethodBase
60
+ {
61
+ public KotlinConstructorFlags Flags { get ; set ; }
62
+ public List < KotlinValueParameter > ValueParameters { get ; set ; }
63
+
57
64
internal static KotlinConstructor FromProtobuf ( Constructor c , JvmNameResolver resolver )
58
65
{
59
66
if ( c is null )
60
67
return null ;
61
68
62
69
return new KotlinConstructor {
63
- Flags = c . Flags ,
70
+ Flags = ( KotlinConstructorFlags ) c . Flags ,
64
71
ValueParameters = c . ValueParameters ? . Select ( vp => KotlinValueParameter . FromProtobuf ( vp , resolver ) ) . ToList ( ) ,
65
72
VersionRequirements = c . VersionRequirements
66
73
} ;
67
74
}
75
+
76
+ public override string GetSignature ( )
77
+ {
78
+ return $ "({ ValueParameters . GetSignature ( ) } )V";
79
+ }
68
80
}
69
81
70
82
public class KotlinAnnotation
@@ -113,7 +125,7 @@ public class KotlinAnnotationArgumentValue
113
125
public KotlinAnnotation Annotation { get ; set ; }
114
126
public List < KotlinAnnotationArgumentValue > ArrayElements { get ; set ; }
115
127
public int ArrayDimensionCount { get ; set ; }
116
- public int Flags { get ; set ; }
128
+ public KotlinAnnotationFlags Flags { get ; set ; }
117
129
118
130
internal static KotlinAnnotationArgumentValue FromProtobuf ( org . jetbrains . kotlin . metadata . jvm . Annotation . Argument . Value value , JvmNameResolver resolver )
119
131
{
@@ -131,7 +143,7 @@ internal static KotlinAnnotationArgumentValue FromProtobuf (org.jetbrains.kotlin
131
143
Annotation = KotlinAnnotation . FromProtobuf ( value . Annotation , resolver ) ,
132
144
ArrayDimensionCount = value . ArrayDimensionCount ,
133
145
ArrayElements = value . ArrayElements ? . Select ( vp => KotlinAnnotationArgumentValue . FromProtobuf ( vp , resolver ) ) . ToList ( ) ,
134
- Flags = value . Flags
146
+ Flags = ( KotlinAnnotationFlags ) value . Flags
135
147
} ;
136
148
}
137
149
}
@@ -159,7 +171,7 @@ internal static KotlinEffect FromProtobuf (Effect ef, JvmNameResolver resolver)
159
171
160
172
public class KotlinExpression
161
173
{
162
- public int Flags { get ; set ; }
174
+ public KotlinExpressionFlags Flags { get ; set ; }
163
175
public int ValueParameterReference { get ; set ; }
164
176
public KotlinConstantValue ConstantValue { get ; set ; }
165
177
public KotlinType IsInstanceType { get ; set ; }
@@ -173,7 +185,7 @@ internal static KotlinExpression FromProtobuf (Expression exp, JvmNameResolver r
173
185
return null ;
174
186
175
187
return new KotlinExpression {
176
- Flags = exp . Flags ,
188
+ Flags = ( KotlinExpressionFlags ) exp . Flags ,
177
189
ValueParameterReference = exp . ValueParameterReference ,
178
190
ConstantValue = ( KotlinConstantValue ) exp . constant_value ,
179
191
IsInstanceType = KotlinType . FromProtobuf ( exp . IsInstanceType , resolver ) ,
@@ -184,27 +196,26 @@ internal static KotlinExpression FromProtobuf (Expression exp, JvmNameResolver r
184
196
}
185
197
}
186
198
187
- public class KotlinFunction
199
+ public class KotlinFunction : KotlinMethodBase
188
200
{
189
- public int Flags { get ; set ; }
190
201
public string Name { get ; set ; }
202
+ public KotlinFunctionFlags Flags { get ; set ; }
191
203
public KotlinType ReturnType { get ; set ; }
192
204
public int ReturnTypeId { get ; set ; }
193
205
public List < KotlinTypeParameter > TypeParameters { get ; set ; }
194
206
public KotlinType ReceiverType { get ; set ; }
195
207
public int ReceiverTypeId { get ; set ; }
196
- public List < KotlinValueParameter > ValueParameters { get ; set ; }
197
208
public KotlinTypeTable TypeTable { get ; set ; }
198
- public int [ ] VersionRequirements { get ; set ; }
199
209
public KotlinContract Contract { get ; set ; }
210
+ public List < KotlinValueParameter > ValueParameters { get ; set ; }
200
211
201
212
internal static KotlinFunction FromProtobuf ( Function f , JvmNameResolver resolver )
202
213
{
203
214
if ( f is null )
204
215
return null ;
205
216
206
217
return new KotlinFunction {
207
- Flags = f . Flags ,
218
+ Flags = ( KotlinFunctionFlags ) f . Flags ,
208
219
Name = resolver . GetString ( f . Name ) ,
209
220
ReturnType = KotlinType . FromProtobuf ( f . ReturnType , resolver ) ,
210
221
ReturnTypeId = f . ReturnTypeId ,
@@ -215,6 +226,8 @@ internal static KotlinFunction FromProtobuf (Function f, JvmNameResolver resolve
215
226
VersionRequirements = f . VersionRequirements
216
227
} ;
217
228
}
229
+
230
+ public override string ToString ( ) => Name ;
218
231
}
219
232
220
233
public class KotlinContract
@@ -229,10 +242,10 @@ internal static KotlinContract FromProtobuf (Contract c, JvmNameResolver resolve
229
242
}
230
243
}
231
244
232
- public class KotlinProperty
245
+ public class KotlinProperty : KotlinMethodBase
233
246
{
234
- public int Flags { get ; set ; }
235
247
public string Name { get ; set ; }
248
+ public KotlinPropertyFlags Flags { get ; set ; }
236
249
public KotlinType ReturnType { get ; set ; }
237
250
public int ReturnTypeId { get ; set ; }
238
251
public List < KotlinTypeParameter > TypeParameters { get ; set ; }
@@ -241,15 +254,14 @@ public class KotlinProperty
241
254
public KotlinValueParameter SetterValueParameter { get ; set ; }
242
255
public int GetterFlags { get ; set ; }
243
256
public int SetterFlags { get ; set ; }
244
- public int [ ] VersionRequirements { get ; set ; }
245
257
246
258
internal static KotlinProperty FromProtobuf ( Property p , JvmNameResolver resolver )
247
259
{
248
260
if ( p is null )
249
261
return null ;
250
262
251
263
return new KotlinProperty {
252
- Flags = p . Flags ,
264
+ Flags = ( KotlinPropertyFlags ) p . Flags ,
253
265
Name = resolver . GetString ( p . Name ) ,
254
266
ReturnTypeId = p . ReturnTypeId ,
255
267
ReturnType = KotlinType . FromProtobuf ( p . ReturnType , resolver ) ,
@@ -268,18 +280,18 @@ public class KotlinType
268
280
{
269
281
public List < KotlinTypeArgument > Arguments { get ; set ; }
270
282
public bool Nullable { get ; set ; }
271
- public int FlexibleTypeCapabilitiesId { get ; set ; }
283
+ public int ? FlexibleTypeCapabilitiesId { get ; set ; }
272
284
public KotlinType FlexibleUpperBound { get ; set ; }
273
285
public int FlexibleUpperBoundId { get ; set ; }
274
286
public string ClassName { get ; set ; }
275
- public int TypeParameter { get ; set ; }
287
+ public int ? TypeParameter { get ; set ; }
276
288
public string TypeParameterName { get ; set ; }
277
289
public string TypeAliasName { get ; set ; }
278
290
public KotlinType OuterType { get ; set ; }
279
- public int OuterTypeId { get ; set ; }
291
+ public int ? OuterTypeId { get ; set ; }
280
292
public KotlinType AbbreviatedType { get ; set ; }
281
- public int AbbreviatedTypeId { get ; set ; }
282
- public int Flags { get ; set ; }
293
+ public int ? AbbreviatedTypeId { get ; set ; }
294
+ public KotlinTypeFlags Flags { get ; set ; }
283
295
284
296
internal static KotlinType FromProtobuf ( Type t , JvmNameResolver resolver )
285
297
{
@@ -291,16 +303,21 @@ internal static KotlinType FromProtobuf (Type t, JvmNameResolver resolver)
291
303
Nullable = t . Nullable ,
292
304
FlexibleTypeCapabilitiesId = t . FlexibleTypeCapabilitiesId ,
293
305
FlexibleUpperBound = FromProtobuf ( t . FlexibleUpperBound , resolver ) ,
294
- ClassName = t . ClassName > 0 ? resolver . GetString ( t . ClassName ) : null ,
306
+ ClassName = t . ClassName >= 0 ? resolver . GetString ( t . ClassName . Value ) : null ,
295
307
TypeParameter = t . TypeParameter ,
296
- TypeParameterName = t . TypeParameterName > 0 ? resolver . GetString ( t . TypeParameterName ) : null ,
308
+ TypeParameterName = t . TypeParameterName >= 0 ? resolver . GetString ( t . TypeParameterName . GetValueOrDefault ( ) ) : null ,
297
309
OuterType = FromProtobuf ( t . OuterType , resolver ) ,
298
310
OuterTypeId = t . OuterTypeId ,
299
311
AbbreviatedType = FromProtobuf ( t . AbbreviatedType , resolver ) ,
300
312
AbbreviatedTypeId = t . AbbreviatedTypeId ,
301
- Flags = t . Flags
313
+ Flags = ( KotlinTypeFlags ) t . Flags
302
314
} ;
303
315
}
316
+
317
+ public string GetSignature ( )
318
+ {
319
+ return KotlinUtilities . ConvertKotlinTypeSignature ( this ) ;
320
+ }
304
321
}
305
322
306
323
public class KotlinTypeAlias
@@ -436,7 +453,7 @@ internal static KotlinVersionRequirementTable FromProtobuf (VersionRequirementTa
436
453
437
454
public class KotlinValueParameter
438
455
{
439
- public int Flags { get ; set ; }
456
+ public KotlinParameterFlags Flags { get ; set ; }
440
457
public string Name { get ; set ; }
441
458
public KotlinType Type { get ; set ; }
442
459
public int TypeId { get ; set ; }
@@ -449,14 +466,16 @@ internal static KotlinValueParameter FromProtobuf (ValueParameter vp, JvmNameRes
449
466
return null ;
450
467
451
468
return new KotlinValueParameter {
452
- Flags = vp . Flags ,
469
+ Flags = ( KotlinParameterFlags ) vp . Flags ,
453
470
Name = resolver . GetString ( vp . Name ) ,
454
471
Type = KotlinType . FromProtobuf ( vp . Type , resolver ) ,
455
472
TypeId = vp . TypeId ,
456
473
VarArgElementType = KotlinType . FromProtobuf ( vp . VarargElementType , resolver ) ,
457
474
VarArgElementTypeId = vp . VarargElementTypeId
458
475
} ;
459
476
}
477
+
478
+ public string GetSignature ( ) => Type . GetSignature ( ) ;
460
479
}
461
480
462
481
public enum KotlinVariance
@@ -557,4 +576,134 @@ public enum KotlinClassFlags
557
576
IsExpectClass = 0b_01000_000_00_000_0 ,
558
577
IsInlineClass = 0b_10000_000_00_000_0
559
578
}
579
+
580
+ [ Flags ]
581
+ public enum KotlinConstructorFlags
582
+ {
583
+ HasAnnotations = 0b0_000_1 ,
584
+
585
+ Internal = 0b0_000_0 ,
586
+ Private = 0b0_001_0 ,
587
+ Protected = 0b0_010_0 ,
588
+ Public = 0b0_011_0 ,
589
+ PrivateToThis = 0b0_100_0 ,
590
+ Local = 0b0_101_0 ,
591
+
592
+ IsSecondary = 0b1_000_0
593
+ }
594
+
595
+ [ Flags ]
596
+ public enum KotlinFunctionFlags
597
+ {
598
+ HasAnnotations = 0b00_00_000_1 ,
599
+
600
+ Internal = 0b00_00_000_0 ,
601
+ Private = 0b00_00_001_0 ,
602
+ Protected = 0b00_00_010_0 ,
603
+ Public = 0b00_00_011_0 ,
604
+ PrivateToThis = 0b00_00_100_0 ,
605
+ Local = 0b00_00_101_0 ,
606
+
607
+ Final = 0b00_00_000_0 ,
608
+ Open = 0b00_01_000_0 ,
609
+ Abstract = 0b00_10_000_0 ,
610
+ Sealed = 0b00_11_000_0 ,
611
+
612
+ Declaration = 0b00_00_000_0 ,
613
+ FakeOverride = 0b01_00_000_0 ,
614
+ Delegation = 0b10_00_000_0 ,
615
+ Synthesized = 0b11_00_000_0 ,
616
+
617
+ IsOperator = 0b_0000001_000_00_000_0 ,
618
+ IsInfix = 0b_0000010_000_00_000_0 ,
619
+ IsInline = 0b_0000100_000_00_000_0 ,
620
+ IsTailrec = 0b_0001000_000_00_000_0 ,
621
+ IsExternalFunction = 0b_0010000_000_00_000_0 ,
622
+ IsSuspend = 0b_0100000_000_00_000_0 ,
623
+ IsExpectFunction = 0b_1000000_000_00_000_0
624
+ }
625
+
626
+ [ Flags ]
627
+ public enum KotlinPropertyFlags
628
+ {
629
+ HasAnnotations = 0b00_00_000_1 ,
630
+
631
+ Internal = 0b00_00_000_0 ,
632
+ Private = 0b00_00_001_0 ,
633
+ Protected = 0b00_00_010_0 ,
634
+ Public = 0b00_00_011_0 ,
635
+ PrivateToThis = 0b00_00_100_0 ,
636
+ Local = 0b00_00_101_0 ,
637
+
638
+ Final = 0b00_00_000_0 ,
639
+ Open = 0b00_01_000_0 ,
640
+ Abstract = 0b00_10_000_0 ,
641
+ Sealed = 0b00_11_000_0 ,
642
+
643
+ Declaration = 0b00_00_000_0 ,
644
+ FakeOverride = 0b01_00_000_0 ,
645
+ Delegation = 0b10_00_000_0 ,
646
+ Synthesized = 0b11_00_000_0 ,
647
+
648
+ IsVar = 0b_000000001_000_00_000_0 ,
649
+ HasGetter = 0b_000000010_000_00_000_0 ,
650
+ HasSetter = 0b_000000100_000_00_000_0 ,
651
+ IsConst = 0b_000001000_000_00_000_0 ,
652
+ IsLateInit = 0b_000010000_000_00_000_0 ,
653
+ HasConstant = 0b_000100000_000_00_000_0 ,
654
+ IsExternalProperty = 0b_001000000_000_00_000_0 ,
655
+ IsDelegated = 0b_010000000_000_00_000_0 ,
656
+ IsExpectProperty = 0b_100000000_000_00_000_0
657
+ }
658
+
659
+ [ Flags ]
660
+ public enum KotlinParameterFlags
661
+ {
662
+ HasAnnotations = 0b000_1 ,
663
+
664
+ DeclaresDefaultValue = 0b001_0 ,
665
+ IsCrossInline = 0b010_0 ,
666
+ IsNoInline = 0b100_0
667
+ }
668
+
669
+ [ Flags ]
670
+ public enum KotlinAccessorFlags
671
+ {
672
+ HasAnnotations = 0b00_00_000_1 ,
673
+
674
+ Internal = 0b00_00_000_0 ,
675
+ Private = 0b00_00_001_0 ,
676
+ Protected = 0b00_00_010_0 ,
677
+ Public = 0b00_00_011_0 ,
678
+ PrivateToThis = 0b00_00_100_0 ,
679
+ Local = 0b00_00_101_0 ,
680
+
681
+ Final = 0b00_00_000_0 ,
682
+ Open = 0b00_01_000_0 ,
683
+ Abstract = 0b00_10_000_0 ,
684
+ Sealed = 0b00_11_000_0 ,
685
+
686
+ IsNotDefault = 0b001_00_000_0 ,
687
+ IsExternalAccessor = 0b010_00_000_0 ,
688
+ IsInlineAccessor = 0b100_00_000_0
689
+ }
690
+
691
+ [ Flags ]
692
+ public enum KotlinExpressionFlags
693
+ {
694
+ IsNegated = 0b01 ,
695
+ IsNullCheckPredicate = 0b10
696
+ }
697
+
698
+ [ Flags ]
699
+ public enum KotlinAnnotationFlags
700
+ {
701
+ IsUnsigned = 0b01
702
+ }
703
+
704
+ [ Flags ]
705
+ public enum KotlinTypeFlags
706
+ {
707
+ SuspendType = 0b01
708
+ }
560
709
}
0 commit comments