Annotated Ada Reference Manual (Ada 202y Draft 1)Legal Information
Contents   Index   References   Search   Previous   Next 

3.3 Objects and Named Numbers

1
[Objects are created at run time and contain a value of a given type. An object can be created and initialized as part of elaborating a declaration, evaluating an allocator, aggregate, or function_call, or passing a parameter by copy. Prior to reclaiming the storage for an object, it is finalized if necessary (see 7.6.1).]

Static Semantics

2
All of the following are objects: 
2.a/5
Term entry: object — entity that contains a value, and is either a constant or a variable
Note: An object is created by an object_declaration or by an allocator. A formal parameter is (a view of) an object. A subcomponent of an object is an object.
3
the entity declared by an object_declaration;
4
a formal parameter of a subprogram, entry, or generic subprogram;
5
a generic formal object;
6
a loop parameter;
6.1/5
{AI12-0061-1} the index parameter of an iterated_component_association;
6.2/5
{AI12-0308-1} the chunk parameter of a chunk_specification;
7
a choice parameter of an exception_handler;
8
an entry index of an entry_body;
9
the result of dereferencing an access-to-object value (see 4.1);
10/3
{AI95-00416-01} {AI05-0015-1} the return object of a function;
11
the result of evaluating an aggregate;
11.1/5
{AI05-0003-1} {AI12-0226-1} a value conversion or qualified_expression whose operand denotes an object;
12
a component, slice, or view conversion of another object. 
13/3
{AI05-0054-2} An object is either a constant object or a variable object. Similarly, a view of an object is either a constant or a variable. All views of a constant elementary object are constant. All views of a constant composite object are constant, except for parts that are of controlled or immutably limited types; variable views of those parts and their subcomponents may exist. In this sense, objects of controlled and immutably limited types are inherently mutable. A constant view of an object cannot be used to modify its value. The terms constant and variable by themselves refer to constant and variable views of objects.
13.a/5
Ramification: {AI12-0422-1} If some part of an object has a variable view, then the object as a whole has a variable view, and not all views of the object are constant. That's true even if only a subcomponent has a variable view. 
13.1/5
  {AI12-0422-1} A constant object is known to have no variable views if it does not have a part that is immutably limited, or of a controlled type, private type, or private extension.
13.b/5
Reason: {AI12-0422-1} This definition can be used in Legality Rules as it respects privacy. It is an assume-the-worst rule, as all private types and private extensions might have a controlled component. 
14
The value of an object is read when the value of any part of the object is evaluated, or when the value of an enclosing object is evaluated. The value of a variable is updated when an assignment is performed to any part of the variable, or when an assignment is performed to an enclosing object.
14.a
Ramification: Reading and updating are intended to include read/write references of any kind, even if they are not associated with the evaluation of a particular construct. Consider, for example, the expression “X.all(F)”, where X is an access-to-array object, and F is a function. The implementation is allowed to first evaluate “X.all” and then F. Finally, a read is performed to get the value of the F'th component of the array. Note that the array is not necessarily read as part of the evaluation of “X.all”. This is important, because if F were to free X using Unchecked_Deallocation, we want the execution of the final read to be erroneous. 
15/5
{AI12-0392-1} Whether a view of an object is constant or variable is determined by the definition of the view. The following (and no others) represent variables:
16/5
{AI12-0392-1} an object declared by an object_declaration without the reserved word constant;
16.a/2
To be honest: {AI95-00385-01} We mean the word constant as defined by the grammar for object_declaration, not some random word constant. Thus, 
16.b/2
X : access constant T;
16.c/2
is not a constant. 
17/5
{AI12-0392-1} a formal parameter of mode in out or out;
17.1/5
{AI12-0392-1} a generic formal object of mode in out;
18/5
{AI12-0392-1} a non-discriminant component of a variable;
18.a/5
Ramification: {AI12-0392-1} This includes both selected_components and indexed_components.
18.1/5
{AI12-0392-1} a slice of a variable;
18.2/5
{AI05-0262-1} {AI12-0392-1} a loop parameter that is specified to be a variable for a generalized loop (see 5.5.2);
19/5
{AI05-0262-1} {AI12-0392-1} a view conversion of a variable;
20/5
{AI12-0392-1} a dereference of an access-to-variable value;
20.1/5
{AI05-0015-1} {AI12-0392-1} the return object declared by an extended_return_statement without the reserved word constant;
21/5
{AI05-0015-1} {AI12-0392-1} the current instance of a type other than a protected type[, if the current instance is an object and not a value (see 8.6)];
21.a/5
Reason: {AI12-0392-1} We exclude current instances of protected types as they are protected units and the next bullet applies. 
21.b/5
Proof: {AI12-0392-1} This list of bullets only applies to views of objects, so current instances that are not objects are not considered here. 
21.1/5
This paragraph was deleted.{AI05-0003-1} {AI12-0392-1}
21.2/5
{AI05-0120-1} {AI12-0392-1} the current instance of a protected unit except within the body of a protected function of that protected unit, or within a function declared immediately within the body of the protected unit;
22/5
{AI12-0392-1} an attribute_reference where the attribute is defined to denote a variable (for example, the Storage_Pool attribute – see 13.11).
22.a/5
Ramification: {AI12-0392-1} In particular, this implies that the following are not variables: 
22.b/5
{AI12-0226-1} {AI12-0392-1} the result of evaluating a function_call, an aggregate, a value conversion, a qualified_expression, a conditional_expression, a raise_expression, or a parenthesized expression;
22.c/5
{AI12-0125-3} a target_name of an assignment_statement (see 5.2.1);
22.d/5
{AI12-0061-1} the index parameter of an iterated_component_association;
22.e/5
{AI12-0392-1} a choice parameter or entry index;
22.f/5
{AI12-0308-1} a chunk parameter of a chunk_specification.
22.g/5
{AI12-0392-1} This list of constructs that yield constant views is not exhaustive.
23/5
{AI05-0264-1} {AI12-0191-1} {AI12-0294-1} At the place where a view of an object is defined, a nominal subtype is associated with the view. The nominal type of a view is the type of the nominal subtype of the view. The object's actual subtype (that is, its subtype) can be more restrictive than the nominal subtype of the view; it always is more restrictive if the nominal subtype is an indefinite subtype. A subtype is an indefinite subtype if it is an unconstrained array subtype, or if it has unknown discriminants or unconstrained discriminants without defaults (see 3.7); otherwise, the subtype is a definite subtype [(all elementary subtypes are definite subtypes)]. [A class-wide subtype is defined to have unknown discriminants, and is therefore an indefinite subtype. An indefinite subtype does not by itself provide enough information to create an object; an additional constraint or explicit initialization expression is necessary (see 3.3.1). A component cannot have an indefinite nominal subtype.]
23.a/5
Term entry: nominal subtype — subtype specified when a view of an object is defined
23.1/3
  {AI05-0008-1} A view of a composite object is known to be constrained if:
