Ejemplo n.º 1
0
        Tuple <T, JvmNameResolver> ParseStream <T> ()
        {
            var md = KotlinBitEncoding.DecodeBytes(Data1);

            using (var ms = ToMemoryStream(md)) {
                // The first element is the length of the string table
                var first = ms.ReadByte();

                if (first == -1)
                {
                    return(null);
                }

                ms.Position = 0;

                var size = KotlinBitEncoding.ReadRawVarint32(ms);

                using (var partial = new PartialStream(ms, ms.Position, size)) {
                    // Read the string table from the stream
                    var string_table = Serializer.Deserialize <org.jetbrains.kotlin.metadata.jvm.StringTableTypes> (partial);
                    var resolver     = new JvmNameResolver(string_table, Data2.ToList());

                    partial.MoveNext();

                    // Read the metadata structure from the stream
                    var metadata = Serializer.Deserialize <T> (partial);
                    return(Tuple.Create(metadata, resolver));
                }
            }
        }
Ejemplo n.º 2
0
 internal static KotlinFile FromProtobuf(Package c, JvmNameResolver resolver)
 {
     return(new KotlinFile {
         Functions = c.Functions.ToList(resolver, KotlinFunction.FromProtobuf),
         Properties = c.Properties.ToList(resolver, KotlinProperty.FromProtobuf),
         TypeAliases = c.TypeAlias.ToList(resolver, KotlinTypeAlias.FromProtobuf),
         TypeTable = KotlinTypeTable.FromProtobuf(c.TypeTable, resolver),
         VersionRequirementTable = KotlinVersionRequirementTable.FromProtobuf(c.VersionRequirementTable, resolver)
     });
 }
Ejemplo n.º 3
0
 internal static KotlinFile FromProtobuf(Package c, JvmNameResolver resolver)
 {
     return(new KotlinFile {
         Functions = c.Functions?.Select(f => KotlinFunction.FromProtobuf(f, resolver)).ToList(),
         Properties = c.Properties?.Select(p => KotlinProperty.FromProtobuf(p, resolver)).ToList(),
         TypeAliases = c.TypeAlias?.Select(tp => KotlinTypeAlias.FromProtobuf(tp, resolver)).ToList(),
         TypeTable = KotlinTypeTable.FromProtobuf(c.TypeTable, resolver),
         VersionRequirementTable = KotlinVersionRequirementTable.FromProtobuf(c.VersionRequirementTable, resolver)
     });
 }
Ejemplo n.º 4
0
        internal static KotlinTypeTable FromProtobuf(TypeTable ta, JvmNameResolver resolver)
        {
            if (ta is null)
            {
                return(null);
            }

            return(new KotlinTypeTable {
                Types = ta.Types?.Select(t => KotlinType.FromProtobuf(t, resolver)).ToList(),
                FirstNullable = ta.FirstNullable
            });
        }
Ejemplo n.º 5
0
        internal static KotlinConstructor FromProtobuf(Constructor c, JvmNameResolver resolver)
        {
            if (c is null)
            {
                return(null);
            }

            return(new KotlinConstructor {
                Flags = c.Flags,
                ValueParameters = c.ValueParameters?.Select(vp => KotlinValueParameter.FromProtobuf(vp, resolver)).ToList(),
                VersionRequirements = c.VersionRequirements
            });
        }
Ejemplo n.º 6
0
        internal static KotlinTypeArgument FromProtobuf(Type.Argument ta, JvmNameResolver resolver)
        {
            if (ta is null)
            {
                return(null);
            }

            return(new KotlinTypeArgument {
                Projection = (KotlinProjection)ta.projection,
                Type = KotlinType.FromProtobuf(ta.Type, resolver),
                TypeId = ta.TypeId
            });
        }
Ejemplo n.º 7
0
        internal static KotlinEffect FromProtobuf(Effect ef, JvmNameResolver resolver)
        {
            if (ef is null)
            {
                return(null);
            }

            return(new KotlinEffect {
                EffectType = (KotlinEffectType)ef.effect_type,
                EffectConstructorArguments = ef.EffectConstructorArguments?.Select(vp => KotlinExpression.FromProtobuf(vp, resolver)).ToList(),
                ConclusionOfConditionalEffect = KotlinExpression.FromProtobuf(ef.ConclusionOfConditionalEffect, resolver),
                Kind = (KotlinInvocationKind)ef.Kind
            });
        }
