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:
a formal parameter of a subprogram, entry, or generic
subprogram;
a generic formal object;
a loop parameter;
the result of dereferencing an access-to-object
value (see
4.1);
the return object of a function;
a component, slice, or view conversion of another
object.
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.
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.
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.
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:
a formal parameter of mode in out or out;
a generic formal object of mode in out;
a non-discriminant component of a variable;
a loop parameter that is specified to be a variable
for a generalized loop (see
5.5.2);
a view conversion of a variable;
a dereference of an access-to-variable value;
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);
This paragraph
was deleted.
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;
an
attribute_reference
where the attribute is defined to denote a variable (for example, the
Storage_Pool attribute – see
13.11).
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.
A view of a composite
object is
known to be constrained if:
its nominal subtype is constrained and not an untagged
partial view, and it is neither a value conversion nor a
qualified_expression;
or
its nominal subtype is indefinite; or
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 a value conversion or
qualified_expression
where the operand denotes a view of a composite object that is known
to be constrained; or
it is a dereference of a pool-specific access type,
and there is no ancestor of its type that has a constrained partial view.
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.
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.
NOTE 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).
NOTE 3 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.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe