static int ComputeMetadataBoundsFromSuperClass(SwiftNominalTypeDescriptor descHandle)
        {
            // the computed size of a class metadata is the size of its members + the size of its super class.
            // If there is no super class, the size of the basic class metadata
            int bounds   = 0;
            var superPtr = descHandle.ResilientSuperclass;

            if (superPtr != IntPtr.Zero)
            {
                bounds = ComputeMetadataBoundsFromSuperClass(new SwiftNominalTypeDescriptor(superPtr));
            }
            else
            {
                bounds = SwiftMetatype.ClassSizeWithoutMembers;
            }
            if (descHandle.ImmediateMembersAreNegative())
            {
                bounds -= descHandle.MetadataNegativeSizeInWords;
            }
            else
            {
                bounds += descHandle.MetadataPositiveSizeInWords;
            }
            return(bounds);
        }
Beispiel #2
0
        internal static IntPtr DescriptorHandleForType(Type interfaceType)
        {
            // internal version, no exceptions
            var typeAttribute = interfaceType.GetCustomAttribute <SwiftProtocolTypeAttribute> ();

            if (typeAttribute == null)
            {
                return(IntPtr.Zero);
            }
            var desc = SwiftNominalTypeDescriptor.FromDylibFile(typeAttribute.LibraryName, DLOpenMode.Now, typeAttribute.ProtocolDescriptor);

            if (!desc.HasValue)
            {
                return(IntPtr.Zero);
            }
            return(desc.Value.Handle);
        }
Beispiel #3
0
        public static SwiftNominalTypeDescriptor DescriptorForType(Type interfaceType)
        {
            Exceptions.ThrowOnNull(interfaceType, nameof(interfaceType));
            if (!interfaceType.IsInterface)
            {
                throw new SwiftRuntimeException($"Type {interfaceType.Name} is not an interface.");
            }
            var typeAttribute = interfaceType.GetCustomAttribute <SwiftProtocolTypeAttribute> ();

            if (typeAttribute == null)
            {
                throw new SwiftRuntimeException($"Type {interfaceType.Name} does not have a SwiftProtocolType attribute");
            }
            var desc = SwiftNominalTypeDescriptor.FromDylibFile(typeAttribute.LibraryName, DLOpenMode.Now, typeAttribute.ProtocolDescriptor);

            if (!desc.HasValue)
            {
                throw new SwiftRuntimeException($"Unable to find swift protocol type descriptor for {interfaceType.Name} with symbol {typeAttribute.ProtocolDescriptor} in file {typeAttribute.LibraryName}");
            }
            return(desc.Value);
        }