本文整理汇总了C#中System.Reflection.Emit.CodeGenerator.EmitVariableCopy方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.EmitVariableCopy方法的具体用法?C# CodeGenerator.EmitVariableCopy怎么用?C# CodeGenerator.EmitVariableCopy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.EmitVariableCopy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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:
//.........这里部分代码省略.........
示例2: EmitValue
/// <summary>
/// Emit IL instructions that load the value of array item at the stack and make a copy
/// of it if necessary.
/// </summary>
internal override PhpTypeCode EmitValue(CodeGenerator/*!*/ codeGenerator)
{
Debug.Assert(valueExpr != null);
Statistics.AST.AddNode("Array.ValueItem");
codeGenerator.EmitBoxing(valueExpr.Emit(codeGenerator));
codeGenerator.EmitVariableCopy(CopyReason.Assigned, valueExpr);
return PhpTypeCode.Object;
}
示例3: EmitAssignListArray
private void EmitAssignListArray(CodeGenerator codeGenerator, List<Expression> vals, LocalBuilder o1)
{
//
// the array is on the top of the evaluation stack, value will be kept, must be duplicated to be used
//
// Process in the reverse order !
for (int i = vals.Count - 1; i >= 0; i--)
{
if (vals[i] == null)
continue;
// push the array item onto the stack
// LOAD array.GetArrayItem(i,false)
codeGenerator.IL.Emit(OpCodes.Dup); // copy of the array
codeGenerator.IL.Emit(OpCodes.Ldc_I4, i); // i
codeGenerator.IL.Emit(OpCodes.Ldc_I4_0); // false (!quiet)
codeGenerator.IL.Emit(OpCodes.Callvirt, Methods.PhpArray.GetArrayItem_Int32);
// assign the item from the stack into vals[i]
if (vals[i] is VariableUse)
{
// o1 = stack[0]
codeGenerator.IL.Stloc(o1); // store the value into local variable o1
// PREPARE <variable>:
codeGenerator.ChainBuilder.Create();
vals[i].Emit(codeGenerator);
// LOAD o1
codeGenerator.IL.Ldloc(o1);
// LOAD PhpVariable.Copy(STACK,CopyReason.Assigned)
codeGenerator.EmitVariableCopy(CopyReason.Assigned, null);
// STORE <variable>:
(vals[i] as VariableUse).EmitAssign(codeGenerator);
codeGenerator.ChainBuilder.End();
}
else if (vals[i] is ListEx)
{
EmitAssignList(codeGenerator, (vals[i] as ListEx).LValues, o1);
codeGenerator.IL.Emit(OpCodes.Pop); // removes used value from the stack
}
else
{
codeGenerator.IL.Emit(OpCodes.Pop); // removes used value from the stack
Debug.Fail("Unsupported list argument of type " + vals[i].GetType().ToString());
}
}
}