=> NativeFieldsOffset + NativeFields.Sum(fld => fld.SwiftType.NativeDataSize);                  // FIXME: alignment?

        #region Native Fields

        /// <summary>
        /// Determines the fields to expose to Swift.
        /// </summary>
        /// <remarks>
        /// This method is called from the constructor. The only instance state that
        ///  is guaranteed to be initialized before this method is called is <see cref="ManagedType"/>.
        /// </remarks>
        protected virtual unsafe IReadOnlyList <SwiftFieldInfo> DetermineNativeFields()
        {
            var offset        = NativeFieldsOffset;
            var managedFields = ManagedType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var swiftFields   = new List <SwiftFieldInfo> (managedFields.Length);

            foreach (var fld in managedFields)
            {
                if (!typeof(ISwiftFieldExposable).IsAssignableFrom(fld.FieldType))
                {
                    continue;
                }
                var nullability = Nullability.Of(fld);
                var swiftType   = SwiftType.Of(fld.FieldType, nullability);
                Debug.Assert(swiftType != null, "ISwiftFieldExposable types must be SwiftTypes");
                // FIXME: '!' shouldn't be needed as we have Debug.Assert
                swiftFields.Add(new SwiftFieldInfo(fld, swiftType !, nullability, offset));
                offset += swiftType !.NativeDataSize;                // FIXME: alignment?
            }
            return(swiftFields.ToArray());
        }
Ejemplo n.º 2
0
 void ISwiftFieldExposable.SetSwiftType(SwiftType swiftType, Nullability nullability)
 {
     this.swiftType = swiftType;
     SetNullability(nullability);
 }
Ejemplo n.º 3
0
 public SwiftProtocolAttribute(string libraryPath, string module, string name)
     : this(libraryPath, SwiftType.Mangle(module, name))
 {
 }
Ejemplo n.º 4
0
 public SwiftHandle(object toPin, SwiftType swiftType, bool destroyOnDispose = false)
 {
     this.swiftType = swiftType ?? throw new ArgumentNullException(nameof(swiftType));
     this.handle    = GCHandle.Alloc(toPin, GCHandleType.Pinned);
     this.tp        = new TaggedPointer(handle.AddrOfPinnedObject(), destroyOnDispose);
 }
Ejemplo n.º 5
0
 public SwiftHandle(void *pointer, SwiftType swiftType, GCHandle handle = default)
 {
     this.swiftType = swiftType ?? throw new ArgumentNullException(nameof(swiftType));
     this.tp        = new TaggedPointer(pointer, false);
     this.handle    = handle;
 }
Ejemplo n.º 6
0
 // FIXME: Does this belong somewhere else?
 public ProtocolDescriptor *GetProtocol(string module, string name)
 => (ProtocolDescriptor *)RequireSymbol("$s" + SwiftType.Mangle(module, name) + "Mp");