Annotated Ada Reference ManualLegal Information
Contents   Index   References   Search   Previous   Next 

4.1.5 User-Defined References

Static Semantics

1/3
{AI05-0139-2} Given a discriminated type T, the following type-related operational aspect may be specified:
2/3
Implicit_Dereference

This aspect is specified by a name that denotes an access discriminant declared for the type T.
2.a/3
Aspect Description for Implicit_Dereference: Mechanism for user-defined implicit .all.
3/3
{AI05-0139-2} A (view of a) type with a specified Implicit_Dereference aspect is a reference type. A reference object is an object of a reference type. The discriminant named by the Implicit_Dereference aspect is the reference discriminant of the reference type or reference object. [A generalized_reference is a name that identifies a reference object, and denotes the object or subprogram designated by the reference discriminant of the reference object.]
3.a.1/3
Glossary entry: A reference type is one that has user-defined behavior for “.all”, defined by the Implicit_Dereference aspect.

Syntax

4/3
{AI05-0139-2} generalized_reference ::= reference_object_name

Name Resolution Rules

5/3
{AI05-0139-2} {AI05-0269-1} The expected type for the reference_object_name in a generalized_reference is any reference type. 

Static Semantics

5.1/4
 {AI12-0138-1} The Implicit_Dereference aspect is nonoverridable (see 13.1.1).
5.a/4
Reason: This ensures that all descendants of a reference type have the same reference discriminant. This prevents generic contract problems with formal derived types. 
6/3
{AI05-0139-2} A generalized_reference denotes a view equivalent to that of a dereference of the reference discriminant of the reference object.
7/3
{AI05-0139-2} Given a reference type T, the Implicit_Dereference aspect is inherited by descendants of type T if not overridden. If a descendant type constrains the value of the reference discriminant of T by a new discriminant, that new discriminant is the reference discriminant of the descendant. [If the descendant type constrains the value of the reference discriminant of T by an expression other than the name of a new discriminant, a generalized_reference that identifies an object of the descendant type denotes the object or subprogram designated by the value of this constraining expression.]

Dynamic Semantics

8/3
{AI05-0139-2} The evaluation of a generalized_reference consists of the evaluation of the reference_object_name and a determination of the object or subprogram designated by the reference discriminant of the named reference object. A check is made that the value of the reference discriminant is not the null access value. Constraint_Error is raised if this check fails. The generalized_reference denotes the object or subprogram designated by the value of the reference discriminant of the named reference object.

Examples

9/3
{AI05-0268-1} type Barrel is tagged ...  -- holds objects of type Element
10/3
{AI05-0139-2} {AI05-0299-1} type Ref_Element(Data : access Element) is limited private
   with Implicit_Dereference => Data;
      -- This Ref_Element type is a "reference" type.
      -- "Data" is its reference discriminant.
11/3
{AI05-0139-2} {AI05-0268-1} function Find (B : aliased in out Barrel; Key : String) return Ref_Element;
   -- Return a reference to an element of a barrel.
12/3
{AI05-0268-1} {AI05-0299-1} B: aliased Barrel;
13/3
{AI05-0139-2} ...
14/3
{AI05-0139-2} {AI05-0268-1} Find (B, "grape") := Element'(...);  -- Assign through a reference.
15/3
{AI05-0139-2} {AI05-0268-1} -- This is equivalent to:
Find (B, "grape").Data.all := Element'(...);

Extensions to Ada 2005

15.a/3
{AI05-0139-2} The aspect Implicit_Dereference and the generalized_reference are new. 

Incompatibilities With Ada 2012

15.b/4
{AI12-0138-1} Corrigendum: Defined Implicit_Dereference to be nonoveridable, which makes redefinitions and hiding of the aspect illegal. It's possible that some program could violate one of these new restrictions, but this is not very likely as reference types are not likely to be used in a hierarchy. 

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe