コード例 #1
0
        public void TestEmptyTuple()
        {
            TupleTypeSpec tuple = TypeSpecParser.Parse("()") as TupleTypeSpec;

            Assert.IsNotNull(tuple);
            Assert.AreEqual(0, tuple.Elements.Count);
        }
コード例 #2
0
 void GetUniqueGenericTypeNamesFor(TupleTypeSpec candidate, HashSet <string> result)
 {
     foreach (var element in candidate.Elements)
     {
         GetUniqueGenericTypeNamesFor(element, result);
     }
 }
コード例 #3
0
        public void TestFuncVoidVoid()
        {
            ClosureTypeSpec close = TypeSpecParser.Parse("() -> ()") as ClosureTypeSpec;

            Assert.NotNull(close);
            TupleTypeSpec ts = close.Arguments as TupleTypeSpec;

            Assert.NotNull(ts);
            Assert.AreEqual(0, ts.Elements.Count);
            ts = close.ReturnType as TupleTypeSpec;
            Assert.NotNull(ts);
            Assert.AreEqual(0, ts.Elements.Count);
        }
コード例 #4
0
        public void TestDoubleTuple()
        {
            TupleTypeSpec tuple = TypeSpecParser.Parse("(Swift.Int, Swift.Float)") as TupleTypeSpec;

            Assert.IsNotNull(tuple);
            Assert.AreEqual(2, tuple.Elements.Count);
            NamedTypeSpec ns = tuple.Elements [0] as NamedTypeSpec;

            Assert.NotNull(ns);
            Assert.AreEqual("Swift.Int", ns.Name);
            ns = tuple.Elements [1] as NamedTypeSpec;
            Assert.NotNull(ns);
            Assert.AreEqual("Swift.Float", ns.Name);
        }
コード例 #5
0
        public void TestWithAttributes()
        {
            TupleTypeSpec tupled = TypeSpecParser.Parse("(Builtin.RawPointer, (@convention[thin] (Builtin.RawPointer, inout Builtin.UnsafeValueBuffer, inout SomeModule.Foo, @thick SomeModule.Foo.Type) -> ())?)")
                                   as TupleTypeSpec;

            Assert.NotNull(tupled);
            var ns = tupled.Elements [1] as NamedTypeSpec;

            Assert.IsTrue(ns.ContainsGenericParameters);
            Assert.AreEqual("Swift.Optional", ns.Name);
            var close = ns.GenericParameters[0] as ClosureTypeSpec;

            Assert.AreEqual(1, close.Attributes.Count);
        }
コード例 #6
0
 bool TupleTypesMatch(FunctionDeclaration protoFunc, TupleTypeSpec protoType, FunctionDeclaration classFunc, TupleTypeSpec classType)
 {
     if (protoType.Elements.Count != classType.Elements.Count)
     {
         return(false);
     }
     for (int i = 0; i < protoType.Elements.Count; i++)
     {
         if (!TypesMatch(protoFunc, protoType.Elements [i], classFunc, classType.Elements [i]))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #7
0
        static bool TypeMatches(FunctionDeclaration decl, TupleTypeSpec ts, SwiftType st, TypeMapper typeMap)
        {
            var tuple = st as SwiftTupleType;

            if (tuple == null || tuple.Contents.Count != ts.Elements.Count)
            {
                return(false);
            }
            for (int i = 0; i < ts.Elements.Count; i++)
            {
                if (!TypeMatches(decl, ts.Elements [i], tuple.Contents [i], typeMap))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #8
0
        TypeSpec RebuildTypeWithGenericType(TupleTypeSpec type, out bool changed)
        {
            changed = false;
            var newTupleElems = new TypeSpec [type.Elements.Count];

            for (int i = 0; i < type.Elements.Count; i++)
            {
                bool elemChanged;
                newTupleElems [i] = RebuildTypeWithGenericType(type.Elements [i], out elemChanged);
                changed           = changed || elemChanged;
            }

            if (changed)
            {
                return(new TupleTypeSpec(newTupleElems));
            }
            return(type);
        }
コード例 #9
0
        SLBaseExpr MarshalTupleTypeSpec(BaseDeclaration declContext, string name, TupleTypeSpec tuple)
        {
            var bindingName = new SLIdentifier(MarshalEngine.Uniqueify(name, identifiersUsed));
            var argType     = typeMapper.TypeSpecMapper.MapType(declContext, imports, tuple, 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 (tuple.IsInOut)
            {
                postMarshalCode.Add(new SLLine(new SLBinding(name, bindingName.Dot(new SLIdentifier("pointee")))));
            }
            return(new SLFunctionCall("toIntPtr", false, new SLArgument(new SLIdentifier("value"), bindingName, true)));
        }
コード例 #10
0
 SLType MapType(BaseDeclaration declContext, SLImportModules modules, TupleTypeSpec spec)
 {
     return(new SLTupleType(spec.Elements.Select(p => new SLNameTypePair((string)null, MapType(declContext, modules, p, false))).ToList()));
 }