예제 #1
0
        // BinaryExpression
        private Result RewriteBinaryExpression(Expression expr, Stack stack)
        {
            BinaryExpression node = (BinaryExpression)expr;

            ChildRewriter cr = new ChildRewriter(this, stack, 3);

            // Left expression executes on the stack as left by parent
            cr.Add(node.Left);
            // Right expression always has non-empty stack (left is on it)
            cr.Add(node.Right);
            // conversion is a lambda, stack state will be ignored
            cr.Add(node.Conversion);

            if (cr.Action == RewriteAction.SpillStack)
            {
#if LINQ
                RequireNoRefArgs(node.Method);
#else
                MarkRefArgs(cr, node.Method, 0);
#endif
            }

            return(cr.Finish(cr.Rewrite ?
                             BinaryExpressionStubs.Create(
                                 node.NodeType,
                                 cr[0],
                                 cr[1],
                                 node.Type,
                                 node.Method,
                                 (LambdaExpression)cr[2]) :
                             expr));
        }
예제 #2
0
        // BinaryExpression: AndAlso, OrElse
        private Result RewriteLogicalBinaryExpression(Expression expr, Stack stack)
        {
            BinaryExpression node = (BinaryExpression)expr;

            // Left expression runs on a stack as left by parent
            Result left = RewriteExpression(node.Left, stack);
            // ... and so does the right one
            Result right = RewriteExpression(node.Right, stack);
            //conversion is a lambda. stack state will be ignored.
            Result conversion = RewriteExpression(node.Conversion, stack);

            RewriteAction action = left.Action | right.Action | conversion.Action;

            if (action != RewriteAction.None)
            {
                // We don't have to worry about byref parameters here, because the
                // factory doesn't allow it (it requires identical parameters and
                // return type from the AndAlso/OrElse method)

                expr = BinaryExpressionStubs.Create(
                    node.NodeType,
                    left.Node,
                    right.Node,
                    node.Type,
                    node.Method,
                    (LambdaExpression)conversion.Node
                    );
            }
            return(new Result(action, expr));
        }
예제 #3
0
        // BinaryExpression: AndAlso, OrElse
        private Result RewriteLogicalBinaryExpression(Expression expr, Stack stack)
        {
            BinaryExpression node = (BinaryExpression)expr;

            // Left expression runs on a stack as left by parent
            Result left = RewriteExpression(node.Left, stack);
            // ... and so does the right one
            Result right = RewriteExpression(node.Right, stack);
            //conversion is a lambda. stack state will be ignored.
            Result conversion = RewriteExpression(node.Conversion, stack);

            RewriteAction action = left.Action | right.Action | conversion.Action;

            if (action != RewriteAction.None)
            {
                // We don't have to worry about byref parameters here, because the
                // factory doesn't allow it (it requires identical parameters and
                // return type from the AndAlso/OrElse method)

                expr = BinaryExpressionStubs.Create(
                    node.NodeType,
                    left.Node,
                    right.Node,
                    node.Type,
                    node.Method,
                    (LambdaExpression)conversion.Node
                    );

#if !LINQ
                /*
                 * CONSIDER: Move logic to reduce logical binary nodes from the Reducer to the stack spiller.
                 *
                 * switch (expr.NodeType)
                 * {
                 *  case ExpressionType.AndAlso:
                 *  case ExpressionType.OrElse:
                 *      expr = Microsoft.CSharp.Expressions.Compiler.Reducer.ReduceLogical((BinaryExpression)expr);
                 *      break;
                 *  case ExpressionType.Coalesce:
                 *      expr = Microsoft.CSharp.Expressions.Compiler.Reducer.ReduceCoalesce((BinaryExpression)expr);
                 *      break;
                 * }
                 */
#endif
            }
            return(new Result(action, expr));
        }