Пример #1
0
            private void BinaryShiftExpression(BinaryExpression binaryExpression)
            {
                binaryExpression.Left.Accept(this);

                binaryExpression.Right.Accept(this);

                int bits = Marshal.SizeOf(binaryExpression.Left.Type) * 8;

                ILUtil.EmitConstant(_il, bits - 1);
                _il.Emit(OpCodes.And);

                switch (binaryExpression.ExpressionType)
                {
                case ExpressionType.ShiftLeft:
                    _il.Emit(OpCodes.Shl);
                    break;

                case ExpressionType.ShiftRight:
                    if (TypeUtil.IsUnsigned(binaryExpression.Left.Type))
                    {
                        _il.Emit(OpCodes.Shr_Un);
                    }
                    else
                    {
                        _il.Emit(OpCodes.Shr);
                    }
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }
Пример #2
0
            public void VariableAccess(VariableAccess variableAccess)
            {
                _il.Emit(OpCodes.Ldarg_0);
                ILUtil.EmitConstant(_il, variableAccess.ParameterIndex);
                _il.Emit(OpCodes.Ldelem_Ref);

                _compiler.ExtendedConvertToType(typeof(object), variableAccess.Type, false);
            }
Пример #3
0
            public void UnaryExpression(UnaryExpression unaryExpression)
            {
                switch (unaryExpression.ExpressionType)
                {
                case ExpressionType.Minus:
                    unaryExpression.Operand.Accept(this);

                    _il.Emit(OpCodes.Neg);
                    break;

                case ExpressionType.Not:
                    unaryExpression.Operand.Accept(this);

                    if (TypeUtil.IsInteger(unaryExpression.Operand.Type))
                    {
                        _il.Emit(OpCodes.Not);
                    }
                    else
                    {
                        ILUtil.EmitConstant(_il, 0);
                        _il.Emit(OpCodes.Ceq);
                    }
                    break;

                case ExpressionType.LogicalNot:
                    unaryExpression.Operand.Accept(this);

                    ILUtil.EmitConstant(_il, 0);
                    _il.Emit(OpCodes.Ceq);
                    break;

                case ExpressionType.BitwiseNot:
                    unaryExpression.Operand.Accept(this);

                    _il.Emit(OpCodes.Not);
                    break;

                case ExpressionType.Plus:
                case ExpressionType.Group:
                    // No-ops.

                    unaryExpression.Operand.Accept(this);
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
Пример #4
0
 public void Constant(Constant constant)
 {
     if (constant.Value == null)
     {
         ILUtil.EmitNull(_il);
     }
     else if (constant.Value is DateTime)
     {
         ILUtil.EmitConstant(_il, ((DateTime)constant.Value).Ticks);
         ILUtil.EmitNew(_il, typeof(DateTime).GetConstructor(new[] { typeof(long) }));
     }
     else if (constant.Value is TimeSpan)
     {
         ILUtil.EmitConstant(_il, ((TimeSpan)constant.Value).Ticks);
         ILUtil.EmitNew(_il, typeof(TimeSpan).GetConstructor(new[] { typeof(long) }));
     }
     else
     {
         ILUtil.EmitConstant(_il, constant.Value);
     }
 }
Пример #5
0
            private void BinaryLogicalExpression(BinaryExpression binaryExpression)
            {
                Label beforeLabel;
                Label afterLabel;

                switch (binaryExpression.ExpressionType)
                {
                case ExpressionType.And:
                case ExpressionType.LogicalAnd:
                    beforeLabel = _il.DefineLabel();
                    afterLabel  = _il.DefineLabel();

                    binaryExpression.Left.Accept(this);
                    _il.Emit(OpCodes.Brfalse, beforeLabel);

                    binaryExpression.Right.Accept(this);
                    _il.Emit(OpCodes.Br, afterLabel);

                    _il.MarkLabel(beforeLabel);
                    ILUtil.EmitConstant(_il, 0);
                    _il.MarkLabel(afterLabel);
                    break;

                case ExpressionType.AndBoth:
                    binaryExpression.Left.Accept(this);
                    binaryExpression.Right.Accept(this);

                    _il.Emit(OpCodes.And);
                    break;

                case ExpressionType.Or:
                case ExpressionType.LogicalOr:
                    beforeLabel = _il.DefineLabel();
                    afterLabel  = _il.DefineLabel();

                    binaryExpression.Left.Accept(this);
                    _il.Emit(OpCodes.Brtrue, beforeLabel);

                    binaryExpression.Right.Accept(this);
                    _il.Emit(OpCodes.Br, afterLabel);

                    _il.MarkLabel(beforeLabel);
                    ILUtil.EmitConstant(_il, 1);
                    _il.MarkLabel(afterLabel);
                    break;

                case ExpressionType.OrBoth:
                    binaryExpression.Left.Accept(this);
                    binaryExpression.Right.Accept(this);

                    _il.Emit(OpCodes.Or);
                    break;

                case ExpressionType.Xor:
                    binaryExpression.Left.Accept(this);
                    binaryExpression.Right.Accept(this);

                    _il.Emit(OpCodes.Xor);
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }