Convert enumerations to constants
This CIF to CIF transformation converts enumerations to integer constants.
See also: Merge enumerations and Convert enumerations to integers.
This transformation supports a subset of CIF specifications. The following restrictions apply:
Component definitions and component instantiations are not supported.
To increase the subset of specifications that can be transformed, apply the following CIF to CIF transformations (in the given order) prior to using this transformation:
Enumerations, which are used as types, are replaced by integer types, with range
[0 .. n-1], where
n is the number of literals of the enumeration.
Enumeration literals, which are used as values, are replaced by constants. If the used enumeration literal is the
nth literal in the corresponding enumeration (declaration), then a constant with value
n - 1 is used. That is, the integer value is the 0-based index of the enumeration literal into the literals of the enumeration declaration.
All enumeration declarations are replaced by constant integer declarations, one for each literal in the enumeration declaration.
For instance, the following specification:
group x: enum EX = A, B; alg EX x = A; end group y: enum EY = B, A; alg EY y = A; end
is transformed to the following specification:
group x: alg int[0..1] x = A; const int A = 0; const int B = 1; end group y: alg int[0..1] y = A; const int B = 0; const int A = 1; end
This transformation itself does not perform any renaming.
If enumeration literals are renamed, this may influence value equality for compatible enumerations (enumerations with the same number of literals, with the same names, in the same order). Therefore, either apply this transformation before applying other transformations that perform renaming on enumeration literals (such as the Eliminate groups CIF to CIF transformation), or otherwise ensure that renaming does not result in an invalid specification.
The number of added constants is linear in the number of enumeration literals of the specification. Integer types are slightly larger than enumeration types, but the increase is linear. Constant references in expressions are not larger than enumeration literal references.