Ada Conformity Assessment Authority      Home Conformity Assessment   Test Suite ARGAda Standard
Annotated Ada Reference ManualLegal Information
Contents   Index   References   Search   Previous   Next 

3.3 Objects and Named Numbers

[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

All of the following are objects: 
Glossary entry: An object is either a constant or a variable. An object contains a value. 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.
the entity declared by an object_declaration;
a formal parameter of a subprogram, entry, or generic subprogram;
a generic formal object;
a loop parameter;
a choice parameter of an exception_handler;
an entry index of an entry_body;
the result of dereferencing an access-to-object value (see 4.1);
{AI95-00416-01} {AI05-0015-1} the return object of a function;
the result of evaluating an aggregate;
{AI05-0003-1} a qualified_expression whose operand denotes an object;
a component, slice, or view conversion of another object. 
 {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.
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.
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. 
Whether a view of an object is constant or variable is determined by the definition of the view. The following (and no others) represent constants: 
an object declared by an object_declaration with the reserved word constant;
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, 
X : access constant T;
is not a constant. 
a formal parameter or generic formal object of mode in;
a discriminant;
{AI05-0262-1} a loop parameter unless specified to be a variable for a generalized loop (see 5.5.2);
{AI05-0262-1} a choice parameter or entry index;
the dereference of an access-to-constant value;
{AI05-0015-1} the return object declared by an extended_return_statement with the reserved word constant;
{AI05-0015-1} the object denoted by a function_call or an aggregate;
{AI05-0003-1} the result of evaluating a qualified_expression;
{AI05-0120-1} within the body of a protected function (or a function declared immediately within a protected_body), the current instance of the enclosing protected unit;
a selected_component, indexed_component, slice, or view conversion of a constant. 
 {AI05-0264-1} At the place where a view of an object is defined, a nominal subtype is associated with 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 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.]
   {AI05-0008-1} A view of a composite object is known to be constrained if:
its nominal subtype is constrained, and is not an untagged partial view; or
its nominal subtype is indefinite; or
{AI05-0008-1} {AI05-0093-1} its type is immutably limited (see 7.5); or
it is part of a stand-alone constant (including a generic formal object of mode in); or
it is part of a formal parameter of mode in; or
it is part of the object denoted by a function_call or aggregate; or
it is part of a constant return object of an extended_return_statement; or
{AI05-0008-1} {AI05-0041-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.
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).
{AI05-0005-1} {AI05-0008-1} There are other cases that could have been included in this definition (view conversions, the current instance of a type, objects of a formal discriminated private type), but these are not relevant to the places this term is used, so they were not included. If this term is used in additional places, the definition should be checked to see if any of these additional cases are relevant and appropriate wording added if necessary. 
    {AI05-0008-1} {AI05-0041-1} For the purposes of determining within a generic body whether an object is known to be constrained: 
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;
if a subtype is a descendant of a formal access type, it is not considered pool-specific.
A named number provides a name for a numeric value known at compile time. It is declared by a number_declaration.
10  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.
11  {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).
12  {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

There are additional kinds of objects (choice parameters and entry indices of entry bodies).
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

{AI05-0299-1} This subclause now follows the subclauses on types and subtypes, to cut down on the number of forward references.
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.
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.
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.
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.
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

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

Extensions to Ada 2005

{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

{AI05-0008-1} {AI05-0041-1} {AI05-0093-1} Correction: Added a definition of known to be constrained, for use in other rules.
{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.
{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.
{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.

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