public override void Emit(IMemberEmitter member, ILGenerator gen) { foreach (Statement s in statements) { s.Emit(member, gen); } }
public override void Emit(IMemberEmitter member, ILGenerator gen) { ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen); var notNull = gen.DefineLabel(); gen.Emit(OpCodes.Brtrue_S, notNull); ifNull.Emit(member, gen); gen.MarkLabel(notNull); ifNotNull.Emit(member, gen); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { right.Emit(member, gen); if (fromType == target) { return; } if (fromType.IsByRef) { fromType = fromType.GetElementType(); } if (target.IsByRef) { target = target.GetElementType(); } if (target.IsArray()) { if (fromType.IsValueType()) { throw new NotImplementedException("Cannot convert between distinct value types"); } else { // Unbox conversion // Assumes fromType is a boxed value // if we can, we emit a box and ldind, otherwise, we will use unbox.any if (LdindOpCodesDictionary.Instance[target] != LdindOpCodesDictionary.EmptyOpCode) { gen.Emit(OpCodes.Unbox, target); OpCodeUtil.EmitLoadIndirectOpCodeForType(gen, target); } else { gen.Emit(OpCodes.Unbox_Any, target); } } } else { if (fromType.IsValueType()) { // Box conversion gen.Emit(OpCodes.Box, fromType); EmitCastIfNeeded(typeof(object), target, gen); } else { // Possible down-cast EmitCastIfNeeded(fromType, target, gen); } } }
public override void Emit(IMemberEmitter member, ILGenerator gen) { expression.Emit(member, gen); gen.Emit(OpCodes.Dup); var label = gen.DefineLabel(); gen.Emit(OpCodes.Brtrue_S, label); gen.Emit(OpCodes.Pop); @default.Emit(member, gen); gen.MarkLabel(label); }
public override void Emit(IMemberEmitter member, ILGenerator il) { ArgumentsUtil.EmitLoadOwnerAndReference(targetArray, il); il.Emit(OpCodes.Ldc_I4, targetPosition); value.Emit(member, il); il.Emit(OpCodes.Stelem_Ref); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { gen.Emit(OpCodes.Ldarg_0); foreach (var exp in args) { exp.Emit(member, gen); } gen.Emit(OpCodes.Call, cmethod); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { var ci = exceptionType.GetConstructor(new[] { typeof(String) }); var constRef = new ConstReference(errorMessage); var creationStmt = new NewInstanceExpression(ci, constRef.ToExpression()); creationStmt.Emit(member, gen); gen.Emit(OpCodes.Throw); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { Label elseTarget = gen.DefineLabel(); _condition.Emit(member, gen); gen.Emit(_condition.BranchIfFalse, elseTarget); foreach (Statement s in _thenStatements) { s.Emit(member, gen); } gen.MarkLabel(elseTarget); }
internal void Generate(IMemberEmitter member, ILGenerator il) { foreach (var local in ilmarkers) { local.Generate(il); } foreach (var stmt in stmts) { stmt.Emit(member, il); } }
public override void Emit(IMemberEmitter member, ILGenerator gen) { if (arguments != null) { foreach (var exp in arguments) { exp.Emit(member, gen); } } gen.Emit(OpCodes.Newobj, constructor); }
internal void Generate(IMemberEmitter member, ILGenerator il) { foreach (var local in locals) { local.Generate(il); } foreach (var statement in statements) { statement.Emit(member, il); } }
internal void Generate(IMemberEmitter member, ILGenerator il) { foreach (Reference local in ilmarkers) { local.Generate(il); } foreach (Statement stmt in stmts) { stmt.Emit(member, il); } }
public override void Emit(IMemberEmitter member, ILGenerator gen) { gen.Emit(OpCodes.Ldtoken, method); if (declaringType == null) { throw new GeneratorException("declaringType can't be null for this situation"); } gen.Emit(OpCodes.Ldtoken, declaringType); var minfo = MethodBaseMethods.GetMethodFromHandle2; gen.Emit(OpCodes.Call, minfo); gen.Emit(OpCodes.Castclass, typeof(MethodInfo)); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen); var notNull = gen.DefineLabel(); gen.Emit(OpCodes.Brtrue_S, notNull); ifNull.Emit(member, gen); gen.MarkLabel(notNull); if (ifNotNull != null) // yeah, I know that reads funny :) { ifNotNull.Emit(member, gen); } }
public override void Emit(IMemberEmitter member, ILGenerator gen) { owner.Emit(member, gen); gen.Emit(OpCodes.Dup); if (methodToBindTo.IsFinal) { gen.Emit(OpCodes.Ldftn, methodToBindTo); } else { gen.Emit(OpCodes.Ldvirtftn, methodToBindTo); } gen.Emit(OpCodes.Newobj, delegateCtor); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { switch (value) { case -1: gen.Emit(OpCodes.Ldc_I4_M1); break; case 0: gen.Emit(OpCodes.Ldc_I4_0); break; case 1: gen.Emit(OpCodes.Ldc_I4_1); break; case 2: gen.Emit(OpCodes.Ldc_I4_2); break; case 3: gen.Emit(OpCodes.Ldc_I4_3); break; case 4: gen.Emit(OpCodes.Ldc_I4_4); break; case 5: gen.Emit(OpCodes.Ldc_I4_5); break; case 6: gen.Emit(OpCodes.Ldc_I4_6); break; case 7: gen.Emit(OpCodes.Ldc_I4_7); break; case 8: gen.Emit(OpCodes.Ldc_I4_8); break; default: gen.Emit(OpCodes.Ldc_I4, value); break; } }
public override void Emit(IMemberEmitter member, ILGenerator gen) { right.Emit(member, gen); if (fromType == target) { return; } if (fromType.IsByRef) { fromType = fromType.GetElementType(); } if (target.IsByRef) { target = target.GetElementType(); } if (target.IsValueType) { if (fromType.IsValueType) { throw new NotImplementedException("Cannot convert between distinct value types"); } else { // Unbox conversion // Assumes fromType is a boxed value gen.Emit(OpCodes.Unbox, target); OpCodeUtil.EmitLoadIndirectOpCodeForType(gen, target); } } else { if (fromType.IsValueType) { // Box conversion gen.Emit(OpCodes.Box, fromType); EmitCastIfNeeded(typeof(object), target, gen); } else { // Possible down-cast EmitCastIfNeeded(fromType, target, gen); } } }
public override void Emit(IMemberEmitter member, ILGenerator gen) { Label trueLabel = gen.DefineLabel(); Label falseLabel = gen.DefineLabel(); _expression.Emit(member, gen); gen.Emit(_expression.BranchIfTrue, trueLabel); _expression.Emit(member, gen); gen.Emit(_expression.BranchIfFalse, falseLabel); gen.Emit(OpCodes.Ldstr, "No label selected"); gen.Emit(OpCodes.Ret); gen.MarkLabel(trueLabel); gen.Emit(OpCodes.Ldstr, "True"); gen.Emit(OpCodes.Ret); gen.MarkLabel(falseLabel); gen.Emit(OpCodes.Ldstr, "False"); gen.Emit(OpCodes.Ret); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { ArgumentsUtil.EmitLoadOwnerAndReference(owner, gen); foreach (Expression exp in args) { exp.Emit(member, gen); } if (virtualCall) { gen.Emit(OpCodes.Callvirt, method); } else { gen.Emit(OpCodes.Call, method); } }
public override void Emit(IMemberEmitter member, ILGenerator gen) { ArgumentsUtil.EmitLoadOwnerAndReference(owner, gen); foreach (var exp in args) { exp.Emit(member, gen); } if (VirtualCall) { gen.Emit(OpCodes.Callvirt, method); } else { gen.Emit(OpCodes.Call, method); } }
public override void Emit(IMemberEmitter member, ILGenerator gen) { foreach (Expression exp in arguments) { exp.Emit(member, gen); } if (constructor == null) { constructor = type.GetConstructor(constructorArgs); } if (constructor == null) { throw new ProxyGenerationException("Could not find constructor matching specified arguments"); } gen.Emit(OpCodes.Newobj, constructor); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { foreach (Expression exp in arguments) { exp.Emit(member, gen); } if (constructor == null) { constructor = type.GetConstructor(constructor_args); } if (constructor == null) { throw new ProxyGenerationException("Could not find constructor matching specified arguments"); } gen.Emit(OpCodes.Newobj, constructor); }
public MutableNestedTypeCodeGeneratorFactory( IReflectionEmitCodeGenerator reflectionEmitCodeGenerator, IEmittableOperandProvider emittableOperandProvider, IMemberEmitter memberEmitter, IInitializationBuilder initializationBuilder, IProxySerializationEnabler proxySerializationEnabler) { ArgumentUtility.CheckNotNull("reflectionEmitCodeGenerator", reflectionEmitCodeGenerator); ArgumentUtility.CheckNotNull("emittableOperandProvider", emittableOperandProvider); ArgumentUtility.CheckNotNull("memberEmitter", memberEmitter); ArgumentUtility.CheckNotNull("initializationBuilder", initializationBuilder); ArgumentUtility.CheckNotNull("proxySerializationEnabler", proxySerializationEnabler); _reflectionEmitCodeGenerator = reflectionEmitCodeGenerator; _emittableOperandProvider = emittableOperandProvider; _memberEmitter = memberEmitter; _initializationBuilder = initializationBuilder; _proxySerializationEnabler = proxySerializationEnabler; }
public override void Emit(IMemberEmitter member, ILGenerator gen) { LoadOwnersRecursively(_callTarget.OwnerReference, gen); if (_callTarget.Type.IsValueType) { _callTarget.LoadAddressOfReference(gen); } else { _callTarget.LoadReference(gen); } foreach (Expression argument in _arguments) { argument.Emit(member, gen); } EmitCall(member, gen); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { gen.Emit(OpCodes.Ldtoken, method); #if !MONO if (declaringType == null) { throw new GeneratorException("declaringType can't be null for this situation"); } gen.Emit(OpCodes.Ldtoken, declaringType); #endif MethodInfo minfo = Constants.GetMethodFromHandle1; #if !MONO minfo = Constants.GetMethodFromHandle2; #endif gen.Emit(OpCodes.Call, minfo); gen.Emit(OpCodes.Castclass, typeof(MethodInfo)); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { if (reference != null) { ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen); } else if (expression != null) { expression.Emit(member, gen); } else { if (member.ReturnType != typeof(void)) { OpCodeUtil.EmitLoadOpCodeForDefaultValueOfType(gen, member.ReturnType); } } gen.Emit(OpCodes.Ret); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { var local = gen.DeclareLocal(typeof(object[])); gen.Emit(OpCodes.Ldc_I4, args.Length); gen.Emit(OpCodes.Newarr, typeof(object)); gen.Emit(OpCodes.Stloc, local); for (var i = 0; i < args.Length; i++) { gen.Emit(OpCodes.Ldloc, local); gen.Emit(OpCodes.Ldc_I4, i); var reference = args[i]; ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen); if (reference.Type.IsByRef) { throw new NotSupportedException(); } if (reference.Type.IsPointer) { gen.Emit(OpCodes.Call, ArgumentsUtil.IntPtrFromPointer()); gen.Emit(OpCodes.Box, typeof(IntPtr)); } else if (reference.Type.IsValueType) { gen.Emit(OpCodes.Box, reference.Type.UnderlyingSystemType); } else if (reference.Type.IsGenericParameter) { gen.Emit(OpCodes.Box, reference.Type); } gen.Emit(OpCodes.Stelem_Ref); } gen.Emit(OpCodes.Ldloc, local); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { var local = gen.DeclareLocal(typeof(object[])); gen.Emit(OpCodes.Ldc_I4, args.Length); gen.Emit(OpCodes.Newarr, typeof(object)); gen.Emit(OpCodes.Stloc, local); for (var i = 0; i < args.Length; i++) { gen.Emit(OpCodes.Ldloc, local); gen.Emit(OpCodes.Ldc_I4, i); var reference = args[i]; ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen); if (reference.Type.GetTypeInfo().IsByRef) { throw new NotSupportedException(); } if (reference.Type.GetTypeInfo().IsPointer) { gen.Emit(OpCodes.Call, ArgumentsUtil.IntPtrFromPointer()); gen.Emit(OpCodes.Box, typeof(IntPtr)); } if (reference.Type.GetTypeInfo().IsValueType) { gen.Emit(OpCodes.Box, reference.Type); } else if (reference.Type.GetTypeInfo().IsGenericParameter) { gen.Emit(OpCodes.Box, reference.Type); } gen.Emit(OpCodes.Stelem_Ref); } gen.Emit(OpCodes.Ldloc, local); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { ArgumentUtility.CheckNotNull("member", member); ArgumentUtility.CheckNotNull("gen", gen); gen.BeginExceptionBlock(); foreach (Statement statement in _tryStatements) { statement.Emit(member, gen); } gen.BeginFinallyBlock(); foreach (Statement statement in _finallyStatements) { statement.Emit(member, gen); } gen.EndExceptionBlock(); gen.Emit(OpCodes.Nop); // ensure a leave target for try block }
public override void Emit(IMemberEmitter member, ILGenerator gen) { // @mbrit - 2012-06-04 - can't do anything other than pass proper MethodInfo // instances down a this is all MSIL knows how to deal with... gen.Emit(OpCodes.Ldtoken, method.AsMethodInfo()); #if !MONO if (declaringType == null) { throw new GeneratorException("declaringType can't be null for this situation"); } gen.Emit(OpCodes.Ldtoken, declaringType); #endif var minfo = MethodBaseMethods.GetMethodFromHandle1; #if !MONO minfo = MethodBaseMethods.GetMethodFromHandle2; #endif gen.Emit(OpCodes.Call, minfo); gen.Emit(OpCodes.Castclass, typeof(MethodInfo)); }
public MutableNestedTypeCodeGenerator( ITypeBuilder enclosingTypeBuilder, MutableType mutableType, IMutableNestedTypeCodeGeneratorFactory nestedTypeCodeGeneratorFactory, IReflectionEmitCodeGenerator codeGenerator, IEmittableOperandProvider emittableOperandProvider, IMemberEmitter memberEmitter, IInitializationBuilder initializationBuilder, IProxySerializationEnabler proxySerializationEnabler) : base( mutableType, nestedTypeCodeGeneratorFactory, codeGenerator, emittableOperandProvider, memberEmitter, initializationBuilder, proxySerializationEnabler) { ArgumentUtility.CheckNotNull("enclosingTypeBuilder", enclosingTypeBuilder); _enclosingTypeBuilder = enclosingTypeBuilder; }
public override void Emit(IMemberEmitter member, ILGenerator gen) { LocalBuilder local = gen.DeclareLocal(typeof(object[])); gen.Emit(OpCodes.Ldc_I4, args.Length); gen.Emit(OpCodes.Newarr, typeof(object)); gen.Emit(OpCodes.Stloc, local); for (int i = 0; i < args.Length; i++) { gen.Emit(OpCodes.Ldloc, local); gen.Emit(OpCodes.Ldc_I4, i); TypeReference reference = args[i]; ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen); if (reference.Type.IsByRef) { throw new NotSupportedException(); } if (reference.Type.IsValueType) { gen.Emit(OpCodes.Box, reference.Type.UnderlyingSystemType); } if (reference.Type.IsGenericParameter) { gen.Emit(OpCodes.Box, reference.Type); } gen.Emit(OpCodes.Stelem_Ref); } gen.Emit(OpCodes.Ldloc, local); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { // TODO: check if this can be simplified by using more of OpCodeUtil and other existing types if (IsPrimitiveOrClass(type)) { OpCodeUtil.EmitLoadOpCodeForDefaultValueOfType(gen, type); } else if(type.IsValueType || type.IsGenericParameter) { // TODO: handle decimal explicitly var local = gen.DeclareLocal(type); gen.Emit(OpCodes.Ldloca_S, local); gen.Emit(OpCodes.Initobj, type); gen.Emit(OpCodes.Ldloc, local); } else if (type.IsByRef) { EmitByRef(gen); } else { throw new ProxyGenerationException("Can't emit default value for type " + type); } }
public override void Emit(IMemberEmitter member, ILGenerator gen) { // TODO: check if this can be simplified by using more of OpCodeUtil and other existing types if (IsPrimitiveOrClass(type)) { OpCodeUtil.EmitLoadOpCodeForDefaultValueOfType(gen, type); } else if (type.IsValueType || type.IsGenericParameter) { // TODO: handle decimal explicitly var local = gen.DeclareLocal(type); gen.Emit(OpCodes.Ldloca_S, local); gen.Emit(OpCodes.Initobj, type); gen.Emit(OpCodes.Ldloc, local); } else if (type.IsByRef) { EmitByRef(gen); } else { throw new ProxyGenerationException("Can't emit default value for type " + type); } }
public override void Emit(IMemberEmitter member, ILGenerator gen) { gen.Emit(OpCodes.Ldnull); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { // TODO: Should it discard any possible return value with a pop? expression.Emit(member, gen); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { ArgumentsUtil.EmitLoadOwnerAndReference(arrayReference, gen); ArgumentsUtil.EmitLoadOwnerAndReference(index, gen); gen.Emit(OpCodes.Ldelem, returnType); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { gen.BeginExceptionBlock(); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { gen.BeginFinallyBlock(); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { ArgumentsUtil.EmitLoadOwnerAndReference(reference.OwnerReference, gen); reference.LoadAddressOfReference(gen); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { gen.EndExceptionBlock(); }
public abstract void Emit(IMemberEmitter member, ILGenerator gen);
public override void Emit(IMemberEmitter member, ILGenerator gen) { ArgumentsUtil.EmitLoadOwnerAndReference(target.OwnerReference, gen); expression.Emit(member, gen); target.StoreReference(gen); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { gen.Emit(OpCodes.Ldc_I4, size); gen.Emit(OpCodes.Newarr, arrayType); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { statements.ForEach(s => s.Emit(member, gen)); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { gen.Emit(OpCodes.Ldtoken, type); gen.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle")); }
public override void Emit(IMemberEmitter member, ILGenerator gen) { gen.Emit(OpCodes.Ldtoken, type); gen.Emit(OpCodes.Call, TypeMethods.GetTypeFromHandle); }