예제 #1
0
        internal FunctionAnalysisUnit(
            UserFunctionValue function,
            AnalysisUnit declUnit,
            EnvironmentRecord declScope,
            IJsProjectEntry declEntry
        )
            : base(function.FunctionObject, declUnit.Tree, null) {
            _declUnit = declUnit;
            Function = function;

            var scope = new FunctionEnvironmentRecord(Function, this, Function.FunctionObject, declScope, declEntry);
            scope.EnsureParameters(this);
            _env = scope;
        }
예제 #2
0
        internal FunctionAnalysisUnit(
            UserFunctionValue function,
            AnalysisUnit declUnit,
            EnvironmentRecord declScope,
            IJsProjectEntry declEntry
            )
            : base(function.FunctionObject, declUnit.Tree, null)
        {
            _declUnit = declUnit;
            Function  = function;

            var scope = new FunctionEnvironmentRecord(Function, this, Function.FunctionObject, declScope, declEntry);

            scope.EnsureParameters(this);
            _env = scope;
        }
예제 #3
0
        public bool AddArgumentTypes(FunctionEnvironmentRecord funcScope, IAnalysisSet @this, IAnalysisSet[] arguments, int typeLimit = Int32.MaxValue)
        {
            bool added = false, withinTypeCountRange = true;

            if (Ast.ParameterDeclarations != null)
            {
                for (int i = 0; i < Ast.ParameterDeclarations.Length && i < arguments.Length; i++)
                {
                    var variable = funcScope.GetVariable(Ast.ParameterDeclarations[i].Name);
                    if (typeLimit != Int32.MaxValue)
                    {
                        added |= variable.MakeUnionStrongerIfMoreThan(typeLimit, arguments[i]);
                        if (variable.AddTypes(this, arguments[i], false))
                        {
                            if (variable.UnionStrength == UnionComparer.MAX_STRENGTH &&
                                variable.TypesNoCopy.Count > typeLimit * 3)
                            {
                                withinTypeCountRange = false;
                            }
                        }
                    }
                    else
                    {
                        added |= variable.AddTypes(this, arguments[i], false);
                    }
                }
            }

            if (@this != null)
            {
                added |= funcScope._this.AddTypes(this, @this, false);
                if (typeLimit != Int32.MaxValue)
                {
                    added |= funcScope._this.MakeUnionStrongerIfMoreThan(typeLimit, @this);
                }
            }
            return(withinTypeCountRange && added);
        }
예제 #4
0
        public bool AddArgumentTypes(FunctionEnvironmentRecord funcScope, IAnalysisSet @this, IAnalysisSet[] arguments, int typeLimit = Int32.MaxValue) {
            bool added = false, withinTypeCountRange = true;
            if (Ast.ParameterDeclarations != null) {
                for (int i = 0; i < Ast.ParameterDeclarations.Length && i < arguments.Length; i++) {
                    var variable = funcScope.GetVariable(Ast.ParameterDeclarations[i].Name);
                    if (typeLimit != Int32.MaxValue) {
                        added |= variable.MakeUnionStrongerIfMoreThan(typeLimit, arguments[i]);                        
                        if (variable.AddTypes(this, arguments[i], false)) {
                            if (variable.UnionStrength == UnionComparer.MAX_STRENGTH &&
                                variable.TypesNoCopy.Count > typeLimit * 3) {
                                withinTypeCountRange = false;
                            }
                        }
                    } else {
                        added |= variable.AddTypes(this, arguments[i], false);
                    }
                }
            }

            if (@this != null) {
                added |= funcScope._this.AddTypes(this, @this, false);
                if (typeLimit != Int32.MaxValue) {
                    added |= funcScope._this.MakeUnionStrongerIfMoreThan(typeLimit, @this);
                }
            }
            return withinTypeCountRange && added;
        }