4.1 Names
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
[Name
s can denote declared entities, whether declared explicitly or implicitly (see 3.1). Name
s can also denote objects or subprograms designated by access values; the results of type_conversion
s or function_call
s; subcomponents and slices of objects and values; protected subprograms, single entries, entry families, and entries in families of entries. Finally, name
s can denote attributes of any of the foregoing.]
Syntax
2/5name
::=
direct_name
| explicit_dereference
| indexed_component
| slice
| selected_component
| attribute_reference
| type_conversion
| function_call
| character_literal
| qualified_expression
| generalized_reference
| generalized_indexing
| target_name
3direct_name
::=
identifier
| operator_symbol
character_literal
is no longer a direct_name
. character_literal
s are usable even when the corresponding enumeration type declaration is not visible. See 4.2. prefix
::=
name
| implicit_dereference
5explicit_dereference
::=
name
.all
6implicit_dereference
::=
name
7/3[Certain forms of name
(indexed_component
s, selected_component
s, slice
s, and attribute_reference
s) include a prefix
that is either itself a name
that denotes some related entity, or an implicit_dereference
of an access value that designates some related entity.]
Name Resolution Rules
8The name
in a dereference (either an implicit_dereference
or an explicit_dereference
) is expected to be of any access type.
Static Semantics
9/3If the type of the name
in a dereference is some access-to-object type T, then the dereference denotes a view of an object, the nominal subtype of the view being the designated subtype of T. If the designated subtype has unconstrained discriminants, the (actual) subtype of the view is constrained by the values of the discriminants of the designated object, except when there is a partial view of the type of the designated subtype that does not have discriminants, in which case the dereference is not constrained by its discriminant values.
If the type of the name
in a dereference is some access-to-subprogram type S, then the dereference denotes a view of a subprogram, the profile of the view being the designated profile of S.
name
or prefix
is a dereference are those of the designated profile, which need not be the same as those of the subprogram designated by the access value, since 'Access requires only subtype conformance, not full conformance. Dynamic Semantics
11/2The evaluation of a name
determines the entity denoted by the name
. This evaluation has no other effect for a name
that is a direct_name
or a character_literal
.
[The evaluation of a name
that has a prefix
includes the evaluation of the prefix
.] The evaluation of a prefix
consists of the evaluation of the name
or the implicit_dereference
. The prefix
denotes the entity denoted by the name
or the implicit_dereference
.
The evaluation of a dereference consists of the evaluation of the name
and the determination of the object or subprogram that is designated by the value of the name
. A check is made that the value of the name
is not the null access value. Constraint_Error is raised if this check fails. The dereference denotes the object or subprogram designated by the value of the name
.
Examples
14Examples of direct names:
Pi -- the direct name of a number (see 3.3.2)
Limit -- the direct name of a constant (see 3.3.1)
Count -- the direct name of a scalar variable (see 3.3.1)
Board -- the direct name of an array variable (see 3.6.1)
Matrix -- the direct name of a type (see 3.6)
Random -- the direct name of a function (see 6.1)
Error -- the direct name of an exception (see 11.1)
16Examples of dereferences:
Next_Car.all -- explicit dereference denoting the object designated by
-- the access variable Next_Car (see 3.10.1)
Next_Car.Owner -- selected component with implicit dereference;
-- same as Next_Car.all.Owner
Extensions to Ada 83
assignment_statement
. If the operand is an object, then the type conversion can appear in an object renaming or as a prefix
. See 4.6. Wording Changes from Ada 83
name
(...) is now syntactically a name
. In any realistic parser, this would be a necessity since distinguishing among the various name
(...) constructs inevitably requires name resolution. In cases where the construct yields a value rather than an object, the name denotes a value rather than an object. Names already denote values in Ada 83 with named numbers, components of the result of a function call, etc. This is partly just a wording change, and partly an extension of functionality (see Extensions heading above).direct_name
is new. It is used in places where direct visibility is required. It's kind of like Ada 83's simple_name
, but simple_name
applied to both direct visibility and visibility by selection, and furthermore, it didn't work right for operator_symbol
s. The syntax rule for simple_name
is removed, since its use is covered by a combination of direct_name
and selector_name
. The syntactic categories direct_name
and selector_name
are similar; it's mainly the visibility rules that distinguish the two. The introduction of direct_name
requires the insertion of one new explicit textual rule: to forbid statement_identifier
s from being operator_symbol
s. This is the only case where the explicit rule is needed, because this is the only case where the declaration of the entity is implicit. For example, there is no need to syntactically forbid (say) “X: "Rem";”, because it is impossible to declare a type whose name is an operator_symbol
in the first place.explicit_dereference
and implicit_dereference
are new; this makes other rules simpler, since dereferencing an access value has substantially different semantics from selected_component
s. We also use name
instead of prefix
in the explicit_dereference
rule since that seems clearer. Note that these rules rely on the fact that function calls are now names, so we don't need to use prefix to allow functions calls in front of .all. primary
in front of .all, since only the value is needed, but that would be a bit radical. Extensions to Ada 2005
qualified_expression
is now a name
denoting a constant view; this allows them to be used as a prefix and to be renamed as an object. They are often used to remove ambiguity from function calls, and there may be no other way to do that. Interestingly, a type_conversion
of a qualified_expression
is already legal in these contexts, so this change mainly reduces clutter by eliminating an otherwise unneeded type_conversion
from some expressions. Wording Changes from Ada 2005
generalized_reference
and generalized_indexing
as types of name
; these are documented as extensions in the appropriate subclauses. Wording Changes from Ada 2012
4.1.1 Indexed Components
1[An indexed_component
denotes either a component of an array or an entry in a family of entries. ]
Syntax
2indexed_component
::=
prefix
(expression
{, expression
})
Name Resolution Rules
3The prefix
of an indexed_component
with a given number of expression
s shall resolve to denote an array (after any implicit dereference) with the corresponding number of index positions, or shall resolve to denote an entry family of a task or protected object (in which case there shall be only one expression
).
The expected type for each expression
is the corresponding index type.
Static Semantics
5When the prefix
denotes an array, the indexed_component
denotes the component of the array with the specified index value(s). The nominal subtype of the indexed_component
is the component subtype of the array type.
When the prefix
denotes an entry family, the indexed_component
denotes the individual entry of the entry family with the specified index value.
Dynamic Semantics
7For the evaluation of an indexed_component
, the prefix
and the expression
s are evaluated in an arbitrary order. The value of each expression
is converted to the corresponding index type. A check is made that each index value belongs to the corresponding index range of the array or entry family denoted by the prefix
. Constraint_Error is raised if this check fails.
Examples
8Examples of indexed components:
My_Schedule(Sat) -- a component of a one-dimensional array (see 3.6.1)
Page(10) -- a component of a one-dimensional array (see 3.6)
Board(M, J + 1) -- a component of a two-dimensional array (see 3.6.1)
Page(10)(20) -- a component of a component (see 3.6)
Request(Medium) -- an entry in a family of entries (see 9.1)
Next_Frame(L)(M, N) -- a component of a function call (see 6.1)
4.1.2 Slices
1[ A slice
denotes a one-dimensional array formed by a sequence of consecutive components of a one-dimensional array. A slice
of a variable is a variable; a slice
of a constant is a constant;] a slice
of a value is a value.
Syntax
2slice
::=
prefix
(discrete_range
)
Name Resolution Rules
3The prefix
of a slice
shall resolve to denote a one-dimensional array (after any implicit dereference).
The expected type for the discrete_range
of a slice
is the index type of the array type.
Static Semantics
5A slice
denotes a one-dimensional array formed by the sequence of consecutive components of the array denoted by the prefix
, corresponding to the range of values of the index given by the discrete_range
.
The type of the slice
is that of the prefix
. Its bounds are those defined by the discrete_range
.
Dynamic Semantics
7For the evaluation of a slice
, the prefix
and the discrete_range
are evaluated in an arbitrary order. If the slice
is not a null slice (a slice
where the discrete_range
is a null range), then a check is made that the bounds of the discrete_range
belong to the index range of the array denoted by the prefix
. Constraint_Error is raised if this check fails.
slice
is not permitted as the prefix
of an Access attribute_reference
, even if the components or the array as a whole are aliased. See 3.10.2. slice
A(N .. N) denotes an array that has only one component; its type is the type of A. On the other hand, A(N) denotes a component of the array A and has the corresponding component type. Examples
10Examples of slices:
Stars(1 .. 15) -- a slice of 15 characters (see 3.6.3)
Page(10 .. 10 + Size) -- a slice of 1 + Size components (see 3.6)
Page(L)(A .. B) -- a slice of the array Page(L) (see 3.6)
Stars(1 .. 0) -- a null slice (see 3.6.3)
My_Schedule(Weekday) -- bounds given by subtype (see 3.6.1 and 3.5.1)
Stars(5 .. 15)(K) -- same as Stars(K) (see 3.6.3)
-- provided that K is in 5 .. 15
4.1.3 Selected Components
1[Selected_component
s are used to denote components (including discriminants), entries, entry families, and protected subprograms; they are also used as expanded names as described below. ]
Syntax
2selected_component
::=
prefix
. selector_name
3selector_name
::=
identifier
| character_literal
| operator_symbol
Name Resolution Rules
4A 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
).
A selected_component
that is not an expanded name shall resolve to denote one of the following:
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. - A component [(including a discriminant)]:
- The
prefix
shall resolve to denote an object or value of some non-array composite type (after any implicit dereference). Theselector_name
shall resolve to denote adiscriminant_specification
of the type, or, unless the type is a protected type, acomponent_declaration
of the type. Theselected_component
denotes the corresponding component of the object or value.
direct_name
). selected_component
can be selected, since a selector_name
can only denote declarations that are visible (see 8.3). - A single entry, an entry family, or a protected subprogram:
- The
prefix
shall resolve to denote an object or value of some task or protected type (after any implicit dereference). Theselector_name
shall resolve to denote anentry_declaration
orsubprogram_declaration
occurring (implicitly or explicitly) within the visible part of that type. Theselected_component
denotes the corresponding entry, entry family, or protected subprogram.
- A view of a subprogram whose first formal parameter is of a tagged type or is an access parameter whose designated type is tagged:
- The
prefix
(after any implicit dereference) shall resolve to denote an object or value of a specific tagged type T or class-wide type T'Class. Theselector_name
shall resolve to denote a view of a subprogram declared immediately within the declarative region in which an ancestor of the type T is declared. The first formal parameter of the subprogram shall be of type T, or a class-wide type that covers T, or an access parameter designating one of these types. The designator of the subprogram shall not be the same as that of a component of the tagged type visible at the point of theselected_component
. The subprogram shall not be an implicitly declared primitive operation of type T that overrides an inherited subprogram implemented by an entry or protected subprogram visible at the point of theselected_component
. Theselected_component
denotes a view of this subprogram that omits the first formal parameter. This view is called a prefixed view of the subprogram, and theprefix
of theselected_component
(after any implicit dereference) is called the prefix of the prefixed view.
An expanded name shall resolve to denote a declaration that occurs immediately within a named declarative region, as follows:
- The
prefix
shall resolve to denote either a package [(including the current instance of a generic package, or a rename of a package)], or an enclosing named construct. 12 - The
selector_name
shall resolve to denote a declaration that occurs immediately within the declarative region of the package or enclosing construct [(the declaration shall be visible at the place of the expanded name — see 8.3)]. The expanded name denotes that declaration.
with_clause
s. - If the
prefix
does not denote a package, then it shall be adirect_name
or an expanded name, and it shall resolve to denote a program unit (other than a package), the current instance of a type, ablock_statement
, aloop_statement
, or anaccept_statement
(in the case of anaccept_statement
orentry_body
, no family index is allowed); the expanded name shall occur within the declarative region of this construct. Further, if this construct is a callable construct and theprefix
denotes more than one such enclosing callable construct, then the expanded name is ambiguous, independently of theselector_name
.
Legality Rules
13.1/5For a prefixed view of a subprogram whose first formal parameter is an access parameter, the prefix shall be legal as the prefix
of an attribute_reference
with attribute_designator
Access appearing as the first actual parameter in a call on the unprefixed view of the subprogram .
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.
Dynamic Semantics
14The evaluation of a selected_component
includes the evaluation of the prefix
.
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. The exception Constraint_Error is raised if this check fails.
Examples
16Examples of selected components:
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.1 )
18Examples of expanded names:
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
Wording Changes from Ada 83
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.name
.all is no longer considered a selected_component
.Extensions to Ada 95
use_clause
s. This is sometimes known as “distinguished receiver notation”. procedure Do_Something (Obj : in out T; Count : in Natural);
procedure Do_Something_Else (Obj : access T; Flag : in Boolean);
My_Object : aliased T;
Do_Something (My_Object, Count => 10);
My_Object.Do_Something (Count => 10);
Do_Something_Else (My_Object'Access, Flag => True);
My_Object.Do_Something_Else (Flag => True);
Wording Changes from Ada 2005
Incompatibilities With Ada 2012
4.1.4 Attributes
1[An attribute is a characteristic of an entity that can be queried via an attribute_reference
or a range_attribute_reference
.]
Syntax
3/5attribute_reference
::=
prefix
'attribute_designator
| reduction_attribute_reference
4/2attribute_designator
::=
identifier
[(static_expression
)]
| Access | Delta | Digits | Mod
5range_attribute_reference
::=
prefix
'range_attribute_designator
6range_attribute_designator
::=
Range[(static_expression
)]
Name Resolution Rules
7/5In an attribute_reference
that is not a reduction_attribute_reference
, if the attribute_designator
is for an attribute defined for (at least some) objects of an access type, then the prefix
is never interpreted as an implicit_dereference
; otherwise (and for all range_attribute_reference
s and reduction_attribute_reference
s), if there is a prefix
and the type of the name
within the prefix
is of an access type, the prefix
is interpreted as an implicit_dereference
. Similarly, if the attribute_designator
is for an attribute defined for (at least some) functions, then the prefix
is never interpreted as a parameterless function_call
; otherwise (and for all range_attribute_reference
s and reduction_attribute_reference
s), if there is a prefix
and the prefix
consists of a name
that denotes a function, it is interpreted as a parameterless function_call
.
prefix
.prefix
of each attribute are defined as Name Resolution Rules for that attribute. If no such rules are defined, then no context at all should be used when resolving the prefix
. In particular, any knowledge about the kind of entities required must not be used for resolution unless that is required by Name Resolution Rules. This matters in obscure cases; for instance, given the following declarations: function Get_It return Integer is ... -- (1)
function Get_It return Some_Record_Type is ... -- (2)
attribute_reference
cannot be resolved and is illegal: if Get_It'Valid then
prefix
. The same would be true if (2) had been a procedure; even though the procedure does not denote an object, the attribute_reference
is still illegal. The expression
, if any, in an attribute_designator
or range_attribute_designator
is expected to be of any integer type.
Legality Rules
9The expression
, if any, in an attribute_designator
or range_attribute_designator
shall be static.
Static Semantics
10/4An attribute_reference
denotes a value, an object, a subprogram, or some other kind of program entity. Unless explicitly specified otherwise, for an attribute_reference
that denotes a value or an object, if its type is scalar, then its nominal subtype is the base subtype of the type; if its type is tagged, its nominal subtype is the first subtype of the type; otherwise, its nominal subtype is a subtype of the type without any constraint, null_exclusion
, or predicate. Similarly, unless explicitly specified otherwise, for an attribute_reference
that denotes a function, when its result type is scalar, its result subtype is the base subtype of the type, when its result type is tagged, the result subtype is the first subtype of the type, and when the result type is some other type, the result subtype is a subtype of the type without any constraint, null_exclusion
, or predicate.
attribute_reference
, or a call on an attribute_reference
, is used as the expression
of a case statement, due to the full coverage requirement based on the nominal subtype. For nondiscrete cases, we define the nominal subtype mainly for completeness. Implementations may specify otherwise for implementation-defined attribute functions.[A range_attribute_reference
X'Range(N) is equivalent to the range
X'First(N) .. X'Last(N), except that the prefix
is only evaluated once. Similarly, X'Range is equivalent to X'First .. X'Last, except that the prefix
is only evaluated once.]
Dynamic Semantics
12/5The evaluation of a range_attribute_reference
or an attribute_reference
that is not a reduction_attribute_reference
consists of the evaluation of the prefix
.[ The evaluation of a reduction_attribute_reference
is defined in 4.5.10.]
Implementation Permissions
13/5{8652/0015} An implementation may provide implementation-defined attributes; the identifier
for such an implementation-defined attribute shall differ from those of the language-defined attributes .
An implementation may extend the definition of a language-defined attribute by accepting uses of that attribute that would otherwise be illegal in the following cases:
- in order to support compatibility with a previous edition of of this Reference Manual; or
- in the case of a language-defined attribute whose
prefix
is required by this document to be a floating point subtype, an implementation may accept anattribute_reference
whoseprefix
is a fixed point subtype[; the semantics of such anattribute_reference
are implementation defined.]
name
in a prefix
of an attribute_reference
(or a range_attribute_reference
) has to be resolved without using any context. However, in the case of the Access attribute, the expected type for the attribute_reference
has to be a single access type, and the resolution of the name
can use the fact that the type of the object or the profile of the callable entity denoted by the prefix
has to match the designated type or be type conformant with the designated profile of the access type. prefix
of an attribute_reference
. In the special case of 'Access, there is an “expected type” or “expected profile” for the prefix
. Examples
19Examples of attributes:
Color'First -- minimum value of the enumeration type Color (see 3.5.1)
Rainbow'Base'First -- same as Color'First (see 3.5.1)
Real'Digits -- precision of the type Real (see 3.5.7)
Board'Last(2) -- upper bound of the second dimension of Board (see 3.6.1)
Board'Range(1) -- index range of the first dimension of Board (see 3.6.1)
Pool(K)'Terminated -- True if task Pool(K) is terminated (see 9.1)
Date'Size -- number of bits for records of type Date (see 3.8)
Message'Address -- address of the record variable Message (see 3.7.1)
Extensions to Ada 83
expression
of an attribute designator, not just a value of universal_integer. The preference rules ensure upward compatibility. Wording Changes from Ada 83
attribute_reference
rather than simply "attribute" to avoid confusing the name of something with the thing itself.attribute_reference
now uses identifier
instead of simple_name
, because attribute identifier
s are not required to follow the normal visibility rules.attribute_reference
from range_attribute_reference
, and enumerate the reserved words that are legal attribute or range attribute designators. We do this because identifier
no longer includes reserved words.Wording Changes from Ada 95
Wording Changes from Ada 2005
attribute_reference
to close a minor language hole. Wording Changes from Ada 2012
attribute_reference
for an object; that is used elsewhere in this standard.reduction_attribute_reference
and cleaned up the rules here to avoid trampling the definition of those in 4.5.10.4.1.5 User-Defined References
Static Semantics
1/3Given a discriminated type T, the following type-related operational aspect may be specified:
Implicit_Dereference
- This aspect is specified by a
name
that denotes an access discriminant declared for the type T.
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.]
Syntax
5/3generalized_reference
::=
reference_object_name
Name Resolution Rules
6/3The expected type for the reference_object_name
in a generalized_reference
is any reference type.
Static Semantics
6.1/4The Implicit_Dereference aspect is nonoverridable (see 13.1.1).
A generalized_reference
denotes a view equivalent to that of a dereference of the reference discriminant of the reference object.
Given a reference type T, the Implicit_Dereference aspect is inherited by descendants of type T if not overridden [(which is only permitted if confirming)]. 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
9/3The 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
10/5Examples of the specification and use of generalized references:
type Barrel is tagged ... -- holds objects of type Element
12/3type 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.
13/3function Find (B : aliased in out Barrel; Key : String) return Ref_Element;
-- Returns a reference to an element of a barrel.
14/3B: aliased Barrel;
15/3...
16/3Find (B, "grape") := Element'(...); -- Assign through a reference.
17/3-- This is equivalent to:
Find (B, "grape").Data.all := Element'(...);
Extensions to Ada 2005
Incompatibilities With Ada 2012
4.1.6 User-Defined Indexing
Static Semantics
1/3Given a tagged type T, the following type-related, operational aspects may be specified:
Constant_Indexing
- This aspect shall be specified by a
name
that denotes one or more functions declared immediately within the same declaration list in which T, or the declaration completed by T, is declared. All such functions shall have at least two parameters, the first of which is of type T or T'Class, or is an access-to-constant parameter with designated type T or T'Class.
indexed_component
s.Variable_Indexing
- This aspect shall be specified by a
name
that denotes one or more functions declared immediately within the same declaration list in which T, or the declaration completed by T, is declared. All such functions shall have at least two parameters, the first of which is of type T or T'Class, or is an access parameter with designated type T or T'Class. All such functions shall have a return type that is a reference type (see 4.1.5), whose reference discriminant is of an access-to-variable type.
indexed_component
s.These aspects are inherited by descendants of T (including the class-wide type T'Class).
An indexable container type is (a view of) a tagged type with at least one of the aspects Constant_Indexing or Variable_Indexing specified. An indexable container object is an object of an indexable container type. [A generalized_indexing
is a name
that denotes the result of calling a function named by a Constant_Indexing or Variable_Indexing aspect.]
The Constant_Indexing and Variable_Indexing aspects are nonoverridable (see 13.1.1).
Legality Rules
7/5If an ancestor of a type T is an indexable container type, then any explicit specification of the Constant_Indexing or Variable_Indexing aspects shall be confirming; that is, the specified name
shall match the inherited aspect (see 13.1.1).
Paragraphs 7 through 8 were deleted.
In addition to the places where Legality Rules normally apply (see 12.3), this rule applies also in the private part of an instance of a generic unit.
A generalized_indexing
is illegal if the equivalent prefixed view (see below) is illegal.
Syntax
11/3generalized_indexing
::=
indexable_container_object_prefix
actual_parameter_part
Name Resolution Rules
12/3The expected type for the indexable_container_object_prefix
of a generalized_indexing
is any indexable container type.
prefix
can be an implicit_dereference
(see 4.1), so an access-to-indexable_container_object can be the prefix (English meaning!) of a generalized_indexing
. If the Constant_Indexing aspect is specified for the type of the indexable_container_object_prefix
of a generalized_indexing
, then the generalized_indexing
is interpreted as a constant indexing under the following circumstances:
- when the Variable_Indexing aspect is not specified for the type of the indexable_container_object_
prefix
; 15/3 - when the indexable_container_object_
prefix
denotes a constant; 16/3 - when the
generalized_indexing
is used within aprimary
where aname
denoting a constant is permitted.
name
in the LHS of an assignment (not inside a primary
), nor for the name
used for an out or in out parameter (not allowed to be a constant), nor for the name
in an object renaming (not inside a primary), unless there is no Variable_Indexing aspect defined. Otherwise, the generalized_indexing
is interpreted as a variable indexing.
When a generalized_indexing
is interpreted as a constant (or variable) indexing, it is equivalent to a call on a prefixed view of one of the functions named by the Constant_Indexing (or Variable_Indexing) aspect of the type of the indexable_container_object_prefix
with the given actual_parameter_part
, and with the indexable_container_object_prefix
as the prefix
of the prefixed view.
generalized_indexing
is equivalent to:indexable_container_object_prefix.Indexing actual_parameter_part
Examples
20/5Examples of the specification and use of generalized indexing:
type Indexed_Barrel is tagged ...
with Variable_Indexing => Find;
-- Indexed_Barrel is an indexable container type,
-- Find is the generalized indexing operation.
22/3function Find (B : aliased in out Indexed_Barrel; Key : String) return Ref_Element;
-- Return a reference to an element of a barrel (see 4.1.5).
23/3IB: aliased Indexed_Barrel;
24/3-- All of the following calls are then equivalent:
Find (IB,"pear").Data.all := Element'(...); -- Traditional call
IB.Find ("pear").Data.all := Element'(...); -- Call of prefixed view
IB.Find ("pear") := Element'(...); -- Implicit dereference (see 4.1.5)
IB ("pear") := Element'(...); -- Implicit indexing and dereference
IB ("pear").Data.all := Element'(...); -- Implicit indexing only
Extensions to Ada 2005
generalized_indexing
syntax are new.