As for the Java programming language, a method invocation expression is used to invoke a class or instance method. The XL programming language extends the semantics of method invocation expressions in several directions:
Depending on the context of the method invocation expression, there may be some implicit arguments for the invocation. These are specified by the available argument transformations of the context.
Generator method invocations are generator expressions whose evaluation results in a sequence of values.
Aggregate method invocations invoke aggregate methods repeatedly for each result of the sequential evaluation of its arguments or for each component of arrays and return a single result.
Filter method invocations invoke filter methods repeatedly for each result of the evaluation of generator expressions or for each component of arrays and are used to filter sequentially yielded results.
The Java Language Specification defines steps to determine the method that will be invoked by a method invocation expressions. The new features of the XL programming language modify these steps; the modifications are described in the chapter on signatures (Chapter 13, Signatures) and in the following.
In the context of a normal expression, a method invocation expression has four alternatives of argument transformations (Section 13.1, “Argument Transformations”):
The arguments are not transformed at all. The invocation uses the explicitly specified argument expressions as it is known from the Java programming language.
The invocation has an implicit consumer argument as first actual argument. Then the invocation is a generator method invocation.
The invocation has an implicit aggregate argument as first actual argument. Then the invocation is an aggregate method invocation.
The invocation has an implicit filter argument as first actual argument. Then the invocation is a filter method invocation.
A generator method invocation expression is a generator expression. It invokes a generator method, the result is a sequence of values.
A generator method (Section 11.2.1, “Generator Method Declarations”)
is a method with a non-void
return type T
and a first parameter of type
de.grogra.xl.lang.
S
Consumer
,
where S
is
the type affix (Section 6.1, “Type Affixes and Type Letters”) of
T
.
The type of the generator method invocation
expression is T
.
A generator method invocation for such a method has a single
implicit argument which
is prepended before the explicit argument expressions and is
commensurate with the consumer parameter.
The evaluation of a generator method invocation expression is performed in several steps:
An instance of S
Consumer
is provided as first argument, the other arguments are obtained by the
evaluation of the corresponding argument expressions.
The generator method is invoked.
Possibly the generator method yields a value by invoking the
consume
-method on the consumer. This
method has to be implemented by the compiler such that it continues
the sequential evaluation of the yielded values, i.e., such that the
control flow continues at the expression
containing the generator method invocation expression.
Finally, if the method invocation completes normally, its result value is discarded.
An aggregate method invocation expression invokes an aggregate method in order to compute some aggregate value for a sequence of values. This sequence may result from a sequential expression or an expression of array type.
An aggregate method
is a method with at least two parameters. The first parameter has to be
of the type de.grogra.xl.lang.Aggregate
.
An aggregate method invocation for such a method uses an argument
transformation with a single
implicit argument of the type Aggregate
which
is prepended before the explicit argument expressions and
commensurate with the aggregate parameter. In addition, if
the first explicit argument expression has an array type whose component type
can be converted to the type of the second parameter by a
method invocation conversion, the second
actual argument expression is the array generator expression
(Section 16.6, “Array Generator Expressions”) of the first explicit argument expression.
The return type of an aggregate method invocation expression is
determined as follows: Let T
be the type of the
second actual argument expression. If T
is
a primitive type, then let U
be the type
of the corresponding method parameter. Otherwise,
let U
be T
.
Now if the return type of the method declaration is
void
, the return type of the invocation expression
is U
. If the return type of the declaration
is java.lang.reflect.Array
, the return type of the
invocation is U[]
. Otherwise, the return type
of the invocation is the return type of the declaration.
The evaluation of an aggregate method invocation expression is performed in several steps:
An instance a
of
Aggregate
is allocated by the method
Aggregate.allocate
. The
type
-argument to this method is the return type of
the aggregate method invocation expression.
The method invocation expression is evaluated sequentially, with
a
being the value of the first actual
argument expression. For each yielded result, it is checked whether
the invocation of the method
isFinished
on a
returns true
. If this is the case, the evaluation
of the whole aggregate method invocation completes, its result is
the result of the invocation of the method
c
val
on a
, where c
is
the type letter (Section 6.1, “Type Affixes and Type Letters”) of the return type
of the aggregate method invocation expression.
The returned value is converted to this type if necessary.
Finally, if the sequential evaluation has completed and
the invocation of the method
isFinished
on a
has always returned false
, the method
setFinished
is invoked on
a
. Then the aggregate method is invoked
for a last time, with a
as first argument
and null
-values of the corresponding parameter types
as the other arguments. The evaluation of the aggregate method invocation
completes with a result obtained as described in the previous step.
A filter method invocation expression is a generator expression which invokes a filter method in order to filter a sequence of values. This sequence may result from a sequential expression or an expression of array type.
A filter method
is a method with at least two parameters. The first parameter has to be
of the type de.grogra.xl.lang.Filter
.
A filter method invocation for such a method uses an argument
transformation with a single
implicit argument of the type Filter
which
is prepended before the explicit argument expressions and
commensurate with the filter parameter. In addition, if
the first explicit argument expression has an array type whose component type
can be converted to the type of the second parameter by a
method invocation conversion, the second
actual argument expression is the array generator expression
(Section 16.6, “Array Generator Expressions”) of the first explicit argument expression.
The return type of a filter method invocation expression is determined
as described for an aggregate method invocation expression.
The sequential evaluation of a filter method invocation expression is performed in several steps:
An instance f
of
Filter
is allocated by the method
Filter.allocate
. The
type
-argument to this method is the return type of
the filter method invocation expression.
The method invocation expression is evaluated sequentially, with
f
being the value of the first actual
argument expression. For each yielded result, it is checked whether
the field accept
of f
is true
. Only if this is the case, the value of the field
c
val
of f
is yielded as a result of the
sequential evaluation of the filter method invocation expression,
where c
is
the type letter (Section 6.1, “Type Affixes and Type Letters”) of the return type
of the filter method invocation expression;
the field value is converted to this type if necessary.
Then it is checked if the invocation of the method
isFinished
on f
returns true
. If this is the case, the evaluation
of the whole filter method invocation completes.