Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public SLIfElse(SLBaseExpr condition, SLCodeBlock ifClause, SLCodeBlock elseClause = null, bool isCase = false)
            : base()
        {
            Condition  = new IfElem(Exceptions.ThrowOnNull(condition, nameof(condition)), isCase);
            IfClause   = Exceptions.ThrowOnNull(ifClause, nameof(ifClause));
            ElseClause = elseClause;

            Add(Condition);
            Add(IfClause);
            if (ElseClause != null && ElseClause.Count > 0)
            {
                Add(new SimpleLineElement("else", false, true, false));
                Add(ElseClause);
            }
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
 public SLFunc(Visibility vis, SLType type, SLIdentifier name, SLParameterList parms, SLCodeBlock body)
     : this(vis, type, name, parms, body, false)
 {
 }
Exemplo n.º 5
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)
 {
 }