static bool TypeMatches(FunctionDeclaration decl, TypeSpec ts, SwiftType st, TypeMapper typeMap)
        {
            switch (ts.Kind)
            {
            case TypeSpecKind.Named:
                return(TypeMatches(decl, ts as NamedTypeSpec, st, typeMap));

            case TypeSpecKind.Closure:
                return(TypeMatches(decl, ts as ClosureTypeSpec, st, typeMap));

            case TypeSpecKind.Tuple:
                return(TypeMatches(decl, ts as TupleTypeSpec, st, typeMap));

            case TypeSpecKind.ProtocolList:
                return(TypeMatches(decl, ts as ProtocolListTypeSpec, st, typeMap));

            default:
                throw new ArgumentOutOfRangeException(nameof(ts));
            }
        }
Ejemplo n.º 2
0
        static SwiftType ProjectAsNonReference(SwiftType a)
        {
            if (a.IsReference)
            {
                return(a.NonReferenceCloneOf());
            }
            var bgt = a as SwiftBoundGenericType;

            if (bgt != null && bgt.BoundTypes.Count == 1)
            {
                var baseType = bgt.BaseType as SwiftClassType;
                if (baseType != null)
                {
                    string name = baseType.ClassName.ToFullyQualifiedName(true);
                    if (name == "Swift.UnsafePointer" || name == "Swift.UnsafeMutablePointer")
                    {
                        return(bgt.BoundTypes [0]);
                    }
                }
            }
            return(a);
        }
Ejemplo n.º 3
0
 public SwiftConstructorType(bool isAllocating, SwiftType unCurriedParameter, SwiftType parms, SwiftType ret, bool isReference, bool canThrow, SwiftType extensionOn = null)
     : base(isAllocating ? MemberType.Allocator : MemberType.Constructor,
            unCurriedParameter, parms, ret, isReference, canThrow, isAllocating ? Decomposer.kSwiftAllocatingConstructorName :
            Decomposer.kSwiftNonAllocatingConstructorName, extensionOn)
 {
 }
Ejemplo n.º 4
0
        protected override bool LLEquals(SwiftType other)
        {
            var ucf = other as SwiftUncurriedFunctionType;

            return(ucf != null && ucf.UncurriedParameter.Equals(UncurriedParameter) && base.LLEquals(other));
        }
Ejemplo n.º 5
0
 protected SwiftUncurriedFunctionType(MemberType memberType, SwiftType unCurriedParameter, SwiftType parms, SwiftType ret, bool isReference, bool canThrow, SwiftName name = null, SwiftType extensionOn = null)
     : base(parms, ret, isReference, canThrow, name, extensionOn)
 {
     // oddly enough, this is allowed to be null
     UncurriedParameter = unCurriedParameter;
     this.memberType    = memberType;
 }
Ejemplo n.º 6
0
 public SwiftUncurriedFunctionType(SwiftType unCurriedParameter,
                                   SwiftType parms, SwiftType ret, bool isReference, bool canThrow, SwiftName name = null, SwiftType extensionOn = null)
     : this(MemberType.UncurriedFunction, unCurriedParameter, parms, ret, isReference, canThrow, name, extensionOn)
 {
 }
Ejemplo n.º 7
0
        protected override bool LLEquals(SwiftType other)
        {
            var meta = other as SwiftMetaClassType;

            return(meta != null && Class.Equals(meta.Class));
        }
Ejemplo n.º 8
0
        protected override bool LLEquals(SwiftType other)
        {
            SwiftBuiltInType sb = other as SwiftBuiltInType;

            return(sb != null && BuiltInType == sb.BuiltInType);
        }
Ejemplo n.º 9
0
 public SwiftInitializerType(InitializerType initType, SwiftType ret, SwiftClassType owner, SwiftName name)
     : base(SwiftTupleType.Empty, ret, false, false, name, null)
 {
     Owner           = Ex.ThrowOnNull(owner, nameof(owner));
     InitializerType = initType;
 }
Ejemplo n.º 10
0
 public SwiftAddressorType(AddressorType addressor, SwiftType ret, bool isReference, SwiftName name = null)
     : base(SwiftTupleType.Empty, ret, isReference, false, name, null)
 {
     AddressorType = addressor;
 }
Ejemplo n.º 11
0
 public SwiftCFunctionType(SwiftType parms, SwiftType ret, bool isReference, SwiftName name = null)
     : base(parms, ret, isReference, false, name, null)
 {
 }
Ejemplo n.º 12
0
 public SwiftBaseFunctionType(SwiftType parms, SwiftType ret, bool isReference, bool canThrow, SwiftName name = null, SwiftType extensionOn = null)
     : base(CoreCompoundType.Function, isReference, name)
 {
     Parameters       = Ex.ThrowOnNull(parms, nameof(parms));
     ReturnType       = Ex.ThrowOnNull(ret, nameof(ret));
     GenericArguments = new List <GenericArgument> ();
     CanThrow         = canThrow;
     ExtensionOn      = extensionOn;
 }
