コード例 #1
0
        // Block
        private Result RewriteBlockExpression(Expression expr, Stack stack)
        {
            BlockExpression node = (BlockExpression)expr;

            int           count  = node.ExpressionCount;
            RewriteAction action = RewriteAction.None;

            Expression[] clone = null;
            for (int i = 0; i < count; i++)
            {
                Expression expression = node.GetExpression(i);
                // All statements within the block execute at the
                // same stack state.
                Result rewritten = RewriteExpression(expression, stack);
                action |= rewritten.Action;

                if (clone == null && rewritten.Action != RewriteAction.None)
                {
                    clone = Clone(node.Expressions, i);
                }

                if (clone != null)
                {
                    clone[i] = rewritten.Node;
                }
            }

            if (action != RewriteAction.None)
            {
                // okay to wrap since we know no one can mutate the clone array
                expr = node.Rewrite(null, clone);
            }
            return(new Result(action, expr));
        }
コード例 #2
0
            protected internal override Expression VisitBlock(BlockExpression node)
            {
                if (node.Variables.Count > 0)
                {
                    _shadowedVars.Push(new HashSet <ParameterExpression>(node.Variables));
                }

                var b = ExpressionVisitorUtils.VisitBlockExpressions(this, node);

                if (node.Variables.Count > 0)
                {
                    _shadowedVars.Pop();
                }

                return(b == null ? node : node.Rewrite(node.Variables, b));
            }
コード例 #3
0
        /// <summary>
        /// Visits the children of the <see cref="BlockExpression" />.
        /// </summary>
        /// <param name="node">The expression to visit.</param>
        /// <returns>The modified expression, if it or any subexpression was modified;
        /// otherwise, returns the original expression.</returns>
        protected internal virtual Expression VisitBlock(BlockExpression node)
        {
            int count = node.ExpressionCount;

            Expression[] nodes = null;
            for (int i = 0; i < count; i++)
            {
                Expression oldNode = node.GetExpression(i);
                Expression newNode = Visit(oldNode);

                if (oldNode != newNode)
                {
                    if (nodes == null)
                    {
                        nodes = new Expression[count];
                    }
                    nodes[i] = newNode;
                }
            }
            var v = VisitAndConvert(node.Variables, "VisitBlock");

            if (v == node.Variables && nodes == null)
            {
                return(node);
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    if (nodes[i] == null)
                    {
                        nodes[i] = node.GetExpression(i);
                    }
                }
            }

            return(node.Rewrite(v, nodes));
        }