예제 #1
0
        public override string GenerateControl(ControlInput input, ControlGenerationData data, int indent)
        {
            var output = string.Empty;

            if (input == Unit.enter)
            {
                var values    = Unit.enumType.GetEnumValues();
                var outputs   = Unit.outputs.ToArray();
                var isLiteral = [email protected] && [email protected] as Literal != null;
                var localName = string.Empty;
                if (isLiteral)
                {
                    localName = data.AddLocalName("@enum");
                }
                var newLiteral = isLiteral ? CodeBuilder.Indent(indent) + "var ".ConstructHighlight() + localName + " = " + ((Unit)[email protected]).GenerateValue([email protected]) : string.Empty;
                var @enum      = [email protected] ? (isLiteral ? localName : ((Unit)[email protected]).GenerateValue([email protected])) : base.GenerateControl(input, data, indent);

                if (isLiteral)
                {
                    output += newLiteral + "\n";
                }
                output += CodeBuilder.Indent(indent) + "switch".ConstructHighlight() + " (" + @enum + ")";
                output += "\n";
                output += CodeBuilder.Indent(indent) + "{";
                output += "\n";

                for (int i = 0; i < values.Length; i++)
                {
                    var connection = ((ControlOutput)outputs[i])?.connection;

                    output += CodeBuilder.Indent(indent + 1) + "case ".ConstructHighlight() + Unit.enumType.Name.EnumHighlight() + "." + values.GetValue(i).ToString() + ":";
                    output += "\n";

                    var controlData = new ControlGenerationData();
                    controlData.returns    = data.returns;
                    controlData.mustBreak  = controlData.returns == typeof(Lasm.UAlive.Void);
                    controlData.mustReturn = !controlData.mustBreak;
                    controlData.localNames = data.localNames;

                    if (((ControlOutput)outputs[i]).hasValidConnection)
                    {
                        output += ((Unit)connection.destination.unit).GenerateControl(connection.destination as ControlInput, controlData, indent + 2);
                        output += "\n";
                    }

                    if (controlData.mustBreak && !controlData.hasBroke)
                    {
                        output += CodeBuilder.Indent(indent + 2) + "/* Case Must Break */".WarningHighlight() + "\n";
                    }
                    if (controlData.mustReturn && !controlData.hasReturned)
                    {
                        output += CodeBuilder.Indent(indent + 2) + "/* Case Must Return or Break */".WarningHighlight() + "\n";
                    }
                }

                output += CodeBuilder.Indent(indent) + "}";
                output += "\n";

                return(output);
            }

            return(base.GenerateControl(input, data, indent));
        }
예제 #2
0
        public override string GenerateControl(ControlInput input, ControlGenerationData data, int indent)
        {
            var output = string.Empty;

            if (input == Unit.enter)
            {
                var values    = Unit.branches;
                var outputs   = Unit.outputs.ToArray();
                var isLiteral = Unit.selector.hasValidConnection && Unit.selector.connection.source.unit as Literal != null;
                var localName = string.Empty;
                if (isLiteral)
                {
                    localName = data.AddLocalName("@int");
                }
                var newLiteral = isLiteral ? CodeBuilder.Indent(indent) + "var ".ConstructHighlight() + $"{localName} = " + ((Unit)Unit.selector.connection.source.unit).GenerateValue(Unit.selector.connection.source) + ";" : string.Empty;
                var @enum      = Unit.selector.hasValidConnection ? (isLiteral ? localName : ((Unit)Unit.selector.connection.source.unit).GenerateValue(Unit.selector.connection.source)) : base.GenerateControl(input, data, indent);

                if (isLiteral)
                {
                    output += newLiteral + "\n";
                }
                output += CodeBuilder.Indent(indent) + "switch".ConstructHighlight() + $" ({@enum})";
                output += "\n";
                output += CodeBuilder.Indent(indent) + "{";
                output += "\n";

                for (int i = 0; i < values.Count; i++)
                {
                    var _connection = ((ControlOutput)outputs[i])?.connection;

                    output += CodeBuilder.Indent(indent + 1) + "case ".ConstructHighlight() + $" {values[i].Key}".NumericHighlight() + ":";
                    output += "\n";

                    var _controlData = new ControlGenerationData();
                    _controlData.returns    = data.returns;
                    _controlData.mustBreak  = _controlData.returns == typeof(Lasm.UAlive.Void);
                    _controlData.mustReturn = !_controlData.mustBreak;
                    _controlData.localNames = data.localNames;

                    if (((ControlOutput)outputs[i]).hasValidConnection)
                    {
                        output += ((Unit)_connection.destination.unit).GenerateControl(_connection.destination as ControlInput, _controlData, indent + 2);
                        output += "\n";
                    }

                    if (_controlData.mustBreak && !_controlData.hasBroke)
                    {
                        output += CodeBuilder.Indent(indent + 2) + "/* Case Must Break */".WarningHighlight() + "\n";
                    }
                    if (_controlData.mustReturn && !_controlData.hasReturned)
                    {
                        output += CodeBuilder.Indent(indent + 2) + "/* Case Must Return or Break */".WarningHighlight() + "\n";
                    }
                }

                var connection = [email protected];

                output += CodeBuilder.Indent(indent + 1) + "default ".ConstructHighlight() + ":";
                output += "\n";

                var controlData = new ControlGenerationData();
                controlData.returns    = data.returns;
                controlData.mustBreak  = controlData.returns == typeof(Lasm.UAlive.Void);
                controlData.mustReturn = !controlData.mustBreak;
                controlData.localNames = data.localNames;

                if ([email protected])
                {
                    output += ((Unit)connection.destination.unit).GenerateControl(connection.destination as ControlInput, controlData, indent + 2);
                    output += "\n";
                }

                if (controlData.mustBreak && !controlData.hasBroke)
                {
                    output += CodeBuilder.Indent(indent + 2) + "/* Case Must Break */".WarningHighlight() + "\n";
                }
                if (controlData.mustReturn && !controlData.hasReturned)
                {
                    output += CodeBuilder.Indent(indent + 2) + "/* Case Must Return or Break */".WarningHighlight() + "\n";
                }

                output += CodeBuilder.Indent(indent) + "}";
                output += "\n";

                return(output);
            }

            return(base.GenerateControl(input, data, indent));
        }