本文整理汇总了C#中System.Reflection.Emit.CodeGenerator.EmitConversion方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.EmitConversion方法的具体用法?C# CodeGenerator.EmitConversion怎么用?C# CodeGenerator.EmitConversion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.EmitConversion方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
/// <include file='Doc/Nodes.xml' path='doc/method[@name="Emit"]/*'/>
internal override PhpTypeCode Emit(CodeGenerator/*!*/ codeGenerator)
{
#if !SILVERLIGHT
Debug.Assert(access == AccessType.Read || access == AccessType.None);
Statistics.AST.AddNode("ShellEx");
// CALL Execution.ShellExec(<(string) command>);
codeGenerator.EmitConversion(command, PhpTypeCode.String);
codeGenerator.IL.Emit(OpCodes.Call, Methods.ShellExec);
if (access == AccessType.None)
{
codeGenerator.IL.Emit(OpCodes.Pop);
return PhpTypeCode.Void;
}
#endif
// ShellExec returns a string containing the standard output of executed command
return PhpTypeCode.String;
}
示例2: EmitDynamicInclusion
/// <summary>
/// Emits dynamic inclusion.
/// </summary>
private PhpTypeCode EmitDynamicInclusion(CodeGenerator/*!*/ codeGenerator)
{
// do not generate dynamic auto inclusions:
if (InclusionTypesEnum.IsAutoInclusion(inclusionType))
return PhpTypeCode.Void;
ILEmitter il = codeGenerator.IL;
// CALL context.DynamicInclude(<file name>,<relative includer source path>,variables,self,includer);
codeGenerator.EmitLoadScriptContext();
codeGenerator.EmitConversion(fileNameEx, PhpTypeCode.String);
il.Emit(OpCodes.Ldstr, codeGenerator.SourceUnit.SourceFile.RelativePath.ToString());
codeGenerator.EmitLoadRTVariablesTable();
codeGenerator.EmitLoadSelf();
codeGenerator.EmitLoadClassContext();
il.LoadLiteral(inclusionType);
il.Emit(OpCodes.Call, Methods.ScriptContext.DynamicInclude);
return PhpTypeCode.Object;
}
示例3: EmitName
/// <summary>
/// Emits load of the name to the stack.
/// </summary>
internal override void EmitName(CodeGenerator codeGenerator)
{
codeGenerator.ChainBuilder.Create();
codeGenerator.EmitConversion(this.VarNameEx, PhpTypeCode.String);
codeGenerator.ChainBuilder.End();
}
示例4: EmitBinaryBooleanOperation
/// <summary>
/// Emits binary boolean operation (AND or OR).
/// </summary>
/// <param name="codeGenerator">A code generator.</param>
/// <param name="isAnd">Whether to emit AND.</param>
/// <returns>A type code of the result.</returns>
private PhpTypeCode EmitBinaryBooleanOperation(CodeGenerator codeGenerator, bool isAnd)
{
ILEmitter il = codeGenerator.IL;
Label partial_eval_label = il.DefineLabel();
Label end_label = il.DefineLabel();
// IF [!]<(bool) leftSon> THEN GOTO partial_eval;
codeGenerator.EmitConversion(leftExpr, PhpTypeCode.Boolean);
il.Emit(isAnd ? OpCodes.Brfalse : OpCodes.Brtrue, partial_eval_label);
// LOAD <(bool) leftSon>;
codeGenerator.EmitConversion(rightExpr, PhpTypeCode.Boolean);
il.Emit(OpCodes.Br, end_label);
il.MarkLabel(partial_eval_label, true);
il.LdcI4(isAnd ? 0 : 1);
il.MarkLabel(end_label, true);
return PhpTypeCode.Boolean;
}
示例5: Emit
//.........这里部分代码省略.........
break;
case Operations.ShiftLeft:
// LOAD Operators.ShiftLeft(box left, box right);
codeGenerator.EmitBoxing(leftExpr.Emit(codeGenerator));
codeGenerator.EmitBoxing(rightExpr.Emit(codeGenerator));
returned_typecode = codeGenerator.EmitMethodCall(Methods.Operators.ShiftLeft);
break;
case Operations.ShiftRight:
// LOAD Operators.ShiftRight(box left, box right);
codeGenerator.EmitBoxing(leftExpr.Emit(codeGenerator));
codeGenerator.EmitBoxing(rightExpr.Emit(codeGenerator));
returned_typecode = codeGenerator.EmitMethodCall(Methods.Operators.ShiftRight);
break;
#endregion
#region Boolean and Bitwise Operations
case Operations.And:
returned_typecode = EmitBinaryBooleanOperation(codeGenerator, true);
break;
case Operations.Or:
returned_typecode = EmitBinaryBooleanOperation(codeGenerator, false);
break;
case Operations.Xor:
// LOAD <(bool) leftSon> == <(bool) rightSon>;
codeGenerator.EmitConversion(leftExpr, PhpTypeCode.Boolean);
codeGenerator.EmitConversion(rightExpr, PhpTypeCode.Boolean);
codeGenerator.IL.Emit(OpCodes.Ceq);
codeGenerator.IL.Emit(OpCodes.Ldc_I4_0);
codeGenerator.IL.Emit(OpCodes.Ceq);
returned_typecode = PhpTypeCode.Boolean;
break;
case Operations.BitAnd:
returned_typecode = EmitBitOperation(codeGenerator, Operators.BitOp.And);
break;
case Operations.BitOr:
returned_typecode = EmitBitOperation(codeGenerator, Operators.BitOp.Or);
break;
case Operations.BitXor:
returned_typecode = EmitBitOperation(codeGenerator, Operators.BitOp.Xor);
break;
#endregion
#region Comparing Operations
case Operations.Equal:
// LOAD PhpComparer.Default.CompareEq
returned_typecode = EmitComparison(codeGenerator, true);
break;
case Operations.NotEqual:
示例6: Emit
internal override PhpTypeCode Emit(CodeGenerator/*!*/ codeGenerator)
{
LinqBuilder builder = codeGenerator.LinqBuilder;
ILEmitter il = builder.IL;
codeGenerator.EmitConversion(expression, PhpTypeCode.LinqSource);
firstOp.Emit(builder);
return PhpTypeCode.LinqSource;
}
示例7: Emit
/// <include file='Doc/Nodes.xml' path='doc/method[@name="Emit"]/*'/>
internal override PhpTypeCode Emit(CodeGenerator codeGenerator)
{
Statistics.AST.AddNode("TernaryEx");
Debug.Assert(access == AccessType.Read || access == AccessType.None);
Label end_label = codeGenerator.IL.DefineLabel();
if (trueExpr != null) // standard ternary operator
{
Label else_label = codeGenerator.IL.DefineLabel();
// IF (<(bool) condition>) THEN
codeGenerator.EmitConversion(condExpr, PhpTypeCode.Boolean);
codeGenerator.IL.Emit(OpCodes.Brfalse, else_label);
{
codeGenerator.EmitBoxing(trueExpr.Emit(codeGenerator));
codeGenerator.IL.Emit(OpCodes.Br, end_label);
}
// ELSE
codeGenerator.IL.MarkLabel(else_label, true);
{
codeGenerator.EmitBoxing(falseExpr.Emit(codeGenerator));
}
}
else
{ // ternary shortcut:
var il = codeGenerator.IL;
// condExpr ?? rightExpr
il.EmitBoxing(condExpr.Emit(codeGenerator));
// IF (<stack>):
il.Emit(OpCodes.Dup);
il.Emit(OpCodes.Call, Methods.Convert.ObjectToBoolean);
codeGenerator.IL.Emit(OpCodes.Brtrue, end_label);
// ELSE:
{
il.Emit(OpCodes.Pop);
il.EmitBoxing(falseExpr.Emit(codeGenerator));
}
}
// END IF;
codeGenerator.IL.MarkLabel(end_label, true);
if (access == AccessType.None)
{
codeGenerator.IL.Emit(OpCodes.Pop);
return PhpTypeCode.Void;
}
return PhpTypeCode.Object;
}
示例8: Emit
/// <include file='Doc/Nodes.xml' path='doc/method[@name="Emit"]/*'/>
internal override void Emit(CodeGenerator codeGenerator)
{
Statistics.AST.AddNode("JumpStmt");
// marks a sequence point:
codeGenerator.MarkSequencePoint(
position.FirstLine,
position.FirstColumn,
position.LastLine,
position.LastColumn + 1);
switch (type)
{
case Types.Break:
// Emit simple break; - break the most inner loop
if (expr == null)
{
codeGenerator.BranchingStack.EmitBreak();
}
else if (expr.HasValue)
{
// We can get the number at compile time and generate the right branch
// instruction for break x; where x is Literal
codeGenerator.BranchingStack.EmitBreak(Convert.ObjectToInteger(expr.Value));
}
else
{
// In this case we emit the switch that decides where to branch at runtime.
codeGenerator.EmitConversion(expr, PhpTypeCode.Integer);
codeGenerator.BranchingStack.EmitBreakRuntime();
}
break;
case Types.Continue:
// Emit simple continue; - banch back to the condition of the most inner loop
if (expr == null)
{
codeGenerator.BranchingStack.EmitContinue();
}
else if (expr.HasValue)
{
// We can get the number at compile time and generate the right branch
// instruction for continue x; where x is Literal
codeGenerator.BranchingStack.EmitContinue(Convert.ObjectToInteger(expr.Value));
}
else
{
// In this case we emit the switch that decides where to branch at runtime.
codeGenerator.EmitConversion(expr, PhpTypeCode.Integer);
codeGenerator.BranchingStack.EmitContinueRuntime();
}
break;
case Types.Return:
if (codeGenerator.ReturnsPhpReference)
EmitReturnPhpReference(codeGenerator);
else
EmitReturnObject(codeGenerator);
break;
default:
throw null;
}
}