Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
0
        SolidityFunction CreateProcessReturnFunction()
        {
            var function = new SolidityFunction(ConversionTemplates.CallActivityReturnFunctionName(GetElementCallName()), SolidityVisibility.Internal);

            function.AddParameters(processConverter.GetIdentifiersAsParameters());

            var nextElementStatement      = CreateNextElementStatement();
            var incrementStatement        = new SolidityStatement($"{ConversionTemplates.CallActivityCounter(GetElementCallName())}++");
            var checkConditionBlock       = new SolidityIfElse();
            var calledStartEventConverter = processConverter.ContractConverter.GetStartEventConverter(callActivity);
            var callSubprocessStatement   = calledStartEventConverter.GetStatementForPrevious(callActivity);

            checkConditionBlock.AddConditionBlock($"{ConversionTemplates.CallActivityCounter(GetElementCallName())} >= {GetCountTarget(callActivity)}",
                                                  nextElementStatement);

            switch (callActivity.InstanceType)
            {
            case InstanceType.Single:
                function.AddToBody(nextElementStatement);
                break;

            case InstanceType.Sequential:
                //increment the counter, check if counter reached limit.
                //If counter reached limit, then call the next element. If not, call the subprocess again.
                function.AddToBody(incrementStatement);

                checkConditionBlock.AddConditionBlock("", callSubprocessStatement);
                function.AddToBody(checkConditionBlock);

                break;

            case InstanceType.Parallel:
                //increment the counter, check if counter reached limit.
                //If counter reached limit, then call the next element. If not, do nothing.
                function.AddToBody(incrementStatement);
                function.AddToBody(checkConditionBlock);
                break;
            }
            return(function);
        }