public IBoundScope <TItem> GetScope(MethodDefinitionNode node, IScope <TItem> parentScope)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var            methodName  = node.MethodName;
            IScope <TItem> methodScope = new MethodScope <TItem>(methodName, parentScope);


            // Define the method itself
            _scopingStrategy.Define(node, parentScope);

            // Bind the parameters
            foreach (var parameter in node.Parameters)
            {
                _scopingStrategy.Define(parameter, methodScope);
            }

            // Bind the variables
            var body = node.MethodBody;

            if (body == null)
            {
                return(new BoundScope <TItem>(methodScope, node));
            }

            var variableDeclarations = body.Children
                                       .OfType <VariableDefinitionNode>()
                                       .Where(n => n != null)
                                       .ToArray();

            foreach (var declaration in variableDeclarations)
            {
                _scopingStrategy.Define(declaration, methodScope);
            }

            // Bind the method body
            var subBuilder = new ScopeBuilder <TItem>(methodScope, _scopingStrategy);
            var bodyScope  = subBuilder.Visit(body);

            var boundScope = new BoundScope <TItem>(methodScope, node, new[] { bodyScope });

            return(boundScope);
        }
Exemplo n.º 2
0
        public override INode <IScope <TItem> > Clone()
        {
            var clone = new BoundScope <TItem>(_scope, _node, this.Children);

            return(clone);
        }