示例#1
0
        public override string GenerateControlInput(ControlInput input, int indent)
        {
            var outputString = string.Empty;

            if (input == liveUnit.enter)
            {
                var doConnection        = [email protected];
                var doDestination       = doConnection?.destination;
                var conditionConnection = liveUnit.condition.connection;
                var conditionSource     = conditionConnection?.source;

                outputString += CodeBuilder.Indent(indent) + "do" + "\n";
                outputString += CodeBuilder.OpenBody(indent) + "\n";

                if (doConnection != null)
                {
                    doDestination.unit.CodeGenerator().GenerateControlInput(doDestination, indent);
                }

                outputString += CodeBuilder.CloseBody(indent) + "\n";

                string whileCondition = string.Empty;

                whileCondition = conditionSource == null?Patcher.ActualValue(typeof(bool), liveUnit.condition.data.defaultValue) : conditionSource.unit.CodeGenerator().GenerateValueOutput(conditionSource, indent + 1);

                outputString += CodeBuilder.Indent(indent) + "while (" + whileCondition + ");";

                var nextConnection  = liveUnit.next.connection;
                var nextDestination = nextConnection?.destination;

                if (nextConnection != null)
                {
                    outputString += "\n" + nextDestination.unit.CodeGenerator().GenerateControlInput(nextDestination, indent);
                }
            }

            return(outputString);
        }
示例#2
0
        public override string GenerateControlInput(ControlInput input, int indent)
        {
            string output = string.Empty;

            var inputSource     = liveUnit.input.connection.source;
            var exitDestination = liveUnit.exit.connection.destination;

            var type  = liveUnit.type.CSharpName();
            var name  = Patcher.LegalVariableName(liveUnit.name, false);
            var value = string.Empty;

            if (liveUnit.input.connection != null && liveUnit.input.connection.sourceExists)
            {
                value = inputSource.unit.CodeGenerator().GenerateValueOutput(inputSource, 0);
            }
            var next = string.Empty;

            if (liveUnit.exit.connection != null && liveUnit.exit.connection.destinationExists)
            {
                next = exitDestination.unit.CodeGenerator().GenerateControlInput(exitDestination, indent);
            }

            return(CodeBuilder.Indent(indent) + type + " " + name + " = " + value + ";" + (string.IsNullOrEmpty(next) ? "\n" : "\n\n" + next));
        }
示例#3
0
        public override string GenerateValueOutput(ValueOutput output, int indent)
        {
            var outputString = string.Empty;

            if (output == liveUnit.result)
            {
                var a           = liveUnit.a;
                var b           = liveUnit.b;
                var entry       = (unit.graph.units.ToListPooled().Where((x) => { return((x as EntryUnit) != null); }).ToListPooled()[0] as EntryUnit);
                var methodInput = entry as MethodInputUnit;

                GraphReference reference = null;

                if (methodInput != null)
                {
                    reference = GraphReference.New(methodInput.macro, BoltX.UnitGuids(methodInput.graph as FlowGraph), false);
                }

                var aConnection = a.connection;
                var bConnection = b.connection;
                var aSource     = aConnection.source;
                var bSource     = bConnection.source;

                outputString += aConnection != null?aSource.unit.CodeGenerator().GenerateValueOutput(aSource, 0) : Patcher.ActualValue(a.type, Flow.FetchValue(a, a.type, reference));

                outputString += CodeBuilder.Operator(BinaryOperator.Or);

                outputString += bConnection != null?bSource.unit.CodeGenerator().GenerateValueOutput(bSource, 0) : Patcher.ActualValue(b.type, Flow.FetchValue(b, b.type, reference));
            }

            return(outputString);
        }
        public override string GenerateControlInput(ControlInput input, int indent)
        {
            var outputString = string.Empty;

            var conditionConnection = liveUnit.condition.connection;
            var conditionSource     = conditionConnection.source;

            var defaultValue = liveUnit.valueInputsData.GetValueOrDefault("condition").defaultValue;
            var logic        = conditionConnection != null?liveUnit.condition.connection.source.unit.CodeGenerator().GenerateValueOutput(conditionSource, 0) : Patcher.ActualValue(typeof(bool), defaultValue);

            var hasTrue  = [email protected] != null;
            var hasFalse = [email protected] != null;

            var trueDestination = [email protected]?.destination;

            outputString += CodeBuilder.Indent(indent) + "if (" + logic + ") \n";
            outputString += CodeBuilder.OpenBody(indent) + "\n";
            outputString += (hasTrue ? trueDestination.unit.CodeGenerator().GenerateControlInput(trueDestination, indent + 1) : string.Empty) + "\n";
            outputString += CodeBuilder.CloseBody(indent);

            if (hasFalse)
            {
                var falseDestination = [email protected];

                outputString += "\n" + CodeBuilder.Indent(indent) + "else" + "\n";
                outputString += CodeBuilder.OpenBody(indent) + "\n";
                outputString += falseDestination.unit.CodeGenerator().GenerateControlInput(falseDestination, indent + 1) + "\n";
                outputString += CodeBuilder.CloseBody(indent) + "\n";
            }

            return(outputString);
        }