23.2/5
{AI12-0401-1} its nominal subtype is constrained and not an untagged partial view, and it is neither a value conversion nor a qualified_expression; or
23.3/3
its nominal subtype is indefinite; or
23.4/3
{AI05-0008-1} {AI05-0093-1} its type is immutably limited (see 7.5); or
23.5/3
it is part of a stand-alone constant (including a generic formal object of mode in); or
23.6/3
it is part of a formal parameter of mode in; or
23.7/3
it is part of the object denoted by a function_call or aggregate; or
23.8/5
{AI12-0226-1} {AI12-0228-1} it is a value conversion or qualified_expression where the operand denotes a view of a composite object that is known to be constrained; or
23.9/5
{AI12-0228-1} it is part of a constant return object of an extended_return_statement; or
23.10/5
{AI05-0008-1} {AI05-0041-1} {AI12-0228-1} it is a dereference of a pool-specific access type, and there is no ancestor of its type that has a constrained partial view.
23.b/3
Discussion: We do not include dereferences of general access types because they might denote stand-alone aliased unconstrained variables. That's true even for access-to-constant types (the denoted object does not have to be a constant).
23.c/5
{AI05-0005-1} {AI05-0008-1} {AI12-0228-1} We don't mention view conversions as there are no mutable tagged types (discriminant defaults are allowed only if the type is immutably limited), so all tagged view conversions are either of an indefinite type (if it has discriminants without defaults), an immutably limited type (if the discriminants do have defaults), or constrained (if there are no discriminants). This matches the first three bullets here, so all tagged view conversions are known to be constrained without needing to mention them explicitly. Untagged view conversions only can occur in parameter passing (as actuals to in out or out parameters), and "known to be constrained" is not used there.
23.d/5
{AI12-0228-1} We don't need to mention the current instance of a (sub)type, either. If a current instance of a type or subtype appears in an aspect specification, it represents a value, so whether or not it is known to be constrained is irrelevant (the term is only defined for composite objects). Otherwise, the current instance of a type can only be used in an immutably limited type, so all such instances are known to be constrained by the third bullet. 
23.11/5
   {AI05-0008-1} {AI05-0041-1} {AI12-0228-1} For the purposes of determining within a generic body whether an object is known to be constrained: 
