当前位置: 首页>>代码示例>>C#>>正文


C# EmitContext.Emit方法代码示例

本文整理汇总了C#中EmitContext.Emit方法的典型用法代码示例。如果您正苦于以下问题:C# EmitContext.Emit方法的具体用法?C# EmitContext.Emit怎么用?C# EmitContext.Emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EmitContext的用法示例。


在下文中一共展示了EmitContext.Emit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Emit

        public override void Emit(EmitContext ec)
        {
            Label is_null_label = ec.DefineLabel ();
            Label end_label = ec.DefineLabel ();

            unwrap.EmitCheck (ec);
            ec.Emit (OpCodes.Brfalse, is_null_label);

            expr.Emit (ec);

            ec.Emit (OpCodes.Br, end_label);
            ec.MarkLabel (is_null_label);

            null_value.Emit (ec);
            ec.MarkLabel (end_label);
        }
开发者ID:RainsSoft,项目名称:MonoCompilerAsAService,代码行数:16,代码来源:nullable.cs

示例2: Emit

		public override void Emit (EmitContext ec)
		{
			Label end_label = ec.DefineLabel ();

			if (unwrap != null) {
				Label is_null_label = ec.DefineLabel ();

				unwrap.EmitCheck (ec);
				ec.Emit (OpCodes.Brfalse, is_null_label);

				//
				// When both expressions are nullable the unwrap
				// is needed only for null check not for value uwrap
				//
				if (type.IsNullableType)
					unwrap.Load (ec);
				else
					left.Emit (ec);

				ec.Emit (OpCodes.Br, end_label);

				ec.MarkLabel (is_null_label);
				right.Emit (ec);

				ec.MarkLabel (end_label);
				return;
			}

			left.Emit (ec);
			ec.Emit (OpCodes.Dup);

			// Only to make verifier happy
			if (left.Type.IsGenericParameter)
				ec.Emit (OpCodes.Box, left.Type);

			ec.Emit (OpCodes.Brtrue, end_label);

			ec.Emit (OpCodes.Pop);
			right.Emit (ec);

			ec.MarkLabel (end_label);
		}
开发者ID:bl8,项目名称:mono,代码行数:42,代码来源:nullable.cs

示例3: EmitBranchable

		public override void EmitBranchable (EmitContext ec, Label target, bool onTrue)
		{
			Emit (ec);
			ec.Emit (onTrue ? OpCodes.Brtrue : OpCodes.Brfalse, target);
		}			
开发者ID:saga,项目名称:mono,代码行数:5,代码来源:nullable.cs

示例4: EmitBitwiseBoolean

		void EmitBitwiseBoolean (EmitContext ec)
		{
			Label load_left = ec.DefineLabel ();
			Label load_right = ec.DefineLabel ();
			Label end_label = ec.DefineLabel ();

			// null & value, null | value
			if (left_unwrap == null) {
				left_unwrap = right_unwrap;
				right_unwrap = null;
				right = left;
			}

			left_unwrap.Emit (ec);
			ec.Emit (OpCodes.Brtrue_S, load_right);

			// value & null, value | null
			if (right_unwrap != null) {
				right_unwrap.Emit (ec);
				ec.Emit (OpCodes.Brtrue_S, load_left);
			}

			left_unwrap.EmitCheck (ec);
			ec.Emit (OpCodes.Brfalse_S, load_right);

			// load left
			ec.MarkLabel (load_left);

			if (Oper == Operator.BitwiseAnd) {
				left_unwrap.Load (ec);
			} else {
				if (right_unwrap == null) {
					right.Emit (ec);
					if (right is EmptyConstantCast || right is EmptyCast)
						ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
				} else {
					right_unwrap.Load (ec);
					right_unwrap = left_unwrap;
				}
			}
			ec.Emit (OpCodes.Br_S, end_label);

			// load right
			ec.MarkLabel (load_right);
			if (right_unwrap == null) {
				if (Oper == Operator.BitwiseAnd) {
					right.Emit (ec);
					if (right is EmptyConstantCast || right is EmptyCast)
						ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
				} else {
					left_unwrap.Load (ec);
				}
			} else {
				right_unwrap.Load (ec);
			}

			ec.MarkLabel (end_label);
		}
开发者ID:saga,项目名称:mono,代码行数:58,代码来源:nullable.cs

