Generate production quality code from state diagrams created with Eclipse Papyrus#
SinelaboreRT generates readable and maintainable code from hierarchical UML state machines created with Eclipse Papyrus. It is suitable for embedded applications and for desktop/server software through additional language backends.
Code generation is supported for Eclipse Papyrus version 2022-12. When using Papyrus, some tool-specific things need to be considered. The following sections cover these points.

An example state machine diagram created with Papyrus
Organizing your project#
The code-generator needs to know how to find your state-based class in the UML file. The path to your class in your project tree must be specified on the command line using the -t flag. For the model tree shown in the figure below an example command line to generate C-code from a file called Papyrus.uml would look as follows:
... -t "MyModel:MyPackage:A" -l cx -p Papyrus -o testcase Papyrus.uml

Papyrus’ project browser. From the used structure the path can be directly derived.
States#
Papyrus allows you to define entry, do and exit activities for a state. Right click to the state and select ’show properties’ to bring up the properties view. In the view you can add the activities. It is important that actions are always only created as OpaqueBehaviour. Otherwise code generation cannot generate activity code.

Activities must always be created as OpaqueBehaviour. Inside the dialog click on the plus symbol to define the implementation language - e.g. C. Then add the activity code in the shown text box.
Regions#
A region is an orthogonal part of a state. It allows to express parallelism within a state. A state can have two or more regions. Region contains states and transitions. States in regions can contain regions again. See the figure above for an example state diagram with regions.
General rules when using regions:
- Transitions must not cross region borders. I.e. it is not allowed to add a transition from
RighttoOff. - A region might contain a history state, choices, final states and normal states
- To express that a transition should fire if the machine is in both regions
RightandOffuse a conditional transition like follows:#machineIsInRight(…) && machineIsInOff(…) - Regions can contain states which contain regions again
Transitions#
Select the transition to set any transition properties. In the properties window the trigger, guard and effect statements can be defined. A transition must usually have a triggering event. To add a new signal event right click on the package that contains the class with the state-machine. Select menu New Child and add a SignalEvent. It is important to add the signal events at the correct hierarchical level. Otherwise the code generator does not find them. For the code generation only signal events are supported!
The effect of a transition must be defined as OpaqueBehaviour.
To add a guard first add a Constraint and then add a OpaqueExpression to the Specification.
History State and other Pseudo States#
Just add final states or history states from the tool bar into your diagram.
Attaching action and include comments#
By default the code generator includes the minimally needed header files into the generated code. But often it is necessary to add further includes or define local variables etc. In this case you can specify code that is just copied at the beginning of the state machine implementation file.
You can also add code that is added to the beginning of the state machine handler function. The code can be used to perform some actions each time the state machine is executed.
Add this code to your model by using comments starting with the keywords action: and include:. Link those comments to the class owning the state machine. An example is shown in the figure below. You must use plain text in the comment. It is not possible to use html comments.

Connect comments with the class that contains the state machine to define generation details. Classes can contain properties of various types.
Adding Attributes and Operations to Classes#
It is possible to add attributes and operations to the class containing the state machine. To add a property drag and drop a Property symbol from the tool bar to the class. Then specify the name, data type and default value in the properties dialog. The initial value must be specified as OpaqueExpression. The data type can be a built-in data type, an own defined primitive data types as shown in the figure above or a class. In case of a class, specify the Aggregation type.
To add operations drag an operation from the toolbar to the class. Add details using the operation’s property dialog. If no return type is specified void is assumed. Using the Owned Parameter feature you can add parameters to the operation. For each parameter specify the name, type and default value. Parameters marked as out or inout are generated as pointers.
There is a default mapping of UML data types to C/C++ types. If you want to use own data types (e.g. uint16_t) define own primitive data types. The default mapping of the UML data types can be changed in the configuration file.
Supported / Unsupported#
The code generator supports a subset of the design elements provided by Papyrus. The supported elements are as follows:
- Hierarchical states
- Regions and “regions in regions”
- (Signal-)Events with event name, guard and action
- Initial and final pseudo-states
- History states (deep, flat), Extended history handling
- Choices
- Junctions
- Attributes / Operations
The unsupported elements are:
- Constraints
- Sync-states
- Entry and exit points (not to compare with entry/exit actions within states)
- Terminate and Fork/Join
- Submachines
Papyrus How-To#
- Opaque behavior not visible in the diagram: check Papyrus preferences and increase the number of lines shown for opaque behavior.
- Inner transition in a state: create a self-transition and set transition kind to
internal.
Example#

Quick Start#
Use the Papyrus microwave example from the examples folder, regenerate code from the model, and compile/run the sample to iterate quickly on changes.