23.12/5
if a subtype is a descendant of an untagged generic formal private or derived type, and the subtype is not an unconstrained array subtype, it is not considered indefinite and is considered to have a constrained partial view;
23.13/5
if a subtype is a descendant of a formal access type, it is not considered pool-specific.
24
A named number provides a name for a numeric value known at compile time. It is declared by a number_declaration.
25
NOTE 1   A constant cannot be the target of an assignment operation, nor be passed as an in out or out parameter, between its initialization and finalization, if any.
25.1/3
NOTE 2   {AI05-0054-2} The value of a constant object cannot be changed after its initialization, except in some cases where the object has a controlled or immutably limited part (see 7.5, 7.6, and 13.9.1).
26/3
NOTE 3   {AI05-0264-1} The nominal and actual subtypes of an elementary object are always the same. For a discriminated or array object, if the nominal subtype is constrained, then so is the actual subtype. 

Extensions to Ada 83

26.a
There are additional kinds of objects (choice parameters and entry indices of entry bodies).
26.b
The result of a function and of evaluating an aggregate are considered (constant) objects. This is necessary to explain the action of finalization on such things. Because a function_call is also syntactically a name (see 4.1), the result of a function_call can be renamed, thereby allowing repeated use of the result without calling the function again. 

Wording Changes from Ada 83

26.c/3
{AI05-0299-1} This subclause now follows the subclauses on types and subtypes, to cut down on the number of forward references.
26.d
The term nominal subtype is new. It is used to distinguish what is known at compile time about an object's constraint, versus what its "true" run-time constraint is.
26.e
The terms definite and indefinite (which apply to subtypes) are new. They are used to aid in the description of generic formal type matching, and to specify when an explicit initial value is required in an object_declaration.
26.f
We have moved the syntax for object_declaration and number_declaration down into their respective subclauses, to keep the syntax close to the description of the associated semantics.
26.g
We talk about variables and constants here, since the discussion is not specific to object_declarations, and it seems better to have the list of the kinds of constants juxtaposed with the kinds of objects.
26.h
We no longer talk about indirect updating due to parameter passing. Parameter passing is handled in 6.2 and 6.4.1 in a way that there is no need to mention it here in the definition of read and update. Reading and updating now includes the case of evaluating or assigning to an enclosing object. 

Wording Changes from Ada 95

26.i/2
{AI95-00416-01} Clarified that the return object is the object created by a function call. 

Extensions to Ada 2005

26.j/3
{AI05-0015-1} Added wording to allow return objects to be declared as constants, and corrected the definition of return objects as objects.

Wording Changes from Ada 2005

26.k/3
{AI05-0008-1} {AI05-0041-1} {AI05-0093-1} Correction: Added a definition of known to be constrained, for use in other rules.
26.l/3
{AI05-0054-2} Correction: We now recognize the fact that not all declared constant objects are immutable; for those that a variable view can be constructed, they can be changed via that view.
26.m/3
{AI05-0120-1} Correction: Added the current instance of a protected object to the list of constant views; since the list claims to include all possibilities, it had better include that one.
26.n/3
{AI05-0003-1} The result of a qualified_expression is defined to be a constant view and is defined to be an object if the operand of the qualified_expression is an object. These definitions, combined with some grammar changes, allow qualified_expressions to be used in more places. See 4.1 for details.

Incompatibilities With Ada 2012

26.o/5
{AI12-0401-1} Correction: Corrected the definition of “known to be constrained” so that the status of the operand of value conversions and qualified_expressions is always used to determine whether the property exists. As the rules are ored together, a value conversion or qualified_expression with a constrained nominal subtype would have always met the requirements in Ada 2012, regardless of the operand. This change will mean that some conversions or qualifications (mostly of variables) will no longer be considered “known to be constrained” and therefore 'Access and renaming of such prefixes will now be illegal. This is necessary to meet the design goal that subsequent execution cannot cause a renaming or 'Access to cause erroneous execution.

Extensions to Ada 2012

26.p/5
{AI12-0228-1} Correction: A qualified_expression of an object that is known to be constrained is now also known to be constrained. This allows qualification to be used to disambiguate a function call used as a prefix in a renaming_declaration without making the renaming_declaration illegal.
26.q/5
{AI12-0226-1} A value conversion of an object is an object; this makes value conversions consistent with qualified expressions. 

Wording Changes from Ada 2012

26.r/5
{AI12-0392-1} Correction: Changed from a list of constants to a list of variables. This makes the default to be a constant, which is the more common case, and eliminates issues caused by omissions from the list (such as parenthesized expressions).
26.s/5
{AI12-0422-1} Added the term “known to have no variable views” in order to have a definition that can be used in Legality Rules without breaking privacy. 

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