示例5: AddressOf

		public void AddressOf (EmitContext ec, AddressOp Mode)
		{
			LocalTemporary value_target = new LocalTemporary (type);
				
			value_target.AddressOf (ec, AddressOp.Store);
			ec.Emit (OpCodes.Initobj, type);
			((IMemoryLocation) value_target).AddressOf (ec, Mode);
		}
开发者ID:saga,项目名称:mono,代码行数:8,代码来源:nullable.cs

示例6: Emit

		public override void Emit (EmitContext ec)
		{
			child.Emit (ec);
			ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
		}
开发者ID:saga,项目名称:mono,代码行数:5,代码来源:nullable.cs

示例7: EmitBitwiseBoolean

		void EmitBitwiseBoolean (EmitContext ec)
		{
			Label load_left = ec.DefineLabel ();
			Label load_right = ec.DefineLabel ();
			Label end_label = ec.DefineLabel ();
			Label is_null_label = ec.DefineLabel ();

			bool or = Binary.Oper == Binary.Operator.BitwiseOr;

			//
			// Both operands are bool? types
			//
			if (UnwrapLeft != null && UnwrapRight != null) {
				if (ec.HasSet (BuilderContext.Options.AsyncBody) && Binary.Right.ContainsEmitWithAwait ()) {
					Left = Left.EmitToField (ec);
					Right = Right.EmitToField (ec);
				}

				Left.Emit (ec);
				ec.Emit (OpCodes.Brtrue_S, load_right);

				Right.Emit (ec);
				ec.Emit (OpCodes.Brtrue_S, load_left);

				UnwrapLeft.EmitCheck (ec);
				ec.Emit (OpCodes.Brfalse_S, load_right);

				// load left
				ec.MarkLabel (load_left);
				if (or)
					UnwrapRight.Load (ec);
				else
					UnwrapLeft.Load (ec);

				ec.Emit (OpCodes.Br_S, end_label);

				// load right
				ec.MarkLabel (load_right);
				if (or)
					UnwrapLeft.Load (ec);
				else
					UnwrapRight.Load (ec);

				ec.MarkLabel (end_label);
				return;
			}

			//
			// Faster version when one operand is bool
			//
			if (UnwrapLeft == null) {
				//
				// (bool, bool?)
				//
				// Optimizes remaining (false & bool?), (true | bool?) which are not easy to handle
				// in binary expression reduction
				//
				var c = Left as BoolConstant;
				if (c != null) {
					// Keep evaluation order
					UnwrapRight.Store (ec);

					ec.EmitInt (or ? 1 : 0);
					ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
				} else if (Left.IsNull) {
					UnwrapRight.Emit (ec);
					ec.Emit (or ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, is_null_label);

					UnwrapRight.Load (ec);
					ec.Emit (OpCodes.Br_S, end_label);

					ec.MarkLabel (is_null_label);
					LiftedNull.Create (type, loc).Emit (ec);
				} else {
					Left.Emit (ec);
					ec.Emit (or ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, load_right);

					ec.EmitInt (or ? 1 : 0);
					ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));

					ec.Emit (OpCodes.Br_S, end_label);

					ec.MarkLabel (load_right);
					UnwrapRight.Original.Emit (ec);
				}
			} else {
				//
				// (bool?, bool)
				//
				// Keep left-right evaluation order
				UnwrapLeft.Store (ec);

				//
				// Optimizes remaining (bool? & false), (bool? | true) which are not easy to handle
				// in binary expression reduction
				//
				var c = Right as BoolConstant;
				if (c != null) {
					ec.EmitInt (or ? 1 : 0);
					ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
//.........这里部分代码省略.........
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:101,代码来源:nullable.cs

示例8: EmitConvertFromNullable

		void EmitConvertFromNullable (EmitContext ec)
		{
			if (IsBoxing ()) {
				ec.Emit (operand);
				EmitBox (ec);
				return;
			}

			ec.EmitCall (operand, operand.Type.GetMethod ("get_Value"));

			if (operand.Type.GetNotNullableType () != Type) {
				EmitPrimitiveConversion (ec,
					operand.Type.GetNotNullableType (),
					Type);
			}
		}
开发者ID:qwertie,项目名称:Theraot,代码行数:16,代码来源:UnaryExpression.net30.cs

示例9: EmitConvertToNullable

		void EmitConvertToNullable (EmitContext ec)
		{
			ec.Emit (operand);

			if (IsUnBoxing ()) {
				EmitUnbox (ec);
				return;
			}

			if (operand.Type != Type.GetNotNullableType ()) {
				EmitPrimitiveConversion (ec,
					operand.Type,
					Type.GetNotNullableType ());
			}

			ec.EmitNullableNew (Type);
		}
开发者ID:qwertie,项目名称:Theraot,代码行数:17,代码来源:UnaryExpression.net30.cs

示例10: EmitBitwiseBoolean

		void EmitBitwiseBoolean (EmitContext ec)
		{
			Label load_left = ec.DefineLabel ();
			Label load_right = ec.DefineLabel ();
			Label end_label = ec.DefineLabel ();

			left_unwrap.Emit (ec);
			ec.Emit (OpCodes.Brtrue_S, load_right);

			right_unwrap.Emit (ec);
			ec.Emit (OpCodes.Brtrue_S, load_left);

			left_unwrap.EmitCheck (ec);
			ec.Emit (OpCodes.Brfalse_S, load_right);

			// load left
			ec.MarkLabel (load_left);

			if (Oper == Operator.BitwiseAnd) {
				left_unwrap.Load (ec);
			} else {
				right_unwrap.Load (ec);
				right_unwrap = left_unwrap;
			}
			ec.Emit (OpCodes.Br_S, end_label);

			// load right
			ec.MarkLabel (load_right);
			right_unwrap.Load (ec);

			ec.MarkLabel (end_label);
		}
开发者ID:MichaelWalsh,项目名称:mono,代码行数:32,代码来源:nullable.cs

示例11: EmitEquality

		//
		// Emits optimized equality or inequality operator when possible
		//
		void EmitEquality (EmitContext ec)
		{
			//
			// Either left or right is null
			//
			if (left_unwrap != null && (IsRightNullLifted || right.IsNull)) {
				left_unwrap.EmitCheck (ec);
				if (Oper == Binary.Operator.Equality) {
					ec.EmitInt (0);
					ec.Emit (OpCodes.Ceq);
				}
				return;
			}

			if (right_unwrap != null && (IsLeftNullLifted || left.IsNull)) {
				right_unwrap.EmitCheck (ec);
				if (Oper == Binary.Operator.Equality) {
					ec.EmitInt (0);
					ec.Emit (OpCodes.Ceq);
				}
				return;
			}

			Label dissimilar_label = ec.DefineLabel ();
			Label end_label = ec.DefineLabel ();

			if (user_operator != null) {
				user_operator.Emit (ec);
				ec.Emit (Oper == Operator.Equality ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, dissimilar_label);
			} else {
				if (ec.HasSet (BuilderContext.Options.AsyncBody) && right.ContainsEmitWithAwait ()) {
					left = left.EmitToField (ec);
					right = right.EmitToField (ec);
				}

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

				ec.Emit (OpCodes.Bne_Un_S, dissimilar_label);
			}

			if (left_unwrap != null)
				left_unwrap.EmitCheck (ec);

			if (right_unwrap != null)
				right_unwrap.EmitCheck (ec);

			if (left_unwrap != null && right_unwrap != null) {
				if (Oper == Operator.Inequality)
					ec.Emit (OpCodes.Xor);
				else
					ec.Emit (OpCodes.Ceq);
			} else {
				if (Oper == Operator.Inequality) {
					ec.EmitInt (0);
					ec.Emit (OpCodes.Ceq);
				}
			}

			ec.Emit (OpCodes.Br_S, end_label);

			ec.MarkLabel (dissimilar_label);
			if (Oper == Operator.Inequality)
				ec.EmitInt (1);
			else
				ec.EmitInt (0);

			ec.MarkLabel (end_label);
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:72,代码来源:nullable.cs

示例12: Emit

        public override void Emit(EmitContext ec)
        {
            Label end_label = ec.DefineLabel ();

            if (unwrap != null) {
                Label is_null_label = ec.DefineLabel ();

                unwrap.EmitCheck (ec);
                ec.Emit (OpCodes.Brfalse, is_null_label);

                left.Emit (ec);
                ec.Emit (OpCodes.Br, end_label);

                ec.MarkLabel (is_null_label);
                right.Emit (ec);

                ec.MarkLabel (end_label);
                return;
            }

            left.Emit (ec);

            ec.Emit (OpCodes.Dup);
            ec.Emit (OpCodes.Brtrue, end_label);

            ec.Emit (OpCodes.Pop);
            right.Emit (ec);

            ec.MarkLabel (end_label);
        }
开发者ID:speier,项目名称:shake,代码行数:30,代码来源:nullable.cs

示例13: Emit

		public override void Emit (EmitContext ec)
		{
			Label end_label = ec.DefineLabel ();

			if (unwrap != null) {
				Label is_null_label = ec.DefineLabel ();

				unwrap.EmitCheck (ec);
				ec.Emit (OpCodes.Brfalse, is_null_label);

				//
				// When both expressions are nullable the unwrap
				// is needed only for null check not for value uwrap
				//
				if (type.IsNullableType && TypeSpecComparer.IsEqual (NullableInfo.GetUnderlyingType (type), unwrap.Type))
					unwrap.Load (ec);
				else
					left.Emit (ec);

				ec.Emit (OpCodes.Br, end_label);

				ec.MarkLabel (is_null_label);
				right.Emit (ec);

				ec.MarkLabel (end_label);
				return;
			}

			//
			// Null check is done on original expression not after expression is converted to
			// result type. This is in most cases same but when user conversion is involved
			// we can end up in situation when user operator does the null handling which is
			// not what the operator is supposed to do.
			// There is tricky case where cast of left expression is meant to be cast of
			// whole source expression (null check is done on it) and cast from right-to-left
			// conversion needs to do null check on unconverted source expression.
			//
			if (user_conversion_left) {
				var op_expr = (UserCast) left;

				op_expr.Source.Emit (ec);
				LocalTemporary temp;

				// TODO: More load kinds can be special cased
				if (!(op_expr.Source is VariableReference)) {
					temp = new LocalTemporary (op_expr.Source.Type);
					temp.Store (ec);
					temp.Emit (ec);
					op_expr.Source = temp;
				} else {
					temp = null;
				}

				var right_label = ec.DefineLabel ();
				ec.Emit (OpCodes.Brfalse_S, right_label);
				left.Emit (ec);
				ec.Emit (OpCodes.Br, end_label);
				ec.MarkLabel (right_label);

				if (temp != null)
					temp.Release (ec);
			} else {
				//
				// Common case where expression is not modified before null check and
				// we generate better/smaller code
				//
				left.Emit (ec);
				ec.Emit (OpCodes.Dup);

				// Only to make verifier happy
				if (left.Type.IsGenericParameter)
					ec.Emit (OpCodes.Box, left.Type);

				ec.Emit (OpCodes.Brtrue, end_label);

				ec.Emit (OpCodes.Pop);
			}

			right.Emit (ec);

			ec.MarkLabel (end_label);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:82,代码来源:nullable.cs

示例14: EmitOperation

		protected override void EmitOperation (EmitContext ec)
		{
			Label is_null_label = ec.DefineLabel ();
			Label end_label = ec.DefineLabel ();

			LocalTemporary lt = new LocalTemporary (type);

			// Value is on the stack
			lt.Store (ec);

			var call = new CallEmitter ();
			call.InstanceExpression = lt;
			call.EmitPredefined (ec, NullableInfo.GetHasValue (expr.Type), null);

			ec.Emit (OpCodes.Brfalse, is_null_label);

			call = new CallEmitter ();
			call.InstanceExpression = lt;
			call.EmitPredefined (ec, NullableInfo.GetGetValueOrDefault (expr.Type), null);

			lt.Release (ec);

			base.EmitOperation (ec);

			ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
			ec.Emit (OpCodes.Br_S, end_label);

			ec.MarkLabel (is_null_label);
			LiftedNull.Create (type, loc).Emit (ec);

			ec.MarkLabel (end_label);
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:32,代码来源:nullable.cs

示例15: EmitUserDefinedOperator

		void EmitUserDefinedOperator (EmitContext ec)
		{
			if (!IsLifted) {
				ec.Emit (operand);
				ec.EmitCall (method);
			} else if (IsLiftedToNull) {
				EmitUserDefinedLiftedToNullOperator (ec);
			} else
				EmitUserDefinedLiftedOperator (ec);
		}
开发者ID:qwertie,项目名称:Theraot,代码行数:10,代码来源:UnaryExpression.net30.cs


注:本文中的EmitContext.Emit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。