internal bool GetCallingConverterDataFromMethodSignature_NativeLayout_Common( TypeSystemContext context, RuntimeSignature methodSig, Instantiation typeInstantiation, Instantiation methodInstantiation, out bool hasThis, out TypeDesc[] parameters, out bool[] parametersWithGenericDependentLayout, NativeReader nativeReader) { NativeLayoutInfoLoadContext nativeLayoutContext = new NativeLayoutInfoLoadContext(); nativeLayoutContext._module = (NativeFormatModuleInfo)methodSig.GetModuleInfo(); nativeLayoutContext._typeSystemContext = context; nativeLayoutContext._typeArgumentHandles = typeInstantiation; nativeLayoutContext._methodArgumentHandles = methodInstantiation; NativeFormatModuleInfo module = ModuleList.Instance.GetModuleInfoByHandle(new TypeManagerHandle(methodSig.ModuleHandle)); NativeReader reader = GetNativeLayoutInfoReader(methodSig); NativeParser parser = new NativeParser(reader, methodSig.NativeLayoutOffset); MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned(); hasThis = !callingConvention.HasFlag(MethodCallingConvention.Static); if (callingConvention.HasFlag(MethodCallingConvention.Generic)) { parser.SkipInteger(); // numGenArgs } uint parameterCount = parser.GetUnsigned(); parameters = new TypeDesc[parameterCount + 1]; parametersWithGenericDependentLayout = new bool[parameterCount + 1]; // One extra parameter to account for the return type for (uint i = 0; i <= parameterCount; i++) { // NativeParser is a struct, so it can be copied. NativeParser parserCopy = parser; // Parse the signature twice. The first time to find out the exact type of the signature // The second time to identify if the parameter loaded via the signature should be forced to be // passed byref as part of the universal generic calling convention. parameters[i] = GetConstructedTypeFromParserAndNativeLayoutContext(ref parser, nativeLayoutContext); parametersWithGenericDependentLayout[i] = TypeSignatureHasVarsNeedingCallingConventionConverter(ref parserCopy, module, context, HasVarsInvestigationLevel.Parameter); if (parameters[i] == null) { return(false); } } return(true); }
private static bool CompareCallingConventions(MethodCallingConvention callingConvention, MethodBase methodBase) { if (callingConvention.HasFlag(MethodCallingConvention.Static) != methodBase.IsStatic) { return(false); } if (callingConvention.HasFlag(MethodCallingConvention.Generic) != (methodBase.IsGenericMethod | methodBase.IsGenericMethodDefinition)) { return(false); } return(true); }
private bool MethodSignatureHasVarsNeedingCallingConventionConverter_NativeLayout(TypeSystemContext context, RuntimeSignature methodSig) { NativeReader reader = GetNativeLayoutInfoReader(methodSig); NativeParser parser = new NativeParser(reader, methodSig.NativeLayoutOffset); NativeFormatModuleInfo module = ModuleList.Instance.GetModuleInfoByHandle(new TypeManagerHandle(methodSig.ModuleHandle)); MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned(); uint numGenArgs = callingConvention.HasFlag(MethodCallingConvention.Generic) ? parser.GetUnsigned() : 0; uint parameterCount = parser.GetUnsigned(); // Check the return type of the method if (TypeSignatureHasVarsNeedingCallingConventionConverter(ref parser, module, context, HasVarsInvestigationLevel.Parameter)) { return(true); } // Check the parameters of the method for (uint i = 0; i < parameterCount; i++) { if (TypeSignatureHasVarsNeedingCallingConventionConverter(ref parser, module, context, HasVarsInvestigationLevel.Parameter)) { return(true); } } return(false); }
private bool MethodSignatureHasVarsNeedingCallingConventionConverter_NativeLayout(TypeSystemContext context, IntPtr methodSig) { IntPtr moduleHandle = RuntimeAugments.GetModuleFromPointer(methodSig); NativeReader reader = GetNativeLayoutInfoReader(moduleHandle); NativeParser parser = new NativeParser(reader, reader.AddressToOffset(methodSig)); MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned(); uint numGenArgs = callingConvention.HasFlag(MethodCallingConvention.Generic) ? parser.GetUnsigned() : 0; uint parameterCount = parser.GetUnsigned(); // Check the return type of the method if (TypeSignatureHasVarsNeedingCallingConventionConverter(ref parser, context, HasVarsInvestigationLevel.Parameter)) { return(true); } // Check the parameters of the method for (uint i = 0; i < parameterCount; i++) { if (TypeSignatureHasVarsNeedingCallingConventionConverter(ref parser, context, HasVarsInvestigationLevel.Parameter)) { return(true); } } return(false); }
internal bool GetCallingConverterDataFromMethodSignature_NativeLayout(TypeSystemContext context, IntPtr methodSig, NativeLayoutInfoLoadContext nativeLayoutContext, out bool hasThis, out TypeDesc[] parameters, out bool[] parametersWithGenericDependentLayout) { hasThis = false; parameters = null; IntPtr moduleHandle = RuntimeAugments.GetModuleFromPointer(methodSig); NativeReader reader = GetNativeLayoutInfoReader(moduleHandle); NativeParser parser = new NativeParser(reader, reader.AddressToOffset(methodSig)); MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned(); hasThis = !callingConvention.HasFlag(MethodCallingConvention.Static); uint numGenArgs = callingConvention.HasFlag(MethodCallingConvention.Generic) ? parser.GetUnsigned() : 0; uint parameterCount = parser.GetUnsigned(); parameters = new TypeDesc[parameterCount + 1]; parametersWithGenericDependentLayout = new bool[parameterCount + 1]; // One extra parameter to account for the return type for (uint i = 0; i <= parameterCount; i++) { // NativeParser is a struct, so it can be copied. NativeParser parserCopy = parser; // Parse the signature twice. The first time to find out the exact type of the signature // The second time to identify if the parameter loaded via the signature should be forced to be // passed byref as part of the universal generic calling convention. parameters[i] = GetConstructedTypeFromParserAndNativeLayoutContext(ref parser, nativeLayoutContext); parametersWithGenericDependentLayout[i] = TypeSignatureHasVarsNeedingCallingConventionConverter(ref parserCopy, context, HasVarsInvestigationLevel.Parameter); if (parameters[i] == null) { return(false); } } return(true); }
internal bool IsStaticMethodSignature(RuntimeSignature methodSig) { if (methodSig.IsNativeLayoutSignature) { NativeReader reader = GetNativeLayoutInfoReader(methodSig.ModuleHandle); NativeParser parser = new NativeParser(reader, methodSig.NativeLayoutOffset); MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned(); return(callingConvention.HasFlag(MethodCallingConvention.Static)); } else { var metadataReader = ModuleList.Instance.GetMetadataReaderForModule(methodSig.ModuleHandle); var methodHandle = methodSig.Token.AsHandle().ToMethodHandle(metadataReader); var method = methodHandle.GetMethod(metadataReader); return((method.Flags & MethodAttributes.Static) != 0); } }
internal bool IsStaticMethodSignature(RuntimeSignature methodSig) { if (methodSig.IsNativeLayoutSignature) { NativeReader reader = GetNativeLayoutInfoReader(methodSig); NativeParser parser = new NativeParser(reader, methodSig.NativeLayoutOffset); MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned(); return(callingConvention.HasFlag(MethodCallingConvention.Static)); } else { ModuleInfo module = methodSig.GetModuleInfo(); #if ECMA_METADATA_SUPPORT if (module is NativeFormatModuleInfo) #endif { NativeFormatModuleInfo nativeFormatModule = (NativeFormatModuleInfo)module; var metadataReader = nativeFormatModule.MetadataReader; var methodHandle = methodSig.Token.AsHandle().ToMethodHandle(metadataReader); var method = methodHandle.GetMethod(metadataReader); return((method.Flags & MethodAttributes.Static) != 0); } #if ECMA_METADATA_SUPPORT else { EcmaModuleInfo ecmaModuleInfo = (EcmaModuleInfo)module; var metadataReader = ecmaModuleInfo.MetadataReader; var ecmaHandle = (System.Reflection.Metadata.MethodDefinitionHandle)System.Reflection.Metadata.Ecma335.MetadataTokens.Handle(methodSig.Token); var method = metadataReader.GetMethodDefinition(ecmaHandle); var blobHandle = method.Signature; var blobReader = metadataReader.GetBlobReader(blobHandle); byte sigByte = blobReader.ReadByte(); return((sigByte & (byte)System.Reflection.Metadata.SignatureAttributes.Instance) == 0); } #endif } }
private static bool CompareCallingConventions(MethodCallingConvention callingConvention, MethodBase methodBase) { if (callingConvention.HasFlag(MethodCallingConvention.Static) != methodBase.IsStatic) return false; if (callingConvention.HasFlag(MethodCallingConvention.Generic) != (methodBase.IsGenericMethod | methodBase.IsGenericMethodDefinition)) return false; return true; }
private bool CompareCallingConventions(MethodCallingConvention callingConvention) { return((callingConvention.HasFlag(MethodCallingConvention.Static) == _isStatic) && (callingConvention.HasFlag(MethodCallingConvention.Generic) == _isGeneric)); }
private bool CompareCallingConventions(MethodCallingConvention callingConvention) { return (callingConvention.HasFlag(MethodCallingConvention.Static) == _isStatic) && (callingConvention.HasFlag(MethodCallingConvention.Generic) == _isGeneric); }