Implement enums-to-consts CIF to CIF transformation
When code is generated from a CIF model, the CIF to CIF linearize merge transformation is used. This transformation introduced location pointers to represent the locations of an automaton. The location pointer has an
enum type. Not all PLCs support enumeration types (e.g., Siemens S7-300), that's why the CIF to PLC transformation has an option
Eliminate enumerations. This is the CIF to CIF
This transformation transforms enumeration literals into integers. A downside of this transformation is that it introduces a lot of magic numbers.
An alternative solution to replace enums with constants.
If we decide to do this, we should:
- Rename the current
- Add CIF to PLC option to replace enums with constants.
- Use ranged integers, similar to enums-to-ints, but the values are not numbers directly, but use constants. The constants have the names of the original enumeration literals, to keep the original names alive.
- Scoping issues for constants: must eliminate component definition/instantiation first (or demand as pre-condition, as other CIF to CIF transformations do).
- Works with variables of enumeration type and 'any' as initial value, due to use of ranged int type.
- Performance similar to enums-to-ints, as it also uses integers, especially if we eliminate constants.
- The constants are created in the same scope as the original enumeration literals, so no renaming needed.
I know @ahofkamp is working on a new version of the PLC code generator and then this might not be needed anymore. However, until then this is an easy to implement alternative. Moreover, this transformation can also be useful for other applications.