Exemplo n.º 1
0
        public override void PostWalk(PythonAst node)
        {
            _scope.PopScope();

            foreach (var walker in _postWalkers)
            {
                walker.Walk();
            }

            base.PostWalk(node);
        }
Exemplo n.º 2
0
        public void Walk()
        {
            IMember self = null;
            bool    classmethod, staticmethod;

            GetMethodType(_target, out classmethod, out staticmethod);
            if (!staticmethod)
            {
                self = _scope.LookupNameInScopes("__class__", NameLookupContext.LookupOptions.Local);
                if (!classmethod)
                {
                    var cls = self as IPythonType;
                    if (cls == null)
                    {
                        self = null;
                    }
                    else
                    {
                        self = new AstPythonConstant(cls, ((cls as ILocatedMember)?.Locations).MaybeEnumerate().ToArray());
                    }
                }
            }

            _scope.PushScope();
            if (self != null)
            {
                var p0 = _target.Parameters?.FirstOrDefault();
                if (p0 != null && !string.IsNullOrEmpty(p0.Name))
                {
                    _scope.SetInScope(p0.Name, self);
                }
            }
            _target.Walk(this);
            _scope.PopScope();
        }
Exemplo n.º 3
0
        public void Walk()
        {
            var self = GetSelf();

            _selfType = (self as AstPythonConstant)?.Type as AstPythonType;

            if (_target.ReturnAnnotation != null)
            {
                var retAnn = new TypeAnnotation(_scope.Ast.LanguageVersion, _target.ReturnAnnotation);
                var m      = retAnn.GetValue(new AstTypeAnnotationConverter(_scope));
                if (m is IPythonMultipleMembers mm)
                {
                    _returnTypes.AddRange(mm.Members.OfType <IPythonType>());
                }
                else if (m is IPythonType type)
                {
                    _returnTypes.Add(type);
                }
            }

            _scope.PushScope();
            if (self != null)
            {
                var p0 = _target.ParametersInternal?.FirstOrDefault();
                if (p0 != null && !string.IsNullOrEmpty(p0.Name))
                {
                    _scope.SetInScope(p0.Name, self);
                }
            }
            _target.Walk(this);
            _scope.PopScope();
        }
Exemplo n.º 4
0
        public void Walk()
        {
            IMember self = null;
            bool    classmethod, staticmethod;

            GetMethodType(_target, out classmethod, out staticmethod);
            if (!staticmethod)
            {
                self = _scope.LookupNameInScopes("__class__", NameLookupContext.LookupOptions.Local);
                if (!classmethod)
                {
                    var cls = self as IPythonType;
                    if (cls == null)
                    {
                        self = null;
                    }
                    else
                    {
                        self = new AstPythonConstant(cls, ((cls as ILocatedMember)?.Locations).MaybeEnumerate().ToArray());
                    }
                }
            }

            if (_target.ReturnAnnotation != null)
            {
                var retAnn = new TypeAnnotation(_scope.Ast.LanguageVersion, _target.ReturnAnnotation);
                var m      = retAnn.GetValue(new AstTypeAnnotationConverter(_scope));
                if (m is IPythonMultipleMembers mm)
                {
                    _returnTypes.AddRange(mm.Members.OfType <IPythonType>());
                }
                else if (m is IPythonType type)
                {
                    _returnTypes.Add(type);
                }
            }

            _scope.PushScope();
            if (self != null)
            {
                var p0 = _target.ParametersInternal?.FirstOrDefault();
                if (p0 != null && !string.IsNullOrEmpty(p0.Name))
                {
                    _scope.SetInScope(p0.Name, self);
                }
            }
            _target.Walk(this);
            _scope.PopScope();
        }
        public void Walk()
        {
            var self = GetSelf();

            _selfType = (self as AstPythonConstant)?.Type as AstPythonType;

            _overload.ReturnTypes.AddRange(_scope.GetTypesFromAnnotation(_target.ReturnAnnotation));

            _scope.PushScope();
            if (self != null)
            {
                var p0 = _target.Parameters.FirstOrDefault();
                if (p0 != null && !string.IsNullOrEmpty(p0.Name))
                {
                    _scope.SetInScope(p0.Name, self);
                }
            }
            _target.Walk(this);
            _scope.PopScope();
        }
        public void Walk()
        {
            var self = GetSelf();

            _selfType = (self as AstPythonConstant)?.Type as AstPythonType;

            var annotationTypes = _scope.GetTypesFromAnnotation(Target.ReturnAnnotation).ExcludeDefault();

            _overload.ReturnTypes.AddRange(annotationTypes);

            _scope.PushScope();

            // Declare self, if any
            var skip = 0;

            if (self != null)
            {
                var p0 = Target.Parameters.FirstOrDefault();
                if (p0 != null && !string.IsNullOrEmpty(p0.Name))
                {
                    _scope.SetInScope(p0.Name, self);
                    skip++;
                }
            }

            // Declare parameters in scope
            foreach (var p in Target.Parameters.Skip(skip).Where(p => !string.IsNullOrEmpty(p.Name)))
            {
                var value = _scope.GetValueFromExpression(p.DefaultValue);
                _scope.SetInScope(p.Name, value ?? _scope.UnknownType);
            }

            // return type from the annotation always wins, no need to walk the body.
            if (!annotationTypes.Any())
            {
                Target.Walk(this);
            }
            _scope.PopScope();
        }
Exemplo n.º 7
0
        public override void PostWalk(PythonAst node)
        {
            _scope.PopScope();

            base.PostWalk(node);
        }