EmitGet() protected method

protected EmitGet ( CodeGen g ) : void
g CodeGen
return void
Esempio n. 1
0
        internal void EmitGetHelper(Operand op, Type desiredType, bool allowExplicitConversion)
        {
            if (desiredType.IsByRef)
            {
                if (op.Type != desiredType.GetElementType())
                {
                    throw new InvalidOperationException(Properties.Messages.ErrByRefTypeMismatch);
                }

                op.EmitAddressOf(this);
                return;
            }

            if ((object)op == null)
            {
                if (desiredType.IsValueType)
                {
                    throw new ArgumentNullException("op");
                }
                il.Emit(OpCodes.Ldnull);
                return;
            }

            op.EmitGet(this);
            Convert(op, desiredType, allowExplicitConversion);
        }
Esempio n. 2
0
        void EmitGetHelper_Conversion(Operand op, Type desiredType, Conversion conv, Type from = null)
        {
            if (conv.RequiresAddress)
            {
                if (ReferenceEquals(op, null))
                {
                    throw new ArgumentException("Conversion from nullref to " + desiredType.Name + " is impossible; for nullables variable it's required to load address.");
                }

                op.EmitAddressOf(this);
            }
            else if (ReferenceEquals(op, null))
            {
                IL.Emit(OpCodes.Ldnull);
            }
            else
            {
                op.EmitGet(this);
            }
            if (from == null)
            {
                from = (object)op == null ? null : op.GetReturnType(TypeMapper);
            }
            conv.Emit(this, from, desiredType);
        }
Esempio n. 3
0
        public void EmitGetHelper(Operand op, Type desiredType, bool allowExplicitConversion)
        {
            if (desiredType.IsByRef)
            {
                if (op.Type != desiredType.GetElementType())
                {
                    throw new InvalidOperationException("Argument passed by reference must have exactly the same type as the formal argument");
                }

                op.EmitAddressOf(this);
                return;
            }

            if ((object)op == null)
            {
                if (desiredType.IsValueType)
                {
                    throw new ArgumentNullException("op");
                }
                il.Emit(OpCodes.Ldnull);
                return;
            }

            op.EmitGet(this);
            Convert(op, desiredType, allowExplicitConversion);
        }
        void DoInvoke(Operand invocation)
        {
            BeforeStatement();

            invocation.EmitGet(this);
            if (invocation.Type != typeof(void))
            {
                il.Emit(OpCodes.Pop);
            }
        }
Esempio n. 5
0
        void DoInvoke(Operand invocation)
        {
            BeforeStatement();

            invocation.EmitGet(this);
            if (!Helpers.AreTypesEqual(invocation.GetReturnType(TypeMapper), typeof(void), TypeMapper))
            {
                IL.Emit(OpCodes.Pop);
            }
        }
            protected override void BeginImpl()
            {
                lbDecision = g.il.DefineLabel();
                lbDefault  = lbEnd = g.il.DefineLabel();

                expression.EmitGet(g);
                if (conv != null)
                {
                    conv.Emit(g, expression.Type, govType);
                }
                exp = g.il.DeclareLocal(govType);
                g.il.Emit(OpCodes.Stloc, exp);
                g.il.Emit(OpCodes.Br, lbDecision);
                g.reachable = false;
            }
Esempio n. 7
0
            protected override void BeginImpl()
            {
                _lbDecision = G.IL.DefineLabel();
                _lbDefault  = _lbEnd = G.IL.DefineLabel();

                _expression.EmitGet(G);
                if (_conv != null)
                {
                    _conv.Emit(G, _expression.GetReturnType(G.TypeMapper), _govType);
                }
                _exp = G.IL.DeclareLocal(_govType);
                G.IL.Emit(OpCodes.Stloc, _exp);
                G.IL.Emit(OpCodes.Br, _lbDecision);
                G._reachable = false;
            }
            protected override void BeginImpl()
            {
                _lbDecision = G.IL.DefineLabel();
                _lbDefault  = _lbEnd = G.IL.DefineLabel();

                if (_conv != null)
                {
                    G.EmitGetHelper(_expression, _govType, _conv);
                }
                else
                {
                    _expression.EmitGet(G);
                }
                _exp = G.IL.DeclareLocal(_govType);
                G.IL.Emit(OpCodes.Stloc, _exp);
                G.IL.Emit(OpCodes.Br, _lbDecision);
                G.IsReachable = false;
            }
Esempio n. 9
0
        void EmitArg(CodeGen g, int index, Operand arg)
        {
            if (appliedSignature[index].IsByRef)
            {
                arg.EmitAddressOf(g);
                return;
            }

            if ((object)arg == null)
            {
                g.IL.Emit(OpCodes.Ldnull);
            }
            else
            {
                arg.EmitGet(g);
            }

            conversions[index].Emit(g, paramsSignature[index], appliedSignature[index]);
        }
