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


7.3.1 Private Operations

(1)
For a type declared in the visible part of a package or generic package, certain operations on the type do not become visible until later in the package -- either in the private part or the body. Such private operations are available only inside the declarative region of the package or generic package.
Static Semantics
(2)
The predefined operators that exist for a given type are determined by the classes to which the type belongs. For example, an integer type has a predefined "+" operator. In most cases, the predefined operators of a type are declared immediately after the definition of the type; the exceptions are explained below. Inherited subprograms are also implicitly declared immediately after the definition of the type, except as stated below.
(3)
For a composite type, the characteristics (see 7.3) of the type are determined in part by the characteristics of its component types. At the place where the composite type is declared, the only characteristics of component types used are those characteristics visible at that place. If later within the immediate scope of the composite type additional characteristics become visible for a component type, then any corresponding characteristics become visible for the composite type. Any additional predefined operators are implicitly declared at that place.
(4)
The corresponding rule applies to a type defined by a derived_type_definition, if there is a place within its immediate scope where additional characteristics of its parent type become visible.
(5)
For example, an array type whose component type is limited private becomes nonlimited if the full view of the component type is nonlimited and visible at some later place within the immediate scope of the array type. In such a case, the predefined "=" operator is implicitly declared at that place, and assignment is allowed after that place.
(6)
Inherited primitive subprograms follow a different rule. For a derived_type_definition, each inherited primitive subprogram is implicitly declared at the earliest place, if any, within the immediate scope of the type_declaration, but after the type_declaration, where the corresponding declaration from the parent is visible. If there is no such place, then the inherited subprogram is not declared at all. An inherited subprogram that is not declared at all cannot be named in a call and cannot be overridden, but for a tagged type, it is possible to dispatch to it.
(7)
For a private_extension_declaration, each inherited subprogram is declared immediately after the private_extension_declaration if the corresponding declaration from the ancestor is visible at that place. Otherwise, the inherited subprogram is not declared for the private extension, though it might be for the full type.
(8)
The Class attribute is defined for tagged subtypes in 3.9. In addition, for every subtype S of an untagged private type whose full view is tagged, the following attribute is defined:
(9)
S'Class

(10)
(11)
(12)
(13)
Examples
(14)
Example of a type with private operations:
(15)
       package Key_Manager is
          type Key is private;
          Null_Key : constant Key; -- a deferred constant declaration (see 7.4)
          procedure Get_Key(K : out Key);
          function "<" (X, Y : Key) return Boolean;
       private
          type Key is new Natural;
          Null_Key : constant Key := Key'First;
       end Key_Manager;
(16)
       package body Key_Manager is
          Last_Key : Key := Null_Key;
          procedure Get_Key(K : out Key) is
          begin
             Last_Key := Last_Key + 1;
             K := Last_Key;
          end Get_Key;
(17)
          function "<" (X, Y : Key) return Boolean is
          begin
             return Natural(X) < Natural(Y);
          end "<";
       end Key_Manager;

(18)
(19)
(20)

____ | Up | ____ | 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