Subprograms and Packages 131
Let’s discuss the resolved subtype method first. To create a resolved sub-
type, the designer declares the base type, then declares the subtype speci-
fying the resolution function to use for this type. An example looks like this:
TYPE fourval IS (X, L, H, Z); -- won’t compile
SUBTYPE resfour IS resolve fourval; -- as is
The first declaration declares the enumerated type fourval. The second
declaration is used to declare a subtype named resfour, which uses a
resolution function named resolveto resolve the base type fourval. This
syntax does not compile as is because the function resolveis not visible.
To declare a resolved subtype requires a very specific combination of
statements, in a very specific ordering.
Following is a correct example of the resolved type:
PACKAGE fourpack IS
TYPE fourval IS (X, L, H, Z); -- line 1
TYPE fourvalvector IS ARRAY(natural RANGE <>)
OF fourval; -- line 2
FUNCTION resolve( s: fourvalvector) RETURN fourval;
-- line 3
SUBTYPE resfour IS resolve fourval; -- line 4
END fourpack;
The statement in line 2 declares an unconstrained array of the base
type that is used to contain the driver values passed to the resolution
function. The statement in line 3 declares the definition of the resolution
function resolveso that the subtype declaration can make use of it. The
body of the resolution function is implemented in the package body. Finally,
the statement in line 4 declares the resolved subtype using the base type
and the resolution function declaration.
The order of the statements is important, because each statement
declares something that is used in the next statement. If the uncon-
strained array declaration is left out, the resolution function could not be
declared, and if the resolution function was not declared, the subtype
could not be declared.
The second method of obtaining a resolved signal is to specify the reso-
lution function in the signal declaration. In the following example, a signal
is declared using the resolution function resolve:
PACKAGE fourpack IS
TYPE fourval IS (X, L, H, Z);