コード例 #1
0
        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();
        }