____ | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


3.9.1 Type Extensions

(1)
Every type extension is a tagged type, and is either a record extension or a private extension of some other tagged type.
Syntax
(2)
       record_extension_part ::= with record_definition
Legality Rules
(3)
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.
(4)
A type extension shall not be declared in a generic body if the parent type is declared outside that body.
Dynamic Semantics
(5)
The elaboration of a record_extension_part consists of the elaboration of the record_definition.

(6)
(7)
(8)
(9)
Examples
(10)
Examples of record extensions (of types defined above in 3.9):
(11)
       type Painted_Point is new Point with
         record
           Paint : Color := White;
         end record;
           -- Components X and Y are inherited
(12)
       Origin : constant Painted_Point := (X | Y => 0.0, Paint => Black);
(13)
       type Literal is new Expression with
         record                 -- a leaf in an Expression tree
           Value : Real;
         end record;
(14)
       type Expr_Ptr is access all Expression'Class;
                                      -- see 3.10
(15)
       type Binary_Operation is new Expression with
         record                 -- an internal node in an Expression tree
           Left, Right : Expr_Ptr;
         end record;
(16)
       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
(17)
       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)));

____ | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12