SLType MapType(BaseDeclaration declContext, SLImportModules modules, NamedTypeSpec spec) { SLType retval = null; if (spec.HasModule) { modules.AddIfNotPresent(spec.Module); } if (declContext.IsTypeSpecGeneric(spec) && !spec.ContainsGenericParameters) { Tuple <int, int> depthIndex = declContext.GetGenericDepthAndIndex(spec); retval = new SLGenericReferenceType(depthIndex.Item1, depthIndex.Item2); } else if (spec.ContainsGenericParameters) { retval = new SLBoundGenericType(spec.NameWithoutModule, spec.GenericParameters.Select(p => MapType(declContext, modules, p, false))); } else { retval = new SLSimpleType(spec.Name.NameWithoutModule()); } if (spec.InnerType == null) { return(retval); } else { return(new SLCompoundType(retval, MapType(declContext, modules, spec.InnerType))); } }
SLType ToClass(SLImportModules modules, SwiftBoundGenericType gt) { SLType slType = MapType(modules, gt.BaseType); SLSimpleType baseType = slType as SLSimpleType; if (baseType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 15, $"Mapping SwiftType to SLType, expected a simple type, but got {baseType.GetType ().Name}."); } IEnumerable <SLType> boundTypes = gt.BoundTypes.Select(st => MapType(modules, st)); return(new SLBoundGenericType(baseType.Name, boundTypes)); }
SLType MapType(BaseDeclaration declContext, SLImportModules modules, NamedTypeSpec spec) { SLType retval = null; if (spec.HasModule(declContext, this.parent)) { modules.AddIfNotPresent(spec.Module); } if (declContext.IsTypeSpecGeneric(spec) && !spec.ContainsGenericParameters) { Tuple <int, int> depthIndex = declContext.GetGenericDepthAndIndex(spec); retval = new SLGenericReferenceType(depthIndex.Item1, depthIndex.Item2); } else if (spec.ContainsGenericParameters) { retval = new SLBoundGenericType(spec.NameWithoutModule, spec.GenericParameters.Select(p => MapType(declContext, modules, p, false))); } else { if (declContext.IsProtocolWithAssociatedTypesFullPath(spec, parent)) { // for T.AssocType var genPart = spec.Module; var depthIndex = declContext.GetGenericDepthAndIndex(genPart); var newGenPart = new SLGenericReferenceType(depthIndex.Item1, depthIndex.Item2); retval = new SLSimpleType($"{newGenPart}.{spec.NameWithoutModule}"); } else { retval = new SLSimpleType(spec.NameWithoutModule); } } if (spec.InnerType == null) { return(retval); } else { return(new SLCompoundType(retval, MapType(declContext, modules, spec.InnerType))); } }