本文整理汇总了C#中PHP.Core.Emit.ILEmitter类的典型用法代码示例。如果您正苦于以下问题:C# ILEmitter类的具体用法?C# ILEmitter怎么用?C# ILEmitter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILEmitter类属于PHP.Core.Emit命名空间,在下文中一共展示了ILEmitter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: EmitAddFrame
public static void EmitAddFrame(ILEmitter/*!*/ il, IPlace/*!*/ scriptContextPlace, int typeArgCount, int argCount,
Action<ILEmitter, int> typeArgEmitter, Action<ILEmitter, int>/*!*/ argEmitter)
{
Debug.Assert(typeArgCount == 0 || typeArgEmitter != null);
// type args:
if (typeArgCount > 0)
{
scriptContextPlace.EmitLoad(il);
il.Emit(OpCodes.Ldfld, Fields.ScriptContext_Stack);
il.EmitOverloadedArgs(Types.DTypeDesc[0], typeArgCount, Methods.PhpStack.AddTypeFrame.ExplicitOverloads, typeArgEmitter);
}
// args:
scriptContextPlace.EmitLoad(il);
il.Emit(OpCodes.Ldfld, Fields.ScriptContext_Stack);
il.EmitOverloadedArgs(Types.Object[0], argCount, Methods.PhpStack.AddFrame.ExplicitOverloads, argEmitter);
il.Emit(OpCodes.Call, Methods.PhpStack.AddFrame.Overload(argCount));
// AddFrame adds empty type frame by default, so if there are no type parameters, we can skip AddTypeFrame call:
if (typeArgCount > 0)
il.Emit(OpCodes.Call, Methods.PhpStack.AddTypeFrame.Overload(typeArgCount));
}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:26,代码来源:PhpStackBuilder.cs
示例2: ClrStubBuilder
public ClrStubBuilder(ILEmitter/*!*/ il, IPlace/*!*/ scriptContextPlace, int paramCount, int paramOffset)
{
this.il = il;
this.scriptContextPlace = scriptContextPlace;
this.paramOffset = paramOffset;
this.referenceLocals = new LocalBuilder[paramCount];
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:8,代码来源:ClrStubBuilder.cs
示例3: EmitLoad
/// <summary>
/// Emits code that loads current <see cref="PHP.Core.ScriptContext"/> by calling
/// <see cref="PHP.Core.ScriptContext.CurrentContext"/> and remembers it in a local.
/// </summary>
/// <param name="il"></param>
public void EmitLoad(ILEmitter il)
{
if (localBuilder == null)
{
localBuilder = il.DeclareLocal(typeof(ScriptContext));
il.EmitCall(OpCodes.Call, Methods.ScriptContext.GetCurrentContext, null);
il.Stloc(localBuilder);
}
il.Ldloc(localBuilder);
}
开发者ID:Ashod,项目名称:Phalanger,代码行数:15,代码来源:Places.cs
示例4: Chain
/// <summary>
/// Initializes a new empty instance of the <see cref="Chain"/>.
/// </summary>
/// <param name="il">An IL emitter.</param>
public Chain(ILEmitter il)
{
isChainMember = false;
isArrayItem = false;
IsLastChainMember = false;
length = 0;
errorLabelHasValue = false;
this.il = il;
this.QuietRead = false;
}
开发者ID:hansdude,项目名称:Phalanger,代码行数:14,代码来源:Chains.cs
示例5: EmitArgFullPostCall
public static void EmitArgFullPostCall(ILEmitter/*!*/ il, IPlace/*!*/ stack, LocalBuilder locArgsCount)
{
// args-aware:
if (locArgsCount != null)
{
// CALL stack.RemoveArgsAwareFrame(count);
stack.EmitLoad(il);
il.Ldloc(locArgsCount);
il.Emit(OpCodes.Call, Methods.PhpStack.RemoveArgsAwareFrame);
}
}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:11,代码来源:PhpStackBuilder.cs
示例6: EmitReturnValueCopy
/// <summary>
/// Emit <see cref="PhpVariable.Copy"/> if needed. It means <see cref="Expression.Access"/> has to be <see cref="AccessType.Read"/> and <paramref name="returnType"/> has to be copiable.
/// </summary>
/// <param name="il">The <see cref="ILEmitter"/>.</param>
/// <param name="returnType"><see cref="PhpTypeCode"/> of function call return value.</param>
protected void EmitReturnValueCopy(ILEmitter/*!*/il, PhpTypeCode returnType)
{
Debug.Assert(il != null);
// copy only if we are reading the return value &&
// only if return type is copiable:
if (access != AccessType.None && // reading, not literals:
PhpTypeCodeEnum.IsDeeplyCopied(returnType) &&
returnType != PhpTypeCode.PhpReference) // PhpSmartReference can be an issue if method returns an object field (but this is handled by binders)
{
il.LdcI4((int)CopyReason.ReturnedByCopy);
il.Emit(OpCodes.Call, Methods.PhpVariable.Copy);
}
}
开发者ID:MpApQ,项目名称:Phalanger,代码行数:19,代码来源:FunctionCall.cs
示例7: EmitArgFullPreCall
public static void EmitArgFullPreCall(ILEmitter/*!*/ il, IPlace/*!*/ stack, bool argsAware,
int formalParamCount, int formalTypeParamCount, out LocalBuilder locArgsCount)
{
if (argsAware)
{
locArgsCount = il.DeclareLocal(typeof(int));
// locArgsCount = stack.MakeArgsAware(<formal tpye param count | formal param count>);
stack.EmitLoad(il);
il.LdcI4((formalTypeParamCount << 16) | formalParamCount);
il.Emit(OpCodes.Call, Methods.PhpStack.MakeArgsAware);
il.Stloc(locArgsCount);
}
else
{
locArgsCount = null;
// CALL stack.RemoveFrame();
stack.EmitLoad(il);
il.Emit(OpCodes.Call, Methods.PhpStack.RemoveFrame);
}
}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:22,代码来源:PhpStackBuilder.cs
示例8: DefineContextType
public void DefineContextType()
{
linqContextBuilder = cg.IL.TypeBuilder.DefineNestedType(ContextTypeName + cg.IL.GetNextUniqueIndex(),
TypeAttributes.Class | TypeAttributes.NestedPrivate | TypeAttributes.Sealed,
typeof(PHP.Core.LinqContext), null);
// .ctor:
ConstructorBuilder ctor = linqContextBuilder.DefineConstructor(MethodAttributes.Assembly,
CallingConventions.HasThis, Types.LinqContextArgs);
ILEmitter il = new ILEmitter(ctor);
il.Ldarg(0);
il.Ldarg(1);
il.Ldarg(2);
il.Ldarg(3);
il.Ldarg(4);
il.Emit(OpCodes.Call, Constructors.LinqContext);
il.Emit(OpCodes.Ret);
linqContextCtor = ctor;
}
开发者ID:jdluzen,项目名称:Phalanger,代码行数:22,代码来源:LinqBuilder.cs
示例9: EmitLoadInstance
/// <summary>
/// Emit LOAD <paramref name="instance"/>.
/// </summary>ILEmiter
/// <param name="il"><see cref="ILEmitter"/> object instance.</param>
/// <param name="instance">The place where to load the instance from.</param>
/// <param name="declaringType">The type of resulting instance.</param>
/// <remarks>Instance of value types are wrapped in <see cref="ClrValue<T>"/> object instance.</remarks>
internal static void EmitLoadInstance(ILEmitter/*!*/il, IPlace/*!*/instance, Type/*!*/declaringType)
{
Debug.Assert(il != null && instance != null && declaringType != null, "ClrOverloadBuilder.EmitLoadInstance() null argument!");
// LOAD <instance>
instance.EmitLoad(il);
if (declaringType.IsValueType)
{
var clrValueType = ClrObject.valueTypesCache.Get(declaringType).Item1;
Debug.Assert(clrValueType != null, "Specific ClrValue<T> not found!");
// CAST (ClrValue<T>)
il.Emit(OpCodes.Castclass, clrValueType);
// LOAD .realValue
var realValueField = clrValueType.GetField("realValue");
Debug.Assert(realValueField != null, "ClrValue<T>.realValue field not found!");
il.Emit(OpCodes.Ldflda, clrValueType.GetField("realValue"));
}
else
{
// CAST (T)
il.Emit(OpCodes.Castclass, declaringType);
}
}
开发者ID:hansdude,项目名称:Phalanger,代码行数:33,代码来源:ClrOverloadBuilder.cs
示例10: EmitConvertToPhp
/// <summary>
/// Converts a value of the given CLR type to PHP value.
/// </summary>
internal static PhpTypeCode EmitConvertToPhp(ILEmitter/*!*/ il, Type/*!*/ type)
{
// box generic parameter
if (type.IsGenericParameter)
{
il.Emit(OpCodes.Box, type);
type = Types.Object[0];
}
switch (Type.GetTypeCode(type))
{
// primitives:
case TypeCode.Boolean: return PhpTypeCode.Boolean;
case TypeCode.Int32: return PhpTypeCode.Integer;
case TypeCode.Int64: return PhpTypeCode.LongInteger;
case TypeCode.Double: return PhpTypeCode.Double;
case TypeCode.String: return PhpTypeCode.String;
// coercion:
case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.Byte:
case TypeCode.UInt16:
{
il.Emit(OpCodes.Conv_I4);
return PhpTypeCode.Integer;
}
case TypeCode.UInt32: EmitConstrainedCoercion(il, typeof(int), typeof(long), Int32.MaxValue); return PhpTypeCode.Object;
case TypeCode.UInt64: EmitConstrainedCoercion(il, typeof(int), typeof(long), Int32.MaxValue); return PhpTypeCode.Object;
case TypeCode.Single: il.Emit(OpCodes.Conv_R8); return PhpTypeCode.Double;
case TypeCode.Char:
il.Emit(OpCodes.Box, type);
il.Emit(OpCodes.Callvirt, Methods.Object_ToString);
return PhpTypeCode.String;
case TypeCode.DBNull:
{
il.Emit(OpCodes.Pop);
il.Emit(OpCodes.Ldnull);
return PhpTypeCode.Object;
}
case TypeCode.Decimal: // TODO: what to do with this guy?
case TypeCode.DateTime:
{
il.Emit(OpCodes.Box, type);
il.Emit(OpCodes.Call, Methods.ClrObject_Wrap);
return PhpTypeCode.DObject;
}
case TypeCode.Object:
{
if (!typeof(IPhpVariable).IsAssignableFrom(type))
{
if (type.IsValueType)
il.Emit(OpCodes.Box, type);
il.Emit(OpCodes.Call, Methods.ClrObject_WrapDynamic);
return PhpTypeCode.Object;
}
else return PhpTypeCodeEnum.FromType(type);
}
default:
{
Debug.Fail();
return PhpTypeCode.Invalid;
}
}
}
开发者ID:hansdude,项目名称:Phalanger,代码行数:76,代码来源:ClrOverloadBuilder.cs
示例11: EmitConstrainedCoercion
internal static void EmitConstrainedCoercion(ILEmitter/*!*/ il, Type/*!*/ narrow, Type/*!*/ wide, object threshold)
{
Label else_label = il.DefineLabel();
Label endif_label = il.DefineLabel();
il.Emit(OpCodes.Dup);
// IF (STACK <= threshold) THEN
il.LoadLiteral(threshold);
il.Emit(OpCodes.Bgt_S, else_label);
// LOAD (narrow)STACK
il.Conv(narrow, false);
il.Emit(OpCodes.Box, narrow);
il.Emit(OpCodes.Br_S, endif_label);
// ELSE
il.MarkLabel(else_label);
// LOAD (wide)STACK
il.Conv(wide, false);
il.Emit(OpCodes.Box, wide);
// ENDIF
il.MarkLabel(endif_label);
}
开发者ID:hansdude,项目名称:Phalanger,代码行数:28,代码来源:ClrOverloadBuilder.cs
示例12: EmitConvertObjectToClr
/// <summary>
/// Converts object to CLR type
/// </summary>
private static bool EmitConvertObjectToClr(ILEmitter il, PhpTypeCode typeCode, Type formalType, LocalBuilder strictnessLocal)
{
MethodInfo convert_method = null;
switch (Type.GetTypeCode(formalType))
{
case TypeCode.Boolean: if (typeCode != PhpTypeCode.Boolean)
convert_method = Methods.ConvertToClr.TryObjectToBoolean; break;
case TypeCode.Int32: if (typeCode != PhpTypeCode.Integer)
convert_method = Methods.ConvertToClr.TryObjectToInt32; break;
case TypeCode.Int64: if (typeCode != PhpTypeCode.LongInteger)
convert_method = Methods.ConvertToClr.TryObjectToInt64; break;
case TypeCode.Double: if (typeCode != PhpTypeCode.Double)
convert_method = Methods.ConvertToClr.TryObjectToDouble; break;
case TypeCode.String: if (typeCode != PhpTypeCode.String)
convert_method = Methods.ConvertToClr.TryObjectToString; break;
case TypeCode.SByte: convert_method = Methods.ConvertToClr.TryObjectToInt8; break;
case TypeCode.Int16: convert_method = Methods.ConvertToClr.TryObjectToInt16; break;
case TypeCode.Byte: convert_method = Methods.ConvertToClr.TryObjectToUInt8; break;
case TypeCode.UInt16: convert_method = Methods.ConvertToClr.TryObjectToUInt16; break;
case TypeCode.UInt32: convert_method = Methods.ConvertToClr.TryObjectToUInt32; break;
case TypeCode.UInt64: convert_method = Methods.ConvertToClr.TryObjectToUInt64; break;
case TypeCode.Single: convert_method = Methods.ConvertToClr.TryObjectToSingle; break;
case TypeCode.Decimal: convert_method = Methods.ConvertToClr.TryObjectToDecimal; break;
case TypeCode.Char: convert_method = Methods.ConvertToClr.TryObjectToChar; break;
case TypeCode.DateTime: convert_method = Methods.ConvertToClr.TryObjectToDateTime; break;
case TypeCode.DBNull: convert_method = Methods.ConvertToClr.TryObjectToDBNull; break;
case TypeCode.Object:
{
if (formalType.IsValueType)
{
if (formalType.IsGenericType && NullableType == formalType.GetGenericTypeDefinition())
{
// This is an ugly corner case (using generic TryObjectToStruct wouldn't work, because
// for nullables .IsValueType returns true, but it doesn't match "T : struct" constraint)!
// We have to try converting object to Nullable<T> first and then to T
// (which requires a new call to 'EmitConvertObjectToClr')
Type nullableArg = formalType.GetGenericArguments()[0];
Type nullableType = NullableType.MakeGenericType(nullableArg);
LocalBuilder tmpVar = il.DeclareLocal(typeof(object));
// This succeeds only for exact match
il.Emit(OpCodes.Call, Methods.ConvertToClr.UnwrapNullable);
il.Emit(OpCodes.Dup);
il.Stloc(tmpVar);
// <stack_0> = tmpVar = UnwrapNullable(...)
// if (<stack_0> != null)
Label lblNull = il.DefineLabel(), lblDone = il.DefineLabel();
il.Emit(OpCodes.Ldnull);
il.Emit(OpCodes.Beq, lblNull);
// {
// Convert tmpVar to T and wrap it into Nullable<T>
il.Ldloc(tmpVar);
bool ret = EmitConvertObjectToClr(il, typeCode, nullableArg, strictnessLocal);
// TODO: use reflection cache?
il.Emit(OpCodes.Newobj, nullableType.GetConstructors()[0]);
il.Emit(OpCodes.Br, lblDone);
// } else /* == null */ {
il.MarkLabel(lblNull);
// return (T?)null;
LocalBuilder tmpNull = il.DeclareLocal(nullableType);
il.Ldloca(tmpNull);
il.Emit(OpCodes.Initobj, nullableType);
il.Ldloc(tmpNull);
// }
il.MarkLabel(lblDone);
return ret;
}
else
convert_method = Methods.ConvertToClr.TryObjectToStruct.MakeGenericMethod(formalType);
}
else
{
if (formalType.IsArray)
convert_method = Methods.ConvertToClr.TryObjectToArray.MakeGenericMethod(formalType.GetElementType());
else if (typeof(Delegate).IsAssignableFrom(formalType))
convert_method = Methods.ConvertToClr.TryObjectToDelegate.MakeGenericMethod(formalType);
else
convert_method = Methods.ConvertToClr.TryObjectToClass.MakeGenericMethod(formalType);
}
break;
}
default:
Debug.Fail();
return true;
}
if (convert_method != null)
{
//.........这里部分代码省略.........
开发者ID:hansdude,项目名称:Phalanger,代码行数:101,代码来源:ClrOverloadBuilder.cs
示例13: ClrOverloadBuilder
public ClrOverloadBuilder(ILEmitter/*!*/ il, ClrMethod/*!*/ method, ConstructedType constructedType,
IPlace/*!*/ stack, IPlace/*!*/ instance, bool emitParentCtorCall,
ParameterLoader/*!*/ loadValueArg, ParameterLoader/*!*/ loadReferenceArg)
{
this.il = il;
this.method = method;
this.constructedType = constructedType;
this.stack = stack;
this.instance = instance;
this.loadValueArg = loadValueArg;
this.loadReferenceArg = loadReferenceArg;
this.emitParentCtorCall = emitParentCtorCall;
this.overloads = new List<Overload>(method.Overloads);
SortOverloads(this.overloads);
}
开发者ID:hansdude,项目名称:Phalanger,代码行数:16,代码来源:ClrOverloadBuilder.cs
示例14: EmitConvertToClr
/// <summary>
/// Converts a PHP value to the given CLR type (the caller is not interested in the success of the conversion).
/// </summary>
public static void EmitConvertToClr(ILEmitter/*!*/ il, PhpTypeCode typeCode, Type/*!*/ formalType)
{
EmitConvertToClr(il, typeCode, formalType, il.GetTemporaryLocal(typeof(ConversionStrictness), true));
}
开发者ID:hansdude,项目名称:Phalanger,代码行数:7,代码来源:ClrOverloadBuilder.cs
示例15: ILEmitter
/// <summary>
/// Emit publically accessible stub that just calls argfull of <paramref name="function"/>.
/// </summary>
/// <returns><see cref="MethodInfo"/> of newly created function stub.</returns>
private MethodInfo/*!*/EmitPhpFunctionPublicStub(ref TypeBuilder publicsContainer, PhpFunction/*!*/function)
{
Debug.Assert(function != null);
Debug.Assert(function.ArgFullInfo != null, "!function.ArgFullInfo");
if (publicsContainer == null)
{
publicsContainer = PureAssemblyBuilder.RealModuleBuilder.DefineType(
string.Format("{1}<{0}>",
StringUtils.ToClsCompliantIdentifier(Path.ChangeExtension(PureAssemblyBuilder.FileName, "")),
QualifiedName.Global.ToString()),
TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Class | TypeAttributes.SpecialName);
}
Type returnType;
var parameterTypes = function.Signature.ToArgfullSignature(1, out returnType);
parameterTypes[0] = Types.ScriptContext[0];
var mi = publicsContainer.DefineMethod(function.GetFullName(), MethodAttributes.Public | MethodAttributes.Static, returnType, parameterTypes);
var il = new ILEmitter(mi);
// load arguments
for (int i = 0; i < parameterTypes.Length; i++)
{
if (function.Builder != null)
mi.DefineParameter(i + 1, ParameterAttributes.None, function.Builder.ParameterBuilders[i].Name);
il.Ldarg(i);
}
// call function.ArgFullInfo
il.Emit(OpCodes.Call, function.ArgFullInfo);
// .ret
il.Emit(OpCodes.Ret);
//
return mi;
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:43,代码来源:ModuleBuilders.CLR.cs
示例16: EmitGetterStub
internal static void EmitGetterStub(ILEmitter/*!*/ il, PropertyInfo/*!*/ propertyInfo, Type/*!*/ declaringType)
{
var getter = propertyInfo.GetGetMethod(/*false*/);
if (getter == null)
{
il.Emit(OpCodes.Ldstr, declaringType.Name);
il.Emit(OpCodes.Ldstr, "get_" + propertyInfo.Name);
il.Emit(OpCodes.Call, Methods.PhpException.UndefinedMethodCalled);
il.Emit(OpCodes.Ldnull);
il.Emit(OpCodes.Ret);
return;
}
if (getter.IsStatic)
{
// [ return getter() ]
il.Emit(OpCodes.Call, getter);
}
else
{
// [ return ((self)<instance>).getter() ]
il.Ldarg(0);
il.Emit(OpCodes.Castclass, declaringType);
il.Emit(OpCodes.Call, getter);
}
// box
il.EmitBoxing(PhpTypeCodeEnum.FromType(getter.ReturnType));
//
il.Emit(OpCodes.Ret);
}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:34,代码来源:Properties.cs
示例17: EmitDeclareHelper
/// <summary>
/// Emits helper declaring all single-declared functions and classes in the script being built.
/// </summary>
/// <remarks>
/// For each function and class emits a call to <see cref="ApplicationContext.DeclareFunction"/> and
/// <see cref="ApplicationContext.DeclareType"/>, respectively, which declares it.
/// The helper is called as the first instruction of Main helper.
/// </remarks>
private void EmitDeclareHelper()
{
PureCompilationUnit unit = this.PureCompilationUnit;
ILEmitter il = new ILEmitter(declareHelperBuilder);
IndexedPlace app_context_place = new IndexedPlace(PlaceHolder.Argument, 0);
TypeBuilder publicsContainer = null; // container type for public stubs of global declarations (which are inaccessible from other assemblies)
foreach (PhpFunction function in unit.GetDeclaredFunctions())
{
if (function.IsDefinite)
{
app_context_place.EmitLoad(il);
// NEW RoutineDelegate(<static method>);
il.Emit(OpCodes.Ldnull);
il.Emit(OpCodes.Ldftn, function.ArgLessInfo);
il.Emit(OpCodes.Newobj, Constructors.RoutineDelegate);
// LOAD <full name>;
il.Emit(OpCodes.Ldstr, function.FullName);
// LOAD <attributes>;
il.LdcI4((int)function.MemberDesc.MemberAttributes);
// LOAD <argfull>
if (function.ArgFullInfo != null)
CodeGenerator.EmitLoadMethodInfo(
il,
(function.ArgFullInfo.DeclaringType != null)
? function.ArgFullInfo
: EmitPhpFunctionPublicStub(ref publicsContainer, function) // function.ArgFullInfo is real global method not accessible from other assemblies, must be wrapped
/*, AssemblyBuilder.DelegateBuilder*/);
else
il.Emit(OpCodes.Ldnull);
// CALL <application context>.DeclareFunction(<stub>, <name>, <member attributes>, <argfull>)
il.Emit(OpCodes.Call, Methods.ApplicationContext.DeclareFunction);
}
}
foreach (PhpType type in unit.GetDeclaredTypes())
{
if (type.IsDefinite)
{
// CALL <application context>.DeclareType(<type desc>, <name>);
type.EmitAutoDeclareOnApplicationContext(il, app_context_place);
}
}
foreach (GlobalConstant constant in unit.GetDeclaredConstants())
{
if (constant.IsDefinite)
{
app_context_place.EmitLoad(il);
// CALL <application context>.DeclareConstant(<name>, <value>);
il.Emit(OpCodes.Ldstr, constant.FullName);
//il.Emit(OpCodes.Ldsfld, constant.RealField);
//if (constant.RealField.FieldType.IsValueType) il.Emit(OpCodes.Box, constant.RealField.FieldType);
il.LoadLiteralBox(constant.Value);
il.Emit(OpCodes.Call, Methods.ApplicationContext.DeclareConstant);
}
}
il.Emit(OpCodes.Ret);
// complete the publicsContainer type, if created:
if (publicsContainer != null)
publicsContainer.CreateType();
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:78,代码来源:ModuleBuilders.CLR.cs
示例18: EmitStore
public void EmitStore(ILEmitter/*!*/ il)
{
throw new InvalidOperationException();
}
开发者ID:proff,项目名称:Phalanger,代码行数:4,代码来源:Expression.cs
示例19: GenerateSetterStub
protected virtual SetterDelegate/*!*/ GenerateSetterStub()
{
if (Member is ClrEvent) return new SetterDelegate(EventSetter);
#if SILVERLIGHT
DynamicMethod stub = new DynamicMethod("<^SetterStub>", Types.Void, Types.Object_Object);
/*DynamicMethod stub = new DynamicMethod("<^SetterStub>", PhpFunctionUtils.DynamicStubAttributes, CallingConventions.Standard,
Types.Void, Types.Object_Object, this.declaringType.RealType, true);*/
#else
DynamicMethod stub = new DynamicMethod("<^SetterStub>", PhpFunctionUtils.DynamicStubAttributes, CallingConventions.Standard,
Types.Void, Types.Object_Object, this.declaringType.RealType, true);
#endif
#if DEBUG_DYNAMIC_STUBS
// Debugging - save the generated stub to TEMP
AssemblyName name = new AssemblyName("SetterStub_" + Property.FullName.ToString().Replace(':', '_'));
AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Save, "C:\\Temp");
ModuleBuilder mb = ab.DefineDynamicModule(name.Name, name.Name + ".dll");
TypeBuilder tb = mb.DefineType("Stub");
MethodBuilder meb = tb.DefineMethod(DeclaringType.ToString() + "::" + Property.FullName,
MethodAttributes.PrivateScope | MethodAttributes.Static, Types.Void, Types.Object_Object);
ILEmitter il_dbg = new ILEmitter(meb);
IndexedPlace instance2 = new IndexedPlace(PlaceHolder.Argument, 0);
IndexedPlace stack = new IndexedPlace(PlaceHolder.Argument, 1);
ClrProperty clr_property_dbg = Member as ClrProperty;
if (clr_property_dbg != null && clr_property_dbg.HasSetter)
{
if (!clr_property_dbg.Setter.IsStatic)
{
il_dbg.Emit(OpCodes.Ldarg_0);
if (declaringType.RealType.IsValueType)
il_dbg.Emit(OpCodes.Unbox, declaringType.RealType);
#if EMIT_VERIFIABLE_STUBS
else
il_dbg.Emit(OpCodes.Castclass, declaringType.RealType);
#endif
}
il_dbg.Emit(OpCodes.Ldarg_1);
EmitSetConversion(il_dbg, PhpTypeCode.Object, clr_property_dbg.Setter.GetParameters()[0].ParameterType);
il_dbg.Emit(OpCodes.Call, clr_property_dbg.Setter);
}
il_dbg.Emit(OpCodes.Ret);
tb.CreateType();
ab.Save("SetterStub_" + Property.FullName.ToString().Replace(':', '_') + ".dll");
#endif
ILEmitter il = new ILEmitter(stub);
ClrProperty clr_property = Member as ClrProperty;
Type arg_type;
if (clr_property != null)
{
// return error-throwing setter if the property is read-only
if (!clr_property.HasSetter) return new SetterDelegate(MissingSetter);
if (!clr_property.Setter.IsStatic)
{
ClrOverloadBuilder.EmitLoadInstance(il, IndexedPlace.ThisArg, declaringType.RealType);
// il.Emit(OpCodes.Ldarg_0);
// if (declaringType.RealType.IsValueType)
// il.Emit(OpCodes.Unbox, declaringType.RealType);
//#if EMIT_VERIFIABLE_STUBS
// else
// il.Emit(OpCodes.Castclass, declaringType.RealType);
//#endif
}
il.Emit(OpCodes.Ldarg_1);
arg_type = clr_property.Setter.GetParameters()[0].ParameterType;
EmitSetConversion(il, PhpTypeCode.Object, arg_type);
il.Emit(OpCodes.Call, clr_property.Setter);
}
else
{
ClrField clr_field = ClrField;
// return error-throwing setter if the field is initonly
if (clr_field.FieldInfo.IsInitOnly) return new SetterDelegate(MissingSetter);
if (!clr_field.FieldInfo.IsStatic)
{
ClrOverloadBuilder.EmitLoadInstance(il, IndexedPlace.ThisArg, declaringType.RealType);
//il.Emit(OpCodes.Ldarg_0);
////il.Emit(OpCodes.Castclass, this.declaringType.RealType);
//if (declaringType.RealType.IsValueType) il.Emit(OpCodes.Unbox, declaringType.RealType);
}
il.Emit(OpCodes.Ldarg_1);
arg_type = clr_field.FieldInfo.FieldType;
//.........这里部分代码省略.........
开发者ID:tiaohai,项目名称:Phalanger,代码行数:101,代码来源:Properties.cs
示例20: EmitLoadAccessorDelegate
private void EmitLoadAccessorDelegate(ILEmitter/*!*/ il, ConstructorInfo/*!*/ delegateCtor,
IPlace instance, bool dynamicStub, MethodInfo accessor)
{
if (accessor != null)
{
if (instance != null) instance.EmitLoad(il); else il.Emit(OpCodes.Ldnull);
if (!dynamicStub && accessor.IsVirtual)
{
instance.EmitLoad(il);
il.Emit(OpCodes.Ldvirtftn, accessor);
}
else il.Emit(OpCodes.Ldftn, accessor);
il.Emit(OpCodes.Newobj, delegateCtor);
}
else il.Emit(OpCodes.Ldnull);
}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:17,代码来源:Properties.cs
注:本文中的PHP.Core.Emit.ILEmitter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论