Contents Index Search Previous Next

1

Certain expressions of a scalar or string type
are defined to be static. Similarly, certain discrete ranges are defined
to be static, and certain scalar and string subtypes are defined to be
static subtypes. [{*static*} *Static*
means determinable at compile time, using the declared properties or
values of the program entities.] {*constant: See also
static*}

1.a

1.b

For an expression to be static,
it has to be calculable at compile time.

1.c

Only scalar and string expressions
are static.

1.d

To be static, an expression
cannot have any nonscalar, nonstring subexpressions (though it can have
nonscalar constituent names). A
static scalar expression cannot have any nonscalar subexpressions. There
is one exception -- a membership test for a string subtype can be static,
and the result is scalar, even though a subexpression is nonscalar.

1.e

The rules for evaluating static
expressions are designed to maximize portability of static calculations.

2

{*static
(expression)*} A static expression is [a
scalar or string expression that is] one of the following:

3

- a numeric_literal;

3.a

4

- a string_literal of a static string subtype;

4.a

5

- a name that denotes the declaration of a named number or a static constant;

5.a

6

- a function_call
whose
*function_*name or*function_*prefix statically denotes a static function, and whose actual parameters, if any (whether given explicitly or by default), are all static expressions;

6.a

7

- an attribute_reference that denotes a scalar value, and whose prefix denotes a static scalar subtype;

7.a

7.b

An implementation may define
the staticness and other properties of implementation-defined attributes.

8

- an attribute_reference whose prefix statically denotes a statically constrained array object or array subtype, and whose attribute_designator is First, Last, or Length, with an optional dimension;

9

- a type_conversion whose subtype_mark denotes a static scalar subtype, and whose operand is a static expression;

10

- a qualified_expression whose subtype_mark denotes a static [(scalar or string)] subtype, and whose operand is a static expression;

10.a

10.b

11

- a membership test whose simple_expression is a static expression, and whose range is a static range or whose subtype_mark denotes a static [(scalar or string)] subtype;

11.a

12

- a short-circuit control form both of whose relations are static expressions;

13

- a static expression enclosed in parentheses.

13.a

13.b

14

15

- It is a direct_name, expanded name, or character_literal, and it denotes a declaration other than a renaming_declaration; or

16

- It is an attribute_reference whose prefix statically denotes some entity; or

17

- It denotes a renaming_declaration with a name that statically denotes the renamed entity.

17.a

18

18.a

19

- a predefined operator whose parameter and result types are all scalar types none of which are descendants of formal scalar types;

20

- a predefined concatenation operator whose result type is a string type;

21

- an enumeration literal;

22

- a language-defined attribute that is a function, if the prefix denotes a static scalar subtype, and if the parameter and result types are scalar.

23

In any case, a generic formal subprogram is not
a static function.

24

{*static (constant)*}
A *static constant* is a constant view declared
by a full constant declaration or an object_renaming_declaration
with a static nominal subtype, having a value defined by a static scalar
expression or by a static string expression whose value has a length
not exceeding the maximum length of a string_literal
in the implementation.

24.a

24.b

24.c

The length we're talking about
is the maximum number of characters in the value represented by a string_literal,
not the number of characters in the source representation; the quotes
don't count.

25

{*static (range)*}
A *static range* is a range
whose bounds are static expressions, [or a range_attribute_reference
that is equivalent to such a range.]
{*static (discrete_range)*} A
*static discrete_range* is
one that is a static range or is a subtype_indication
that defines a static scalar subtype. The base range of a scalar type
is a static range, unless the type is a descendant of a formal scalar
type.

26

{*static (subtype)*}
A *static subtype* is either a *static scalar
subtype* or a *static string subtype*. {*static
(scalar subtype)*} A static scalar subtype
is an unconstrained scalar subtype whose type is not a descendant of
a formal scalar type, or a constrained scalar subtype formed by imposing
a compatible static constraint on a static scalar subtype. {*static
(string subtype)*} A static string subtype
is an unconstrained string subtype whose index subtype and component
subtype are static (and whose type is not a descendant of a formal array
type), or a constrained string subtype formed by imposing a compatible
static constraint on a static string subtype. In any case, the subtype
of a generic formal object of mode **in out**, and the result subtype
of a generic formal function, are not static.

26.a

26.b

26.c

26.d

F :

26.e

--

26.f

26.g

The case_statement
is illegal, because the subtype of F is not static, so the choices have
to cover all values of Integer, not just those in the range 1..10. A
similar issue arises for generic formal functions, now that function
calls are object names.

27

28

- A null constraint is always static;

29

- {
*static (range constraint)*} {*static (digits constraint)*} {*static (delta constraint)*} A scalar constraint is static if it has no range_constraint, or one with a static range;

30

- {
*static (index constraint)*} An index constraint is static if each discrete_range is static, and each index subtype of the corresponding array type is static;

31

- {
*static (discriminant constraint)*} A discriminant constraint is static if each expression of the constraint is static, and the subtype of each discriminant is static.

32

{*statically (constrained)*}
A subtype is *statically constrained* if it
is constrained, and its constraint is static. An object is *statically
constrained* if its nominal subtype is statically constrained, or
if it is a static string constant.

33

A static expression
is evaluated at compile time except when it is part of the right operand
of a static short-circuit control form whose value is determined by its
left operand. This evaluation is performed exactly, without performing
Overflow_Checks. For a static expression that is evaluated:

