3.10.1 Incomplete Type Declarations
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.
Syntax
2/2
Static Semantics
2.1/2
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
it occurs within the immediate scope of the completion
of T, or
2.4/3
it occurs within the scope of a
nonlimited_with_clause
that mentions a library package in whose visible part the completion
of
T is declared, or
2.5/3
2.6/3
In these cases, the dereference has the view of
T visible at the point of the dereference.
2.7/3
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 three circumstances
given above, in which case it denotes the view of
T visible at
the point of the
subtype_mark.
Legality Rules
3/3
4/3
5/2
A
name
that denotes an incomplete view of a type may be used as follows:
6/3
7/2
8/3
8.1/3
8.2/3
as a generic actual parameter whose corresponding
generic formal parameter is a formal incomplete type (see
12.5.1).
8.3/2
If such a
name
denotes a tagged incomplete view, it may also be used:
8.4/3
9/2
9.1/3
This
paragraph was deleted.
9.2/3
This paragraph
was deleted.
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/3
A
prefix
that denotes an object shall not be of an incomplete view. An actual
parameter in a call shall not be of an untagged incomplete view. The
result object of a function call shall not be of an incomplete view.
A
prefix shall
not denote a subprogram having a formal parameter of an untagged incomplete
view, nor a return type that is an incomplete view.
Paragraph 11 was
deleted.
Dynamic Semantics
12
13
13.1/3
87 A
name
that denotes an object of an incomplete view is defined to be of a limited
type. Hence, the target of an assignment statement cannot be of an incomplete
view.
Examples
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;
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe