Ejemplo n.º 1
0
        protected override Expression VisitBinary(BinaryExpression node)
        {
            Expression result;

            switch (node.NodeType)
            {
            case ExpressionType.AndAlso:
            {
                var firstConditionIsFalse = Guid.NewGuid().ToString();
                var jump = Guid.NewGuid().ToString();

                result = node;
                Visit(node.Left);
                IL.Brfalse(firstConditionIsFalse);
                Visit(node.Right);
                IL
                .Br_S(jump)
                .MarkLabel(firstConditionIsFalse)
                .Ldc(0)
                .MarkLabel(jump);
            }
            break;

            case ExpressionType.OrElse:
            {
                var firstConditionIsTrue = Guid.NewGuid().ToString();
                var jump = Guid.NewGuid().ToString();

                result = node;
                Visit(node.Left);
                IL.Brtrue(firstConditionIsTrue);
                Visit(node.Right);
                IL
                .Br_S(jump)
                .MarkLabel(firstConditionIsTrue)
                .Ldc(1)
                .MarkLabel(jump);
            }
            break;

            default:
                result = base.VisitBinary(node);
                switch (node.NodeType)
                {
                case ExpressionType.Add:
                    IL.Add();
                    break;

                case ExpressionType.Divide:
                    IL.Div();
                    break;

                case ExpressionType.Multiply:
                    IL.Mul();
                    break;

                case ExpressionType.Subtract:
                    IL.Sub();
                    break;

                case ExpressionType.GreaterThan:
                    IL.Cgt();
                    break;

                case ExpressionType.GreaterThanOrEqual:
                    IL.Cge();
                    break;

                case ExpressionType.LessThan:
                    IL.Clt();
                    break;

                case ExpressionType.LessThanOrEqual:
                    IL.Cle();
                    break;

                case ExpressionType.Equal:
                    IL.Ceq();
                    break;

                default:
                    throw new NotSupportedException();
                }
                break;
            }

            return(result);
        }
Ejemplo n.º 2
0
        protected override Expression VisitBinary(BinaryExpression node)
        {
            Expression result;

            if (node.NodeType == ExpressionType.AndAlso)
            {
                string firstConditionIsFalse = Guid.NewGuid().ToString();
                string jump = Guid.NewGuid().ToString();

                result = node;
                Visit(node.Left);
                IL.Brfalse(firstConditionIsFalse);
                Visit(node.Right);
                IL
                .Br_S(jump)
                .MarkLabel(firstConditionIsFalse)
                .Ldc(0)
                .MarkLabel(jump);
            }
            else if (node.NodeType == ExpressionType.OrElse)
            {
                string firstConditionIsTrue = Guid.NewGuid().ToString();
                string jump = Guid.NewGuid().ToString();

                result = node;
                Visit(node.Left);
                IL.Brtrue(firstConditionIsTrue);
                Visit(node.Right);
                IL
                .Br_S(jump)
                .MarkLabel(firstConditionIsTrue)
                .Ldc(1)
                .MarkLabel(jump);
            }
            else
            {
                result = base.VisitBinary(node);
                if (node.NodeType == ExpressionType.Add)
                {
                    IL.Add();
                }
                else if (node.NodeType == ExpressionType.Divide)
                {
                    IL.Div();
                }
                else if (node.NodeType == ExpressionType.Multiply)
                {
                    IL.Mul();
                }
                else if (node.NodeType == ExpressionType.Subtract)
                {
                    IL.Sub();
                }
                else if (node.NodeType == ExpressionType.GreaterThan)
                {
                    IL.Cgt();
                }
                else if (node.NodeType == ExpressionType.GreaterThanOrEqual)
                {
                    IL.Cge();
                }
                else if (node.NodeType == ExpressionType.LessThan)
                {
                    IL.Clt();
                }
                else if (node.NodeType == ExpressionType.LessThanOrEqual)
                {
                    IL.Cle();
                }
                else if (node.NodeType == ExpressionType.Equal)
                {
                    IL.Ceq();
                }
                else
                {
                    throw new NotSupportedException();
                }
            }

            return(result);
        }