34

- The expression is illegal if its evaluation fails a language-defined check other than Overflow_Check.

35

- If the expression is not part of a larger static expression, then its value shall be within the base range of its expected type. Otherwise, the value may be arbitrarily large or small.

36

- If the expression is of type
*universal_real*and its expected type is a decimal fixed point type, then its value shall be a multiple of the*small*of the decimal type.

36.a

37

The last two restrictions above do not apply
if the expected type is a descendant of a formal scalar type (or a corresponding
actual type in an instance).

37.a

37.b

Short-circuit
control forms are a special case:

37.c

X:

37.d

The declaration of X is legal,
since the divide-by-zero part of the expression is not evaluated. X is
a static constant equal to True.

37.e

38

For a real static expression that is not part
of a larger static expression, and whose expected type is not a descendant
of a formal scalar type, the implementation shall round or truncate the
value (according to the Machine_Rounds attribute of the expected type)
to the nearest machine number of the expected type; if the value is exactly
half-way between two machine numbers, any rounding shall be performed
away from zero. If the expected type is a descendant of a formal scalar
type, no special rounding or truncating is required -- normal accuracy
rules apply (see Annex G).

38.a

38.b

When the expected type is a
descendant of a formal floating point type, extended precision (beyond
that of the machine numbers) can be retained when evaluating a static
expression, to ease code sharing for generic instantiations. For similar
reasons, normal (nondeterministic) rounding or truncating rules apply
for descendants of a formal fixed point type.

38.c

38.d

Note that the only values of
a fixed point type are the multiples of the small, so a static conversion
to a fixed-point type, or division by an integer, must do truncation
to a multiple of small. It is not correct for the implementation to do
all static calculations in infinite precision.

NOTES

39

28 An expression can be
static even if it occurs in a context where staticness is not required.

39.a

39.b

39.c

The expression is static, which
means that the value of X must be exactly 1.0, independent of the accuracy
or range of the run-time floating point implementation.

39.d

The following kinds of expressions
are never static: explicit_dereference,
indexed_component, slice,
**null**, aggregate, allocator.

40

29 A static (or run-time)
type_conversion from a real type
to an integer type performs rounding. If the operand value is exactly
half-way between two integers, the rounding is performed away from zero.

40.a

40.b

40.c

41

42

43

Mega :

Long :

44

Deg_To_Rad :

Rad_To_Deg :

44.a

{*extensions to Ada 83*}
The rules for static expressions and static subtypes
are generalized to allow more kinds of compile-time-known expressions
to be used where compile-time-known values are required, as follows:

44.b

- Membership tests and short-circuit control forms may appear in a static expression.

44.c

- The bounds and length of statically constrained array objects or subtypes are static.

44.d

- The Range attribute of a statically constrained array subtype or object gives a static range.

44.e

- A type_conversion is static if the subtype_mark denotes a static scalar subtype and the operand is a static expression.

44.f

- All numeric literals are now static, even if the expected type is a formal scalar type. This is useful in case_statements and variant_parts, which both now allow a value of a formal scalar type to control the selection, to ease conversion of a package into a generic package. Similarly, named array aggregates are also permitted for array types with an index type that is a formal scalar type.

44.g

The rules for the evaluation
of static expressions are revised to require exact evaluation at compile
time, and force a machine number result when crossing from the static
realm to the dynamic realm, to enhance portability and predictability.
Exact evaluation is not required for descendants of a formal scalar type,
to simplify generic code sharing and to avoid generic contract model
problems.

44.h

Static
expressions are legal even if an intermediate in the expression goes
outside the base range of the type. Therefore, the following will succeed
in Ada 95, whereas it might raise an exception in Ada 83:

44.i

I : Short_Int := -32_768;

44.j

This might raise an exception
in Ada 83 because "32_768" is out of range, even though "-32_768"
is not. In Ada 95, this will always succeed.

44.k

Certain expressions involving
string operations (in particular concatenation and membership tests)
are considered static in Ada 95.

44.l

The reason for this change is
to simplify the rule requiring compile-time-known string expressions
as the link name in an interfacing pragma, and to simplify the preelaborability
rules.

44.m

{*incompatibilities with Ada
83*} An Ada 83 program that uses an out-of-range
static value is illegal in Ada 95, unless the expression is part of a
larger static expression, or the expression is not evaluated due to being
on the right-hand side of a short-circuit control form.

44.n

This clause (and 4.5.5,
``Multiplying Operators'') subsumes the RM83
section on Universal Expressions.

44.o

The existence of static string
expressions necessitated changing the definition of static subtype to
include string subtypes. Most occurrences of "static subtype"
have been changed to "static scalar subtype", in order to preserve
the effect of the Ada 83 rules. This has the added benefit of clarifying
the difference between "static subtype" and "statically
constrained subtype", which has been a source of confusion. In cases
where we allow static string subtypes, we explicitly use phrases like
"static string subtype" or "static (scalar or string)
subtype", in order to clarify the meaning for those who have gotten
used to the Ada 83 terminology.

44.p

In
Ada 83, an expression was considered nonstatic if it raised an exception.
Thus, for example:

44.q

44.r

was illegal because 1/0 was
not static. In Ada 95, the above example is still illegal, but for a
different reason: 1/0 is static, but there's a separate rule forbidding
the exception raising.