1
There are no particular limitations on the designated type of an access type. In particular, the type of a component of the designated type can be another access type, or even the same access type. This permits mutually dependent and recursive access types. An incomplete_type_declaration can be used to introduce a type to be used as a designated type, while deferring its full definition to a subsequent full_type_declaration.
2/2
incomplete_type_declaration::= type defining_identifier [discriminant_part] [is tagged];
2.1/2
An incomplete_type_declaration declares an incomplete view of a type and its first subtype; the first subtype is unconstrained if a discriminant_part appears. If the incomplete_type_declaration (see 3.10.1) includes the reserved word tagged, it declares a tagged incomplete view.An incomplete view of a type is a limited view of the type (see 7.5).
2.2/2
Given an access type A whose designated type T is an incomplete view, a dereference of a value of type A also has this incomplete view except when:
2.3/2
2.4/2
2.5/2
In these cases, the dereference has the full view of T.
2.6/2
Similarly, if a subtype_mark denotes a subtype_declaration defining a subtype of an incomplete view T, the subtype_mark denotes an incomplete view except under the same two circumstances given above, in which case it denotes the full view of T.
3
An incomplete_type_declaration requires a completion, which shall be a full_type_declaration (see 3.2.1). If the incomplete_type_declaration (see 3.10.1) occurs immediately within either the visible part of a package_specification (see 7.1) or a declarative_part (see 3.11), then the full_type_declaration (see 3.2.1) shall occur later and immediately within this visible part or declarative_part (see 3.11). If the incomplete_type_declaration (see 3.10.1) occurs immediately within the private part of a given package_specification (see 7.1), then the full_type_declaration (see 3.2.1) shall occur later and immediately within either the private part itself, or the declarative_part (see 3.11) of the corresponding package_body (see 7.2).
4/2
If an incomplete_type_declaration (see 3.10.1) includes the reserved word tagged, then a full_type_declaration (see 3.2.1) that completes it shall declare a tagged type. If an incomplete_type_declaration (see 3.10.1) has a known_discriminant_part (see 3.7), then a full_type_declaration (see 3.2.1) that completes it shall have a fully conforming (explicit) known_discriminant_part (see 3.7) (see 6.3.1). If an incomplete_type_declaration (see 3.10.1) has no discriminant_part (or an unknown_discriminant_part (see 3.7)), then a corresponding full_type_declaration (see 3.2.1) is nevertheless allowed to have discriminants, either explicitly, or inherited via derivation.
5/2
A name that denotes an incomplete view of a type may be used as follows:
6
7/2
8/2
8.1/2
If such a name denotes a tagged incomplete view, it may also be used:
8.2/2
9/2
9.1/2
If such a name occurs within the declaration list containing the completion of the incomplete view, it may also be used:
9.2/2
9.3/2
If any of the above uses occurs as part of the declaration of a primitive subprogram of the incomplete view, and the declaration occurs immediately within the private part of a package, then the completion of the incomplete view shall also occur immediately within the private part; it shall not be deferred to the package body.
9.4/2
No other uses of a name that denotes an incomplete view of a type are allowed.
10/2
A prefix that denotes an object shall not be of an incomplete view.
11/2
This paragraph was deleted.
12
The elaboration of an incomplete_type_declaration has no effect.
NOTES
13
83 Within a declarative_part, an incomplete_type_declaration and a corresponding full_type_declaration cannot be separated by an intervening body. This is because a type has to be completely defined before it is frozen, and a body freezes all types declared prior to it in the same declarative_part (see 13.14).
14
Example of a recursive type:
15
type Cell; −− incomplete type declaration type Link is access Cell;
16
type Cell is record Value : Integer; Succ : Link; Pred : Link; end record;
17
Head : Link := new Cell'(0, null, null); Next : Link := Head.Succ;
18
Examples of mutually dependent access types:
19/2
type Person(<>); −− incomplete type declaration type Car is tagged; −− incomplete type declaration
20/2
type Person_Name is access Person; type Car_Name is access all Car'Class;
21/2
type Car is tagged record Number : Integer; Owner : Person_Name; end record;
22
type Person(Sex : Gender) is record Name : String(1 .. 20); Birth : Date; Age : Integer range 0 .. 130; Vehicle : Car_Name; case Sex is when M => Wife : Person_Name(Sex => F); when F => Husband : Person_Name(Sex => M); end case; end record;
23
My_Car, Your_Car, Next_Car : Car_Name := new Car; −− see 4.8 George : Person_Name := new Person(M); ... George.Vehicle := Your_Car;