예제 #1
0
        public override void ConvertElementLogic()
        {
            processReturnFunction = CreateProcessReturnFunction();
            mainFunction          = new SolidityFunction(GetElementCallName(), SolidityVisibility.Internal);
            mainFunction.AddParameters(processConverter.GetIdentifiersAsParameters());
            var calledStartEventConverter = processConverter.ContractConverter.GetStartEventConverter(callActivity);
            var callSubprocessStatement   = calledStartEventConverter.GetStatementForPrevious(callActivity);

            stateTracker = new SolidityStatement($"uint256 {ConversionTemplates.CallActivityCounter(GetElementCallName())}");
            switch (callActivity.InstanceType)
            {
            case InstanceType.Single:
                //Call the subprocess.
                mainFunction.AddToBody(callSubprocessStatement);
                break;

            case InstanceType.Sequential:
                //Call the subprocess and create a counter.
                mainFunction.AddToBody(new SolidityStatement($"{ConversionTemplates.CallActivityCounter(GetElementCallName())} = 0"));
                mainFunction.AddToBody(callSubprocessStatement);
                break;

            case InstanceType.Parallel:
                //Call all of the subprocesses using an identifier, create a counter.
                mainFunction.AddToBody(new SolidityStatement($"{ConversionTemplates.CallActivityCounter(GetElementCallName())} = 0"));
                var solidityForLoop = new SolidityFor(GetLoopVariable(), GetCountTarget(callActivity));
                solidityForLoop.AddToBody(callSubprocessStatement);
                mainFunction.AddToBody(solidityForLoop);
                break;
            }
        }
예제 #2
0
        //Gets assignemnts for the Task Function
        public override IList <SolidityStatement> GetOutputAssignments()
        {
            var forLoop = new SolidityFor("i", $"{FunctionName}Output.length");
            List <SolidityStatement> outputAssignments = new List <SolidityStatement>();

            outputAssignments.Add(new SolidityStatement($"for(uint256 i = 0; i < {FunctionName}Output.length; i++){{", false));
            foreach (var outputs in Decision.DecisionTable.Outputs)
            {
                outputAssignments.Add(new SolidityStatement($"  {outputs.Name}.push({FunctionName}Output[i].{outputs.Name.ToLowerCamelCase().Replace(".", "__")})", true));
            }
            outputAssignments.Add(new SolidityStatement("}", false));
            return(outputAssignments);
        }
예제 #3
0
        //Functions for comparison of matched rule and already matched outputs
        public override SolidityFunction CreateHelperFunction()
        {
            FunctionName = Regex.Replace(Decision.Id, @" ", "").ToLowerCamelCase();
            SolidityFunction function = new SolidityFunction($"{FunctionName}_decideByPriority", SolidityVisibility.Internal, $"{OutputStructName} memory", true);

            var prioritiesFormatted = GetPriorities(Decision);
            var noUniqueOutputs     = Regex.Matches(prioritiesFormatted, $"{OutputStructName}").Count;

            function.AddParameter(new SolidityParameter($"{OutputStructName}[{noUniqueOutputs}] memory", "priorities"));
            function.AddParameter(new SolidityParameter($"{OutputStructName} memory", "currentOutput"));
            function.AddParameter(new SolidityParameter($"{OutputStructName} memory", "newOutput"));

            var priorityComparison = GetPriorityComparisonBody();
            var priorityIteration  = new SolidityFor("i", $"{noUniqueOutputs}");

            priorityIteration.AddToBody(new SolidityStatement(priorityComparison.ToString(), false));
            function.AddToBody(priorityIteration);
            function.AddToBody(new SolidityStatement("revert('Undefined output')", true));
            return(function);
        }
예제 #4
0
        //Retruns for loop component initializing the output
        private SolidityFor GetInitializationForLoop(int noUniqueOutputs)
        {
            var initForLoop = new SolidityFor("i", $"{noUniqueOutputs}");
            //Add only outputs that meet the conditions
            var    initCheck     = new SolidityIfElse();
            string initCheckBody = $"output[j] = {OutputStructName}(";

            foreach (var output in Decision.DecisionTable.Outputs.Select((value, i) => new { i, value }))
            {
                initCheckBody += $"priorities[i].{output.value.Name}";
                if (output.i + 1 < Decision.DecisionTable.Outputs.Count)
                {
                    initCheckBody += ", ";
                }
            }
            initCheckBody += ");\n";
            initCheckBody += "j++;";
            initCheck.AddConditionBlock("existsInOutput[i]", new SolidityStatement(initCheckBody, false));
            initForLoop.AddToBody(new SolidityStatement(initCheck.ToString(), false));
            return(initForLoop);
        }
예제 #5
0
        public override SolidityFunction CreateDecisionFunction()
        {
            //Define function's header
            FunctionName = Regex.Replace(Decision.Id, @" ", "").ToLowerCamelCase();
            SolidityFunction function = new SolidityFunction(FunctionName, SolidityVisibility.Internal, $"{OutputStructName}[] memory", true);
            //Add declaration of helper varaibles
            var prioritiesFormatted = GetPriorities();
            var noUniqueOutputs     = Regex.Matches(prioritiesFormatted, $"{OutputStructName}").Count;

            function.AddToBody(new SolidityStatement($"{OutputStructName}[{noUniqueOutputs}] memory priorities = {prioritiesFormatted}", true));
            function.AddToBody(new SolidityStatement($"bool[{noUniqueOutputs}] memory existsInOutput", true));
            function.AddToBody(new SolidityStatement($"uint outputSize = 0", true));
            function.AddToBody(new SolidityStatement($"bool matchedRule = false", true));

            var rules = GetAllConditions();

            foreach (var rule in rules.Skip(PriorityOffset).Select((value, i) => new { i, value }))
            {
                string priorityListCheck = GetPirorityListCheck(rule.i + PriorityOffset);
                var    priorityCheckLoop = new SolidityFor("i", $"{noUniqueOutputs}");
                priorityCheckLoop.AddToBody(new SolidityStatement(priorityListCheck, false));

                function.AddToBody(AddBodyBasedOnRule(rule.value, priorityCheckLoop.ToString()));
            }

            //Initialization of output list
            function.AddToBody(new SolidityStatement("uint j = 0", true));
            function.AddToBody(new SolidityStatement($"{OutputStructName}[] memory output = new {OutputStructName}[](outputSize)", true));
            var initForLoop = GetInitializationForLoop(noUniqueOutputs);

            function.AddToBody(initForLoop);

            //Add the rest of the function
            var undefinedOutputCheck = new SolidityIfElse();

            undefinedOutputCheck.AddConditionBlock("!matchedRule", new SolidityStatement("revert('Undefined output')", true));
            function.AddToBody(undefinedOutputCheck);
            function.AddToBody(new SolidityStatement("return output", true));
            return(function);
        }