private TypeDesc ResolveHandle(EntityHandle handle)
 {
     if (_ecmaModule != null)
     {
         return(_ecmaModule.GetType(handle));
     }
     else
     {
         return(_typeResolver(handle));
     }
 }
        public void SetSystemModule(EcmaModule systemModule)
        {
            _systemModule = systemModule;

            // Sanity check the name table
            Debug.Assert(s_wellKnownTypeNames[(int)WellKnownType.MulticastDelegate - 1] == "MulticastDelegate");

            // Initialize all well known types - it will save us from checking the name for each loaded type
            for (int typeIndex = 0; typeIndex < _wellKnownTypes.Length; typeIndex++)
            {
                MetadataType type = _systemModule.GetType("System", s_wellKnownTypeNames[typeIndex]);
                type.SetWellKnownType((WellKnownType)(typeIndex + 1));
                _wellKnownTypes[typeIndex] = type;
            }
        }
Exemple #3
0
        private MetadataType InitializeBaseType()
        {
            var baseTypeHandle = _typeDefinition.BaseType;
            if (baseTypeHandle.IsNil)
            {
                _baseType = null;
                return null;
            }

            var type = _module.GetType(baseTypeHandle) as MetadataType;
            if (type == null)
            {
                // PREFER: "new TypeSystemException.TypeLoadException(ExceptionStringID.ClassLoadBadFormat, this)" but the metadata is too broken
                ThrowHelper.ThrowTypeLoadException(Namespace, Name, Module);
            }
            _baseType = type;
            return type;
        }
Exemple #4
0
        private MetadataType InitializeBaseType()
        {
            var baseTypeHandle = _typeDefinition.BaseType;

            if (baseTypeHandle.IsNil)
            {
                _baseType = null;
                return(null);
            }

            var type = _module.GetType(baseTypeHandle) as MetadataType;

            if (type == null)
            {
                throw new BadImageFormatException();
            }
            _baseType = type;
            return(type);
        }
        internal TypeDesc GetTypeDescFromQHandle(QTypeDefinition qTypeDefinition)
        {
#if ECMA_METADATA_SUPPORT
            if (qTypeDefinition.IsNativeFormatMetadataBased)
#endif
            {
                MetadataReader           nativeFormatMetadataReader = qTypeDefinition.NativeFormatReader;
                TypeDefinitionHandle     typeDefinitionHandle       = qTypeDefinition.NativeFormatHandle;
                NativeFormatModuleInfo   module           = ModuleList.Instance.GetModuleInfoForMetadataReader(nativeFormatMetadataReader);
                NativeFormatMetadataUnit metadataUnit     = ResolveMetadataUnit(module);
                NativeFormatType         nativeFormatType = (NativeFormatType)metadataUnit.GetType(typeDefinitionHandle);
                return(nativeFormatType);
            }
#if ECMA_METADATA_SUPPORT
            else if (qTypeDefinition.IsEcmaFormatMetadataBased)
            {
                EcmaModuleInfo  module     = ModuleList.Instance.GetModuleInfoForMetadataReader(qTypeDefinition.EcmaFormatReader);
                Ecma.EcmaModule ecmaModule = ResolveEcmaModule(module);
                Ecma.EcmaType   ecmaType   = (Ecma.EcmaType)ecmaModule.GetType(qTypeDefinition.EcmaFormatHandle);
                return(ecmaType);
            }
#endif
            return(null);
        }
