本文整理汇总了C#中Mono.CSharp.EmitContext.EmitTopBlock方法的典型用法代码示例。如果您正苦于以下问题:C# EmitContext.EmitTopBlock方法的具体用法?C# EmitContext.EmitTopBlock怎么用?C# EmitContext.EmitTopBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.EmitContext
的用法示例。
在下文中一共展示了EmitContext.EmitTopBlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
//
// Emits the code
//
public virtual void Emit (TypeContainer parent, Block block, object kind)
{
ILGenerator ig;
EmitContext ec;
if ((flags & MethodAttributes.PinvokeImpl) == 0)
ig = builder.GetILGenerator ();
else
ig = null;
ec = new EmitContext (parent, Location, ig, ReturnType, modifiers);
if (OptAttributes != null)
Attribute.ApplyAttributes (ec, builder, kind, OptAttributes);
if (member is MethodCore)
((MethodCore) member).LabelParameters (ec, MethodBuilder, OptAttributes);
//
// abstract or extern methods have no bodies
//
if ((modifiers & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0){
if (block == null) {
SymbolWriter sw = CodeGen.SymbolWriter;
if ((sw != null) && ((modifiers & Modifiers.EXTERN) != 0)) {
sw.OpenMethod (parent, MethodBuilder, Location, Location);
sw.CloseMethod ();
}
return;
}
//
// abstract or extern methods have no bodies.
//
if ((modifiers & Modifiers.ABSTRACT) != 0)
Report.Error (
500, Location, "Abstract method `" +
TypeManager.CSharpSignature (builder) +
"' can not have a body");
if ((modifiers & Modifiers.EXTERN) != 0)
Report.Error (
179, Location, "External method `" +
TypeManager.CSharpSignature (builder) +
"' can not have a body");
return;
}
//
// Methods must have a body unless they're extern or abstract
//
if (block == null) {
Report.Error (
501, Location, "Method `" +
TypeManager.CSharpSignature (builder) +
"' must declare a body since it is not marked " +
"abstract or extern");
return;
}
//
// Handle destructors specially
//
// FIXME: This code generates buggy code
//
if (member.Name == "Finalize" && ReturnType == TypeManager.void_type)
EmitDestructor (ec, block);
else {
SymbolWriter sw = CodeGen.SymbolWriter;
if ((sw != null) && !Location.IsNull (Location) &&
!Location.IsNull (block.EndLocation)) {
sw.OpenMethod (parent, MethodBuilder, Location, block.EndLocation);
ec.EmitTopBlock (block, ParameterInfo, Location);
sw.CloseMethod ();
} else
ec.EmitTopBlock (block, ParameterInfo, Location);
}
}
示例2: EmitDestructor
void EmitDestructor (EmitContext ec, Block block)
{
ILGenerator ig = ec.ig;
Label finish = ig.DefineLabel ();
bool old_in_try = ec.InTry;
ig.BeginExceptionBlock ();
ec.InTry = true;
ec.ReturnLabel = finish;
ec.HasReturnLabel = true;
ec.EmitTopBlock (block, null, Location);
ec.InTry = old_in_try;
// ig.MarkLabel (finish);
bool old_in_finally = ec.InFinally;
ec.InFinally = true;
ig.BeginFinallyBlock ();
if (ec.ContainerType.BaseType != null) {
Expression member_lookup = Expression.MemberLookup (
ec, ec.ContainerType.BaseType, null, ec.ContainerType.BaseType,
"Finalize", MemberTypes.Method, Expression.AllBindingFlags, Location);
if (member_lookup != null){
MethodGroupExpr parent_destructor = ((MethodGroupExpr) member_lookup);
ig.Emit (OpCodes.Ldarg_0);
ig.Emit (OpCodes.Call, (MethodInfo) parent_destructor.Methods [0]);
}
}
ec.InFinally = old_in_finally;
ig.EndExceptionBlock ();
//ig.MarkLabel (ec.ReturnLabel);
ig.Emit (OpCodes.Ret);
}