Annotated Ada Reference ManualLegal Information
Table of Contents   Index   References   Search   Previous   Next 

 4.1.3 Selected Components

1
[Selected_components are used to denote components (including discriminants), entries, entry families, and protected subprograms; they are also used as expanded names as described below. {dot selection: See selected_component} ]

Syntax

2
selected_component ::= prefix . selector_name
3
selector_name ::= identifier | character_literal | operator_symbol

Name Resolution Rules

4
{expanded name} A selected_component is called an expanded name if, according to the visibility rules, at least one possible interpretation of its prefix denotes a package or an enclosing named construct (directly, not through a subprogram_renaming_declaration or generic_renaming_declaration).
4.a
Discussion: See AI83-00187. 
5
A selected_component that is not an expanded name shall resolve to denote one of the following:
5.a
Ramification: If the prefix of a selected_component denotes an enclosing named construct, then the selected_component is interpreted only as an expanded name, even if the named construct is a function that could be called without parameters. 
6
7
7.a/1
Reason: The components of a protected object cannot be named except by an expanded name, even from within the corresponding protected body. The protected body may not reference the the private components of some arbitrary object of the protected type; the protected body may reference components of the current instance only (by an expanded name or a direct_name).
7.b
Ramification: Only the discriminants and components visible at the place of the selected_component can be selected, since a selector_name can only denote declarations that are visible (see 8.3).
8
9
9.a
Reason: This explicitly says “visible part” because even though the body has visibility on the private part, it cannot call the private operations of some arbitrary object of the task or protected type, only those of the current instance (and expanded name notation has to be used for that). 
9.1/2
9.2/2
10
An expanded name shall resolve to denote a declaration that occurs immediately within a named declarative region, as follows: 
11
12
12.a
Ramification: Hence, a library unit or subunit can use an expanded name to refer to the declarations within the private part of its parent unit, as well as to other children that have been mentioned in with_clauses. 
13

Legality Rules

13.1/2
   {AI95-00252-01} {AI95-00407-01} For a subprogram whose first parameter is an access parameter, the prefix of any prefixed view shall denote an aliased view of an object.
13.2/2
   {AI95-00407-01} For a subprogram whose first parameter is of mode in out or out, or of an anonymous access-to-variable type, the prefix of any prefixed view shall denote a variable.
13.a/2
Reason: We want calls through a prefixed view and through a normal view to have the same legality. Thus, the implicit 'Access in this new notation needs the same legality check that an explicit 'Access would have. Similarly, we need to prohibit the object from being constant if the first parameter of the subprogram is in out, because that is (obviously) prohibited for passing a normal parameter. 

Dynamic Semantics

14
{evaluation (selected_component) [partial]} The evaluation of a selected_component includes the evaluation of the prefix.
15
{Discriminant_Check [partial]} {check, language-defined (Discriminant_Check)} For a selected_component that denotes a component of a variant, a check is made that the values of the discriminants are such that the value or object denoted by the prefix has this component. {Constraint_Error (raised by failure of run-time check)} {Constraint_Error (raised by failure of run-time check)} The exception Constraint_Error is raised if this check fails.

Examples

16
Examples of selected components: 
17/2
{AI95-00252-01} {AI95-00407-01}   Tomorrow.Month     --  a record component  (see 3.8)
  Next_Car.Owner     --  a record component                      (see 3.10.1)
  Next_Car.Owner.Age --  a record component                      (see 3.10.1)
                     --  the previous two lines involve implicit dereferences
  Writer.Unit        --  a record component (a discriminant)     (see 3.8.1)
  Min_Cell(H).Value  --  a record component of the result        (see 6.1)
                     --  of the function call Min_Cell(H)
  Cashier.Append     --  a prefixed view of a procedure          (see 3.9.4)
  Control.Seize      --  an entry of a protected object          (see 9.4)
  Pool(K).Write      --  an entry of the task Pool(K)            (see 9.4)
18
Examples of expanded names: 
19
  Key_Manager."<"      --  an operator of the visible part of a package  (see 7.3.1)
  Dot_Product.Sum      --  a variable declared in a function body       (see 6.1)
  Buffer.Pool          --  a variable declared in a protected unit      (see 9.11)
  Buffer.Read          --  an entry of a protected unit                 (see 9.11)
  Swap.Temp            --  a variable declared in a block statement     (see 5.6)
  Standard.Boolean     --  the name of a predefined type                (see A.1)

Extensions to Ada 83

19.a
{extensions to Ada 83} We now allow an expanded name to use a prefix that denotes a rename of a package, even if the selector is for an entity local to the body or private part of the package, so long as the entity is visible at the place of the reference. This eliminates a preexisting anomaly where references in a package body may refer to declarations of its visible part but not those of its private part or body when the prefix is a rename of the package. 

Wording Changes from Ada 83

19.b
The syntax rule for selector_name is new. It is used in places where visibility, but not necessarily direct visibility, is required. See 4.1, “Names” for more information.
19.c
The description of dereferencing an access type has been moved to 4.1, “Names”; name.all is no longer considered a selected_component.
19.d
The rules have been restated to be consistent with our new terminology, to accommodate class-wide types, etc. 

Extensions to Ada 95

19.e/2
{AI95-00252-01} {extensions to Ada 95} The prefixed view notation for tagged objects is new. This provides a similar notation to that used in other popular languages, and also reduces the need for use_clauses. This is sometimes known as “distinguished receiver notation”. {distinguished receiver notation}
19.f/2
Given the following definitions for a tagged type T: 
19.g/2
procedure Do_Something (Obj : in out T; Count : in Natural);
procedure Do_Something_Else (Obj : access T; Flag : in Boolean);
My_Object : aliased T;
19.h/2
the following calls are equivalent: 
19.i/2
Do_Something (My_Object, Count => 10);
My_Object.Do_Something (Count => 10);
19.j/2
as are the following calls: 
19.k/2
Do_Something_Else (My_Object'Access, Flag => True);
My_Object.Do_Something_Else (Flag => True);

Table of Contents   Index   References   Search   Previous   Next 
Ada-Europe Sponsored by Ada-Europe