Пример #1
0
        void EmitLeftLiftedToNullBinary(EmitContext ec)
        {
            var ig = ec.ig;

            var ret  = ig.DefineLabel();
            var done = ig.DefineLabel();

            var left = ec.EmitStored(this.left);

            ec.EmitNullableHasValue(left);
            ig.Emit(OpCodes.Brfalse, ret);

            ec.EmitNullableGetValueOrDefault(left);
            ec.Emit(right);

            EmitBinaryOperator(ec);

            ec.EmitNullableNew(Type);

            ig.Emit(OpCodes.Br, done);

            ig.MarkLabel(ret);

            var temp = ig.DeclareLocal(Type);

            ec.EmitNullableInitialize(temp);

            ig.MarkLabel(done);
        }
        private void EmitUserDefinedLiftedLogicalShortCircuit(EmitContext ec)
        {
            ILGenerator  ig     = ec.ig;
            bool         flag   = base.NodeType == ExpressionType.AndAlso;
            Label        label  = ig.DefineLabel();
            Label        label2 = ig.DefineLabel();
            Label        label3 = ig.DefineLabel();
            Label        label4 = ig.DefineLabel();
            LocalBuilder local  = ec.EmitStored(this.left);

            ec.EmitNullableHasValue(local);
            ig.Emit(OpCodes.Brfalse, (!flag) ? label : label3);
            ec.EmitNullableGetValueOrDefault(local);
            ec.EmitCall((!flag) ? this.GetTrueOperator() : this.GetFalseOperator());
            ig.Emit(OpCodes.Brtrue, label2);
            ig.MarkLabel(label);
            LocalBuilder local2 = ec.EmitStored(this.right);

            ec.EmitNullableHasValue(local2);
            ig.Emit(OpCodes.Brfalse, label3);
            ec.EmitNullableGetValueOrDefault(local);
            ec.EmitNullableGetValueOrDefault(local2);
            ec.EmitCall(this.method);
            ec.EmitNullableNew(base.Type);
            ig.Emit(OpCodes.Br, label4);
            ig.MarkLabel(label2);
            ec.EmitLoad(local);
            ig.Emit(OpCodes.Br, label4);
            ig.MarkLabel(label3);
            LocalBuilder local3 = ig.DeclareLocal(base.Type);

            ec.EmitNullableInitialize(local3);
            ig.MarkLabel(label4);
        }
Пример #3
0
        void EmitLiftedUnary(EmitContext ec)
        {
            var ig = ec.ig;

            var from = ec.EmitStored(operand);
            var to   = ig.DeclareLocal(Type);

            var has_value = ig.DefineLabel();
            var done      = ig.DefineLabel();

            ec.EmitNullableHasValue(from);
            ig.Emit(OpCodes.Brtrue, has_value);

            // if not has value
            ec.EmitNullableInitialize(to);

            ig.Emit(OpCodes.Br, done);

            ig.MarkLabel(has_value);
            // if has value
            ec.EmitNullableGetValueOrDefault(from);

            EmitUnaryOperator(ec);

            ec.EmitNullableNew(Type);

            ig.MarkLabel(done);
        }
