public override IMember Create(ModuleFactory mf, IPythonType declaringType, IGlobalScope gs) { if (_cls != null) { return(_cls); } _cls = new PythonClassType(Name, new Location(mf.Module, IndexSpan.ToSpan())); var bases = CreateBases(mf, gs); _cls.SetBases(bases); _cls.SetDocumentation(Documentation); if (GenericParameterValues.Length > 0) { _cls.StoreGenericParameters( _cls, _cls.GenericParameters.Keys.ToArray(), GenericParameterValues.ToDictionary( k => _cls.GenericParameters.Keys.First(x => x == k.Name), v => mf.ConstructType(v.Type) ) ); } var all = Classes.Concat <MemberModel>(Properties).Concat(Methods).Concat(Fields); foreach (var m in all) { _cls.AddMember(m.Name, m.Create(mf, _cls, gs), false); } return(_cls); }
public override IMember Create(ModuleFactory mf, IPythonType declaringType, IGlobalScope gs) { if (_namedTuple != null) { return(_namedTuple); } var itemTypes = ItemTypes.Select(mf.ConstructType).ToArray(); _namedTuple = new NamedTupleType(Name, ItemNames, itemTypes, mf.Module, IndexSpan.ToSpan()); return(_namedTuple); }
public override IMember Create(ModuleFactory mf, IPythonType declaringType, IGlobalScope gs) => _property ?? (_property = new PythonPropertyType(Name, new Location(mf.Module, IndexSpan.ToSpan()), Documentation, declaringType, (Attributes & FunctionAttributes.Abstract) != 0));
public override void Populate(ModuleFactory mf, IPythonType declaringType, IGlobalScope gs) { // Create inner functions and classes first since function may be returning one of them. var all = Classes.Concat <MemberModel>(Functions).ToArray(); foreach (var model in all) { _function.AddMember(Name, model.Create(mf, _function, gs), overwrite: true); } foreach (var model in all) { model.Populate(mf, _function, gs); } foreach (var om in Overloads) { var o = new PythonFunctionOverload(_function, new Location(mf.Module, IndexSpan.ToSpan())); o.SetDocumentation(Documentation); o.SetReturnValue(mf.ConstructMember(om.ReturnType), true); o.SetParameters(om.Parameters.Select(p => ConstructParameter(mf, p)).ToArray()); _function.AddOverload(o); } }
public override IMember Create(ModuleFactory mf, IPythonType declaringType, IGlobalScope gs) => _function ?? (_function = new PythonFunctionType(Name, new Location(mf.Module, IndexSpan.ToSpan()), declaringType, Documentation));
public override IMember Create(ModuleFactory mf, IPythonType declaringType, IGlobalScope gs) { var m = mf.ConstructMember(Value) ?? mf.Module.Interpreter.UnknownType; return(new Variable(Name, m, VariableSource.Declaration, new Location(mf.Module, IndexSpan?.ToSpan() ?? default))); }