本文整理汇总了C#中System.Reflection.Emit.CodeGenerator.EmitCompareEq方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.EmitCompareEq方法的具体用法?C# CodeGenerator.EmitCompareEq怎么用?C# CodeGenerator.EmitCompareEq使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.EmitCompareEq方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
/// <include file='Doc/Nodes.xml' path='doc/method[@name="Emit"]/*'/>
internal override void Emit(CodeGenerator/*!*/ codeGenerator)
{
Statistics.AST.AddNode("SwitchStmt");
ILEmitter il = codeGenerator.IL;
// Note:
// SwitchStmt is now implemented in the most general (and unefficient) way. The whole switch
// is understood as a series of if-elseif-else statements.
Label exit_label = il.DefineLabel();
bool fall_through = false;
Label fall_through_label = il.DefineLabel();
Label last_default_label = il.DefineLabel();
DefaultItem last_default = GetLastDefaultItem();
LocalBuilder branch_to_lastdefault = null;
if (last_default != null)
{
branch_to_lastdefault = il.DeclareLocal(Types.Bool[0]);
il.LdcI4(0);
il.Stloc(branch_to_lastdefault);
}
codeGenerator.BranchingStack.BeginLoop(exit_label, exit_label,
codeGenerator.ExceptionBlockNestingLevel);
// marks a sequence point containing the discriminator evaluation:
codeGenerator.MarkSequencePoint(
switchValue.Position.FirstLine,
switchValue.Position.FirstColumn,
switchValue.Position.LastLine,
switchValue.Position.LastColumn + 1);
// Evaluate condition value and store the result into local variable
codeGenerator.EmitBoxing(switchValue.Emit(codeGenerator));
LocalBuilder condition_value = il.DeclareLocal(Types.Object[0]);
il.Stloc(condition_value);
foreach (SwitchItem item in switchItems)
{
item.MarkSequencePoint(codeGenerator);
// switch item is either CaseItem ("case xxx:") or DefaultItem ("default") item:
CaseItem case_item = item as CaseItem;
if (case_item != null)
{
Label false_label = il.DefineLabel();
// PhpComparer.Default.CompareEq(<switch expr. value>,<case value>);
/*changed to static method*/ //il.Emit(OpCodes.Ldsfld, Fields.PhpComparer_Default);
codeGenerator.EmitCompareEq(
cg => { cg.IL.Ldloc(condition_value); return PhpTypeCode.Object; },
cg => case_item.EmitCaseValue(cg));
// IF (!STACK) GOTO false_label;
il.Emit(OpCodes.Brfalse, false_label);
if (fall_through == true)
{
il.MarkLabel(fall_through_label, true);
fall_through = false;
}
case_item.EmitStatements(codeGenerator);
if (fall_through == false)
{
fall_through_label = il.DefineLabel();
fall_through = true;
}
il.Emit(OpCodes.Br, fall_through_label);
il.MarkLabel(false_label, true);
}
else
{
DefaultItem default_item = (DefaultItem)item;
// Only the last default branch defined in source code is used.
// So skip default while testing "case" items at runtime.
Label false_label = il.DefineLabel();
il.Emit(OpCodes.Br, false_label);
if (default_item == last_default)
{
il.MarkLabel(last_default_label, false);
}
if (fall_through == true)
{
il.MarkLabel(fall_through_label, true);
fall_through = false;
}
default_item.EmitStatements(codeGenerator);
if (fall_through == false)
{
fall_through_label = il.DefineLabel();
//.........这里部分代码省略.........
示例2: EmitComparison
/// <summary>
/// Emits call to a default comparator method.
/// </summary>
/// <param name="codeGenerator">A code generator.</param>
/// <param name="equality">Whether to emit equality comparison (or generic comparison otherwise).</param>
/// <returns>A type code of the result.</returns>
private PhpTypeCode EmitComparison(CodeGenerator codeGenerator, bool equality)
{
PhpTypeCode x, y;
// PhpComparer.Default.<CompareEq | Compare>(box left, box right <|, false>);
/*changed to static method*/ //codeGenerator.IL.Emit(OpCodes.Ldsfld, Fields.PhpComparer_Default);
if (equality)
{
return codeGenerator.EmitCompareEq(cg => this.leftExpr.Emit(cg), cg => this.rightExpr.Emit(cg));
}
else
{
x = leftExpr.Emit(codeGenerator);
if (x == PhpTypeCode.Integer)
{
y = rightExpr.Emit(codeGenerator);
// int, ?
if (y == PhpTypeCode.Integer)
{
// int, int
codeGenerator.IL.Emit(OpCodes.Call, Methods.CompareOp_int_int);
return PhpTypeCode.Integer;
}
else
{
codeGenerator.EmitBoxing(y);
// int, object
codeGenerator.IL.LdcI4(0); // throws = false
codeGenerator.IL.Emit(OpCodes.Call, Methods.CompareOp_int_object_bool);
return PhpTypeCode.Integer;
}
}
else
{
codeGenerator.EmitBoxing(x);
y = rightExpr.Emit(codeGenerator);
// object, ?
if (y == PhpTypeCode.Integer)
{
// object, int
codeGenerator.IL.LdcI4(0); // throws = false
codeGenerator.IL.Emit(OpCodes.Call, Methods.CompareOp_object_int_bool);
return PhpTypeCode.Integer;
}
else
{
codeGenerator.EmitBoxing(y);
// object, object
codeGenerator.IL.LdcI4(0); // throws = false
codeGenerator.IL.Emit(OpCodes.Call, Methods.CompareOp_object_object_bool);
return PhpTypeCode.Integer;
}
}
}
}