Пример #4
0
        void EmitLiftedLogicalShortCircuit(EmitContext ec)
        {
            var ig            = ec.ig;
            var and           = NodeType == ExpressionType.AndAlso;
            var left_is_null  = ig.DefineLabel();
            var ret_from_left = ig.DefineLabel();
            var ret_null      = ig.DefineLabel();
            var ret_new       = ig.DefineLabel();
            var done          = ig.DefineLabel();

            var left = ec.EmitStored(this.left);

            ec.EmitNullableHasValue(left);
            ig.Emit(OpCodes.Brfalse, left_is_null);

            ec.EmitNullableGetValueOrDefault(left);

            ig.Emit(OpCodes.Ldc_I4_0);
            ig.Emit(OpCodes.Ceq);
            ig.Emit(and ? OpCodes.Brtrue : OpCodes.Brfalse, ret_from_left);

            ig.MarkLabel(left_is_null);
            var right = ec.EmitStored(this.right);

            ec.EmitNullableHasValue(right);
            ig.Emit(OpCodes.Brfalse_S, ret_null);

            ec.EmitNullableGetValueOrDefault(right);

            ig.Emit(OpCodes.Ldc_I4_0);
            ig.Emit(OpCodes.Ceq);

            ig.Emit(and ? OpCodes.Brtrue : OpCodes.Brfalse, ret_from_left);

            ec.EmitNullableHasValue(left);
            ig.Emit(OpCodes.Brfalse, ret_null);

            ig.Emit(and ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
            ig.Emit(OpCodes.Br_S, ret_new);

            ig.MarkLabel(ret_from_left);
            ig.Emit(and ? OpCodes.Ldc_I4_0 : OpCodes.Ldc_I4_1);

            ig.MarkLabel(ret_new);
            ec.EmitNullableNew(Type);
            ig.Emit(OpCodes.Br, done);

            ig.MarkLabel(ret_null);
            var ret = ig.DeclareLocal(Type);

            ec.EmitNullableInitialize(ret);

            ig.MarkLabel(done);
        }
Пример #5
0
 void EmitNullableConstant(EmitContext ec, Type type, object value)
 {
     if (value == null)
     {
         var local = ec.ig.DeclareLocal(type);
         ec.EmitNullableInitialize(local);
     }
     else
     {
         EmitConstant(ec, type.GetFirstGenericArgument(), value);
         ec.EmitNullableNew(type);
     }
 }
Пример #6
0
 private void EmitConvertToNullable(EmitContext ec)
 {
     ec.Emit(operand);
     if (IsUnBoxing())
     {
         EmitUnbox(ec);
         return;
     }
     if (operand.Type != base.Type.GetNotNullableType())
     {
         EmitPrimitiveConversion(ec, operand.Type, base.Type.GetNotNullableType());
     }
     ec.EmitNullableNew(base.Type);
 }
Пример #7
0
 void EmitNullableConstant(EmitContext ec, Type type, object value)
 {
     if (value == null)
     {
         var ig    = ec.ig;
         var local = ig.DeclareLocal(type);
         ig.Emit(OpCodes.Ldloca, local);
         ig.Emit(OpCodes.Initobj, type);
         ig.Emit(OpCodes.Ldloc, local);
     }
     else
     {
         EmitConstant(ec, type.GetFirstGenericArgument(), value);
         ec.EmitNullableNew(type);
     }
 }
Пример #8
0
        private void EmitLiftedUnary(EmitContext ec)
        {
            ILGenerator  ig     = ec.ig;
            LocalBuilder local  = ec.EmitStored(operand);
            LocalBuilder local2 = ig.DeclareLocal(base.Type);
            Label        label  = ig.DefineLabel();
            Label        label2 = ig.DefineLabel();

            ec.EmitNullableHasValue(local);
            ig.Emit(OpCodes.Brtrue, label);
            ec.EmitNullableInitialize(local2);
            ig.Emit(OpCodes.Br, label2);
            ig.MarkLabel(label);
            ec.EmitNullableGetValueOrDefault(local);
            EmitUnaryOperator(ec);
            ec.EmitNullableNew(base.Type);
            ig.MarkLabel(label2);
        }
Пример #9
0
        void EmitUserDefinedLiftedLogicalShortCircuit(EmitContext ec)
        {
            var ig  = ec.ig;
            var and = NodeType == ExpressionType.AndAlso;

            var left_is_null = ig.DefineLabel();
            var ret_left     = ig.DefineLabel();
            var ret_null     = ig.DefineLabel();
            var done         = ig.DefineLabel();

            var left = ec.EmitStored(this.left);

            ec.EmitNullableHasValue(left);
            ig.Emit(OpCodes.Brfalse, and ? ret_null : left_is_null);

            ec.EmitNullableGetValueOrDefault(left);
            ec.EmitCall(and ? GetFalseOperator() : GetTrueOperator());
            ig.Emit(OpCodes.Brtrue, ret_left);

            ig.MarkLabel(left_is_null);
            var right = ec.EmitStored(this.right);

            ec.EmitNullableHasValue(right);
            ig.Emit(OpCodes.Brfalse, ret_null);

            ec.EmitNullableGetValueOrDefault(left);
            ec.EmitNullableGetValueOrDefault(right);
            ec.EmitCall(method);

            ec.EmitNullableNew(Type);
            ig.Emit(OpCodes.Br, done);

            ig.MarkLabel(ret_left);
            ec.EmitLoad(left);
            ig.Emit(OpCodes.Br, done);

            ig.MarkLabel(ret_null);
            var ret = ig.DeclareLocal(Type);

            ec.EmitNullableInitialize(ret);

            ig.MarkLabel(done);
        }
Пример #10
0
        private void EmitUserDefinedLiftedToNullOperator(EmitContext ec)
        {
            ILGenerator  ig     = ec.ig;
            LocalBuilder local  = ec.EmitStored(this.operand);
            Label        label  = ig.DefineLabel();
            Label        label2 = ig.DefineLabel();

            ec.EmitNullableHasValue(local);
            ig.Emit(OpCodes.Brfalse, label);
            ec.EmitNullableGetValueOrDefault(local);
            ec.EmitCall(this.method);
            ec.EmitNullableNew(base.Type);
            ig.Emit(OpCodes.Br, label2);
            ig.MarkLabel(label);
            LocalBuilder local2 = ig.DeclareLocal(base.Type);

            ec.EmitNullableInitialize(local2);
            ig.MarkLabel(label2);
        }
        private void EmitLeftLiftedToNullBinary(EmitContext ec)
        {
            ILGenerator  ig     = ec.ig;
            Label        label  = ig.DefineLabel();
            Label        label2 = ig.DefineLabel();
            LocalBuilder local  = ec.EmitStored(this.left);

            ec.EmitNullableHasValue(local);
            ig.Emit(OpCodes.Brfalse, label);
            ec.EmitNullableGetValueOrDefault(local);
            ec.Emit(this.right);
            this.EmitBinaryOperator(ec);
            ec.EmitNullableNew(base.Type);
            ig.Emit(OpCodes.Br, label2);
            ig.MarkLabel(label);
            LocalBuilder local2 = ig.DeclareLocal(base.Type);

            ec.EmitNullableInitialize(local2);
            ig.MarkLabel(label2);
        }
Пример #12
0
        private void EmitLiftedLogicalShortCircuit(EmitContext ec)
        {
            ILGenerator  ig     = ec.ig;
            bool         flag   = base.NodeType == ExpressionType.AndAlso;
            Label        label  = ig.DefineLabel();
            Label        label2 = ig.DefineLabel();
            Label        label3 = ig.DefineLabel();
            Label        label4 = ig.DefineLabel();
            Label        label5 = ig.DefineLabel();
            LocalBuilder local  = ec.EmitStored(left);

            ec.EmitNullableHasValue(local);
            ig.Emit(OpCodes.Brfalse, label);
            ec.EmitNullableGetValueOrDefault(local);
            ig.Emit(OpCodes.Ldc_I4_0);
            ig.Emit(OpCodes.Ceq);
            ig.Emit((!flag) ? OpCodes.Brfalse : OpCodes.Brtrue, label2);
            ig.MarkLabel(label);
            LocalBuilder local2 = ec.EmitStored(right);

            ec.EmitNullableHasValue(local2);
            ig.Emit(OpCodes.Brfalse_S, label3);
            ec.EmitNullableGetValueOrDefault(local2);
            ig.Emit(OpCodes.Ldc_I4_0);
            ig.Emit(OpCodes.Ceq);
            ig.Emit((!flag) ? OpCodes.Brfalse : OpCodes.Brtrue, label2);
            ec.EmitNullableHasValue(local);
            ig.Emit(OpCodes.Brfalse, label3);
            ig.Emit((!flag) ? OpCodes.Ldc_I4_0 : OpCodes.Ldc_I4_1);
            ig.Emit(OpCodes.Br_S, label4);
            ig.MarkLabel(label2);
            ig.Emit((!flag) ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
            ig.MarkLabel(label4);
            ec.EmitNullableNew(base.Type);
            ig.Emit(OpCodes.Br, label5);
            ig.MarkLabel(label3);
            LocalBuilder local3 = ig.DeclareLocal(base.Type);

            ec.EmitNullableInitialize(local3);
            ig.MarkLabel(label5);
        }
Пример #13
0
        void EmitUserDefinedLiftedToNullOperator(EmitContext ec)
        {
            var ig    = ec.ig;
            var local = ec.EmitStored(operand);

            var ret  = ig.DefineLabel();
            var done = ig.DefineLabel();

            ec.EmitNullableHasValue(local);
            ig.Emit(OpCodes.Brfalse, ret);

            ec.EmitNullableGetValueOrDefault(local);
            ec.EmitCall(method);
            ec.EmitNullableNew(Type);
            ig.Emit(OpCodes.Br, done);

            ig.MarkLabel(ret);

            var temp = ig.DeclareLocal(Type);

            ec.EmitNullableInitialize(temp);

            ig.MarkLabel(done);
        }