internal unsafe DynamicILGenerator(DynamicMethod method, byte[] methodSignature, int size) : base(method, size) { m_scope = new DynamicScope(); // Token #1 int dmMethodToken = m_scope.GetTokenFor(method); Contract.Assert((dmMethodToken & 0x00FFFFFF) == DynamicResolver.TOKENFORDYNAMICMETHOD, "Bad token number!"); // Token #2 m_methodSigToken = m_scope.GetTokenFor(methodSignature); }
internal DynamicILGenerator(DynamicMethod method, byte[] methodSignature, int size) : base(method, size) { m_scope = new DynamicScope(); m_methodSigToken = m_scope.GetTokenFor(methodSignature); }
internal unsafe DynamicILGenerator(DynamicMethod method, byte[] methodSignature, int size) : base(method, size) { m_scope = new DynamicScope(); m_methodSigToken = m_scope.GetTokenFor(methodSignature); }
internal DynamicILInfo(DynamicMethod method, byte[] methodSignature) { m_scope = new DynamicScope(); m_method = method; m_methodSignature = m_scope.GetTokenFor(methodSignature); m_exceptions = Array.Empty <byte>(); m_code = Array.Empty <byte>(); m_localSignature = Array.Empty <byte>(); }
internal DynamicILInfo(DynamicScope scope, DynamicMethod method, byte[] methodSignature) { m_method = method; m_scope = scope; m_methodSignature = m_scope.GetTokenFor(methodSignature); m_exceptions = new byte[0]; m_code = new byte[0]; m_localSignature = new byte[0]; }
internal override unsafe int ParentToken(int token) { RuntimeTypeHandle owner = RuntimeTypeHandle.EmptyHandle; Object handle = m_scope[token]; if (handle is RuntimeMethodHandle) { RuntimeMethodHandle method = (RuntimeMethodHandle)handle; owner = method.GetDeclaringType(); } else if (handle is RuntimeFieldHandle) { RuntimeFieldHandle field = (RuntimeFieldHandle)handle; owner = field.GetApproxDeclaringType(); } else if (handle is DynamicMethod) { DynamicMethod dynMeth = (DynamicMethod)handle; owner = dynMeth.m_method.GetDeclaringType(); } else if (handle is GenericMethodInfo) { GenericMethodInfo gmi = (GenericMethodInfo)handle; owner = gmi.m_context; } else if (handle is VarArgMethod) { VarArgMethod varargMeth = (VarArgMethod)handle; if (varargMeth.m_method is DynamicMethod) { owner = ((DynamicMethod)varargMeth.m_method).m_method.GetDeclaringType(); } else if (varargMeth.m_method is DynamicMethod.RTDynamicMethod) { owner = ((DynamicMethod.RTDynamicMethod)varargMeth.m_method).m_owner.m_method.GetDeclaringType(); } else { owner = varargMeth.m_method.MethodHandle.GetDeclaringType(); } } if (owner.IsNullHandle()) { return(-1); } return(m_scope.GetTokenFor(owner)); }
private int GetTokenFor(RuntimeType rtType) { return(m_scope.GetTokenFor(rtType.TypeHandle)); }
internal DynamicILInfo(DynamicScope scope, DynamicMethod method, byte[] methodSignature) { m_method = method; m_scope = scope; m_methodSignature = m_scope.GetTokenFor(methodSignature); m_exceptions = EmptyArray<Byte>.Value; m_code = EmptyArray<Byte>.Value; m_localSignature = EmptyArray<Byte>.Value; }
internal void AddDynamicArgument(DynamicScope dynamicScope, Type clsArgument, Type[]?requiredCustomModifiers, Type[]?optionalCustomModifiers) { IncrementArgCounts(); Debug.Assert(clsArgument != null); if (optionalCustomModifiers != null) { for (int i = 0; i < optionalCustomModifiers.Length; i++) { Type t = optionalCustomModifiers[i]; if (t is not RuntimeType rtType) { throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(optionalCustomModifiers)); } if (t.HasElementType) { throw new ArgumentException(SR.Argument_ArraysInvalid, nameof(optionalCustomModifiers)); } if (t.ContainsGenericParameters) { throw new ArgumentException(SR.Argument_GenericsInvalid, nameof(optionalCustomModifiers)); } AddElementType(CorElementType.ELEMENT_TYPE_CMOD_OPT); int token = dynamicScope.GetTokenFor(rtType.TypeHandle); Debug.Assert(!MetadataToken.IsNullToken(token)); AddToken(token); } } if (requiredCustomModifiers != null) { for (int i = 0; i < requiredCustomModifiers.Length; i++) { Type t = requiredCustomModifiers[i]; if (t is not RuntimeType rtType) { throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(requiredCustomModifiers)); } if (t.HasElementType) { throw new ArgumentException(SR.Argument_ArraysInvalid, nameof(requiredCustomModifiers)); } if (t.ContainsGenericParameters) { throw new ArgumentException(SR.Argument_GenericsInvalid, nameof(requiredCustomModifiers)); } AddElementType(CorElementType.ELEMENT_TYPE_CMOD_REQD); int token = dynamicScope.GetTokenFor(rtType.TypeHandle); Debug.Assert(!MetadataToken.IsNullToken(token)); AddToken(token); } } AddOneArgTypeHelper(clsArgument); }
private int GetTokenFor(RuntimeType rtType) { #if FEATURE_APPX if (ProfileAPICheck && (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName)); } #endif return(m_scope.GetTokenFor(rtType.TypeHandle)); }
// // // Token resolution calls // // public override void Emit(OpCode opcode, MethodInfo meth) { if (meth == null) { throw new ArgumentNullException("meth"); } int stackchange = 0; int tempVal = 0; DynamicMethod dynMeth = DynamicMethod.AsDynamicMethod(meth); if (dynMeth == null) { if (!(meth is RuntimeMethodInfo)) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "meth"); } if (meth.DeclaringType != null && (meth.DeclaringType.IsGenericType || meth.DeclaringType.IsArray)) { tempVal = m_scope.GetTokenFor(meth.MethodHandle, meth.DeclaringType.TypeHandle); } else { tempVal = m_scope.GetTokenFor(meth.MethodHandle); } } else { // rule out not allowed operations on DynamicMethods if (opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn) || opcode.Equals(OpCodes.Ldvirtftn)) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOpCodeOnDynamicMethod")); } tempVal = m_scope.GetTokenFor(dynMeth); } EnsureCapacity(7); InternalEmit(opcode); if (opcode.m_push == StackBehaviour.Varpush && meth.ReturnType != typeof(void)) { stackchange++; } if (opcode.m_pop == StackBehaviour.Varpop) { stackchange -= meth.GetParametersNoCopy().Length; } // Pop the "this" parameter if the method is non-static, // and the instruction is not newobj/ldtoken/ldftn. if (!meth.IsStatic && !(opcode.Equals(OpCodes.Newobj) || opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn))) { stackchange--; } UpdateStackSize(opcode, stackchange); m_length = PutInteger4(tempVal, m_length, m_ILStream); }