Ejemplo n.º 8
0
        internal static KotlinVersionRequirement FromProtobuf(VersionRequirement vr, JvmNameResolver resolver)
        {
            if (vr is null)
            {
                return(null);
            }

            return(new KotlinVersionRequirement {
                Version = vr.Version,
                VersionFull = vr.VersionFull,
                Level = (KotlinVersionLevel)vr.level,
                ErrorCode = vr.ErrorCode,
                Message = vr.Message,
                VersionKind = (KotlinVersionKind)vr.version_kind
            });
        }
Ejemplo n.º 9
0
        internal static KotlinValueParameter FromProtobuf(ValueParameter vp, JvmNameResolver resolver)
        {
            if (vp is null)
            {
                return(null);
            }

            return(new KotlinValueParameter {
                Flags = vp.Flags,
                Name = resolver.GetString(vp.Name),
                Type = KotlinType.FromProtobuf(vp.Type, resolver),
                TypeId = vp.TypeId,
                VarArgElementType = KotlinType.FromProtobuf(vp.VarargElementType, resolver),
                VarArgElementTypeId = vp.VarargElementTypeId
            });
        }
Ejemplo n.º 10
0
        internal static KotlinTypeParameter FromProtobuf(TypeParameter vp, JvmNameResolver resolver)
        {
            if (vp is null)
            {
                return(null);
            }

            return(new KotlinTypeParameter {
                Id = vp.Id,
                Name = resolver.GetString(vp.Name),
                Reified = vp.Reified,
                Variance = (KotlinVariance)vp.variance,
                UpperBounds = vp.UpperBounds?.Select(ub => KotlinType.FromProtobuf(ub, resolver)).ToList(),
                UpperBoundsIds = vp.UpperBoundIds
            });
        }
Ejemplo n.º 11
0
        internal static KotlinExpression FromProtobuf(Expression exp, JvmNameResolver resolver)
        {
            if (exp is null)
            {
                return(null);
            }

            return(new KotlinExpression {
                Flags = exp.Flags,
                ValueParameterReference = exp.ValueParameterReference,
                ConstantValue = (KotlinConstantValue)exp.constant_value,
                IsInstanceType = KotlinType.FromProtobuf(exp.IsInstanceType, resolver),
                IsInstanceTypeId = exp.IsInstanceTypeId,
                AndArguments = exp.AndArguments?.Select(tp => KotlinExpression.FromProtobuf(tp, resolver)).ToList(),
                OrArguments = exp.OrArguments?.Select(vp => KotlinExpression.FromProtobuf(vp, resolver)).ToList()
            });
        }
Ejemplo n.º 12
0
        internal static KotlinTypeAlias FromProtobuf(TypeAlias ta, JvmNameResolver resolver)
        {
            if (ta is null)
            {
                return(null);
            }

            return(new KotlinTypeAlias {
                Flags = ta.Flags,
                Name = resolver.GetString(ta.Name),
                TypeParameters = ta.TypeParameters?.Select(tp => KotlinTypeParameter.FromProtobuf(tp, resolver)).ToList(),
                UnderlyingType = KotlinType.FromProtobuf(ta.UnderlyingType, resolver),
                UnderlyingTypeId = ta.UnderlyingTypeId,
                ExpandedType = KotlinType.FromProtobuf(ta.ExpandedType, resolver),
                ExpandedTypeId = ta.ExpandedTypeId,
                VersionRequirements = ta.VersionRequirements
            });
        }
Ejemplo n.º 13
0
        internal static KotlinFunction FromProtobuf(Function f, JvmNameResolver resolver)
        {
            if (f is null)
            {
                return(null);
            }

            return(new KotlinFunction {
                Flags = f.Flags,
                Name = resolver.GetString(f.Name),
                ReturnType = KotlinType.FromProtobuf(f.ReturnType, resolver),
                ReturnTypeId = f.ReturnTypeId,
                ReceiverType = KotlinType.FromProtobuf(f.ReceiverType, resolver),
                ReceiverTypeId = f.ReceiverTypeId,
                TypeParameters = f.TypeParameters?.Select(tp => KotlinTypeParameter.FromProtobuf(tp, resolver)).ToList(),
                ValueParameters = f.ValueParameters?.Select(vp => KotlinValueParameter.FromProtobuf(vp, resolver)).ToList(),
                VersionRequirements = f.VersionRequirements
            });
        }
