Example #1
0
        void SetProperty(IProperty property, Expression reference, Expression value, bool leaveValueOnStack)
        {
            OpCode callOpCode = OpCodes.Call;

            MethodInfo setMethod = GetMethodInfo(property.GetSetMethod());
            IType targetType = null;
            if (null != reference)
            {
                if (!setMethod.IsStatic)
                {
                    Expression target = ((MemberReferenceExpression)reference).Target;
                    targetType = target.ExpressionType;
                    if (setMethod.DeclaringType.IsValueType || targetType is IGenericParameter)
                        LoadAddress(target);
                    else
                    {
                        callOpCode = GetCallOpCode(target, property.GetSetMethod());
                        target.Accept(this);
                        PopType();
                    }
                }
            }

            value.Accept(this);
            EmitCastIfNeeded(property.Type, PopType());

            LocalBuilder local = null;
            if (leaveValueOnStack)
            {
                _il.Emit(OpCodes.Dup);
                local = _il.DeclareLocal(GetSystemType(property.Type));
                _il.Emit(OpCodes.Stloc, local);
            }

            if (targetType is IGenericParameter)
            {
                _il.Emit(OpCodes.Constrained, GetSystemType(targetType));
                callOpCode = OpCodes.Callvirt;
            }

            _il.EmitCall(callOpCode, setMethod, null);

            if (leaveValueOnStack)
            {
                _il.Emit(OpCodes.Ldloc, local);
                PushType(property.Type);
            }
        }
Example #2
0
 void EmitRawBranch(bool branch, Expression expression, Label label)
 {
     expression.Accept(this); PopType();
     _il.Emit(branch ? OpCodes.Brtrue : OpCodes.Brfalse, label);
 }
Example #3
0
        void SetField(Node sourceNode, IField field, Expression reference, Expression value, bool leaveValueOnStack)
        {
            OpCode opSetField = OpCodes.Stsfld;
            if (!field.IsStatic)
            {
                opSetField = OpCodes.Stfld;
                if (null != reference)
                {
                    LoadMemberTarget(
                        ((MemberReferenceExpression)reference).Target,
                        field);
                }
            }

            value.Accept(this);
            EmitCastIfNeeded(field.Type, PopType());

            LocalBuilder local = null;
            if (leaveValueOnStack)
            {
                _il.Emit(OpCodes.Dup);
                local = _il.DeclareLocal(GetSystemType(field.Type));
                _il.Emit(OpCodes.Stloc, local);
            }

            if (field.IsVolatile)
                _il.Emit(OpCodes.Volatile);
            _il.Emit(opSetField, GetFieldInfo(field));

            if (leaveValueOnStack)
            {
                _il.Emit(OpCodes.Ldloc, local);
                PushType(field.Type);
            }
        }
Example #4
0
 void EmitDefaultBranch(bool branch, Expression expression, Label label)
 {
     expression.Accept(this);
     IType type = PopType();
     if (type == TypeSystemServices.DoubleType || type == TypeSystemServices.SingleType)
     {
         EmitDefaultValue(type);
         _il.Emit(branch ? OpCodes.Bne_Un : OpCodes.Beq, label);
     }
     else
     {
         EmitToBoolIfNeeded(expression);
         _il.Emit(branch ? OpCodes.Brtrue : OpCodes.Brfalse, label);
     }
 }
Example #5
0
		void EmitDefaultBranch(bool branch, Expression condition, Label label)
		{	
			if (branch && IsOneEquivalent(condition))
			{
				_il.Emit(OpCodes.Br, label);
				return;
			}

			if (!branch && IsZeroEquivalent(condition))
			{
				_il.Emit(OpCodes.Br, label);
				return;
			}

			condition.Accept(this);

			var type = PopType();
			if (TypeSystemServices.IsFloatingPointNumber(type))
			{
				EmitDefaultValue(type);
				_il.Emit(branch ? OpCodes.Bne_Un : OpCodes.Beq, label);
				return;
			}

			EmitToBoolIfNeeded(condition);
			_il.Emit(branch ? OpCodes.Brtrue : OpCodes.Brfalse, label);
		}
Example #6
0
 void EmitRawBranchTrue(Expression expression, Label label)
 {
     expression.Accept(this); PopType();
     _il.Emit(OpCodes.Brtrue, label);
 }
Example #7
0
 void DefaultBranchTrue(Expression expression, Label label)
 {
     expression.Accept(this);
     IType type = PopType();
     if (TypeSystemServices.DoubleType == type)
     {
         _il.Emit(OpCodes.Ldc_R8, 0.0);
         _il.Emit(OpCodes.Bne_Un, label);
     }
     else if (TypeSystemServices.SingleType == type)
     {
         _il.Emit(OpCodes.Ldc_R4, 0.0f);
         _il.Emit(OpCodes.Bne_Un, label);
     }
     else
     {
         EmitToBoolIfNeeded(expression);
         _il.Emit(OpCodes.Brtrue, label);
     }
 }
Example #8
0
 void DefaultBranchFalse(Expression expression, Label label)
 {
     expression.Accept(this);
     IType type = PopType();
     if (TypeSystemServices.DoubleType == type)
     {
         _il.Emit(OpCodes.Ldc_R8, (double)0.0);
         _il.Emit(OpCodes.Ceq);
         _il.Emit(OpCodes.Brtrue, label);
     }
     else if (TypeSystemServices.SingleType == type)
     {
         _il.Emit(OpCodes.Ldc_R4, (float)0.0);
         _il.Emit(OpCodes.Ceq);
         _il.Emit(OpCodes.Brtrue, label);
     }
     else
     {
         EmitToBoolIfNeeded(expression);
         _il.Emit(OpCodes.Brfalse, label);
     }
 }