Beispiel #1
0
        private IEnumerable <IPythonType> CreateBases(ModuleFactory mf, IGlobalScope gs)
        {
            var ntBases = NamedTupleBases.Select(ntb => {
                var n = ntb.Create(mf, _cls, gs);
                ntb.Populate(mf, _cls, gs);
                return(n);
            }).OfType <IPythonType>().ToArray();

            var is3x       = mf.Module.Interpreter.LanguageVersion.Is3x();
            var basesNames = Bases.Select(b => is3x && b == "object" ? null : b).ExcludeDefault().ToArray();
            var bases      = basesNames.Select(mf.ConstructType).ExcludeDefault().Concat(ntBases).ToArray();

            if (GenericBaseParameters.Length > 0)
            {
                // Generic class. Need to reconstruct generic base so code can then
                // create specific types off the generic class.
                var genericBase = bases.OfType <IGenericType>().FirstOrDefault(b => b.Name == "Generic");
                if (genericBase != null)
                {
                    var typeVars = GenericBaseParameters.Select(n => gs.Variables[n]?.Value).OfType <IGenericTypeParameter>().ToArray();
                    //Debug.Assert(typeVars.Length > 0, "Class generic type parameters were not defined in the module during restore");
                    if (typeVars.Length > 0)
                    {
                        var genericWithParameters = genericBase.CreateSpecificType(new ArgumentSet(typeVars, null, null));
                        if (genericWithParameters != null)
                        {
                            bases = bases.Except(Enumerable.Repeat(genericBase, 1)).Concat(Enumerable.Repeat(genericWithParameters, 1)).ToArray();
                        }
                    }
                }
                else
                {
                    Debug.Fail("Generic class does not have generic base.");
                }
            }
            return(bases);
        }
Beispiel #2
0
 protected BaseList GetBaseList()
 => !Any(Bases) ? null
         : BaseLists.Create(
     Bases.Select(b => new BaseType(b.Name,
                                    Any(b.TypeArguments) ? new TypeArgumentList(
                                        b.TypeArguments.Select(typeArgument => new TypeArgumentListAssociation(typeArgument)).ToList()) : null)).ToArray());