Decision / Merge
Please take care when modeling activities with decision/merge nodes. The code generator will map decision/merge constructs to if/else chains, so only control flows which can be expressed by if/else chains are supported.
Have a look at the following diagram:
This diagram is invalid. The reason is that Decision1 can be thought of as an if/else, and Merge2 will close this if/else. There are two paths to take in an if/else, in this case the path beginning with Action1 and the path beginning with Action3. The control flow from Decision2 to Merge1 violates this mapping to if/else, because you're not allowed to jump between paths in C without using goto.
The code generator will warn you if it encounters such an issue:
Warning
The code will not be correct until you resolve this issue in your model.
How to Model If - Else - Paths
This example is another invalid approach for modeling an if - else if path, similar to the example shown above:
In the diagram, you can see the code that would result from this model, if code generation would be performed. Again, a goto statement would be needed, which is invalid.
Apart from that, a merge node is missing before final node.
One possible approach of modelling if - else paths could be:
Another possible approach of modelling if - else paths could be:
By simply numbering the Control Flows 1, 2, 3,... (in the name field) you can change the position/priority in the if
... elseif
... block
/* start of activity code */
if (me->a < 100)
{
}
else if (me->a < 10)
{
}
else if (me->a < 1)
{
}
else
{
/* Empty else clause for MISRA rule 14.10 */
}
Obsolete else block
MISRA Rule 14.10
In the case of a simple if statement then the else statement need not be included.
So we updated the code generator to no longer generate "empty" else blocks for single if statements.