Beispiel #1
0
        public override bool Walk(FunctionDefinition node)
        {
            if (node.Body == null || node.Name == null) {
                return false;
            }

            var queue = _entry.ProjectState.Queue;
            var scopes = new InterpreterScope[_scopes.Count + 1];
            _scopes.CopyTo(scopes);

            _analysisStack.Push(_curUnit);
            var unit = _curUnit = new AnalysisUnit(node, scopes, _curUnit);
            var function = new FunctionInfo(unit, _entry);
            var funcScope = new FunctionScope(function);

            _entry.MyScope.GetOrMakeNodeVariable(node, x => function.SelfSet);
            _scopes.Push(funcScope);
            scopes[scopes.Length - 1] = funcScope;

            if (!node.IsLambda) {
                // lambdas don't have their names published
                var scope = _scopes[_scopes.Count - 2];
                scope.SetVariable(node, unit, node.Name, function.SelfSet);
            }

            var newParams = new VariableDef[node.Parameters.Count];
            int index = 0;
            foreach (var param in node.Parameters) {
                newParams[index++] = funcScope.DefineVariable(param, _curUnit);
            }
            function.SetParameters(newParams);

            PushPositionScope(node, funcScope);

            return true;
        }