public FunctionAnalysisUnit(FunctionAnalysisUnit originalUnit, CallChain callChain, ArgumentSet callArgs) : base(originalUnit.Ast, null) { _originalUnit = originalUnit; _declUnit = originalUnit._declUnit; Function = originalUnit.Function; CallChain = callChain; var scope = new FunctionScope( Function, Ast, originalUnit.Scope.OuterScope, originalUnit.DeclaringModule.ProjectEntry ); scope.UpdateParameters(this, callArgs, false, originalUnit.Scope as FunctionScope); _scope = scope; var walker = new OverviewWalker(_originalUnit.ProjectEntry, this, Tree); if (Ast.Body != null) { Ast.Body.Walk(walker); } AnalysisLog.NewUnit(this); Enqueue(); }
internal FunctionAnalysisUnit( FunctionInfo function, AnalysisUnit declUnit, InterpreterScope declScope, IPythonProjectEntry declEntry ) : base(function.FunctionDefinition, null) { _declUnit = declUnit; Function = function; _decoratorCalls = new Dictionary<Node, Expression>(); var scope = new FunctionScope(Function, Function.FunctionDefinition, declScope, declEntry); scope.EnsureParameters(this); _scope = scope; AnalysisLog.NewUnit(this); }
internal bool UpdateParameters(FunctionAnalysisUnit unit, ArgumentSet others, bool enqueue = true, FunctionScope scopeWithDefaultParameters = null) { EnsureParameters(unit); var astParams = Function.FunctionDefinition.Parameters; bool added = false; var entry = unit.ProjectEntry; var state = unit.ProjectState; var limits = state.Limits; for (int i = 0; i < others.Args.Length && i < astParams.Count; ++i) { VariableDef param; if (!TryGetVariable(astParams[i].Name, out param)) { Debug.Assert(false, "Parameter " + astParams[i].Name + " has no variable in this scope"); param = AddVariable(astParams[i].Name); } param.MakeUnionStrongerIfMoreThan(limits.NormalArgumentTypes, others.Args[i]); added |= param.AddTypes(entry, others.Args[i], false); } if (_seqParameters != null) { _seqParameters.List.MakeUnionStrongerIfMoreThan(limits.ListArgumentTypes, others.SequenceArgs); added |= _seqParameters.List.AddTypes(unit, new[] { others.SequenceArgs }); } if (_dictParameters != null) { _dictParameters.Dict.MakeUnionStrongerIfMoreThan(limits.DictArgumentTypes, others.DictArgs); added |= _dictParameters.Dict.AddTypes(Function.FunctionDefinition, unit, state.GetConstant(""), others.DictArgs); } if (scopeWithDefaultParameters != null) { for (int i = 0; i < others.Args.Length && i < astParams.Count; ++i) { VariableDef defParam, param; if (TryGetVariable(astParams[i].Name, out param) && !param.TypesNoCopy.Any() && scopeWithDefaultParameters.TryGetVariable(astParams[i].Name, out defParam)) { param.MakeUnionStrongerIfMoreThan(limits.NormalArgumentTypes, defParam.TypesNoCopy); added |= param.AddTypes(entry, defParam.TypesNoCopy, false); } } } if (enqueue && added) { unit.Enqueue(); } return added; }
internal bool UpdateParameters(FunctionAnalysisUnit unit, ArgumentSet others, bool enqueue = true, FunctionScope scopeWithDefaultParameters = null) { EnsureParameters(unit); var astParams = Function.FunctionDefinition.Parameters; bool added = false; var entry = unit.DependencyProject; var state = unit.ProjectState; var limits = state.Limits; for (int i = 0; i < others.Args.Length && i < astParams.Count; ++i) { VariableDef param; if (!TryGetVariable(astParams[i].Name, out param)) { Debug.Assert(false, "Parameter " + astParams[i].Name + " has no variable in this scope"); param = AddVariable(astParams[i].Name); } param.MakeUnionStrongerIfMoreThan(limits.NormalArgumentTypes, others.Args[i]); added |= param.AddTypes(entry, others.Args[i], false, unit.ProjectEntry); } if (_seqParameters != null) { _seqParameters.List.MakeUnionStrongerIfMoreThan(limits.ListArgumentTypes, others.SequenceArgs); added |= _seqParameters.List.AddTypes(unit, new[] { others.SequenceArgs }); } if (_dictParameters != null) { _dictParameters.Dict.MakeUnionStrongerIfMoreThan(limits.DictArgumentTypes, others.DictArgs); added |= _dictParameters.Dict.AddTypes(Function.FunctionDefinition, unit, state.GetConstant(""), others.DictArgs); } if (scopeWithDefaultParameters != null) { for (int i = 0; i < others.Args.Length && i < astParams.Count; ++i) { VariableDef defParam, param; if (TryGetVariable(astParams[i].Name, out param) && !param.HasTypes && scopeWithDefaultParameters.TryGetVariable(astParams[i].Name, out defParam)) { param.MakeUnionStrongerIfMoreThan( limits.NormalArgumentTypes, defParam.GetTypesNoCopy(unit, AnalysisValue.DeclaringModule) ); added |= param.AddTypes(entry, defParam.GetTypesNoCopy(unit, AnalysisValue.DeclaringModule), false, unit.ProjectEntry); } } } if (enqueue && added) { unit.Enqueue(); } return(added); }
internal bool UpdateParameters( FunctionAnalysisUnit unit, ArgumentSet others, bool enqueue = true, FunctionScope scopeWithDefaultParameters = null, bool usePlaceholders = false ) { EnsureParameters(unit, usePlaceholders); var astParams = Function.FunctionDefinition.Parameters; var added = false; var entry = unit.DependencyProject; var state = unit.State; var limits = state.Limits; for (int i = 0; i < others.Args.Length && i < astParams.Length; ++i) { var name = astParams[i].Name; VariableDef param; if (string.IsNullOrEmpty(name)) { continue; } if (name == _seqParameters?.Name) { param = _seqParameters; } else if (name == _dictParameters?.Name) { param = _dictParameters; } else if (!_parameters.TryGetValue(name, out param)) { Debug.Fail($"Parameter {name} has no variable in this function"); _parameters[name] = param = new LocatedVariableDef(Function.AnalysisUnit.ProjectEntry, new EncodedLocation(unit, (Node)astParams[i].NameExpression ?? astParams[i])); } var arg = others.Args[i].Resolve(unit); param.MakeUnionStrongerIfMoreThan(limits.NormalArgumentTypes, arg); added |= param.AddTypes(entry, arg, enqueue, unit.ProjectEntry); } if (_seqParameters != null) { var arg = others.SequenceArgs.Resolve(unit); _seqParameters.List.MakeUnionStrongerIfMoreThan(limits.ListArgumentTypes, arg); added |= _seqParameters.List.AddTypes(unit, new[] { arg }); } if (_dictParameters != null) { var arg = others.DictArgs.Resolve(unit); _dictParameters.Dict.MakeUnionStrongerIfMoreThan(limits.DictArgumentTypes, arg); added |= _dictParameters.Dict.AddTypes(Function.FunctionDefinition, unit, state.GetConstant(""), arg); } if (scopeWithDefaultParameters != null) { for (int i = 0; i < others.Args.Length && i < astParams.Length; ++i) { VariableDef defParam, param; if (TryGetVariable(astParams[i].Name, out param) && !param.HasTypes && scopeWithDefaultParameters.TryGetVariable(astParams[i].Name, out defParam)) { param.MakeUnionStrongerIfMoreThan( limits.NormalArgumentTypes, defParam.GetTypesNoCopy(unit, AnalysisValue.DeclaringModule) ); added |= param.AddTypes(entry, defParam.GetTypesNoCopy(unit, AnalysisValue.DeclaringModule), enqueue, unit.ProjectEntry); } } } if (enqueue && added) { unit.Enqueue(); } return(added); }