Ejemplo n.º 13
0
 protected virtual bool LLEquals(SwiftType other)
 {
     return(true);
 }
Ejemplo n.º 14
0
 public SwiftUnboundGenericType(SwiftType dependentType, List <GenericArgument> parms, bool isReference, SwiftName name = null)
     : base(CoreCompoundType.UnboundGeneric, isReference, name)
 {
     DependentType = Ex.ThrowOnNull(dependentType, nameof(dependentType));
     Arguments     = Ex.ThrowOnNull(parms, nameof(parms));
 }
Ejemplo n.º 15
0
 public SwiftPropertyType(SwiftType unCurriedParameter, PropertyType propType, SwiftName propName,
                          SwiftName privateName, SwiftType ofType, bool isStatic, bool isReference, SwiftType extensionOn = null)
     : base(unCurriedParameter,
            (propType == PropertyType.Setter || propType == PropertyType.Materializer) ? ofType : SwiftTupleType.Empty,
            (propType == PropertyType.Getter) ? ofType : SwiftTupleType.Empty,
            isReference, false, propName, extensionOn)
 {
     PropertyType = propType;
     PrivateName  = privateName;
     OfType       = Ex.ThrowOnNull(ofType, "ofType");
     IsSubscript  = false;
     IsStatic     = isStatic;
 }
Ejemplo n.º 16
0
 public SwiftFunctionType(SwiftType parms, SwiftType ret, bool isReference, bool canThrow, SwiftName name = null, SwiftType extensionOn = null, bool isEscaping = true)
     : base(parms, ret, isReference, canThrow, name, extensionOn)
 {
     IsEscaping = isEscaping;
 }
Ejemplo n.º 17
0
 public SwiftPropertyType(SwiftType unCurriedParameter, PropertyType propType, SwiftName propName,
                          SwiftName privateName, SwiftFunctionType accessor, bool isStatic, bool isReference, SwiftType extensionOn = null)
     : base(unCurriedParameter, accessor.Parameters, accessor.ReturnType, isReference, false, propName, extensionOn)
 {
     PropertyType = propType;
     PrivateName  = privateName;
     OfType       = accessor;
     IsSubscript  = true;
     IsStatic     = isStatic;
 }
Ejemplo n.º 18
0
 public SwiftCFunctionPointerType(SwiftType parms, SwiftType ret, bool isReference, bool canThrow, SwiftName name = null)
     : base(parms, ret, isReference, canThrow, name, null)
 {
 }
Ejemplo n.º 19
0
        protected override bool LLEquals(SwiftType other)
        {
            var sct = other as SwiftClassType;

            return(sct != null && ClassName.Equals(sct.ClassName));
        }
Ejemplo n.º 20
0
 public SwiftStaticFunctionType(SwiftType parms, SwiftType ret, bool isReference, bool canThrow, SwiftClassType ofClass, SwiftName name = null, SwiftType extensionOn = null)
     : base(parms, ret, isReference, canThrow, name, extensionOn)
 {
     OfClass = ofClass;
 }
Ejemplo n.º 21
0
        protected override bool LLEquals(SwiftType other)
        {
            var meta = other as SwiftExistentialMetaType;

            return(meta != null && Protocol.Equals(meta.Protocol));
        }
        public CSProperty CompileProperty(string propertyName, CSUsingPackages packs, SwiftType swiftPropertyType, bool hasGetter, bool hasSetter,
                                          CSMethodKind methodKind)
        {
            propertyName = typeMap.SanitizeIdentifier(propertyName);
            NetTypeBundle propertyType = typeMap.MapType(swiftPropertyType, false);

            if (!(swiftPropertyType is SwiftGenericArgReferenceType))
            {
                AddUsingBlock(packs, propertyType);
            }
            ICodeElement [] uselessLine = new ICodeElement [] { CSReturn.ReturnLine(new CSIdentifier("useless")) };

            CSCodeBlock getterBlock = null;

            if (hasGetter)
            {
                getterBlock = new CSCodeBlock(uselessLine);
            }
            CSCodeBlock setterBlock = null;

            if (hasSetter)
            {
                setterBlock = new CSCodeBlock(uselessLine);
            }

            CSProperty theProp = new CSProperty(propertyType.ToCSType(packs), methodKind,
                                                new CSIdentifier(propertyName), CSVisibility.Public, getterBlock, CSVisibility.Public, setterBlock);

            if (getterBlock != null)
            {
                getterBlock.Clear();
            }
            if (setterBlock != null)
            {
                setterBlock.Clear();
            }

            return(theProp);
        }