예제 #1
0
        public override void Emit(IMemberEmitter member, ILGenerator gen)
        {
            if (reference != null)
            {
                ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen);
            }
            else if (expression != null)
            {
                expression.Emit(member, gen);
            }
            else
            {
                if (member.ReturnType != typeof(void))
                {
                    OpCodeUtil.EmitLoadOpCodeForDefaultValueOfType(gen, member.ReturnType);
                }
            }

            gen.Emit(OpCodes.Ret);
        }
예제 #2
0
        public override void Emit(IMemberEmitter member, ILGenerator gen)
        {
            if (reference != null)
            {
                ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen);
            }
            else if (expression != null)
            {
                expression.Emit(member, gen);
            }

            var notNull = gen.DefineLabel();

            gen.Emit(OpCodes.Brtrue_S, notNull);
            ifNull.Emit(member, gen);
            gen.MarkLabel(notNull);
            if (ifNotNull != null)             // yeah, I know that reads funny :)
            {
                ifNotNull.Emit(member, gen);
            }
        }
예제 #3
0
 public override void Emit(IMemberEmitter member, ILGenerator gen)
 {
     ArgumentsUtil.EmitLoadOwnerAndReference(target.OwnerReference, gen);
     expression.Emit(member, gen);
     target.StoreReference(gen);
 }
        public override void Emit(IMemberEmitter member, ILGenerator gen)
        {
            right.Emit(member, gen);

            if (fromType == target)
            {
                return;
            }

            if (fromType.IsByRef)
            {
                fromType = fromType.GetElementType();
            }

            if (target.IsByRef)
            {
                target = target.GetElementType();
            }

            if (target.IsPointer && fromType == typeof(object))
            {
                gen.Emit(OpCodes.Unbox_Any, typeof(IntPtr));
                gen.Emit(OpCodes.Call, ArgumentsUtil.PointerFromIntPtr());
            }
            else if (target == typeof(object) && fromType.IsPointer)
            {
                gen.Emit(OpCodes.Call, ArgumentsUtil.IntPtrFromPointer());
                gen.Emit(OpCodes.Box, typeof(IntPtr));
            }
            else if (target.IsValueType)
            {
                if (fromType.IsValueType)
                {
                    throw new NotImplementedException("Cannot convert between distinct value types");
                }
                else
                {
                    // Unbox conversion
                    // Assumes fromType is a boxed value
                    // if we can, we emit a box and ldind, otherwise, we will use unbox.any
                    if (LdindOpCodesDictionary.Instance[target] != LdindOpCodesDictionary.EmptyOpCode)
                    {
                        gen.Emit(OpCodes.Unbox, target);
                        OpCodeUtil.EmitLoadIndirectOpCodeForType(gen, target);
                    }
                    else
                    {
                        gen.Emit(OpCodes.Unbox_Any, target);
                    }
                }
            }
            else
            {
                if (fromType.IsValueType)
                {
                    // Box conversion
                    gen.Emit(OpCodes.Box, fromType);
                    EmitCastIfNeeded(typeof(object), target, gen);
                }
                else
                {
                    // Possible down-cast
                    EmitCastIfNeeded(fromType, target, gen);
                }
            }
        }
 public override void Emit(IMemberEmitter member, ILGenerator gen)
 {
     // TODO: Should it discard any possible return value with a pop?
     expression.Emit(member, gen);
 }