コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: WebScope.cs プロジェクト: ByteSempai/Ubiquitous
 internal WebScope(RtmpEndpoint endpoint, IGlobalScope globalScope, ApplicationConfiguration appConfig)
     : base(null)
 {
     _endpoint = endpoint;
     _appConfig = appConfig;
     base.Parent = globalScope;
 }
コード例 #3
0
 protected PythonLazyType(TModel model, ModuleFactory mf, IGlobalScope gs, IPythonType declaringType)
 {
     _model        = model ?? throw new ArgumentNullException(nameof(model));
     ModuleFactory = mf ?? throw new ArgumentNullException(nameof(mf));
     GlobalScope   = gs ?? throw new ArgumentNullException(nameof(gs));
     DeclaringType = declaringType;
 }
コード例 #4
0
        public static IMember CreateMember(MemberModel model, ModuleFactory mf, IGlobalScope gs, IPythonType declaringType)
        {
            var unkType = mf.Module.Interpreter.UnknownType;

            switch (model)
            {
            case ClassModel cm:
                return(new PythonLazyClassType(cm, mf, gs, declaringType));

            case FunctionModel fm:
                return(new PythonLazyFunctionType(fm, mf, gs, declaringType));

            case PropertyModel pm:
                return(new PythonLazyPropertyType(pm, mf, gs, declaringType));

            case NamedTupleModel ntm:
                var itemTypes = ntm.ItemTypes.Select(n => mf.ConstructType(n) ?? unkType).ToArray();
                return(new NamedTupleType(ntm.Name, ntm.ItemNames, itemTypes, mf.Module, ntm.IndexSpan.ToSpan()));

            case TypeVarModel tvm:
                return(new GenericTypeParameter(tvm.Name, mf.Module,
                                                tvm.Constraints.Select(n => mf.ConstructType(n) ?? unkType).ToArray(),
                                                mf.ConstructType(tvm.Bound), tvm.Covariant, tvm.Contravariant, default));

            case VariableModel vm:
                var m = mf.ConstructMember(vm.Value) ?? unkType;
                return(new Variable(vm.Name, m, VariableSource.Declaration, new Location(mf.Module, vm.IndexSpan?.ToSpan() ?? default)));
            }
            Debug.Fail("Unsupported model type.");
            return(null);
        }
コード例 #5
0
        public override void Populate(ModuleFactory mf, IPythonType declaringType, IGlobalScope gs)
        {
            var all = Classes.Concat <MemberModel>(Properties).Concat(Methods).Concat(Fields);

            foreach (var m in all)
            {
                m.Populate(mf, _cls, gs);
            }
        }
コード例 #6
0
 public DocumentAnalysis(IDocument document, int version, IGlobalScope globalScope, PythonAst ast)
 {
     Check.ArgumentNotNull(nameof(document), document);
     Check.ArgumentNotNull(nameof(globalScope), globalScope);
     Document    = document;
     Version     = version;
     GlobalScope = globalScope;
     Ast         = ast;
 }
コード例 #7
0
        public override IMember Create(ModuleFactory mf, IPythonType declaringType, IGlobalScope gs)
        {
            var bound = mf.ConstructType(Bound);

            bound = bound.IsUnknown() ? null : bound;
            return(new GenericTypeParameter(Name, mf.Module,
                                            Constraints.Select(mf.ConstructType).ToArray(),
                                            bound, Covariant, Contravariant, default));
        }
コード例 #8
0
 public DocumentAnalysis(IDocument document, int version, IGlobalScope globalScope, IExpressionEvaluator eval, IReadOnlyList <string> starImportMemberNames)
 {
     Check.ArgumentNotNull(nameof(document), document);
     Check.ArgumentNotNull(nameof(globalScope), globalScope);
     Document              = document;
     Version               = version;
     GlobalScope           = globalScope;
     ExpressionEvaluator   = eval;
     StarImportMemberNames = starImportMemberNames;
 }
コード例 #9
0
        public override void Populate(ModuleFactory mf, IPythonType declaringType, IGlobalScope gs)
        {
            _property.SetDocumentation(Documentation);

            var o = new PythonFunctionOverload(_property, mf.DefaultLocation);

            o.SetDocumentation(Documentation);
            o.SetReturnValue(mf.ConstructMember(ReturnType), true);
            _property.AddOverload(o);
        }
コード例 #10
0
        public PythonLazyFunctionType(FunctionModel model, ModuleFactory mf, IGlobalScope gs, IPythonType declaringType)
            : base(model, mf, gs, declaringType)
        {
            var location = new Location(mf.Module, model.IndexSpan.ToSpan());

            _function = new PythonFunctionType(model.Name, location, declaringType, model.Documentation);

            // TODO: restore signature string so hover (tooltip) documentation won't have to restore the function.
            // parameters and return type just to look at them.
            foreach (var om in model.Overloads)
            {
                var o = new PythonLazyOverload(om, mf, _function);
                _function.AddOverload(o);
            }
            SetInnerType(_function);
        }
コード例 #11
0
        public PythonLazyPropertyType(PropertyModel model, ModuleFactory mf, IGlobalScope gs, IPythonType declaringType)
            : base(model, mf, gs, declaringType)
        {
            var location = new Location(mf.Module, model.IndexSpan.ToSpan());

            _property = new PythonPropertyType(model.Name, location, model.Documentation, declaringType,
                                               model.Attributes.HasFlag(FunctionAttributes.Abstract));

            // parameters and return type just to look at them.
            var o = new PythonFunctionOverload(_property, location);

            o.SetDocumentation(model.Documentation);
            _property.AddOverload(o);

            IsReadOnly = model.IsReadOnly;
            SetInnerType(_property);
        }
コード例 #12
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);
            }
        }
コード例 #13
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);
        }
コード例 #14
0
ファイル: ScopeResolver.cs プロジェクト: apakian/fluorinefx
		public ScopeResolver(IGlobalScope globalScope)
		{
			_globalScope = globalScope;
		}