public override bool IsMethodInCompilationGroup(MethodDesc method) { if (method.GetTypicalMethodDefinition().ContainsGenericVariables) return true; return IsTypeInCompilationGroup(method.OwningType); }
public override bool ContainsMethod(MethodDesc method) { if (method.GetTypicalMethodDefinition().ContainsGenericVariables) return true; return ContainsType(method.OwningType); }
public MethodIL GetMethodIL(MethodDesc method) { if (method is EcmaMethod) { // TODO: Workaround: we should special case methods with Intrinsic attribute, but since // CoreLib source is still not in the repo, we have to work with what we have, which is // an MCG attribute on the type itself... if (((MetadataType)method.OwningType).HasCustomAttribute("System.Runtime.InteropServices", "McgIntrinsicsAttribute")) { if (method.Name == "Call") { return CalliIntrinsic.EmitIL(method); } } if (method.IsIntrinsic) { MethodIL result = TryGetIntrinsicMethodIL(method); if (result != null) return result; } if (method.IsPInvoke) { return PInvokeMarshallingILEmitter.EmitIL(method); } return EcmaMethodIL.Create((EcmaMethod)method); } else if (method is MethodForInstantiatedType) { var methodDefinitionIL = GetMethodIL(method.GetTypicalMethodDefinition()); if (methodDefinitionIL == null) return null; return new InstantiatedMethodIL(methodDefinitionIL, method.OwningType.Instantiation, new Instantiation()); } else if (method is InstantiatedMethod) { var methodDefinitionIL = GetMethodIL(method.GetMethodDefinition()); if (methodDefinitionIL == null) return null; return new InstantiatedMethodIL(methodDefinitionIL, new Instantiation(), method.Instantiation); } else if (method is ILStubMethod) { return ((ILStubMethod)method).EmitIL(); } else if (method is ArrayMethod) { return ArrayMethodILEmitter.EmitIL((ArrayMethod)method); } else { return null; } }
/// <summary> /// Resolve a MethodDesc to a callable method address and unboxing stub address by searching /// by searching in the InvokeMaps. This function is a wrapper around TryGetMethodInvokeDataFromInvokeMap /// that produces output in the format which matches the code table system. /// </summary> /// <param name="method">Native metadata method description object</param> /// <param name="methodAddress">Resolved method address</param> /// <param name="unboxingStubAddress">Resolved unboxing stub address</param> /// <returns>true when the resolution succeeded, false when not</returns> private static bool TryGetMethodAddressFromTypeSystemMethodViaInvokeMap( MethodDesc method, out IntPtr methodAddress, out IntPtr unboxingStubAddress, out MethodAddressType foundAddressType) { methodAddress = IntPtr.Zero; unboxingStubAddress = IntPtr.Zero; foundAddressType = MethodAddressType.None; #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING NativeFormatMethod nativeFormatMethod = method.GetTypicalMethodDefinition() as NativeFormatMethod; if (nativeFormatMethod == null) return false; MethodSignatureComparer methodSignatureComparer = new MethodSignatureComparer( nativeFormatMethod.MetadataReader, nativeFormatMethod.Handle); // Try to find a specific canonical match, or if that fails, a universal match if (TryGetMethodInvokeDataFromInvokeMap( nativeFormatMethod, method, ref methodSignatureComparer, CanonicalFormKind.Specific, out methodAddress, out foundAddressType) || TryGetMethodInvokeDataFromInvokeMap( nativeFormatMethod, method, ref methodSignatureComparer, CanonicalFormKind.Universal, out methodAddress, out foundAddressType)) { if (method.OwningType.IsValueType && !method.Signature.IsStatic) { // In this case the invoke map found an unboxing stub, and we should pull the method address out as well unboxingStubAddress = methodAddress; methodAddress = RuntimeAugments.GetCodeTarget(unboxingStubAddress); if (!method.HasInstantiation && ((foundAddressType != MethodAddressType.Exact) || method.OwningType.IsCanonicalSubtype(CanonicalFormKind.Any))) { IntPtr underlyingTarget; // unboxing and instantiating stub handling if (!TypeLoaderEnvironment.TryGetTargetOfUnboxingAndInstantiatingStub(methodAddress, out underlyingTarget)) { Environment.FailFast("Expected this to be an unboxing and instantiating stub."); } methodAddress = underlyingTarget; } } return true; } #endif return false; }
static private MethodDesc FindMethodOnExactTypeWithMatchingTypicalMethod(this TypeDesc type, MethodDesc method) { // Assert that either type is instantiated and its type definition is the type that defines the typical // method definition of method, or that the owning type of the method typical definition is exactly type Debug.Assert((type is InstantiatedType) ? ((InstantiatedType)type).GetTypeDefinition() == method.GetTypicalMethodDefinition().OwningType : type == method.GetTypicalMethodDefinition().OwningType); MethodDesc methodTypicalDefinition = method.GetTypicalMethodDefinition(); foreach (MethodDesc methodToExamine in type.GetMethods()) { if (methodToExamine.GetTypicalMethodDefinition() == methodTypicalDefinition) return methodToExamine; } Debug.Assert(false, "Behavior of typical type not as expected."); return null; }
public InstantiatedMethodIL(MethodDesc owningMethod, MethodIL methodIL) { Debug.Assert(methodIL.GetMethodILDefinition() == methodIL); Debug.Assert(owningMethod.HasInstantiation || owningMethod.OwningType.HasInstantiation); Debug.Assert(owningMethod.GetTypicalMethodDefinition() == methodIL.OwningMethod); _methodIL = methodIL; _method = owningMethod; _typeInstantiation = owningMethod.OwningType.Instantiation; _methodInstantiation = owningMethod.Instantiation; }
static private MethodDesc FindMethodOnExactTypeWithMatchingTypicalMethod(this TypeDesc type, MethodDesc method) { MethodDesc methodTypicalDefinition = method.GetTypicalMethodDefinition(); var instantiatedType = type as InstantiatedType; if (instantiatedType != null) { Debug.Assert(instantiatedType.GetTypeDefinition() == methodTypicalDefinition.OwningType); return method.Context.GetMethodForInstantiatedType(methodTypicalDefinition, instantiatedType); } else { Debug.Assert(type == methodTypicalDefinition.OwningType); return methodTypicalDefinition; } }
static private MethodDesc FindMethodOnExactTypeWithMatchingTypicalMethod(this TypeDesc type, MethodDesc method) { MethodDesc methodTypicalDefinition = method.GetTypicalMethodDefinition(); var instantiatedType = type as InstantiatedType; if (instantiatedType != null) { Debug.Assert(instantiatedType.GetTypeDefinition() == methodTypicalDefinition.OwningType); return(method.Context.GetMethodForInstantiatedType(methodTypicalDefinition, instantiatedType)); } else { Debug.Assert(type == methodTypicalDefinition.OwningType); return(methodTypicalDefinition); } }
static internal MethodDesc FindMethodOnExactTypeWithMatchingTypicalMethod(this TypeDesc type, MethodDesc method) { MethodDesc methodTypicalDefinition = method.GetTypicalMethodDefinition(); var instantiatedType = type as InstantiatedType; if (instantiatedType != null) { Debug.Assert(instantiatedType.GetTypeDefinition() == methodTypicalDefinition.OwningType); return method.Context.GetMethodForInstantiatedType(methodTypicalDefinition, instantiatedType); } else if (type.IsArray) { Debug.Assert(method.OwningType.IsArray); return ((ArrayType)type).GetArrayMethod(((ArrayMethod)method).Kind); } else { Debug.Assert(type == methodTypicalDefinition.OwningType); return methodTypicalDefinition; } }
public virtual MethodDesc InstantiateSignature(Instantiation typeInstantiation, Instantiation methodInstantiation) { Instantiation instantiation = Instantiation; TypeDesc[] clone = null; for (int i = 0; i < instantiation.Length; i++) { TypeDesc uninst = instantiation[i]; TypeDesc inst = uninst.InstantiateSignature(typeInstantiation, methodInstantiation); if (inst != uninst) { if (clone == null) { clone = new TypeDesc[instantiation.Length]; for (int j = 0; j < clone.Length; j++) { clone[j] = instantiation[j]; } } clone[i] = inst; } } MethodDesc method = this; TypeDesc owningType = method.OwningType; TypeDesc instantiatedOwningType = owningType.InstantiateSignature(typeInstantiation, methodInstantiation); if (owningType != instantiatedOwningType) { method = Context.GetMethodForInstantiatedType(method.GetTypicalMethodDefinition(), (InstantiatedType)instantiatedOwningType); if (clone == null && instantiation.Length != 0) { return(Context.GetInstantiatedMethod(method, instantiation)); } } return((clone == null) ? method : Context.GetInstantiatedMethod(method.GetMethodDefinition(), new Instantiation(clone))); }
internal static MethodDesc FindMethodOnExactTypeWithMatchingTypicalMethod(this TypeDesc type, MethodDesc method) { MethodDesc methodTypicalDefinition = method.GetTypicalMethodDefinition(); var instantiatedType = type as InstantiatedType; if (instantiatedType != null) { Debug.Assert(instantiatedType.GetTypeDefinition() == methodTypicalDefinition.OwningType); return(method.Context.GetMethodForInstantiatedType(methodTypicalDefinition, instantiatedType)); } else if (type.IsArray) { Debug.Assert(method.OwningType.IsArray); return(((ArrayType)type).GetArrayMethod(((ArrayMethod)method).Kind)); } else { Debug.Assert(type == methodTypicalDefinition.OwningType); return(methodTypicalDefinition); } }
public EntityHandle GetMethodRef(MethodDesc method) { if (_methodRefs.TryGetValue(method, out var handle)) { return(handle); } EntityHandle methodHandle; if (method.HasInstantiation && (method.GetMethodDefinition() != method)) { EntityHandle uninstantiatedHandle = GetMethodRef(method.GetMethodDefinition()); BlobBuilder methodSpecSig = new BlobBuilder(); BlobEncoder methodSpecEncoder = new BlobEncoder(methodSpecSig); methodSpecEncoder.MethodSpecificationSignature(method.Instantiation.Length); foreach (var type in method.Instantiation) { EncodeType(methodSpecSig, type, EmbeddedSignatureDataEmitter.EmptySingleton); } var methodSpecSigHandle = _metadataBuilder.GetOrAddBlob(methodSpecSig); methodHandle = _metadataBuilder.AddMethodSpecification(uninstantiatedHandle, methodSpecSigHandle); } else { EntityHandle typeHandle = GetTypeRef(method.OwningType); StringHandle methodName = _metadataBuilder.GetOrAddString(method.Name); var sig = method.GetTypicalMethodDefinition().Signature; var sigBlob = GetMethodSignatureBlobHandle(sig); methodHandle = _metadataBuilder.AddMemberReference(typeHandle, methodName, sigBlob); } _methodRefs.Add(method, methodHandle); return(methodHandle); }
private void InitializeMethodReference(Cts.MethodDesc entity, MemberReference record) { record.Name = HandleString(entity.Name); record.Parent = HandleType(entity.OwningType); record.Signature = HandleMethodSignature(entity.GetTypicalMethodDefinition().Signature); }
internal static GenericDictionaryCell CreateMethodCell(MethodDesc method, bool exactCallableAddressNeeded) { #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING var nativeFormatMethod = (TypeSystem.NativeFormat.NativeFormatMethod)method.GetTypicalMethodDefinition(); return new MethodCell { ExactCallableAddressNeeded = exactCallableAddressNeeded, Method = method, MethodSignature = RuntimeMethodSignature.CreateFromMethodHandle(nativeFormatMethod.MetadataUnit.RuntimeModule, nativeFormatMethod.Handle.ToInt()) }; #else Environment.FailFast("Creating a methodcell from a MethodDesc only supported in the presence of metadata based type loading."); return null; #endif }
/// <summary> /// Get the NativeLayout for a method from a ReadyToRun image. /// </summary> public bool TryGetMetadataNativeLayout(MethodDesc concreteMethod, out IntPtr nativeLayoutInfoModule, out uint nativeLayoutInfoToken) { nativeLayoutInfoModule = default(IntPtr); nativeLayoutInfoToken = 0; #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING var nativeMetadataType = concreteMethod.GetTypicalMethodDefinition() as TypeSystem.NativeFormat.NativeFormatMethod; if (nativeMetadataType == null) return false; var canonForm = concreteMethod.GetCanonMethodTarget(CanonicalFormKind.Specific); var hashCode = canonForm.GetHashCode(); var loadedModulesCount = RuntimeAugments.GetLoadedModules(null); var loadedModuleHandles = new IntPtr[loadedModulesCount]; var loadedModules = RuntimeAugments.GetLoadedModules(loadedModuleHandles); Debug.Assert(loadedModulesCount == loadedModules); #if SUPPORTS_R2R_LOADING foreach (var moduleHandle in loadedModuleHandles) { ExternalReferencesTable externalFixupsTable; NativeHashtable methodTemplatesHashtable = LoadHashtable(moduleHandle, ReflectionMapBlob.MetadataBasedGenericMethodsTemplateMap, out externalFixupsTable); if (methodTemplatesHashtable.IsNull) continue; var enumerator = methodTemplatesHashtable.Lookup(hashCode); var nativeMetadataUnit = nativeMetadataType.Context.ResolveMetadataUnit(moduleHandle); NativeParser entryParser; while (!(entryParser = enumerator.GetNext()).IsNull) { var entryTypeHandle = entryParser.GetUnsigned().AsHandle(); MethodDesc methodDesc = nativeMetadataUnit.GetMethod(entryTypeHandle, null); Debug.Assert(methodDesc != null); if (methodDesc == canonForm) { TypeLoaderLogger.WriteLine("Found metadata template for method " + concreteMethod.ToString() + ": " + methodDesc.ToString()); nativeLayoutInfoToken = (uint)externalFixupsTable.GetRvaFromIndex(entryParser.GetUnsigned()); if (nativeLayoutInfoToken == BadTokenFixupValue) { throw new BadImageFormatException(); } nativeLayoutInfoModule = moduleHandle; return true; } } } #endif #endif return false; }
private string ComputeMangledMethodName(MethodDesc method) { string prependTypeName = null; if (!_compilation.IsCppCodeGen) prependTypeName = GetMangledTypeName(method.OwningType); if (method is EcmaMethod) { var deduplicator = new HashSet<string>(); // Add consistent names for all methods of the type, independent on the order in which // they are compiled lock (this) { foreach (var m in method.OwningType.GetMethods()) { string name = SanitizeName(m.Name); if (deduplicator.Contains(name)) { string nameWithIndex; for (int index = 1; ; index++) { nameWithIndex = name + "_" + index.ToString(CultureInfo.InvariantCulture); if (!deduplicator.Contains(nameWithIndex)) break; } name = nameWithIndex; } deduplicator.Add(name); if (prependTypeName != null) name = prependTypeName + "__" + name; _mangledMethodNames = _mangledMethodNames.Add(m, name); } } return _mangledMethodNames[method]; } string mangledName; var methodDefinition = method.GetTypicalMethodDefinition(); if (methodDefinition != method) { mangledName = GetMangledMethodName(methodDefinition.GetMethodDefinition()); var inst = method.Instantiation; for (int i = 0; i < inst.Length; i++) { string instArgName = GetMangledTypeName(inst[i]); if (_compilation.IsCppCodeGen) instArgName = instArgName.Replace("::", "_"); mangledName += "__" + instArgName; } } else { // Assume that Name is unique for all other methods mangledName = SanitizeName(method.Name); } if (prependTypeName != null) mangledName = prependTypeName + "__" + mangledName; lock (this) { _mangledMethodNames = _mangledMethodNames.Add(method, mangledName); } return mangledName; }
internal MethodForInstantiatedType(MethodDesc typicalMethodDef, InstantiatedType instantiatedType) { Debug.Assert(typicalMethodDef.GetTypicalMethodDefinition() == typicalMethodDef); _typicalMethodDef = typicalMethodDef; _instantiatedType = instantiatedType; }
/// <summary> /// Returns method as defined on a non-generic base class or on a base /// instantiation. /// For example, If Foo<T> : Bar<T> and overrides method M, /// if method is Bar<string>.M(), then this returns Bar<T>.M() /// but if Foo : Bar<string>, then this returns Bar<string>.M() /// </summary> /// <param name="typeExamine">A potentially derived type</param> /// <param name="method">A base class's virtual method</param> static public MethodDesc FindMethodOnTypeWithMatchingTypicalMethod(this TypeDesc targetType, MethodDesc method) { // If method is nongeneric and on a nongeneric type, then it is the matching method if (!method.HasInstantiation && !method.OwningType.HasInstantiation) { return method; } // Since method is an instantiation that may or may not be the same as typeExamine's hierarchy, // find a matching base class on an open type and then work from the instantiation in typeExamine's // hierarchy TypeDesc typicalTypeOfTargetMethod = method.GetTypicalMethodDefinition().OwningType; TypeDesc targetOrBase = targetType; do { TypeDesc openTargetOrBase = targetOrBase; if (openTargetOrBase is InstantiatedType) { openTargetOrBase = openTargetOrBase.GetTypeDefinition(); } if (openTargetOrBase == typicalTypeOfTargetMethod) { // Found an open match. Now find an equivalent method on the original target typeOrBase MethodDesc matchingMethod = targetOrBase.FindMethodOnExactTypeWithMatchingTypicalMethod(method); return matchingMethod; } targetOrBase = targetOrBase.BaseType; } while (targetOrBase != null); Debug.Assert(false, "method has no related type in the type hierarchy of type"); return null; }
/// <summary> /// Resolve a call on the interface method targetVirtualMethod, on the type instanceDefTypeToExamine utilizing metadata to /// its associated virtual method. /// </summary> /// <param name="instanceDefTypeToExamine">(in) The class type on which the interface call is made, (out) the class type where the search may continue using non-metadata means</param> /// <param name="targetVirtualMethod">The interface method to translate into a virtual method for execution</param> /// <returns>virtual method slot which implements the interface method OR null if an implementation should fall back to non-metadata based lookup.</returns> public static MethodDesc ResolveInterfaceMethodToVirtualMethod(TypeDesc instanceType, out TypeDesc instanceDefTypeToExamine, MethodDesc targetVirtualMethod) { instanceDefTypeToExamine = instanceType.GetClosestDefType(); MethodDesc newlyFoundVirtualMethod = null; LowLevelList<MethodDesc> variantTargets = null; if (targetVirtualMethod.OwningType.HasVariance) { foreach (TypeDesc type in instanceType.RuntimeInterfaces) { if (type != targetVirtualMethod.OwningType && type.GetTypeDefinition() == targetVirtualMethod.OwningType.GetTypeDefinition()) { // Check to see if these interfaces are appropriately assignable if (RuntimeAugments.IsAssignableFrom(targetVirtualMethod.OwningType.GetRuntimeTypeHandle(), type.GetRuntimeTypeHandle())) { if (variantTargets == null) variantTargets = new LowLevelList<MethodDesc>(); MethodDesc targetVariantMatch = type.Context.GetMethodForInstantiatedType( targetVirtualMethod.GetTypicalMethodDefinition(), (InstantiatedType)type); variantTargets.Add(targetVariantMatch); } } } } do { newlyFoundVirtualMethod = instanceDefTypeToExamine.ResolveInterfaceMethodToVirtualMethodOnType(targetVirtualMethod); if (newlyFoundVirtualMethod == null && variantTargets != null) { for (int i = 0; i < variantTargets.Count; i++) { newlyFoundVirtualMethod = instanceDefTypeToExamine.ResolveInterfaceMethodToVirtualMethodOnType(variantTargets[i]); if (newlyFoundVirtualMethod != null) break; } } instanceDefTypeToExamine = instanceDefTypeToExamine.BaseType; } while ((newlyFoundVirtualMethod == null) && (instanceDefTypeToExamine != null) && !IsPregeneratedOrTemplateTypeLoaded(instanceDefTypeToExamine)); return newlyFoundVirtualMethod; }
public IEnumerable<LocalVariable> GetLocalVariableNamesForMethod(MethodDesc method) { EcmaMethod ecmaMethod = method.GetTypicalMethodDefinition() as EcmaMethod; if (ecmaMethod == null) return null; ModuleData moduleData = _moduleData[ecmaMethod.Module]; if (moduleData.PdbReader == null) return null; return _pdbSymbolProvider.GetLocalVariableNamesForMethod(moduleData.PdbReader, MetadataTokens.GetToken(ecmaMethod.Handle)); }
public override MethodDesc GetTypicalMethodDefinition() { return(_methodDef.GetTypicalMethodDefinition()); }
private void InitializeTypeDef(Cts.MetadataType entity, TypeDefinition record) { Debug.Assert(entity.IsTypeDefinition); Cts.MetadataType containingType = (Cts.MetadataType)entity.ContainingType; if (containingType != null) { var enclosingType = (TypeDefinition)HandleType(containingType); record.EnclosingType = enclosingType; enclosingType.NestedTypes.Add(record); var namespaceDefinition = HandleNamespaceDefinition(containingType.Module, entity.ContainingType.Namespace); record.NamespaceDefinition = namespaceDefinition; } else { var namespaceDefinition = HandleNamespaceDefinition(entity.Module, entity.Namespace); record.NamespaceDefinition = namespaceDefinition; namespaceDefinition.TypeDefinitions.Add(record); } record.Name = HandleString(entity.Name); Cts.ClassLayoutMetadata layoutMetadata = entity.GetClassLayout(); record.Size = checked ((uint)layoutMetadata.Size); record.PackingSize = checked ((ushort)layoutMetadata.PackingSize); record.Flags = GetTypeAttributes(entity); if (entity.HasBaseType) { record.BaseType = HandleType(entity.BaseType); } record.Interfaces.Capacity = entity.ExplicitlyImplementedInterfaces.Length; foreach (var interfaceType in entity.ExplicitlyImplementedInterfaces) { if (IsBlocked(interfaceType)) { continue; } record.Interfaces.Add(HandleType(interfaceType)); } if (entity.HasInstantiation) { record.GenericParameters.Capacity = entity.Instantiation.Length; foreach (var p in entity.Instantiation) { record.GenericParameters.Add(HandleGenericParameter((Cts.GenericParameterDesc)p)); } } foreach (var field in entity.GetFields()) { if (_policy.GeneratesMetadata(field)) { record.Fields.Add(HandleFieldDefinition(field)); } } foreach (var method in entity.GetMethods()) { if (_policy.GeneratesMetadata(method)) { record.Methods.Add(HandleMethodDefinition(method)); } } var ecmaEntity = entity as Cts.Ecma.EcmaType; if (ecmaEntity != null) { Ecma.TypeDefinition ecmaRecord = ecmaEntity.MetadataReader.GetTypeDefinition(ecmaEntity.Handle); foreach (var e in ecmaRecord.GetEvents()) { Event evt = HandleEvent(ecmaEntity.EcmaModule, e); if (evt != null) { record.Events.Add(evt); } } foreach (var property in ecmaRecord.GetProperties()) { Property prop = HandleProperty(ecmaEntity.EcmaModule, property); if (prop != null) { record.Properties.Add(prop); } } Ecma.CustomAttributeHandleCollection customAttributes = ecmaRecord.GetCustomAttributes(); if (customAttributes.Count > 0) { record.CustomAttributes = HandleCustomAttributes(ecmaEntity.EcmaModule, customAttributes); } foreach (var miHandle in ecmaRecord.GetMethodImplementations()) { Ecma.MetadataReader reader = ecmaEntity.EcmaModule.MetadataReader; Ecma.MethodImplementation miDef = reader.GetMethodImplementation(miHandle); Cts.MethodDesc methodBody = (Cts.MethodDesc)ecmaEntity.EcmaModule.GetObject(miDef.MethodBody); if (_policy.IsBlocked(methodBody)) { continue; } Cts.MethodDesc methodDecl = (Cts.MethodDesc)ecmaEntity.EcmaModule.GetObject(miDef.MethodDeclaration); if (_policy.IsBlocked(methodDecl.GetTypicalMethodDefinition())) { continue; } MethodImpl methodImplRecord = new MethodImpl { MethodBody = HandleQualifiedMethod(methodBody), MethodDeclaration = HandleQualifiedMethod(methodDecl) }; record.MethodImpls.Add(methodImplRecord); } } }
public IEnumerable<string> GetParameterNamesForMethod(MethodDesc method) { EcmaMethod ecmaMethod = method.GetTypicalMethodDefinition() as EcmaMethod; if (ecmaMethod == null) yield break; ParameterHandleCollection parameters = ecmaMethod.MetadataReader.GetMethodDefinition(ecmaMethod.Handle).GetParameters(); if (!ecmaMethod.Signature.IsStatic) { yield return "_this"; } foreach (var parameterHandle in parameters) { Parameter p = ecmaMethod.MetadataReader.GetParameter(parameterHandle); yield return ecmaMethod.MetadataReader.GetString(p.Name); } }
private string ComputeMangledMethodName(MethodDesc method) { string prependTypeName = null; if (!_mangleForCplusPlus) prependTypeName = GetMangledTypeName(method.OwningType); if (method is EcmaMethod) { var deduplicator = new HashSet<string>(); // Add consistent names for all methods of the type, independent on the order in which // they are compiled lock (this) { foreach (var m in method.OwningType.GetMethods()) { string name = SanitizeName(m.Name); name = DisambiguateName(name, deduplicator); deduplicator.Add(name); if (prependTypeName != null) name = prependTypeName + "__" + name; _mangledMethodNames = _mangledMethodNames.Add(m, name); } } return _mangledMethodNames[method]; } string mangledName; var methodDefinition = method.GetTypicalMethodDefinition(); if (methodDefinition != method) { mangledName = GetMangledMethodName(methodDefinition.GetMethodDefinition()); var inst = method.Instantiation; for (int i = 0; i < inst.Length; i++) { string instArgName = GetMangledTypeName(inst[i]); if (_mangleForCplusPlus) instArgName = instArgName.Replace("::", "_"); mangledName += "__" + instArgName; } } else { // Assume that Name is unique for all other methods mangledName = SanitizeName(method.Name); } if (prependTypeName != null) mangledName = prependTypeName + "__" + mangledName; lock (this) { _mangledMethodNames = _mangledMethodNames.Add(method, mangledName); } return mangledName; }
private IEnumerable<string> GetParameterNamesForMethod(MethodDesc method) { // TODO: The uses of this method need revision. The right way to get to this info is from // a MethodIL. For declarations, we don't need names. method = method.GetTypicalMethodDefinition(); var ecmaMethod = method as EcmaMethod; if (ecmaMethod != null && ecmaMethod.Module.PdbReader != null) { return (new EcmaMethodDebugInformation(ecmaMethod)).GetParameterNames(); } return null; }