MethodSpecification ImportMethodSpecification (MethodReference method, ImportGenericContext context) { if (!method.IsGenericInstance) throw new NotSupportedException (); var instance = (GenericInstanceMethod) method; var element_method = ImportMethod (instance.ElementMethod, context); var imported_instance = new GenericInstanceMethod (element_method); var arguments = instance.GenericArguments; var imported_arguments = imported_instance.GenericArguments; for (int i = 0; i < arguments.Count; i++) imported_arguments.Add (ImportType (arguments [i], context)); return imported_instance; }
public GenericInstanceMethod (MethodReference method) : base (method) { }
public MethodReference ImportMethod (SR.MethodBase method, ImportGenericContext context, ImportGenericKind import_kind) { if (IsMethodSpecification (method) || ImportOpenGenericMethod (method, import_kind)) return ImportMethodSpecification (method, context); var declaring_type = ImportType (method.DeclaringType, context); if (IsGenericInstance (method.DeclaringType)) method = method.Module.ResolveMethod (method.MetadataToken); var reference = new MethodReference { Name = method.Name, HasThis = HasCallingConvention (method, SR.CallingConventions.HasThis), ExplicitThis = HasCallingConvention (method, SR.CallingConventions.ExplicitThis), DeclaringType = ImportType (method.DeclaringType, context, ImportGenericKind.Definition), }; if (HasCallingConvention (method, SR.CallingConventions.VarArgs)) reference.CallingConvention &= MethodCallingConvention.VarArg; if (method.IsGenericMethod) ImportGenericParameters (reference, method.GetGenericArguments ()); context.Push (reference); try { var method_info = method as SR.MethodInfo; reference.ReturnType = method_info != null ? ImportType (method_info.ReturnType, context) : ImportType (typeof (void), default (ImportGenericContext)); var parameters = method.GetParameters (); var reference_parameters = reference.Parameters; for (int i = 0; i < parameters.Length; i++) reference_parameters.Add ( new ParameterDefinition (ImportType (parameters [i].ParameterType, context))); reference.DeclaringType = declaring_type; return reference; } finally { context.Pop (); } }
public MethodReference ImportMethod (MethodReference method, ImportGenericContext context) { if (method.IsGenericInstance) return ImportMethodSpecification (method, context); var declaring_type = ImportType (method.DeclaringType, context); var reference = new MethodReference { Name = method.Name, HasThis = method.HasThis, ExplicitThis = method.ExplicitThis, DeclaringType = declaring_type, CallingConvention = method.CallingConvention, }; if (method.HasGenericParameters) ImportGenericParameters (reference, method); context.Push (reference); try { reference.ReturnType = ImportType (method.ReturnType, context); if (!method.HasParameters) return reference; var reference_parameters = reference.Parameters; var parameters = method.Parameters; for (int i = 0; i < parameters.Count; i++) reference_parameters.Add ( new ParameterDefinition (ImportType (parameters [i].ParameterType, context))); return reference; } finally { context.Pop(); } }
public static MethodDefinition GetMethod (Collection<MethodDefinition> methods, MethodReference reference) { for (int i = 0; i < methods.Count; i++) { var method = methods [i]; if (method.Name != reference.Name) continue; if (method.HasGenericParameters != reference.HasGenericParameters) continue; if (method.HasGenericParameters && method.GenericParameters.Count != reference.GenericParameters.Count) continue; if (!AreSame (method.ReturnType, reference.ReturnType)) continue; if (method.HasParameters != reference.HasParameters) continue; if (!method.HasParameters && !reference.HasParameters) return method; if (!AreSame (method.Parameters, reference.Parameters)) continue; return method; } return null; }
private void DoCallWork(bool virtualCall, ObjectInstance thisArg = null, MethodReference methTok = null, object callInfo = null) { var op = (methTok ?? _instructions[_instructionPtr].Operand) as MethodReference; var methDef = op.Resolve(); { if (methDef.IsInternalCall) { InvokeInternalCall(methDef); return; } } _callThisArg = thisArg; // for .ctor var totalSigArgs = 0; if (false) { } else { totalSigArgs = methDef.Parameters.Count + (methDef.HasThis ? 1 : 0); } // Note that "totalNativeArgs()" includes space for ret buff arg. var nSlots = totalSigArgs + 1; if (methDef.HasGenericParameters) nSlots++; if (methDef.IsVarArg()) nSlots++; // Make sure that the operand stack has the required number of arguments. // (Note that this is IL args, not native.) // // The total number of arguments on the IL stack. Initially we assume that all the IL arguments // the callee expects are on the stack, but may be adjusted downwards if the "this" argument // is provided by an allocation (the call is to a constructor). var totalArgsOnILStack = totalSigArgs; if (_callThisArg != null) { Debug.Assert(totalArgsOnILStack > 0); totalArgsOnILStack--; } var totalArgs = nSlots; var LOCAL_ARG_SLOTS = 8; var localArgs = new ObjectInstance[(totalArgs > LOCAL_ARG_SLOTS) ? totalArgs : LOCAL_ARG_SLOTS]; // Current on-stack argument index. var arg = 0; // FIXME: stack (mayuki) var tmpArgsStack = _opStack.ToArray(); var curArgSlot = 0; if (methDef.HasThis) { if (_callThisArg != null) { localArgs[curArgSlot] = _callThisArg; } else { localArgs[curArgSlot] = tmpArgsStack[tmpArgsStack.Length - (arg+1)]; arg++; } curArgSlot++; } // Now we do the non-this arguments. for (; arg < totalArgsOnILStack; arg++) { localArgs[curArgSlot] = tmpArgsStack[tmpArgsStack.Length - (arg + 1)]; curArgSlot++; } if (methDef.HasThis) { if (thisArg == null) { thisArg = tmpArgsStack[0]; } else { thisArg = _callThisArg; } } ObjectInstance retVal; MethodDefinition exactMethToCall = methDef; if (methDef.DeclaringType.IsInterface) { var slot = thisArg.MethodTable.InterfaceMethodSlotMap[methDef]; exactMethToCall = thisArg.MethodTable.MethodSlots[slot].Definition; } else { if (virtualCall && methDef.IsVirtual) { var methodDesc = _classLoader.LookupMethodDescFromMethodDef(methDef); exactMethToCall = thisArg.MethodTable.MethodSlots[methodDesc.Slot].Definition; } } retVal = InterpretMethodBody(exactMethToCall, true, localArgs, null); // retval for (var i = 0; i < totalArgsOnILStack; i++) { _opStack.Pop(); } if (methDef.ReturnType.FullName != "System.Void") // TODO: should refer typevalue enum { _opStack.Push(retVal); } }
public virtual MethodDefinition Resolve (MethodReference method) { if (method == null) throw new ArgumentNullException ("method"); var type = Resolve (method.DeclaringType); if (type == null) return null; method = method.GetElementMethod (); if (!type.HasMethods) return null; return GetMethod (type, method); }
MethodDefinition GetMethod (TypeDefinition type, MethodReference reference) { while (type != null) { var method = GetMethod (type.Methods, reference); if (method != null) return method; if (type.BaseType == null) return null; type = Resolve (type.BaseType); } return null; }
public override MethodDefinition Resolve(MethodReference method) { return base.Resolve(method); }
public FunctionPointerType () : base (null) { this.function = new MethodReference (); this.function.Name = "method"; this.etype = MD.ElementType.FnPtr; }
public CustomAttribute (MethodReference constructor, byte [] blob) { this.constructor = constructor; this.resolved = false; this.blob = blob; }
public CustomAttribute (MethodReference constructor) { this.constructor = constructor; this.resolved = true; }
internal CustomAttribute (uint signature, MethodReference constructor) { this.signature = signature; this.constructor = constructor; this.resolved = false; }