public override bool Walk(FunctionDefinition node) { if (node.IsLambda) { return(false); } var existing = _scope.LookupNameInScopes(node.Name, NameLookupContext.LookupOptions.Local) as AstPythonFunction; if (existing == null) { existing = new AstPythonFunction(_ast, _module, CurrentClass, node, GetLoc(node)); _scope.SetInScope(node.Name, existing); } var funcScope = _scope.Clone(); if (CreateBuiltinTypes) { funcScope.SuppressBuiltinLookup = true; } var funcWalk = new AstAnalysisFunctionWalker(funcScope, node); _postWalkers.Add(funcWalk); existing.AddOverload(funcWalk.Overload); // Do not recurse into functions return(false); }
public override bool Walk(FunctionDefinition node) { if (node.IsLambda) { return(false); } var dec = (node.Decorators?.DecoratorsInternal).MaybeEnumerate(); if (dec.OfType <NameExpression>().Any(n => n.Name == "property")) { AddProperty(node); return(false); } foreach (var setter in dec.OfType <MemberExpression>().Where(n => n.Name == "setter")) { if (setter.Target is NameExpression src) { var existingProp = _scope.LookupNameInScopes(src.Name, NameLookupContext.LookupOptions.Local) as AstPythonProperty; if (existingProp != null) { // Setter for an existing property, so don't create a function existingProp.MakeSettable(); return(false); } } } var existing = _scope.LookupNameInScopes(node.Name, NameLookupContext.LookupOptions.Local) as AstPythonFunction; if (existing == null) { existing = new AstPythonFunction(_ast, _module, CurrentClass, node, GetLoc(node)); _scope.SetInScope(node.Name, existing); } var funcScope = _scope.Clone(); if (CreateBuiltinTypes) { funcScope.SuppressBuiltinLookup = true; } var funcWalk = new AstAnalysisFunctionWalker(funcScope, node); _postWalkers.Add(funcWalk); existing.AddOverload(funcWalk.Overload); // Do not recurse into functions return(false); }
public AstAnalysisFunctionWalker( NameLookupContext scope, FunctionDefinition targetFunction ) { _scope = scope ?? throw new ArgumentNullException(nameof(scope)); _target = targetFunction ?? throw new ArgumentNullException(nameof(targetFunction)); _returnTypes = new List <IPythonType>(); _overload = new AstPythonFunctionOverload( AstPythonFunction.MakeParameters(_scope.Ast, _target), _scope.GetLocOfName(_target, _target.NameExpression), _returnTypes ); }
public IPythonFunction GetConstructors() { if (_constructor == null) { var fns = _members.Select(m => m.GetConstructors()).Where(c => c != null).ToList(); if (fns.Count == 0) { return(null); } var fn = new AstPythonFunction(fns[0]); foreach (var o in fns.Skip(1).SelectMany(f => f.Overloads)) { fn.AddOverload(o); } _constructor = fn; } return(_constructor); }