Esempio n. 10
0
        public void UnsubscribeEvent(Operand target, string eventName, Operand handler)
        {
            if ((object)target == null)
            {
                throw new ArgumentNullException("target");
            }
            if ((object)handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            IMemberInfo evt = TypeInfo.FindEvent(target.Type, eventName, target.IsStaticTarget);
            MethodInfo  mi  = ((EventInfo)evt.Member).GetRemoveMethod();

            if (!target.IsStaticTarget)
            {
                target.EmitGet(this);
            }
            handler.EmitGet(this);
            EmitCallHelper(mi, target);
        }
Esempio n. 11
0
        public void SubscribeEvent(Operand target, string eventName, Operand handler)
        {
            if ((object)target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if ((object)handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            IMemberInfo evt = TypeMapper.TypeInfo.FindEvent(target.GetReturnType(TypeMapper), eventName, target.IsStaticTarget);
            MethodInfo  mi  = ((EventInfo)evt.Member).GetAddMethod();

            if (!target.IsStaticTarget)
            {
                target.EmitGet(this);
            }
            handler.EmitGet(this);
            EmitCallHelper(mi, target);
        }
Esempio n. 12
0
        /// <summary>
        /// Allows evaluation of <see cref="StaticFactory.Invoke"/>, <see cref="ExpressionFactory.New"/> and others. The result of the evaluation is discarded.
        /// </summary>
        /// <remarks>E.g. if you already have `exp.New(typeof(MyClass))` part you may wrap it with Eval: g.Eval(myExp).</remarks>
        public void Eval(Operand operand)
        {
            BeforeStatement();

            operand.EmitGet(this);
            if (!Helpers.AreTypesEqual(operand.GetReturnType(TypeMapper), typeof(void), TypeMapper))
            {
                if (!_leaveNextReturnOnStack)
                {
                    IL.Emit(OpCodes.Pop);
                }
                else
                {
                    _leaveNextReturnOnStack = false;
                }
            }
            else if (_leaveNextReturnOnStack)
            {
                throw new InvalidOperationException(nameof(LeaveNextReturnOnStack) + " called but operand " + operand.ToString() + " doesn't return a value");
            }
        }
		void DoInvoke(Operand invocation)
		{
			BeforeStatement();

			invocation.EmitGet(this);
			if (invocation.Type != typeof(void))
				il.Emit(OpCodes.Pop);
		}
		public void UnsubscribeEvent(Operand target, string eventName, Operand handler)
		{
			if ((object)target == null)
				throw new ArgumentNullException("target");
			if ((object)handler == null)
				throw new ArgumentNullException("handler");

			IMemberInfo evt = TypeInfo.FindEvent(target.Type, eventName, target.IsStaticTarget);
			MethodInfo mi = ((EventInfo)evt.Member).GetRemoveMethod();
			if (!target.IsStaticTarget)
				target.EmitGet(this);
			handler.EmitGet(this);
			EmitCallHelper(mi, target);
		}
Esempio n. 15
0
 protected internal override void EmitGet(CodeGen g)
 {
     OperandExtensions.SetLeakedState(this, false);
     _operand.EmitGet(g);
 }
Esempio n. 16
0
        void EmitGetHelper_Conversion(Operand op, Type desiredType, Conversion conv, Type from = null)
        {
            if (conv.RequiresAddress)
            {
                if (ReferenceEquals(op, null))
                    throw new ArgumentException("Conversion from nullref to " + desiredType.Name + " is impossible; for nullables variable it's required to load address.");

                op.EmitAddressOf(this);
            }
            else if (ReferenceEquals(op, null))
                IL.Emit(OpCodes.Ldnull);
            else
                op.EmitGet(this);
            if (from == null)
                from = (object)op == null ? null : op.GetReturnType(TypeMapper);
            conv.Emit(this, from, desiredType);
        }
Esempio n. 17
0
        void EmitArg(CodeGen g, int index, Operand arg)
        {
            if (appliedSignature[index].IsByRef)
            {
                arg.EmitAddressOf(g);
                return;
            }

            if ((object)arg == null)
                g.IL.Emit(OpCodes.Ldnull);
            else
                arg.EmitGet(g);

            conversions[index].Emit(g, paramsSignature[index], appliedSignature[index]);
        }
Esempio n. 18
0
        internal void EmitGetHelper(Operand op, Type desiredType, bool allowExplicitConversion)
        {
            if (desiredType.IsByRef)
            {
                if (op.Type != desiredType.GetElementType())
                    throw new InvalidOperationException(Properties.Messages.ErrByRefTypeMismatch);

                op.EmitAddressOf(this);
                return;
            }

            if ((object)op == null)
            {
                if (desiredType.IsValueType)
                    throw new ArgumentNullException("op");
                il.Emit(OpCodes.Ldnull);
                return;
            }

            op.EmitGet(this);
            Convert(op, desiredType, allowExplicitConversion);
        }
Esempio n. 19
0
 public void GotoTrue(Operand operation, string labelName)
 {
     CheckBreakpoint(labelName);
     operation.EmitGet(this);
     IL.Emit(OpCodes.Brtrue, GetNamedLabel(labelName));
 }
Esempio n. 20
0
 public void Switch(Operand expression, Label[] labels)
 {
     expression.EmitGet(this);
     IL.Emit(OpCodes.Switch, labels);
 }