Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        private void AddProperty(FunctionDefinition node)
        {
            var existing = _scope.LookupNameInScopes(node.Name, NameLookupContext.LookupOptions.Local) as AstPythonProperty;

            if (existing == null)
            {
                existing = new AstPythonProperty(_ast, node, GetLoc(node));
                _scope.SetInScope(node.Name, existing);
            }

            // Treat the rest of the property as a function. "AddOverload" takes the return type
            // and sets it as the property type.
            var funcScope = _scope.Clone();

            if (CreateBuiltinTypes)
            {
                funcScope.SuppressBuiltinLookup = true;
            }
            var funcWalk = new AstAnalysisFunctionWalker(funcScope, node);

            _postWalkers.Add(funcWalk);
            existing.AddOverload(funcWalk.Overload);
        }
 private void ProcessWalker(AstAnalysisFunctionWalker walker)
 {
     // Remove walker before processing as to prevent reentrancy.
     _functionWalkers.Remove(walker.Target);
     walker.Walk();
 }
 public void Add(AstAnalysisFunctionWalker walker)
 => _functionWalkers[walker.Target] = walker;