public SLAttribute(SLIdentifier name, CommaListElementCollection <SLBaseExpr> args, bool isSingleLine = false)
            : base(isSingleLine, false, isSingleLine)
        {
            Name = Exceptions.ThrowOnNull(name, nameof(name));
            Add(new SimpleElememt("@"));
            var stringRep = new StringBuilder(Name.Name);

            Add(Name);
            if (args != null)
            {
                Add(new SimpleElememt("("));
                Add(args);
                Add(new SimpleElememt(")"));
                stringRep.Append("(");
                foreach (var arg in args)
                {
                    if (arg is SLIdentifier argId)
                    {
                        stringRep.Append(argId.Name);
                    }
                }
                stringRep.Append(")");
            }
            StringRep = stringRep.ToString();
        }
 public SLNameTypePair(SLParameterKind kind, SLIdentifier id, SLType type)
     : base()
 {
     ParameterKind  = kind;
     Name           = id;
     TypeAnnotation = type;
 }
 SLConditionalCompilation(SLIdentifier tag, SLIdentifier condition)
     : base(true, false, false)
 {
     Add(tag);
     if (condition != null)
     {
         Add(SimpleElememt.Spacer);
         Add(condition);
     }
 }
        public SLProperty(Visibility vis, FunctionKind funcKind, SLType type, SLIdentifier name,
                          SLCodeBlock getter, SLCodeBlock setter)
        {
            Visibility = vis;
            Type       = Exceptions.ThrowOnNull(type, nameof(type));
            Name       = Exceptions.ThrowOnNull(name, nameof(name));
            GetterBody = Exceptions.ThrowOnNull(getter, nameof(getter));
            SetterBody = setter;

            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.Required) != 0)
            {
                elems.Add("required ");
            }
            if ((funcKind & FunctionKind.Override) != 0)
            {
                elems.Add("override ");
            }
            if ((funcKind & FunctionKind.Static) != 0)
            {
                elems.Add("static ");
            }
            if ((funcKind & FunctionKind.Class) != 0)
            {
                elems.Add("class ");
            }

            elems.Add("var ");
            AddRange(elems.Select((el, i) => i == 0 ? (ICodeElement) new SimpleLineElement(el, false, true, true) : new SimpleElememt(el)));
            Add(Name);
            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);
        }
 public SLAttribute(SLIdentifier name, CommaListElementCollection <SLBaseExpr> args, bool isSingleLine = false)
     : base(isSingleLine, false, isSingleLine)
 {
     Name = Exceptions.ThrowOnNull(name, nameof(name));
     Add(new SimpleElememt("@"));
     Add(Name);
     if (args != null)
     {
         Add(new SimpleElememt("("));
         Add(args);
         Add(new SimpleElememt(")"));
     }
 }
Example #6
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;
        }
Example #7
0
        public SLClass(Visibility vis, SLIdentifier name, IEnumerable <SLFunc> methods = null,
                       bool isStatic = false, bool isSealed = false, NamedType namedType = NamedType.Class)
        {
            // swift hates when you put public on an extension on a public type
            Visibility   = vis == Visibility.Public && namedType == NamedType.Extension ? Visibility.None : vis;
            IsStatic     = isStatic;
            IsSealed     = isSealed;
            NamedType    = namedType;
            Name         = Exceptions.ThrowOnNull(name, "name");
            Inheritance  = new SLInheritance();
            Fields       = new List <ICodeElement> ();
            Constructors = new List <SLFunc> ();
            Methods      = new List <SLFunc> ();
            Properties   = new List <SLProperty> ();
            InnerClasses = new SLClasses();
            Subscripts   = new List <SLSubscript> ();
            Generics     = new SLGenericTypeDeclarationCollection();

            if (methods != null)
            {
                Methods.AddRange(methods);
            }
        }
 public SLSubscriptExpr(SLIdentifier identifier, IEnumerable <SLBaseExpr> parameters)
     : this(identifier, new CommaListElementCollection <SLBaseExpr> (parameters))
 {
 }
 public static SLConditionalCompilation If(SLIdentifier condition)
 {
     return(new SLConditionalCompilation(new SLIdentifier("#if"), Exceptions.ThrowOnNull(condition, nameof(condition))));
 }
Example #10
0
 public static SLTupleType Of(SLIdentifier id, SLType type)
 {
     return(new SLTupleType(new SLNameTypePair [] { new SLNameTypePair(id, type) }));
 }
 public SLNameTypePair(SLIdentifier id, SLType type)
     : this(SLParameterKind.None, id, type)
 {
 }
Example #12
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 SLParameter(SLIdentifier name, SLType type, SLParameterKind kind = SLParameterKind.None)
     : this(name, name, type, kind)
 {
 }
 public SLParameter(SLIdentifier publicName, SLIdentifier privateName, SLType type, SLParameterKind kind = SLParameterKind.None)
     : base(type, kind)
 {
     PublicName  = publicName;
     PrivateName = Exceptions.ThrowOnNull(privateName, nameof(privateName));
 }
 public SLSubscriptExpr(SLIdentifier ident, CommaListElementCollection <SLBaseExpr> paramList)
 {
     Name       = Exceptions.ThrowOnNull(ident, nameof(ident));
     Parameters = Exceptions.ThrowOnNull(paramList, nameof(paramList));
 }
Example #16
0
 public SLFunc(Visibility vis, SLType type, SLIdentifier name, SLParameterList parms, SLCodeBlock body)
     : this(vis, type, name, parms, body, false)
 {
 }
Example #17
0
 public SLGenericTypeDeclaration(SLIdentifier name)
 {
     Name        = Exceptions.ThrowOnNull(name, nameof(name));
     Constraints = new List <SLGenericConstraint>();
 }