Exemple #1
0
        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.State;
            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);
        }
Exemple #2
0
        internal bool UpdateParameters(
            FunctionAnalysisUnit unit,
            ArgumentSet others,
            bool enqueue = true,
            FunctionScope scopeWithDefaultParameters = null,
            bool usePlaceholders = false
            )
        {
            EnsureParameters(unit, usePlaceholders);

            var astParams = Function.FunctionDefinition.ParametersInternal;
            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);
        }
Exemple #3
0
        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;
        }