Ejemplo n.º 14
0
        internal static KotlinProperty FromProtobuf(Property p, JvmNameResolver resolver)
        {
            if (p is null)
            {
                return(null);
            }

            return(new KotlinProperty {
                Flags = p.Flags,
                Name = resolver.GetString(p.Name),
                ReturnTypeId = p.ReturnTypeId,
                ReturnType = KotlinType.FromProtobuf(p.ReturnType, resolver),
                ReceiverType = KotlinType.FromProtobuf(p.ReceiverType, resolver),
                ReceiverTypeId = p.ReceiverTypeId,
                SetterValueParameter = KotlinValueParameter.FromProtobuf(p.SetterValueParameter, resolver),
                GetterFlags = p.GetterFlags,
                SetterFlags = p.SetterFlags,
                TypeParameters = p.TypeParameters?.Select(tp => KotlinTypeParameter.FromProtobuf(tp, resolver)).ToList(),
                VersionRequirements = p.VersionRequirements
            });
        }
Ejemplo n.º 15
0
 internal static KotlinClass FromProtobuf(Class c, JvmNameResolver resolver)
 {
     return(new KotlinClass {
         CompanionObjectName = c.CompanionObjectName > 0 ? resolver.GetString(c.CompanionObjectName) : null,
         Constructors = c.Constructors?.Select(ctor => KotlinConstructor.FromProtobuf(ctor, resolver)).ToList(),
         EnumEntries = c.EnumEntries?.Select(e => resolver.GetString(e.Name)).ToList(),
         Flags = (KotlinClassFlags)c.Flags,
         FullyQualifiedName = c.FqName > 0 ? resolver.GetString(c.FqName) : null,
         Functions = c.Functions?.Select(f => KotlinFunction.FromProtobuf(f, resolver)).ToList(),
         NestedClassNames = c.NestedClassNames?.Select(n => resolver.GetString(n)).ToList(),
         Properties = c.Properties?.Select(p => KotlinProperty.FromProtobuf(p, resolver)).ToList(),
         SealedSubclassFullyQualifiedNames = c.SealedSubclassFqNames?.Select(n => resolver.GetString(n)).ToList(),
         SuperTypeIds = c.SupertypeIds?.Select(n => resolver.GetString(n)).ToList(),
         SuperTypes = c.Supertypes?.Select(st => KotlinType.FromProtobuf(st, resolver)).ToList(),
         TypeAliases = c.TypeAlias?.Select(tp => KotlinTypeAlias.FromProtobuf(tp, resolver)).ToList(),
         TypeParameters = c.TypeParameters?.Select(tp => KotlinTypeParameter.FromProtobuf(tp, resolver)).ToList(),
         VersionRequirements = c.VersionRequirements,
         TypeTable = KotlinTypeTable.FromProtobuf(c.TypeTable, resolver),
         VersionRequirementTable = KotlinVersionRequirementTable.FromProtobuf(c.VersionRequirementTable, resolver)
     });
 }
Ejemplo n.º 16
0
        internal static KotlinType FromProtobuf(Type t, JvmNameResolver resolver)
        {
            if (t is null)
            {
                return(null);
            }

            return(new KotlinType {
                Arguments = t.Arguments?.Select(a => KotlinTypeArgument.FromProtobuf(a, resolver)).ToList(),
                Nullable = t.Nullable,
                FlexibleTypeCapabilitiesId = t.FlexibleTypeCapabilitiesId,
                FlexibleUpperBound = FromProtobuf(t.FlexibleUpperBound, resolver),
                ClassName = t.ClassName > 0 ? resolver.GetString(t.ClassName) : null,
                TypeParameter = t.TypeParameter,
                TypeParameterName = t.TypeParameterName > 0 ? resolver.GetString(t.TypeParameterName) : null,
                OuterType = FromProtobuf(t.OuterType, resolver),
                OuterTypeId = t.OuterTypeId,
                AbbreviatedType = FromProtobuf(t.AbbreviatedType, resolver),
                AbbreviatedTypeId = t.AbbreviatedTypeId,
                Flags = t.Flags
            });
        }
