3.9.1 Type Extensions
Every type extension is a tagged type, and is either a record extension or a private extension of some other tagged type.
record_extension_part ::= with record_definition
The parent type of a record extension shall not be a class-wide type. If the parent type is nonlimited, then each of the components of the record_extension_part shall be nonlimited. The accessibility level (see 3.10.2) of a record extension shall not be statically deeper than that of its parent type. In addition to the places where Legality Rules normally apply (see 12.3), these rules apply also in the private part of an instance of a generic unit.
A type extension shall not be declared in a generic body if the parent type is declared outside that body.
The elaboration of a record_extension_part consists of the elaboration of the record_definition.
66 The term type extension refers to a type as a whole. The term extension part refers to the piece of text that defines the additional components (if any) the type extension has relative to its specified ancestor type.
67 The accessibility rules imply that a tagged type declared in a library package_specification can be extended only at library level or as a generic formal. When the extension is declared immediately within a package_body, primitive subprograms are inherited and are overridable, but new primitive subprograms cannot be added.
68 A name that denotes a component (including a discriminant) of the parent type is not allowed within the record_extension_part. Similarly, a name that denotes a component defined within the record_extension_part is not allowed within the record_extension_part. It is permissible to use a name that denotes a discriminant of the record extension, providing there is a new known_discriminant_part in the enclosing type declaration. (The full rule is given in 3.8.)
69 Each visible component of a record extension has to have a unique name, whether the component is (visibly) inherited from the parent type or declared in the record_extension_part (see 8.3).
Examples of record extensions (of types defined above in 3.9):
type Painted_Point is new Point with record Paint : Color := White; end record; -- Components X and Y are inherited
Origin : constant Painted_Point := (X | Y => 0.0, Paint => Black);
type Literal is new Expression with record -- a leaf in an Expression tree Value : Real; end record;
type Expr_Ptr is access all Expression'Class; -- see 3.10
type Binary_Operation is new Expression with record -- an internal node in an Expression tree Left, Right : Expr_Ptr; end record;
type Addition is new Binary_Operation with null record; type Subtraction is new Binary_Operation with null record; -- No additional components needed for these extensions
Tree : Expr_Ptr := -- A tree representation of ''5.0 + (13.0-7.0)'' new Addition'( Left => new Literal'(Value => 5.0), Right => new Subtraction'( Left => new Literal'(Value => 13.0), Right => new Literal'(Value => 7.0)));
Copyright © 1992,1993,1994,1995 Intermetrics, Inc.
Copyright © 2000 The MITRE Corporation, Inc. Ada Reference Manual