6.8 Expression Functions
Syntax
Name Resolution Rules
Static Semantics
{
AI12-0075-1}
A potentially static expression is defined
in the same way as a static expression except that
a name denoting a formal
parameter of an expression function is a potentially static expression;
and
each use of “static
expression” in the definition of “static expression”
is replaced with a corresponding use of “potentially static expression”
in the definition of “potentially static expression”.
Discussion: These
uses occur in the definition of “static expression” in the
cases of function calls, type conversions, qualified expressions, membership
tests, short circuit control forms, conditional expressions, and parenthesized
expressions.
{
AI12-0075-1}
The following language-defined representation aspect
may be specified for an expression function:
Static
The type of aspect Static is Boolean. When aspect
Static is True for an expression function, the function is a static
expression function. If directly specified, the aspect_definition
shall be a static expression.
Aspect Description
for Static: Specifies
that an associated expression function can be used in static expressions.
The Static value for an inherited function is True
if some corresponding primitive function of the parent or progenitor
type is a static expression function; otherwise, if not directly specified,
the aspect is False.
{
AI12-0075-1}
[A static expression function is a static function;
see 4.9.]
Legality Rules
Ramification: This can only fail if the
discriminant is an access to a part of a nonaliased parameter, as there
can be no local declarations here.
Discussion: {
AI12-0005-1}
We don't need to repeat any of the other Legality Rules for return statements
since none of them can fail here: the implicit return statement has to
apply to this function (and isn't nested in something), there clearly
is a return statement in this function, and the static
class-wide classwide
accessibility check cannot fail as a tagged type cannot be declared locally
in an expression function.
is not a completion;
has an expression
that is a potentially static expression;
contains no calls to itself;
each parameter (if any) is
of mode in and is of a static subtype;
has a result subtype that
is a static subtype;
has no applicable precondition
or postcondition expression; and
{
AI12-0075-1}
{
AI12-0191-1}
for result type R, if the function is a
boundary entity for type R (see 7.3.2),
no type invariant applies to type R; if R has a component
type C, a similar rule applies to C.
Ramification: Since
a string subtype can be static, this allows an expression function of
a string type to be static.
Paragraph 6 was deleted.
Static Semantics
Dynamic Semantics
Discussion: The last sentence effectively
means that all of the dynamic wording in
6.5
applies as needed, and we don't have to repeat it here.
Examples
{
AI05-0177-1}
function Is_Origin (P :
in Point)
return Boolean
is --
see 3.9
(P.X = 0.0
and P.Y = 0.0);
Extensions to Ada 2005
{
AI05-0177-1}
Expression functions are new in Ada 2012.
Extensions to Ada 2012
{
AI12-0157-1}
Corrigendum: A aggregate
can directly be the return expression of an expression function. This
eliminates the double parentheses that otherwise would be necessary.
{
AI12-0075-1}
Aspect Static is new; it allows using suitable
expression functions in static expressions.
Wording Changes from Ada 2012
{
AI12-0408-1}
Clarified the term “expression function”
so it matches the meaning expected in 6.1.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe