Ejemplo n.º 1
0
        internal FunctionAnalysisUnit(FunctionInfo function, AnalysisUnit declUnit, InterpreterScope declScope)
            : base(function.FunctionDefinition, null)
        {
            _declUnit = declUnit;
            Function = function;
            _decoratorCalls = new Dictionary<Node, Expression>();

            var scope = new FunctionScope(Function, Function.FunctionDefinition, declScope);
            scope.EnsureParameters(this, null);
            _scope = scope;

            AnalysisLog.NewUnit(this);
        }
Ejemplo n.º 2
0
        public FunctionAnalysisUnit(FunctionAnalysisUnit originalUnit, CallChain callChain, ArgumentSet callArgs)
            : base(originalUnit.Ast, null)
        {
            _originalUnit = originalUnit;
            _declUnit = originalUnit._declUnit;
            Function = originalUnit.Function;
            _decoratorCalls = originalUnit._decoratorCalls;

            CallChain = callChain;

            var scope = new FunctionScope(Function, Ast, originalUnit.Scope.OuterScope);
            scope.UpdateParameters(this, callArgs, false, originalUnit.Scope as FunctionScope);
            _scope = scope;

            var walker = new OverviewWalker(originalUnit.ProjectEntry, this);
            if (Ast.Body != null) {
                Ast.Body.Walk(walker);
            }

            AnalysisLog.NewUnit(this);
            Enqueue();
        }
Ejemplo n.º 3
0
        internal bool UpdateParameters(FunctionAnalysisUnit unit, ArgumentSet others, bool enqueue = true, FunctionScope scopeWithDefaultParameters = null)
        {
            EnsureParameters(unit, scopeWithDefaultParameters);

            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 (!Variables.TryGetValue(astParams[i].Name, out param)) {
                    Debug.Assert(false, "Parameter " + astParams[i].Name + " has no variable in this scope");
                }
                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 (enqueue && added) {
                unit.Enqueue();
            }
            return added;
        }
Ejemplo n.º 4
0
 internal void EnsureParameters(FunctionAnalysisUnit unit, FunctionScope scopeWithDefaultParameters = null)
 {
     var astParams = Function.FunctionDefinition.Parameters;
     for (int i = 0; i < astParams.Count; ++i) {
         VariableDef param, defParam;
         if (!Variables.TryGetValue(astParams[i].Name, out param)) {
             if (astParams[i].Kind == ParameterKind.List) {
                 param = _seqParameters = _seqParameters ?? new ListParameterVariableDef(unit, astParams[i]);
             } else if (astParams[i].Kind == ParameterKind.Dictionary) {
                 param = _dictParameters = _dictParameters ?? new DictParameterVariableDef(unit, astParams[i]);
             } else {
                 param = new LocatedVariableDef(unit.ProjectEntry, astParams[i]);
             }
             if (scopeWithDefaultParameters != null && scopeWithDefaultParameters != this &&
                 scopeWithDefaultParameters.Variables.TryGetValue(astParams[i].Name, out defParam)) {
                 defParam.CopyTo(param);
             }
             AddVariable(astParams[i].Name, param);
         }
     }
 }