Skip to end of metadata
Go to start of metadata

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:

The code will not be correct until you resolve this issue in your model.

Some Examples How to Model If - Else - Paths

Invalid Approach

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.

Solution 1

One possible approach of modelling if - else paths could be:

Solution 2

Another possible approach of modelling if - else paths could be:

Ordered Decisions / Solution 3

(available since version 2.2)

This is basically the approach of Solution 2 but with version 2.2 the names of the guards will be used for ordering the if ... elseif ... blocks.

By simply numbering the Control Flows 1, 2, 3,... (in the name field) you can change the position/priority in the if ... elseif ... block

Generated code
 /* 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

(available since version 3.1)

As Rule 14.10 states:  "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.


MISRA complient example
if (me->a < 100)
{
    // your code here
} /* else not needed */