Ada Reference Manual (Ada 2022)
8.5.1 Object Renaming Declarations
An object_renaming_declaration is used to rename an object or value.
Syntax
object_renaming_declaration ::=
defining_identifier [: [null_exclusion] subtype_mark] renames object_name
[aspect_specification];
| defining_identifier : access_definition renames object_name
[aspect_specification];
defining_identifier [: [null_exclusion] subtype_mark] renames object_name
[aspect_specification];
| defining_identifier : access_definition renames object_name
[aspect_specification];
Name Resolution Rules
The type of the object_name shall resolve to the type determined by the subtype_mark, if present. If no subtype_mark or access_definition is present, the expected type of the object_name is any type.
In the case where the type is defined by an access_definition, the type of the object_name shall resolve to an anonymous access type. If the anonymous access type is an access-to-object type, the type of the object_name shall have the same designated type as that of the access_definition. If the anonymous access type is an access-to-subprogram type, the type of the object_name shall have a designated profile that is type conformant with that of the access_definition.
Legality Rules
The renamed entity shall be an object or value.
In the case where the type is defined by an access_definition, the type of the renamed entity and the type defined by the access_definition:
- shall both be access-to-object types with statically matching designated subtypes and with both or neither being access-to-constant types; or
- shall both be access-to-subprogram types with subtype conformant designated profiles.
For an object_renaming_declaration with a null_exclusion or an access_definition that has a null_exclusion, the subtype of the object_name shall exclude null. In addition, if the object_renaming_declaration occurs within the body of a generic unit G or within the body of a generic unit declared within the declarative region of generic unit G, then:
- if the object_name statically denotes a generic formal object of mode in out of G, then the declaration of that object shall have a null_exclusion;
- if the object_name statically denotes a call of a generic formal function of G, then the declaration of the result of that function shall have a null_exclusion.
In the case where the object_name is a qualified_expression with a nominal subtype S and whose expression is a name that denotes an object Q:
- if S is an elementary subtype, then:
Q shall be a constant other than a dereference of an access type; or
the nominal subtype of Q shall be statically compatible with S; or
S shall statically match the base subtype of its type if scalar, or the first subtype of its type if an access type.
- if S is a composite subtype, then Q shall be known to be constrained or S shall statically match the first subtype of its type.
The renamed entity shall not be a subcomponent that depends on discriminants of an object whose nominal subtype is unconstrained unless the object is known to be constrained. A slice of an array shall not be renamed if this restriction disallows renaming of the array.
In addition to the places where Legality Rules normally apply (see 12.3), these rules also apply in the private part of an instance of a generic unit.
Static Semantics
An object_renaming_declaration declares a new view of the renamed entity whose properties are identical to those of the renamed view. Thus, the properties of the renamed entity are not affected by the renaming_declaration. In particular, its nominal subtype, whether it is a value or an object, its value if it is an object, and whether or not it is a constant, are unaffected; similarly, the constraints and other properties of its nominal subtype are not affected by renaming (any constraint implied by the subtype_mark or access_definition of the object_renaming_declaration is ignored).
Examples
Example of renaming an object:
Example of renaming a value:
Uno renames One; -- see 3.3.2