====== Subtype declarations ======
===== subtype_declaration =====
subtype identifier is subtype_indication ;
===== Parents =====
* entity_declarative_part
* architecture_declarative_part
* package
* package_body
* block_declarative_part
* function_declarative_part
* procedure_declarative_part
* process_declarative_part
===== Further definitions =====
==== identifier ====
* [[.:bnf#basic_identifier]]
* [[.:bnf#extended_identifier]]
==== subtype_indication ====
''[ resolution_function_ [[.:bnf#name]] ] [[.:bnf#type_mark]] [ [[.:bnf#constraint]] ]''
===== Examples =====
These are standard predefined subtypes. //natural// is an //integer// -type which is restricted to the range of 0 to the maximum //integer// -value. //positive// is also an //integer// -type which is restricted to the range of 1 to the maximum //integer// -value.
SUBTYPE natural IS integer
RANGE 0 TO integer'high ;
SUBTYPE positive IS integer
RANGE 1 TO integer'high ;
----
These are common examples such as subtypes which are created from basic types by means of range-constraints.
The ranges of //integer// - and //real// subtypes are declared with the keyword //RANGE// .
The ranges of //character// -, //string// - and //enumeration// subtypes are declared by explicitly stating a certain section.
SUBTYPE primary_color IS
color RANGE yellow TO blue ;
SUBTYPE same_color IS primary_color ;
SUBTYPE address_integer IS
integer RANGE 0 TO 127 ;
SUBTYPE human_size IS
real RANGE 0.50 TO 2.50 ;
SUBTYPE byte IS
bit_vector (7 DOWNTO 0);
SUBTYPE name IS string ( 1 TO 31 );
SUBTYPE color_10 IS colors (1 TO 10);
----
The two subtypes //sbit// and //xbit// are declared as subtypes of //zbit// and a [[.:resolution function]] is assigned to both of them. The resolution function makes sure that in a multiple assignment to a signal only definite values are assigned.
SUBTYPE sbit IS wiredX zbit ;
SUBTYPE xbit IS wiredX zbit
RANGE 'X' TO '1' ;