コード例 #1
0
 void GetUniqueGenericTypeNamesFor(ProtocolListTypeSpec candidate, HashSet <string> result)
 {
     foreach (var element in candidate.Protocols.Keys)
     {
         GetUniqueGenericTypeNamesFor(element, result);
     }
 }
コード例 #2
0
        public void TestProtocolListAlphabetical1()
        {
            var specs = new NamedTypeSpec [] {
                new NamedTypeSpec("🤡Foo"),
                new NamedTypeSpec("💩Foo"),
            };

            var protos = new ProtocolListTypeSpec(specs);

            Assert.AreEqual("💩Foo & 🤡Foo", protos.ToString(), "ToString mismatch");
        }
コード例 #3
0
        public void TestProtocolListAlphabetical()
        {
            var specs = new NamedTypeSpec [] {
                new NamedTypeSpec("Cfoo"),
                new NamedTypeSpec("Afoo"),
                new NamedTypeSpec("Dfoo"),
                new NamedTypeSpec("Bfoo")
            };

            var protos = new ProtocolListTypeSpec(specs);

            Assert.AreEqual("Afoo & Bfoo & Cfoo & Dfoo", protos.ToString(), "ToString mismatch");
        }
コード例 #4
0
 bool ProtoListTypesMatch(FunctionDeclaration protoFunc, ProtocolListTypeSpec protoType, FunctionDeclaration classFunc, ProtocolListTypeSpec classType)
 {
     if (protoType.Protocols.Count != classType.Protocols.Count)
     {
         return(false);
     }
     for (int i = 0; i < protoType.Protocols.Count; i++)
     {
         if (!NamedTypesMatch(protoFunc, protoType.Protocols.Keys [i], classFunc, classType.Protocols.Keys [i]))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #5
0
        static bool TypeMatches(FunctionDeclaration decl, ProtocolListTypeSpec ps, SwiftType st, TypeMapper typeMap)
        {
            var protoList = st as SwiftProtocolListType;

            if (protoList == null || protoList.Protocols.Count != ps.Protocols.Count)
            {
                return(false);
            }
            for (int i = 0; i < ps.Protocols.Count; i++)
            {
                if (!TypeMatches(decl, ps.Protocols.Keys [i], protoList.Protocols [i], typeMap))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #6
0
        public void TestProtocolListNotMatch()
        {
            var specs1 = new NamedTypeSpec [] {
                new NamedTypeSpec("Cfoo"),
                new NamedTypeSpec("Afoo"),
                new NamedTypeSpec("Dfoo"),
                new NamedTypeSpec("Bfoo")
            };

            var specs2 = new NamedTypeSpec [] {
                new NamedTypeSpec("Afoo"),
                new NamedTypeSpec("Efoo"),
                new NamedTypeSpec("Cfoo"),
                new NamedTypeSpec("Bfoo")
            };

            var protos1 = new ProtocolListTypeSpec(specs1);
            var protos2 = new ProtocolListTypeSpec(specs2);

            Assert.IsFalse(protos1.Equals(protos2), "lists match?!");
        }
コード例 #7
0
        SLBaseExpr MarshalProtocolListTypeSpec(BaseDeclaration declContext, string name, ProtocolListTypeSpec protocols)
        {
            // let p = UnsafeMutablePointer<protoType>.allocate (argName)
            // p.initialize(to: argName)
            // exp is toIntPtr(value: p)
            // ...
            // if isInOut:
            // argName = p.pointee
            // always:
            // p.deinitialize ()
            // p.deallocate ()
            var bindingName = new SLIdentifier(MarshalEngine.Uniqueify(name, identifiersUsed));
            var argType     = typeMapper.TypeSpecMapper.MapType(declContext, imports, protocols, false);
            var ptrType     = new SLBoundGenericType("UnsafeMutablePointer", argType);

            identifiersUsed.Add(bindingName.Name);
            var decl = new SLDeclaration(true, bindingName, ptrType,
                                         new SLFunctionCall(ptrType + ".allocate", false, new SLArgument(new SLIdentifier("capacity"), SLConstant.Val(1), true)),
                                         Visibility.None, false);
            var varBinding = new SLLine(decl);

            preMarshalCode.Add(varBinding);
            var initCall = SLFunctionCall.FunctionCallLine(bindingName.Name + ".initialize",
                                                           new SLArgument(new SLIdentifier("to"), new SLIdentifier(name), true));

            preMarshalCode.Add(initCall);
            imports.AddIfNotPresent("XamGlue");
            if (protocols.IsInOut)
            {
                postMarshalCode.Add(new SLLine(new SLBinding(name, bindingName.Dot(new SLIdentifier("pointee")))));
            }
            postMarshalCode.Add(SLFunctionCall.FunctionCallLine($"{bindingName.Name}.deinitialize", new SLArgument(new SLIdentifier("count"), SLConstant.Val(1), true)));
            postMarshalCode.Add(SLFunctionCall.FunctionCallLine($"{bindingName.Name}.deallocate"));
            return(new SLFunctionCall("toIntPtr", false, new SLArgument(new SLIdentifier("value"), bindingName, true)));
        }
コード例 #8
0
 SLType MapType(BaseDeclaration declContext, SLImportModules modules, ProtocolListTypeSpec spec)
 {
     return(new SLProtocolListType(spec.Protocols.Keys.Select(proto => MapType(declContext, modules, proto))));
 }