Example #1
0
        public override void Emit(IEasyMember member, ILGenerator gen)
        {
            _right.Emit(member, gen);

            if (_fromType == _target)
            {
                return;
            }

            if (_fromType.IsByRef)
            {
                throw new NotSupportedException("Cannot convert from ByRef types");
            }

            if (_target.IsByRef)
            {
                throw new NotSupportedException("Cannot convert to ByRef types");
            }

            if (_target.IsValueType)
            {
                if (_fromType.IsValueType)
                {
                    throw new NotImplementedException("Cannot convert between distinct value types at the moment");
                }
                else
                {
                    // Unbox conversion
                    // Assumes fromType is a boxed value
                    gen.Emit(OpCodes.Unbox, _target);
                    OpCodeUtil.EmitLoadIndirectOpCodeForType(gen, _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(IEasyMember member, ILGenerator gen)
        {
            if (OpCodes.Brfalse.Equals(_operation) ||
                OpCodes.Brfalse_S.Equals(_operation) ||
                OpCodes.Brtrue.Equals(_operation) ||
                OpCodes.Brtrue_S.Equals(_operation))
            {
                // Unary operators
                _left.Emit(member, gen);
            }
            else
            {
                // Binary operators
                _left.Emit(member, gen);
                _right.Emit(member, gen);
            }

            Label truePart = gen.DefineLabel();
            Label exitPart = gen.DefineLabel();

            gen.Emit(_operation, truePart);

            if (_falseStmts.Count != 0)
            {
                foreach (Statement stmt in _falseStmts)
                {
                    stmt.Emit(member, gen);
                }
            }

            gen.Emit(OpCodes.Br_S, exitPart);

            gen.MarkLabel(truePart);
            if (_trueStmts.Count != 0)
            {
                foreach (Statement stmt in _trueStmts)
                {
                    stmt.Emit(member, gen);
                }
            }

            gen.MarkLabel(exitPart);
        }
Example #3
0
 public override void Emit(IEasyMember member, System.Reflection.Emit.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);
 }
Example #4
0
 public override void Emit(IEasyMember member, ILGenerator gen)
 {
     _left.Emit(member, gen);
     _right.Emit(member, gen);
     gen.Emit(_operation);
 }
Example #5
0
 public override void Emit(IEasyMember member, System.Reflection.Emit.ILGenerator gen)
 {
     _expression.Emit(member, gen);
 }