本文整理汇总了C#中System.Reflection.Emit.CodeGenerator.EmitMethodCall方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.EmitMethodCall方法的具体用法?C# CodeGenerator.EmitMethodCall怎么用?C# CodeGenerator.EmitMethodCall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.EmitMethodCall方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
/// <remarks>
/// Nothing is expected at the evaluation stack. If AST node is read by other node,
/// the operation result is left at the stack, otherwise it is poped from the stack.
/// </remarks>
/// <include file='Doc/Nodes.xml' path='doc/method[@name="Emit"]/*'/>
internal override PhpTypeCode Emit(CodeGenerator codeGenerator)
{
Debug.Assert(access == AccessType.None || access == AccessType.Read);
Statistics.AST.AddNode("BinaryEx");
PhpTypeCode returned_typecode;
PhpTypeCode lo_typecode;
PhpTypeCode ro_typecode;
switch (operation)
{
#region Arithmetic Operations
case Operations.Add:
// Template: x + y : Operators.Add(x,y) [overloads]
switch (lo_typecode = leftExpr.Emit(codeGenerator))
{
case PhpTypeCode.Double:
switch (ro_typecode = rightExpr.Emit(codeGenerator))
{
case PhpTypeCode.Integer:
codeGenerator.IL.Emit(OpCodes.Conv_R8);
goto case PhpTypeCode.Double; // fallback:
case PhpTypeCode.Double:
codeGenerator.IL.Emit(OpCodes.Add);
returned_typecode = PhpTypeCode.Double;
break;
default:
codeGenerator.EmitBoxing(ro_typecode);
returned_typecode = codeGenerator.EmitMethodCall(Methods.Operators.Add.Double_Object);
break;
}
break;
default:
codeGenerator.EmitBoxing(lo_typecode);
ro_typecode = rightExpr.Emit(codeGenerator);
switch (ro_typecode)
{
case PhpTypeCode.Integer:
returned_typecode = codeGenerator.EmitMethodCall(Methods.Operators.Add.Object_Int32);
break;
case PhpTypeCode.Double:
returned_typecode = codeGenerator.EmitMethodCall(Methods.Operators.Add.Object_Double);
break;
default:
codeGenerator.EmitBoxing(ro_typecode);
returned_typecode = codeGenerator.EmitMethodCall(Methods.Operators.Add.Object_Object);
break;
}
break;
}
break;
case Operations.Sub:
//Template: "x - y" Operators.Subtract(x,y) [overloads]
lo_typecode = leftExpr.Emit(codeGenerator);
switch (lo_typecode)
{
case PhpTypeCode.Integer:
codeGenerator.EmitBoxing(rightExpr.Emit(codeGenerator));
returned_typecode = codeGenerator.EmitMethodCall(Methods.Operators.Subtract.Int32_Object);
break;
case PhpTypeCode.Double:
switch (ro_typecode = rightExpr.Emit(codeGenerator))
{
case PhpTypeCode.Integer:
codeGenerator.IL.Emit(OpCodes.Conv_R8);
goto case PhpTypeCode.Double; // fallback:
case PhpTypeCode.Double:
codeGenerator.IL.Emit(OpCodes.Sub);
returned_typecode = PhpTypeCode.Double;
break;
default:
codeGenerator.EmitBoxing(ro_typecode);
returned_typecode = codeGenerator.EmitMethodCall(Methods.Operators.Subtract.Double_Object);
break;
}
break;
default:
codeGenerator.EmitBoxing(lo_typecode);
ro_typecode = rightExpr.Emit(codeGenerator);
if (ro_typecode == PhpTypeCode.Integer)
{
returned_typecode = codeGenerator.EmitMethodCall(Methods.Operators.Subtract.Object_Int);
}
else
{
codeGenerator.EmitBoxing(ro_typecode);
returned_typecode = codeGenerator.EmitMethodCall(Methods.Operators.Subtract.Object_Object);
//.........这里部分代码省略.........
示例2: Emit
/// <include file='Doc/Nodes.xml' path='doc/method[@name="Emit"]/*'/>
internal override PhpTypeCode Emit(CodeGenerator/*!*/ codeGenerator)
{
Debug.Assert(access == AccessType.Read || access == AccessType.None);
Statistics.AST.AddNode("UnaryEx");
ILEmitter il = codeGenerator.IL;
PhpTypeCode returned_typecode, o_typecode;
switch (operation)
{
case Operations.AtSign: // special arrangement
// Template:
// context.DisableErrorReporting();
// s;
// context.EnableErrorReporting();
codeGenerator.EmitLoadScriptContext();
il.Emit(OpCodes.Call, Methods.ScriptContext.DisableErrorReporting);
returned_typecode = expr.Emit(codeGenerator);
codeGenerator.EmitLoadScriptContext();
il.Emit(OpCodes.Call, Methods.ScriptContext.EnableErrorReporting);
break;
case Operations.BitNegation:
//Template: "~x" Operators.BitNot(x)
codeGenerator.EmitBoxing(expr.Emit(codeGenerator));
il.Emit(OpCodes.Call, Methods.Operators.BitNot);
returned_typecode = PhpTypeCode.Object;
break;
case Operations.Clone:
// Template: clone x Operators.Clone(x,DTypeDesc,ScriptContext)
codeGenerator.EmitBoxing(expr.Emit(codeGenerator));
codeGenerator.EmitLoadClassContext();
codeGenerator.EmitLoadScriptContext();
il.Emit(OpCodes.Call, Methods.Operators.Clone);
returned_typecode = PhpTypeCode.Object;
break;
case Operations.LogicNegation:
//Template: "!x" !Convert.ObjectToBoolean(x);
if (((returned_typecode = expr.Emit(codeGenerator)) != PhpTypeCode.Boolean))
{
codeGenerator.EmitBoxing(returned_typecode);
il.Emit(OpCodes.Call, Methods.Convert.ObjectToBoolean);
}
il.Emit(OpCodes.Ldc_I4_0);
il.Emit(OpCodes.Ceq);
returned_typecode = PhpTypeCode.Boolean;
break;
case Operations.Minus:
//Template: "-x" Operators.Minus(x)
switch (o_typecode = expr.Emit(codeGenerator))
{
case PhpTypeCode.Double:
il.Emit(OpCodes.Neg);
returned_typecode = PhpTypeCode.Double;
break;
default:
codeGenerator.EmitBoxing(o_typecode);
returned_typecode = codeGenerator.EmitMethodCall(Methods.Operators.Minus);
break;
}
break;
case Operations.ObjectCast:
//Template: "(object)x" Convert.ObjectToDObject(x,ScriptContext)
codeGenerator.EmitBoxing(expr.Emit(codeGenerator));
codeGenerator.EmitLoadScriptContext();
il.Emit(OpCodes.Call, Methods.Convert.ObjectToDObject);
returned_typecode = PhpTypeCode.Object;
break;
case Operations.Plus:
//Template: "+x" Operators.Plus(x)
codeGenerator.EmitBoxing(expr.Emit(codeGenerator));
il.Emit(OpCodes.Call, Methods.Operators.Plus);
returned_typecode = PhpTypeCode.Object;
break;
case Operations.Print:
codeGenerator.EmitEcho(this.expr);
// Always returns 1
il.Emit(OpCodes.Ldc_I4_1);
returned_typecode = PhpTypeCode.Integer;
break;
case Operations.BoolCast:
//Template: "(bool)x" Convert.ObjectToBoolean(x)
if (((returned_typecode = expr.Emit(codeGenerator)) != PhpTypeCode.Boolean))
{
codeGenerator.EmitBoxing(returned_typecode);
il.Emit(OpCodes.Call, Methods.Convert.ObjectToBoolean);
returned_typecode = PhpTypeCode.Boolean;
}
break;
case Operations.Int8Cast:
//.........这里部分代码省略.........
示例3: Emit
/// <summary>
/// Emits assignment.
/// </summary>
/// <remarks>
/// Pattern: a op= b
///
/// PREPARE a (prepared)
/// LOAD a (prepared,a)
/// LOAD b (prepared,a,b)
/// OP (prepared,result)
/// *DUP (prepared,result,result)
/// *STORE tmp (prepared,result) must be this stack here!
/// STORE a ()
/// *LOAD tmp (result)
///
/// * only if the resulting value needs to be propagated to the right
///
/// Note: There is a possible improvement: some store operations (SetVariable) may return the value set
/// which would replace DUP and second temp op.
/// </remarks>
internal override PhpTypeCode Emit(CodeGenerator/*!*/ codeGenerator)
{
Debug.Assert(access == AccessType.Read || access == AccessType.None || access == AccessType.ReadRef ||
access == AccessType.ReadUnknown);
Statistics.AST.AddNode("Assign.Value");
ILEmitter il = codeGenerator.IL;
AccessType old_selector = codeGenerator.AccessSelector;
codeGenerator.ChainBuilder.Create();
PhpTypeCode result;
if (operation == Operations.AssignValue)
{
//
// Access Type = ReadRef/ReadUnknown
// ---------------------------------
//
// f(&$x) { }
//
// f($a = $b);
// f($a = $b =& $c);
//
// Destination variable $a is prepared for reference write.
// A new reference is created and its value set to a deep copy of the result of RHS ($b, $b =& $c).
// RHS has Read access => it has been dereferenced.
//
// PREPARE a:
codeGenerator.AccessSelector = AccessType.Write;
lvalue.Emit(codeGenerator);
codeGenerator.AccessSelector = AccessType.None;
PhpTypeCode src_type_code = EmitSourceValRead(codeGenerator);
// RHS should have Read access => should be dereferenced
Debug.Assert(src_type_code != PhpTypeCode.PhpReference);
// LOAD BOX b
codeGenerator.EmitBoxing(src_type_code);
// makes a copy if necessary:
if (PhpTypeCodeEnum.IsDeeplyCopied(src_type_code))
codeGenerator.EmitVariableCopy(CopyReason.Assigned, rvalue);
}
else
{
// PREPARE a:
codeGenerator.AccessSelector = AccessType.Write;
lvalue.Emit(codeGenerator);
codeGenerator.AccessSelector = AccessType.None;
// LOAD b,a (rvalue must be processed first, than +-*/ with lvalue, since lvalu can be changed by rvalue expression)
//must be the second operand// EmitDestVarRead(codeGenerator);
PhpTypeCode right_type = EmitSourceValRead(codeGenerator);
var rvalue_tmp = codeGenerator.IL.GetTemporaryLocal(PhpTypeCodeEnum.ToType(right_type), false);
codeGenerator.IL.Emit(OpCodes.Stloc, rvalue_tmp);
EmitDestVarRead(codeGenerator);
codeGenerator.IL.Emit(OpCodes.Ldloc, rvalue_tmp);
codeGenerator.IL.ReturnTemporaryLocal(rvalue_tmp);
switch (operation)
{
#region Arithmetic
case Operations.AssignAdd:
{
switch (right_type)
{
case PhpTypeCode.Integer:
result = codeGenerator.EmitMethodCall(Methods.Operators.Add.Object_Int32);
break;
case PhpTypeCode.Double:
result = codeGenerator.EmitMethodCall(Methods.Operators.Add.Object_Double);
break;
default:
//.........这里部分代码省略.........