public SLNameTypePair(SLParameterKind kind, SLIdentifier id, SLType type)
     : base()
 {
     ParameterKind  = kind;
     Name           = id;
     TypeAnnotation = type;
 }
Exemple #2
0
        // VIS subscript(parms) -> type {
        //    get {
        //    }
        //    set { // newValue:type is implicit
        //    }
        // }
        // get is mandatory, set is optional

        public SLSubscript(Visibility vis, FunctionKind funcKind, SLType type,
                           SLParameterList parms, SLCodeBlock getter, SLCodeBlock setter)
        {
            Visibility = vis;
            Type       = Exceptions.ThrowOnNull(type, nameof(type));
            Parameters = Exceptions.ThrowOnNull(parms, nameof(parms));
            GetterBody = Exceptions.ThrowOnNull(getter, nameof(getter));
            SetterBody = setter;             // can be null

            List <string> elems = new List <string> ();

            if (vis != Visibility.None)
            {
                elems.Add(SLFunc.ToVisibilityString(vis) + " ");
            }
            if ((funcKind & FunctionKind.Final) != 0)
            {
                elems.Add("final ");
            }
            if ((funcKind & FunctionKind.Override) != 0)
            {
                elems.Add("override ");
            }
            if ((funcKind & FunctionKind.Required) != 0)
            {
                elems.Add("required ");
            }
            if ((funcKind & FunctionKind.Static) != 0)
            {
                elems.Add("static ");
            }
            if ((funcKind & FunctionKind.Class) != 0)
            {
                elems.Add("class ");
            }
            elems.Add("subscript ");

            AddRange(elems.Select((el, i) => i == 0 ? (ICodeElement) new SimpleLineElement(el, false, true, true) : new SimpleElememt(el)));
            Add(Parameters);
            Add(SimpleElememt.Spacer);
            Add(new SimpleElememt("->"));
            Add(SimpleElememt.Spacer);
            Add(Type);
            SLCodeBlock block = new SLCodeBlock(null);

            block.Add(new SimpleElememt("get"));
            block.Add(SimpleElememt.Spacer);
            block.Add(GetterBody);
            if (SetterBody != null)
            {
                block.Add(new SimpleElememt("set"));
                block.Add(SimpleElememt.Spacer);
                block.Add(SetterBody);
            }
            Add(block);
        }
Exemple #3
0
 public SLFuncType(SLType retType, IEnumerable <SLUnnamedParameter> parameters)
 {
     Exceptions.ThrowOnNull(parameters, nameof(parameters));
     Attributes = new List <SLAttribute> ();
     Parameters = new List <SLUnnamedParameter> ();
     if (parameters != null)
     {
         Parameters.AddRange(parameters);
     }
     ReturnType = Exceptions.ThrowOnNull(retType, nameof(retType));
 }
Exemple #4
0
        public SLFunc(Visibility vis, FunctionKind funcKind, SLType type, SLIdentifier name, SLParameterList parms, SLCodeBlock body, bool isOptional = false)
        {
            GenericParams = new SLGenericTypeDeclarationCollection();
            Visibility    = vis;
            ReturnType    = type;
            bool isConstructor = (funcKind & FunctionKind.Constructor) != 0;

            Name          = isConstructor ? new SLIdentifier(isOptional ? "init?" : "init") : Exceptions.ThrowOnNull(name, nameof(name));
            Parameters    = parms ?? new SLParameterList();
            Body          = Exceptions.ThrowOnNull(body, nameof(body));
            FuncKind      = funcKind;
            IsConstructor = isConstructor;
            IsOptional    = isOptional;
        }
Exemple #5
0
 static IEnumerable <SLUnnamedParameter> ConvertSLTypeToParameters(SLType type)
 {
     if (type is SLTupleType tuple)
     {
         foreach (var elem in tuple.Elements)
         {
             yield return(new SLUnnamedParameter(elem.TypeAnnotation, elem.ParameterKind));
         }
     }
     else
     {
         yield return(new SLUnnamedParameter(type));
     }
 }
