A type can be declared in a record descriptor by using the
%typedef special field. The syntax is:
%typedef: type_name type_description
Where type_name is the name of the new type, and
type_description a description which varies depending of the
kind of type.
For example, this is how a type
be defined as numbers in the range
%typedef: Age_t range 0 120
Type names are identifiers having the following syntax:
Even though any identifier with that syntax could be used for types,
it is a good idea to consistently follow some convention to help
distinguishing type names from field names. For example, the
_t suffix could be used for types.
A type can be declared to be an alias for another type. The syntax is:
%typedef: type_name other_type_name
Where type_name is declared to be a synonym of other_type_name. This is useful to avoid duplicated type descriptions. For example, consider the following example:
%typedef: Id_t int %typedef: Item_t Id_t %typedef: Transaction_t Id_t
Transaction_t are aliases for the type
Id_t. Which is in turn an alias for the type
So, they are both numeric identifiers.
The order of the
%typedef fields is not relevant. In
particular, a type definition can forward-reference another type that is defined
subsequently. The previous example could have been written as:
%typedef: Item_t Id_t %typedef: Transaction_t Id_t %typedef: Id_t int
Integrity check will complain if undefined types are referenced. As well as when any aliases up referencing back (looping back directly or indirectly) in type declarations. For example, the following set of declarations contains a loop. Thus, it’s invalid:
%typedef: A_t B_t %typedef: B_t C_t %typedef: C_t A_t
The scope of a type is the record descriptor where it is defined.