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(); }
public override bool Walk(AssignmentStatement node) { var value = _scope.GetValueFromExpression(node.Right); foreach (var ne in node.Left.OfType <NameExpression>()) { _scope.SetInScope(ne.Name, Clone(value)); } return(base.Walk(node)); }
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(); }
public override bool Walk(AssignmentStatement node) { var value = _scope.GetValueFromExpression(node.Right); if ((value == null || value.MemberType == PythonMemberType.Unknown) && WarnAboutUndefinedValues) { _log?.Log(TraceLevel.Warning, "UndefinedValue", node.Right.ToCodeString(_ast).Trim()); } foreach (var ne in node.Left.OfType <NameExpression>()) { _scope.SetInScope(ne.Name, Clone(value)); } return(base.Walk(node)); }
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() { 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 override bool Walk(AssignmentStatement node) { var value = _scope.GetValueFromExpression(node.Right); if ((value == null || value.MemberType == PythonMemberType.Unknown) && WarnAboutUndefinedValues) { _log?.Log(TraceLevel.Warning, "UndefinedValue", node.Right.ToCodeString(_ast).Trim()); } if ((value as IPythonConstant)?.Type?.TypeId == BuiltinTypeId.Ellipsis) { value = _unknownType; } foreach (var expr in node.Left.OfType <ExpressionWithAnnotation>()) { if (expr.Expression is NameExpression ne) { var annType = _scope.GetValueFromExpression(expr.Annotation) as IPythonType; if (annType != null) { _scope.SetInScope(ne.Name, new AstPythonConstant(annType, GetLoc(expr.Expression))); } else { _scope.SetInScope(ne.Name, _unknownType); } } } foreach (var ne in node.Left.OfType <NameExpression>()) { _scope.SetInScope(ne.Name, Clone(value)); } return(base.Walk(node)); }
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(); }