Exemple #1
0
        private UserFunctionValue CreateUserFunction(FunctionObject node, AnalysisUnit outerUnit)
        {
            UserFunctionValue func = null;

            BaseSpecialization[] specializations;
            var funcName = node.Name ?? node.NameGuess;

            if (funcName != null &&
                _specializations.TryGetValue(funcName, out specializations))
            {
                foreach (var specialization in specializations)
                {
                    if (specialization.IsMatch(node))
                    {
                        func = new SpecializedUserFunctionValue(
                            specialization.Specialization,
                            node,
                            outerUnit,
                            _scope,
                            specialization.CallBase
                            );
                        break;
                    }
                }
            }

            if (func == null)
            {
                func = new UserFunctionValue(node, outerUnit, _scope, _isNested);
            }

            _scope.GlobalEnvironment.AddNodeValue(NodeEnvironmentKind.UserFunctionValue, node, func.Proxy);
            return(func);
        }
        public CartesianProductFunctionAnalysisUnit(UserFunctionValue funcInfo, EnvironmentRecord environment, AnalysisUnit outerUnit, UserFunctionValue.CallArgs callArgs, VariableDef returnValue)
            : base(funcInfo, outerUnit, environment.Parent, outerUnit.ProjectEntry, environment) {
            _callArgs = callArgs;
            _returnValue = returnValue;
            _this = new VariableDef();

            var funcScope = environment as FunctionEnvironmentRecord;

            var specLocals = new List<CartesianLocalVariable>();
            ProcessVariablesForScope(funcScope, specLocals);
            _specializedLocals = specLocals.ToArray();
        }
        internal FunctionAnalysisUnit(
            UserFunctionValue function,
            AnalysisUnit declUnit,
            EnvironmentRecord declScope,
            IJsProjectEntry declEntry,
            EnvironmentRecord scope
        )
            : base(function.FunctionObject, declUnit.Tree, null) {
            _declUnit = declUnit;
            Function = function;

            _env = scope;
        }
Exemple #4
0
        internal FunctionAnalysisUnit AddFunction(FunctionObject node, AnalysisUnit outerUnit, bool isExpression = false)
        {
            EnvironmentRecord scope;

            if (!_scope.GlobalEnvironment.TryGetNodeEnvironment(node, out scope))
            {
                if (node.Body == null)
                {
                    return(null);
                }

                IAnalysisSet      functionObj;
                UserFunctionValue func = null;
                if (!_scope.GlobalEnvironment.TryGetNodeValue(NodeEnvironmentKind.UserFunctionValue, node, out functionObj))
                {
                    func = CreateUserFunction(node, outerUnit);
                }
                else
                {
                    func = (UserFunctionValue)functionObj;
                }

                var funcScope = GetFunctionEnvironment(func);
                scope = funcScope;

                VariableDef[] parameters = new VariableDef[node.ParameterDeclarations != null ? node.ParameterDeclarations.Length : 0];
                for (int i = 0; i < parameters.Length; i++)
                {
                    parameters[i] = funcScope.AddLocatedVariable(
                        node.ParameterDeclarations[i].Name,
                        node.ParameterDeclarations[i],
                        _curUnit.ProjectEntry
                        );
                }

                _scope.Children.Add(scope);
                _scope.GlobalEnvironment.AddNodeEnvironment(node, scope);

                if (!isExpression && node.Name != null)
                {
                    // lambdas don't have their names published
                    var funcVar = _scope.AddLocatedVariable(node.Name, node, funcScope.AnalysisUnit);
                    funcVar.AddTypes(funcScope.AnalysisUnit, func.SelfSet);
                }

                funcScope.AnalysisUnit.Enqueue();
            }

            return(((FunctionEnvironmentRecord)scope).AnalysisUnit);
        }
        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;
        }
Exemple #6
0
        public CartesianProductFunctionAnalysisUnit(UserFunctionValue funcInfo, EnvironmentRecord environment, AnalysisUnit outerUnit, UserFunctionValue.CallArgs callArgs, VariableDef returnValue)
            : base(funcInfo, outerUnit, environment.Parent, outerUnit.ProjectEntry, environment)
        {
            _callArgs    = callArgs;
            _returnValue = returnValue;
            _this        = new VariableDef();

            var funcScope = environment as FunctionEnvironmentRecord;

            var specLocals = new List <CartesianLocalVariable>();

            ProcessVariablesForScope(funcScope, specLocals);
            _specializedLocals = specLocals.ToArray();
        }