Exemple #6
0
 public static SLTupleType Of(string id, SLType type)
 {
     return(Of(new SLIdentifier(id), type));
 }
Exemple #7
0
 public static SLTupleType Of(SLIdentifier id, SLType type)
 {
     return(new SLTupleType(new SLNameTypePair [] { new SLNameTypePair(id, type) }));
 }
Exemple #8
0
 public SLArrayType(SLType elementType)
 {
     ElementType = Exceptions.ThrowOnNull(elementType, nameof(elementType));
 }
Exemple #9
0
 public SLBoundGenericType(string name, SLType singleBoundType)
     : this(name, new SLType [] { singleBoundType })
 {
 }
Exemple #10
0
 public SLOptionalType(SLType opt)
 {
     Optional = Exceptions.ThrowOnNull(opt, nameof(opt));
 }
 public SLParameter(string publicName, string privateName, SLType type, SLParameterKind kind = SLParameterKind.None)
     : this(publicName != null ? new SLIdentifier(publicName) : null, new SLIdentifier(privateName), type, kind)
 {
 }
Exemple #12
0
 public SLVariadicType(SLType repeatingType)
 {
     RepeatingType = Exceptions.ThrowOnNull(repeatingType, nameof(repeatingType));
 }
 public SLGenericConstraint(bool isInheritance, SLType firstType, SLType secondType)
 {
     IsInheritance = isInheritance;
     FirstType     = Exceptions.ThrowOnNull(firstType, nameof(firstType));
     SecondType    = Exceptions.ThrowOnNull(secondType, nameof(secondType));
 }
Exemple #14
0
 public SLFunc(Visibility vis, SLType type, SLIdentifier name, SLParameterList parms, SLCodeBlock body, bool throws)
     : this(vis, (throws ? FunctionKind.Throws : FunctionKind.None), type, name, parms, body)
 {
 }
 public SLUnnamedParameter(SLType type, SLParameterKind kind = SLParameterKind.None)
 {
     ParameterKind  = kind;
     TypeAnnotation = Exceptions.ThrowOnNull(type, nameof(type));
 }
 public SLParameter(string name, SLType type, SLParameterKind kind = SLParameterKind.None)
     : this(name, name, type, kind)
 {
 }
 public SLParameter(SLIdentifier name, SLType type, SLParameterKind kind = SLParameterKind.None)
     : this(name, name, type, kind)
 {
 }
Exemple #18
0
 public SLFuncType(SLType argType, SLType retType)
     : this(retType, ConvertSLTypeToParameters(argType))
 {
 }
 public SLNameTypePair(SLParameterKind kind, string id, SLType type)
     : this(kind, id != null ? new SLIdentifier(id) : null, type)
 {
 }
 public SLNameTypePair(string id, SLType type)
     : this(SLParameterKind.None, id, type)
 {
 }
Exemple #21
0
 public SLCompoundType(SLType parent, SLType child)
 {
     Parent = Exceptions.ThrowOnNull(parent, nameof(parent));
     Child  = Exceptions.ThrowOnNull(child, nameof(child));
 }
Exemple #22
0
 public SLDictionaryType(SLType keyType, SLType valueType)
 {
     KeyType   = Exceptions.ThrowOnNull(keyType, nameof(keyType));
     ValueType = Exceptions.ThrowOnNull(valueType, nameof(valueType));
 }
 public SLParameter(SLIdentifier publicName, SLIdentifier privateName, SLType type, SLParameterKind kind = SLParameterKind.None)
     : base(type, kind)
 {
     PublicName  = publicName;
     PrivateName = Exceptions.ThrowOnNull(privateName, nameof(privateName));
 }
Exemple #24
0
 public SLFunc(Visibility vis, SLType type, SLIdentifier name, SLParameterList parms, SLCodeBlock body)
     : this(vis, type, name, parms, body, false)
 {
 }
 public SLNameTypePair(SLIdentifier id, SLType type)
     : this(SLParameterKind.None, id, type)
 {
 }