Exemplo n.º 1
0
        public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
        {
            var callArgs = ArgumentSet.FromArgs(FunctionDefinition, unit, args, keywordArgNames);

            if (keywordArgNames != null && keywordArgNames.Any())
            {
                _analysisUnit.AddNamedParameterReferences(unit, keywordArgNames);
            }

            var res = DoCall(node, unit, _analysisUnit, callArgs);

            if (_callsWithClosure != null)
            {
                var chain     = new CallChain(node, unit, _callDepthLimit);
                var aggregate = GetAggregate(unit);

                if (!_callsWithClosure.TryGetValue(aggregate, chain, _callDepthLimit, out var calledUnit) &&
                    !unit.ForEval)
                {
                    _callsSinceLimitChange += 1;
                    if (_callsSinceLimitChange >= ProjectState.Limits.DecreaseCallDepth && _callDepthLimit > 1)
                    {
                        _callDepthLimit       -= 1;
                        _callsSinceLimitChange = 0;
                        AnalysisLog.ReduceCallDepth(this, _callsWithClosure.Count, _callDepthLimit);

                        _callsWithClosure.Clear();
                        chain = chain.Trim(_callDepthLimit);
                    }

                    calledUnit = new FunctionClosureAnalysisUnit(aggregate, (FunctionAnalysisUnit)AnalysisUnit, chain);
                    _callsWithClosure.Add(aggregate, chain, calledUnit);
                    calledUnit.Enqueue();
                }

                Debug.Assert(calledUnit != null || unit.ForEval);

                res.Split(v => v.IsResolvable(), out _, out var nonLazy);
                res = DoCall(node, unit, calledUnit, callArgs);
                res = res.Union(nonLazy);
            }

            var context = unit.ForEval ? ResolutionContext.Complete : new ResolutionContext {
                Caller   = this,
                CallArgs = callArgs,
                CallSite = node
            };

            var r = res.Resolve(unit, context, out _);

            return(r);
        }
Exemplo n.º 2
0
        public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
        {
            var callArgs = ArgumentSet.FromArgs(FunctionDefinition, unit, args, keywordArgNames);

            if (keywordArgNames != null && keywordArgNames.Any())
            {
                _analysisUnit.AddNamedParameterReferences(unit, keywordArgNames);
            }

            var res = DoCall(node, unit, _analysisUnit, callArgs);

            if (_derived != null)
            {
                foreach (FunctionInfo derived in _derived)
                {
                    var derivedResult = derived.DoCall(node, unit, derived._analysisUnit, callArgs);
                    res = res.Union(derivedResult);
                }
            }

            if (_analysisUnit.State.Limits.PropagateParameterTypeToBaseMethods &&
                _analysisUnit.Scope.OuterScope is ClassScope parentClass)
            {
                var baseMethods = DDG.LookupBaseMethods(Name, parentClass.Class.Mro, AnalysisUnit.Ast, AnalysisUnit);
                foreach (FunctionInfo baseMethod in baseMethods.OfType <FunctionInfo>())
                {
                    baseMethod.DoCall(node, unit, baseMethod._analysisUnit, callArgs);
                }
            }

            if (_callsWithClosure != null)
            {
                var chain     = new CallChain(node, unit, _callDepthLimit);
                var aggregate = GetAggregate(unit);

                if (!_callsWithClosure.TryGetValue(aggregate, chain, _callDepthLimit, out var calledUnit) &&
                    !unit.ForEval)
                {
                    _callsSinceLimitChange += 1;
                    if (_callsSinceLimitChange >= ProjectState.Limits.DecreaseCallDepth && _callDepthLimit > 1)
                    {
                        _callDepthLimit       -= 1;
                        _callsSinceLimitChange = 0;
                        AnalysisLog.ReduceCallDepth(this, _callsWithClosure.Count, _callDepthLimit);

                        _callsWithClosure.Clear();
                        chain = chain.Trim(_callDepthLimit);
                    }

                    calledUnit = new FunctionClosureAnalysisUnit(aggregate, (FunctionAnalysisUnit)AnalysisUnit, chain);
                    _callsWithClosure.Add(aggregate, chain, calledUnit);
                    calledUnit.Enqueue();
                }

                Debug.Assert(calledUnit != null || unit.ForEval);

                res.Split(v => v.IsResolvable(), out _, out var nonLazy);
                res = DoCall(node, unit, calledUnit, callArgs);
                res = res.Union(nonLazy);
            }

            var context = unit.ForEval ? ResolutionContext.Complete : new ResolutionContext {
                Caller   = this,
                CallArgs = callArgs,
                CallSite = node
            };

            var r = res.Resolve(unit, context, out _);

            return(r);
        }