Exemple #6
0
        private TypeDesc ParseType(SignatureTypeCode typeCode)
        {
            // Switch on the type.
            switch (typeCode)
            {
            case SignatureTypeCode.Void:
                return(GetWellKnownType(WellKnownType.Void));

            case SignatureTypeCode.Boolean:
                return(GetWellKnownType(WellKnownType.Boolean));

            case SignatureTypeCode.SByte:
                return(GetWellKnownType(WellKnownType.SByte));

            case SignatureTypeCode.Byte:
                return(GetWellKnownType(WellKnownType.Byte));

            case SignatureTypeCode.Int16:
                return(GetWellKnownType(WellKnownType.Int16));

            case SignatureTypeCode.UInt16:
                return(GetWellKnownType(WellKnownType.UInt16));

            case SignatureTypeCode.Int32:
                return(GetWellKnownType(WellKnownType.Int32));

            case SignatureTypeCode.UInt32:
                return(GetWellKnownType(WellKnownType.UInt32));

            case SignatureTypeCode.Int64:
                return(GetWellKnownType(WellKnownType.Int64));

            case SignatureTypeCode.UInt64:
                return(GetWellKnownType(WellKnownType.UInt64));

            case SignatureTypeCode.Single:
                return(GetWellKnownType(WellKnownType.Single));

            case SignatureTypeCode.Double:
                return(GetWellKnownType(WellKnownType.Double));

            case SignatureTypeCode.Char:
                return(GetWellKnownType(WellKnownType.Char));

            case SignatureTypeCode.String:
                return(GetWellKnownType(WellKnownType.String));

            case SignatureTypeCode.IntPtr:
                return(GetWellKnownType(WellKnownType.IntPtr));

            case SignatureTypeCode.UIntPtr:
                return(GetWellKnownType(WellKnownType.UIntPtr));

            case SignatureTypeCode.Object:
                return(GetWellKnownType(WellKnownType.Object));

            case SignatureTypeCode.TypeHandle:
                return(_module.GetType(_reader.ReadTypeHandle()));

            case SignatureTypeCode.SZArray:
                return(_module.Context.GetArrayType(ParseType()));

            case SignatureTypeCode.Array:
            {
                var elementType = ParseType();
                var rank        = _reader.ReadCompressedInteger();

                // TODO: Bounds for multi-dimmensional arrays
                var boundsCount = _reader.ReadCompressedInteger();
                for (int i = 0; i < boundsCount; i++)
                {
                    _reader.ReadCompressedInteger();
                }
                var lowerBoundsCount = _reader.ReadCompressedInteger();
                for (int j = 0; j < lowerBoundsCount; j++)
                {
                    _reader.ReadCompressedInteger();
                }

                return(_module.Context.GetArrayType(elementType, rank));
            }

            case SignatureTypeCode.ByReference:
                return(ParseType().MakeByRefType());

            case SignatureTypeCode.Pointer:
                return(_module.Context.GetPointerType(ParseType()));

            case SignatureTypeCode.GenericTypeParameter:
                return(_module.Context.GetSignatureVariable(_reader.ReadCompressedInteger(), false));

            case SignatureTypeCode.GenericMethodParameter:
                return(_module.Context.GetSignatureVariable(_reader.ReadCompressedInteger(), true));

            case SignatureTypeCode.GenericTypeInstance:
            {
                TypeDesc     typeDef         = ParseType();
                MetadataType metadataTypeDef = typeDef as MetadataType;
                if (metadataTypeDef == null)
                {
                    throw new BadImageFormatException();
                }

                TypeDesc[] instance = new TypeDesc[_reader.ReadCompressedInteger()];
                for (int i = 0; i < instance.Length; i++)
                {
                    instance[i] = ParseType();
                }
                return(_module.Context.GetInstantiatedType(metadataTypeDef, new Instantiation(instance)));
            }

            case SignatureTypeCode.TypedReference:
                throw new PlatformNotSupportedException("TypedReference not supported in .NET Core");

            case SignatureTypeCode.FunctionPointer:
                throw new PlatformNotSupportedException("Function pointer types are not supported in .NET Core");

            default:
                throw new BadImageFormatException();
            }
        }
 public TypeDesc GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind)
 {
     Debug.Assert(reader == _module.MetadataReader);
     return(_module.GetType(handle));
 }
 public TypeDesc GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, SignatureTypeHandleCode code)
 {
     Debug.Assert(reader == _module.MetadataReader);
     return(_module.GetType(handle));
 }