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

            if (input == liveUnit.enter)
            {
                var bodyConnection       = liveUnit.body.connection;
                var bodyDestination      = bodyConnection?.destination;
                var exitConnection       = liveUnit.exit.connection;
                var exitDestination      = exitConnection?.destination;
                var firstIndexConnection = liveUnit.firstIndex.connection;
                var firstIndexSource     = firstIndexConnection?.source;
                var lastIndexConnection  = liveUnit.lastIndex.connection;
                var lastIndexSource      = lastIndexConnection?.source;
                var stepConnection       = liveUnit.step.connection;
                var stepSource           = stepConnection?.source;

                var firstIndex = firstIndexConnection == null?
                                 Patcher.ActualValue(typeof(int), liveUnit.firstIndex.data.defaultValue) :
                                     firstIndexSource.unit.CodeGenerator().GenerateValueOutput(firstIndexSource, 0);

                var firstIndexValue = (int)liveUnit.firstIndex.data.defaultValue;

                var lastIndex = lastIndexConnection == null?
                                Patcher.ActualValue(typeof(int), liveUnit.lastIndex.data.defaultValue) :
                                    lastIndexSource.unit.CodeGenerator().GenerateValueOutput(lastIndexSource, 0);

                var lastIndexValue = (int)liveUnit.lastIndex.data.defaultValue;

                var step = stepConnection == null?
                           Patcher.ActualValue(typeof(int), liveUnit.step.data.defaultValue) :
                               stepSource.unit.CodeGenerator().GenerateValueOutput(stepSource, 0);

                var iteratorName      = char.ToString((char)(char.Parse("i") + lastIteratorIndexAdjustment));
                var lessOrGreater     = firstIndexValue <= lastIndexValue ? " < " : " > ";
                var iteratorDirection = int.Parse(step) == 1 ? (firstIndexValue <= lastIndexValue ? "++" : "--") : (firstIndexValue <= lastIndexValue ? "+=" : "-=");

                lastIteratorIndexAdjustment++;

                var onBody  = bodyConnection == null ? string.Empty : bodyDestination.unit.CodeGenerator().GenerateControlInput(bodyDestination, indent + 1);
                var hasExit = exitConnection != null;

                lastIteratorIndexAdjustment--;

                outputString += CodeBuilder.Indent(indent) + "for (int " + iteratorName + " = " + firstIndex + "; " + iteratorName + lessOrGreater + lastIndex + ";" + " " + (int.Parse(step) == 1 ? iteratorName + iteratorDirection : iteratorName + " " + iteratorDirection + " " + step) + ")" + "\n";
                outputString += CodeBuilder.OpenBody(indent) + "\n";
                outputString += onBody + "\n";
                outputString += CodeBuilder.CloseBody(indent);

                if (hasExit)
                {
                    outputString += "\n\n" + exitDestination.unit.CodeGenerator().GenerateControlInput(exitDestination, indent);
                }
            }

            return(outputString);
        }
Example #2
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);
        }
Example #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);
        }