Ejemplo n.º 17
0
 internal static KotlinClass FromProtobuf(Class c, JvmNameResolver resolver)
 {
     return(new KotlinClass {
         CompanionObjectName = c.CompanionObjectName > 0 ? resolver.GetString(c.CompanionObjectName) : null,
         Constructors = c.Constructors.ToList(resolver, KotlinConstructor.FromProtobuf),
         EnumEntries = c.EnumEntries?.Select(e => resolver.GetString(e.Name)).ToList(),
         Flags = (KotlinClassFlags)c.Flags,
         FullyQualifiedName = c.FqName > 0 ? resolver.GetString(c.FqName) : null,
         Functions = c.Functions.ToList(resolver, KotlinFunction.FromProtobuf),
         Inheritability = (KotlinClassInheritability)((c.Flags & 0b110000) >> 4),
         NestedClassNames = c.NestedClassNames?.Select(n => resolver.GetString(n)).ToList() ?? new List <string> (),
         ObjectType = (KotlinClassType)((c.Flags & 0b111000000) >> 6),
         Properties = c.Properties.ToList(resolver, KotlinProperty.FromProtobuf),
         SealedSubclassFullyQualifiedNames = c.SealedSubclassFqNames?.Select(n => resolver.GetString(n)).ToList(),
         SuperTypeIds = c.SupertypeIds?.Select(n => resolver.GetString(n)).ToList(),
         SuperTypes = c.Supertypes.ToList(resolver, KotlinType.FromProtobuf),
         TypeAliases = c.TypeAlias.ToList(resolver, KotlinTypeAlias.FromProtobuf),
         TypeParameters = c.TypeParameters.ToList(resolver, KotlinTypeParameter.FromProtobuf),
         VersionRequirements = c.VersionRequirements,
         TypeTable = KotlinTypeTable.FromProtobuf(c.TypeTable, resolver),
         VersionRequirementTable = KotlinVersionRequirementTable.FromProtobuf(c.VersionRequirementTable, resolver),
         Visibility = (KotlinClassVisibility)((c.Flags & 0b1110) >> 1)
     });
Ejemplo n.º 18
0
        internal static KotlinAnnotation FromProtobuf(org.jetbrains.kotlin.metadata.jvm.Annotation a, JvmNameResolver resolver)
        {
            if (a is null)
            {
                return(null);
            }

            return(new KotlinAnnotation {
                Id = a.Id,
                Arguments = a.Arguments?.Select(vp => KotlinAnnotationArgument.FromProtobuf(vp, resolver)).ToList()
            });
        }
Ejemplo n.º 19
0
 internal static List <TResult>?ToList <TSource, TResult> (this IEnumerable <TSource>?self, JvmNameResolver resolver, Func <TSource, JvmNameResolver, TResult?> creator)
     where TResult : class
 {
     if (self == null)
     {
         return(null);
     }
     return(self.Select(v => creator(v, resolver) !)
            .Where(v => v != null)
            .ToList());
 }
Ejemplo n.º 20
0
        internal static KotlinAnnotationArgumentValue FromProtobuf(org.jetbrains.kotlin.metadata.jvm.Annotation.Argument.Value value, JvmNameResolver resolver)
        {
            if (value is null)
            {
                return(null);
            }

            return(new KotlinAnnotationArgumentValue {
                Type = (KotlinAnnotationArgumentType)value.type,
                IntValue = value.IntValue,
                FloatValue = value.FloatValue,
                DoubleValue = value.DoubleValue,
                StringValue = resolver.GetString(value.StringValue),
                ClassId = value.ClassId,
                EnumValueId = value.EnumValueId,
                Annotation = KotlinAnnotation.FromProtobuf(value.Annotation, resolver),
                ArrayDimensionCount = value.ArrayDimensionCount,
                ArrayElements = value.ArrayElements?.Select(vp => KotlinAnnotationArgumentValue.FromProtobuf(vp, resolver)).ToList(),
                Flags = value.Flags
            });
        }
Ejemplo n.º 21
0
 internal static KotlinContract FromProtobuf(Contract c, JvmNameResolver resolver)
 {
     return(new KotlinContract {
         Effects = c.Effects?.Select(tp => KotlinEffect.FromProtobuf(tp, resolver)).ToList()
     });
 }
Ejemplo n.º 22
0
        internal static KotlinVersionRequirementTable FromProtobuf(VersionRequirementTable vrt, JvmNameResolver resolver)
        {
            if (vrt is null)
            {
                return(null);
            }

            return(new KotlinVersionRequirementTable {
                Requirements = vrt.Requirements?.Select(t => KotlinVersionRequirement.FromProtobuf(t, resolver)).ToList()
            });
        }
Ejemplo n.º 23
0
        internal static KotlinAnnotationArgument FromProtobuf(org.jetbrains.kotlin.metadata.jvm.Annotation.Argument a, JvmNameResolver resolver)
        {
            if (a is null)
            {
                return(null);
            }

            return(new KotlinAnnotationArgument {
                NameId = a.NameId,
                Value = KotlinAnnotationArgumentValue.FromProtobuf(a.value, resolver)
            });
        }