Exemple #7
0
        internal FunctionAnalysisUnit(
            UserFunctionValue function,
            AnalysisUnit declUnit,
            EnvironmentRecord declScope,
            IJsProjectEntry declEntry,
            EnvironmentRecord scope
            )
            : base(function.FunctionObject, declUnit.Tree, null)
        {
            _declUnit = declUnit;
            Function  = function;

            _env = scope;
        }
Exemple #8
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;
        }
        internal IEnumerable <AnalysisVariable> ToVariables(AnalysisUnit unit, IReferenceable referenceable)
        {
            LocatedVariableDef locatedDef = referenceable as LocatedVariableDef;

            if (locatedDef != null &&
                locatedDef.Entry.Tree != null &&    // null tree if there are errors in the file
                locatedDef.DeclaringVersion == locatedDef.Entry.AnalysisVersion)
            {
                var start = locatedDef.Node;

                yield return(new AnalysisVariable(VariableType.Definition, locatedDef.Entry.Tree.ResolveLocation(locatedDef.Entry, start)));
            }

            VariableDef def = referenceable as VariableDef;

            if (def != null)
            {
                foreach (var location in def.GetTypesNoCopy(unit).SelectMany(type => type.Value.Locations))
                {
                    yield return(new AnalysisVariable(VariableType.Value, location));
                }
            }

            UserFunctionValue func = referenceable as UserFunctionValue;

            if (func != null &&
                func.ProjectEntry.Tree != null &&
                func.DeclaringVersion == func.ProjectEntry.AnalysisVersion)
            {
                var start = func.FunctionObject;

                yield return(new AnalysisVariable(VariableType.Definition, func.ProjectEntry.Tree.ResolveLocation(func.ProjectEntry, start)));
            }

            foreach (var reference in referenceable.Definitions)
            {
                yield return(new AnalysisVariable(
                                 _definitionsAreReferences ? VariableType.Reference : VariableType.Definition,
                                 reference.Value.GetLocationInfo(reference.Key)
                                 ));
            }

            foreach (var reference in referenceable.References)
            {
                yield return(new AnalysisVariable(VariableType.Reference, reference.Value.GetLocationInfo(reference.Key)));
            }
        }
        //public readonly GeneratorInfo Generator;

        public FunctionEnvironmentRecord(
            UserFunctionValue function,
            FunctionAnalysisUnit analysisUnit,
            Node node,
            EnvironmentRecord declScope,
            IJsProjectEntry declModule
        )
            : base(node, declScope) {
            _function = function;
            _this = new VariableDef();
            AnalysisUnit = analysisUnit;
#if FALSE
            if (Function.FunctionObject.IsGenerator) {
                Generator = new GeneratorInfo(function.ProjectState, declModule);
                ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false);
            }
#endif
        }
        //public readonly GeneratorInfo Generator;

        public FunctionEnvironmentRecord(
            UserFunctionValue function,
            FunctionAnalysisUnit analysisUnit,
            Node node,
            EnvironmentRecord declScope,
            IJsProjectEntry declModule
            )
            : base(node, declScope)
        {
            _function    = function;
            _this        = new VariableDef();
            AnalysisUnit = analysisUnit;
#if FALSE
            if (Function.FunctionObject.IsGenerator)
            {
                Generator = new GeneratorInfo(function.ProjectState, declModule);
                ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false);
            }
#endif
        }
        private UserFunctionValue CreateUserFunction(FunctionObject node, AnalysisUnit outerUnit) {
            UserFunctionValue func = null;
            BaseSpecialization[] specializations;
            var funcName = node.Name ?? node.NameGuess;
            if (funcName != null &&
                _specializations.TryGetValue(funcName, out specializations)) {
                foreach (var specialization in specializations) {
                    if (specialization.IsMatch(node)) {
                        func = new SpecializedUserFunctionValue(
                            specialization.Specialization,
                            node,
                            outerUnit,
                            _scope,
                            specialization.CallBase
                        );
                        break;
                    }
                }
            }

            if (func == null) {
                func = new UserFunctionValue(node, outerUnit, _scope, _isNested);
            }

            _scope.GlobalEnvironment.AddNodeValue(NodeEnvironmentKind.UserFunctionValue, node, func.Proxy);
            return func;
        }
 protected virtual FunctionEnvironmentRecord GetFunctionEnvironment(UserFunctionValue function) {
     return (FunctionEnvironmentRecord)function.AnalysisUnit.Environment;
 }
Exemple #14
0
 protected virtual FunctionEnvironmentRecord GetFunctionEnvironment(UserFunctionValue function)
 {
     return((FunctionEnvironmentRecord)function.AnalysisUnit.Environment);
 }
Exemple #15
0
 public ArgumentsValue(UserFunctionValue function)
     : base(function.ProjectEntry) {
     _function = function;
 }