Ada Reference Manual (Ada 2022) — Legal Information

# 6.1.2 The Global and Global'Class Aspects

1/5
The Global and Global'Class aspects of a program unit are used to identify the objects global to the unit that can be read or written during its execution.

#### Syntax

2/5
global_aspect_definition ::=
null
| Unspecified
| global_mode global_designator
| (global_aspect_element{; global_aspect_element})
3/5
global_aspect_element ::=
global_mode global_set
| global_mode all
| global_mode synchronized
4/5
global_mode ::=
basic_global_mode
| extended_global_mode
5/5
basic_global_mode ::= in | in out | out
6/5
global_set ::= global_name {, global_name}
7/5
global_designator ::= all | synchronized | global_name
8/5
global_name ::= object_name | package_name

#### Name Resolution Rules

9/5
A global_name shall resolve to statically name an object or a package (including a limited view of a package).

#### Static Semantics

10/5
For a subprogram, an entry, an access-to-subprogram type, a task unit, a protected unit, or a library package or generic library package, the following language-defined aspect may be specified with an aspect_specification (see 13.1.1):
11/5
Global
The Global aspect shall be specified with a global_aspect_definition.
12/5
The Global aspect identifies the set of variables (which, for the purposes of this clause, includes all constants except those which are known to have no variable views (see 3.3)) that are global to a callable entity or task body, and that are read or updated as part of the execution of the callable entity or task body. If specified for a protected unit, it refers to all of the protected operations of the protected unit. Constants of any type may also be mentioned in a Global aspect.
13/5
If not specified or otherwise defined below, the aspect defaults to the Global aspect for the enclosing library unit if the entity is declared at library level, and to Unspecified otherwise. If not specified for a library unit, the aspect defaults to `Global => null` for a library unit that is declared Pure, and to `Global => Unspecified` otherwise.
14/5
For a dispatching subprogram, the following language-defined aspect may be specified with an aspect_specification (see 13.1.1):
15/5
Global'Class
The Global'Class aspect shall be specified with a global_aspect_definition. This aspect identifies an upper bound on the set of variables global to a dispatching operation that can be read or updated as a result of a dispatching call on the operation. If not specified, the aspect defaults to the Global aspect for the dispatching subprogram.
16/5
Together, we refer to the Global and Global'Class aspects as global aspects.
17/5
A global_aspect_definition defines the Global or Global'Class aspect of some entity. The Global aspect identifies the sets of global variables that can be read, written, or modified as a side effect of executing the operation(s) associated with the entity. The Global'Class aspect associated with a dispatching operation of type T represents a restriction on the Global aspect on a corresponding operation of any descendant of type T.
18/5
The Global aspect for a callable entity defines the global variables that can be referenced as part of a call on the entity, including any assertion expressions that apply to the call (even if not enabled), such as preconditions, postconditions, predicates, and type invariants.
19/5
The Global aspect for an access-to-subprogram object (or subtype) identifies the global variables that can be referenced when calling via the object (or any object of that subtype) including assertion expressions that apply.
20/5
For a predefined operator of an elementary type, the function representing an enumeration literal, or any other static function (see 4.9), the Global aspect is null. For a predefined operator of a composite type, the Global aspect of the operator defaults to that of the enclosing library unit (unless a Global aspect is specified for the type — see H.7).
21/5
The following is defined in terms of operations that are performed by or on behalf of an entity. The rules on operations apply to the entity(s) associated with those operations.
22/5
The global variables associated with any global_mode can be read as a side effect of an operation. The in out and out global_modes together identify the set of global variables that can be updated as a side effect of an operation. Creating an access-to-variable value that designates an object is considered an update of the designated object, and creating an access-to-constant value that designates an object is considered a read of the designated object.
23/5
The overall set of objects associated with each global_mode includes all objects identified for the mode in the global_aspect_definition.
24/5
A global_set identifies a global variable set as follows:
25/5
all identifies the set of all global variables;
26/5
synchronized identifies the set of all synchronized variables (see 9.10), as well as variables of a composite type all of whose non-discriminant subcomponents are synchronized;
27/5
global_name{, global_name} identifies the union of the sets of variables identified by the global_names in the list, for the following forms of global_name:
28/5
object_name identifies the specified global variable (or constant);
29/5
package_name identifies the set of all variables declared in the private part or body of the package, or anywhere within a private descendant of the package.

#### Legality Rules

30/5
Within a global_aspect_definition, a given global_mode shall be specified at most once. Similarly, within a global_aspect_definition, a given entity shall be named at most once by a global_name.
31/5
If an entity (other than a library package or generic library package) has a Global aspect other than Unspecified or in out all, then the associated operation(s) shall read only those variables global to the entity that are within the global variable set associated with the in, in out, or out global_modes, and the operation(s) shall update only those variables global to the entity that are within the global variable set associated with either the in out or out global_modes. In the absence of the No_Hidden_Indirect_Globals restriction (see H.4), this ignores objects reached via a dereference of an access value. The above rule includes any possible Global effects of calls occurring during the execution of the operation, except for the following excluded calls:
32/5
calls to formal subprograms;
33/5
calls associated with operations on formal subtypes;
34/5
calls through formal objects of an access-to-subprogram type;
35/5
calls through access-to-subprogram parameters;
36/5
calls on operations with Global aspect Unspecified.
37/5
The possible Global effects of these excluded calls (other than those that are Unspecified) are taken into account by the caller of the original operation, by presuming they occur at least once during its execution. For calls that are not excluded, the possible Global effects of the call are those permitted by the Global aspect of the associated entity, or by its Global'Class aspect if a dispatching call.
38/5
If a Global aspect other than Unspecified or in out all applies to an access-to-subprogram type, then the prefix of an Access attribute_reference producing a value of such a type shall denote a subprogram whose Global aspect is not Unspecified and is covered by that of the result type, where a global aspect G1 is covered by a global aspect G2 if the set of variables that G1 identifies as readable or updatable is a subset of the corresponding set for G2. Similarly on a conversion to such a type, the operand shall be of a named access-to-subprogram type whose Global aspect is covered by that of the target type.
39/5
If an implementation-defined global_mode applies to a given set of variables, an implementation-defined rule determines what sort of references to them are permitted.
40/5
For a subprogram that is a dispatching operation of a tagged type T, each mode of its Global aspect shall identify a subset of the variables identified by the corresponding mode, or by the in out mode, of the Global'Class aspect of a corresponding dispatching subprogram of any ancestor of T, unless the aspect of that ancestor is Unspecified.

#### Implementation Permissions

41/5
An implementation can allow some references to a constant object which are not accounted for by the Global or Global'Class aspect when it is considered a variable in the above rules, if the implementation can determine that the object is in fact immutable.
42/5
Implementations may perform additional checks on calls to operations with an Unspecified Global aspect to ensure that they do not violate any limitations associated with the point of call.
43/5
Implementations may extend the syntax or semantics of the Global aspect in an implementation-defined manner; for example, supporting additional global_modes.
44/5
NOTE For an example of the use of these aspects, see the Vector container definition in A.18.2.

Ada 2005 and 2012 Editions sponsored in part by Ada-Europe