TypeDeclaration ToProtocolDeclaration(TypeDefinition definition) { var name = TypeAggregator.ProtocolAttributeName(definition) ?? definition.Name; var moduleName = definition.Namespace; // FIXME: these cases don't have a clear resolution // don't know what to do about this, so skip I guess? if (name == "NSDraggingDestination" || name == "NSDraggingInfo") { return(null); } TypeAggregator.RemapModuleAndName(platform, ref moduleName, ref name, TypeType.Interface); var protocolDeclaration = new ProtocolDeclaration { Name = name, Access = ToAccessibility(definition), Module = ToModuleDeclaration(moduleName), ParentExtension = null, Kind = TypeKind.Protocol, Members = new List <Member> (), IsObjC = true, IsFinal = definition.IsSealed, IsDeprecated = false, IsUnavailable = false, IsImportedBinding = true }; protocolDeclaration.Inheritance.AddRange(ToInheritance(definition)); return(protocolDeclaration.MakeUnrooted()); }
void AddAssocTypesToNameMap(ProtocolDeclaration decl) { for (int i = 0; i < decl.AssociatedTypes.Count; i++) { nameIndexMap.Add(OverrideBuilder.GenericAssociatedTypeName(decl.AssociatedTypes [i]), i); } }
public static ClassDeclaration FindWrapperClass(WrappingResult wrapper, ProtocolDeclaration protocol) { var className = protocol.HasAssociatedTypes ? OverrideBuilder.AssociatedTypeProxyClassName(protocol) : OverrideBuilder.ProxyClassName(protocol); var theClass = wrapper.Module.Classes.FirstOrDefault(cl => cl.Name == className); return(wrapper.FunctionReferenceCodeMap.OriginalOrReflectedClassFor(theClass) as ClassDeclaration); }
public NetTypeBundle(ProtocolDeclaration proto, AssociatedTypeDeclaration assoc) { GenericIndex = -1; AssociatedTypeProtocol = proto; AssociatedType = assoc; Type = OverrideBuilder.GenericAssociatedTypeName(assoc); FullName = Type; NameSpace = String.Empty; }
public PatToGenericMap(ProtocolDeclaration protocolDecl) { Ex.ThrowOnNull(protocolDecl, nameof(protocolDecl)); if (!protocolDecl.HasAssociatedTypes) { throw new ArgumentException("ProtocolDeclaration has no associated types", nameof(protocolDecl)); } this.protocolDecl = protocolDecl; AddAssocTypesToNameMap(this.protocolDecl); }
void CompileProp(PropertyDeclaration propDecl, ProtocolDeclaration proto, CSInterface iface, CSUsingPackages use) { var getter = propDecl.GetGetter(); var setter = propDecl.GetSetter(); var publicProp = topLevelFunctionCompiler.CompileProperty(use, null, getter, setter, CSMethodKind.None); publicProp = new CSProperty(publicProp.PropType, CSMethodKind.None, publicProp.Name, CSVisibility.None, new CSCodeBlock(), CSVisibility.None, setter != null ? new CSCodeBlock() : null); ExportAttribute(getter.ObjCSelector).AttachBefore(publicProp); if (!propDecl.IsOptional) { kAbstractAttribute.AttachBefore(publicProp); } iface.Properties.Add(publicProp); }
void CompileFunc(FunctionDeclaration funcDecl, ProtocolDeclaration proto, CSInterface iface, CSUsingPackages use) { var homonymSuffix = Homonyms.HomonymSuffix(funcDecl, proto.Members.OfType <FunctionDeclaration> (), typeMapper); var publicMethod = topLevelFunctionCompiler.CompileMethod(funcDecl, use, swiftLibPath, null, null, false, false, false); // recast with no visibility and with the homonym suffix, if any publicMethod = new CSMethod(CSVisibility.None, CSMethodKind.Interface, publicMethod.Type, new CSIdentifier(publicMethod.Name.Name + homonymSuffix), publicMethod.Parameters, null); ExportAttribute(funcDecl.ObjCSelector).AttachBefore(publicMethod); if (!funcDecl.IsOptional) { kAbstractAttribute.AttachBefore(publicMethod); } iface.Methods.Add(publicMethod); }
CSInterface CompileProtocol(ProtocolDeclaration proto, CSUsingPackages use) { var iface = new CSInterface(CSVisibility.Public, proto.Name); kProtocolAttribute.AttachBefore(iface); var filteredInheritance = proto.Inheritance.FindAll(inh => !TypeSpecIsAnyOrAnyObject(inh.InheritedTypeSpec)); iface.Inheritance.AddRange(filteredInheritance.Select(inh => { var netIface = typeMapper.GetDotNetNameForTypeSpec(inh.InheritedTypeSpec); use.AddIfNotPresent(netIface.Namespace); return(new CSIdentifier(netIface.TypeName)); })); foreach (var funcDecl in proto.AllMethodsNoCDTor()) { if (funcDecl.IsProperty && !funcDecl.IsSubscript) { continue; } try { CompileFunc(funcDecl, proto, iface, use); } catch (Exception e) { errors.Add(ErrorHelper.CreateWarning(ReflectorError.kWrappingBase + 14, e, $"Error compiling ObjC protocol method {proto.ToFullyQualifiedName ()}.{funcDecl.Name}")); } } foreach (var propDecl in proto.AllProperties()) { try { CompileProp(propDecl, proto, iface, use); } catch (Exception e) { errors.Add(ErrorHelper.CreateWarning(ReflectorError.kWrappingBase + 14, e, $"Error compiling ObjC protocol property {proto.ToFullyQualifiedName ()}.{propDecl.Name}")); } } var anyRequired = proto.AllMethodsNoCDTor().Any(func => !func.IsOptional); if (anyRequired) { kAbstractAttribute.AttachBefore(iface); } return(iface); }
public ProtocolMethodMatcher(ProtocolDeclaration protocol, List <FunctionDeclaration> originalFuncs, WrappingResult wrapper) { this.protocol = Ex.ThrowOnNull(protocol, nameof(protocol)); this.originalFuncs = Ex.ThrowOnNull(originalFuncs, nameof(originalFuncs)); this.wrapper = Ex.ThrowOnNull(wrapper, nameof(wrapper)); }