本文整理汇总了C#中EmitContext.HasSet方法的典型用法代码示例。如果您正苦于以下问题:C# EmitContext.HasSet方法的具体用法?C# EmitContext.HasSet怎么用?C# EmitContext.HasSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EmitContext
的用法示例。
在下文中一共展示了EmitContext.HasSet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitEquality
//
// Emits optimized equality or inequality operator when possible
//
void EmitEquality (EmitContext ec)
{
//
// Either left or right is null
//
if (UnwrapLeft != null && Binary.Right.IsNull) { // TODO: Optimize for EmitBranchable
//
// left.HasValue == false
//
UnwrapLeft.EmitCheck (ec);
if (Binary.Oper == Binary.Operator.Equality) {
ec.EmitInt (0);
ec.Emit (OpCodes.Ceq);
}
return;
}
if (UnwrapRight != null && Binary.Left.IsNull) {
//
// right.HasValue == false
//
UnwrapRight.EmitCheck (ec);
if (Binary.Oper == Binary.Operator.Equality) {
ec.EmitInt (0);
ec.Emit (OpCodes.Ceq);
}
return;
}
Label dissimilar_label = ec.DefineLabel ();
Label end_label = ec.DefineLabel ();
if (UserOperator != null) {
var left = Left;
if (UnwrapLeft != null) {
UnwrapLeft.EmitCheck (ec);
} else {
// Keep evaluation order same
if (!(Left is VariableReference)) {
Left.Emit (ec);
var lt = new LocalTemporary (Left.Type);
lt.Store (ec);
left = lt;
}
}
if (UnwrapRight != null) {
UnwrapRight.EmitCheck (ec);
if (UnwrapLeft != null) {
ec.Emit (OpCodes.Bne_Un, dissimilar_label);
Label compare_label = ec.DefineLabel ();
UnwrapLeft.EmitCheck (ec);
ec.Emit (OpCodes.Brtrue, compare_label);
if (Binary.Oper == Binary.Operator.Equality)
ec.EmitInt (1);
else
ec.EmitInt (0);
ec.Emit (OpCodes.Br, end_label);
ec.MarkLabel (compare_label);
} else {
ec.Emit (OpCodes.Brfalse, dissimilar_label);
}
} else {
ec.Emit (OpCodes.Brfalse, dissimilar_label);
}
var args = new Arguments (2);
args.Add (new Argument (left));
args.Add (new Argument (Right));
var call = new CallEmitter ();
call.EmitPredefined (ec, UserOperator, args);
} else {
if (ec.HasSet (BuilderContext.Options.AsyncBody) && Binary.Right.ContainsEmitWithAwait ()) {
Left = Left.EmitToField (ec);
Right = Right.EmitToField (ec);
}
//
// Emit underlying value comparison first.
//
// For this code: int? a = 1; bool b = a == 1;
//
// We emit something similar to this. Expressions with side effects have local
// variable created by Unwrap expression
//
// left.GetValueOrDefault ()
// right
// bne.un.s dissimilar_label
// left.HasValue
// br.s end_label
//.........这里部分代码省略.........
示例2: Emit
public override void Emit (EmitContext ec)
{
if (IsBitwiseBoolean && UserOperator == null) {
EmitBitwiseBoolean (ec);
return;
}
if ((Binary.Oper & Binary.Operator.EqualityMask) != 0) {
EmitEquality (ec);
return;
}
Label is_null_label = ec.DefineLabel ();
Label end_label = ec.DefineLabel ();
if (ec.HasSet (BuilderContext.Options.AsyncBody) && Right.ContainsEmitWithAwait ()) {
Left = Left.EmitToField (ec);
Right = Right.EmitToField (ec);
}
if (UnwrapLeft != null) {
UnwrapLeft.EmitCheck (ec);
}
//
// Don't emit HasValue check when left and right expressions are same
//
if (UnwrapRight != null && !Binary.Left.Equals (Binary.Right)) {
UnwrapRight.EmitCheck (ec);
if (UnwrapLeft != null) {
ec.Emit (OpCodes.And);
}
}
ec.Emit (OpCodes.Brfalse, is_null_label);
if (UserOperator != null) {
var args = new Arguments (2);
args.Add (new Argument (Left));
args.Add (new Argument (Right));
var call = new CallEmitter ();
call.EmitPredefined (ec, UserOperator, args);
} else {
Binary.EmitOperator (ec, Left, Right);
}
//
// Wrap the result when the operator return type is nullable type
//
if (type.IsNullableType)
ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
ec.Emit (OpCodes.Br_S, end_label);
ec.MarkLabel (is_null_label);
if ((Binary.Oper & Binary.Operator.ComparisonMask) != 0) {
ec.EmitInt (0);
} else {
LiftedNull.Create (type, loc).Emit (ec);
}
ec.MarkLabel (end_label);
}
示例3: 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));
//.........这里部分代码省略.........
示例4: 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);
}