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)));
            }
        }
Ejemplo n.º 2
0
        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)));
            }
        }