Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsXbase and logical containers
https://www.eclipse.org/forums/index.php/mv/msg/461383/1021872/#msg_1021872
I trying to understand how logical containers for expressions work. I've
used it with success so far, but recent problems have tested my
understanding of them...
In my DSL I can declare variable-like elements that provide a scope for
some expressions. The following is not the DSL, but illustrates the point:
val int x = 1 // declare variable
process x+1 // expression x+1 is evaluated in the scope of x
To make the framework handle the scoping for me, I infer (and generate)
two methods as follows:
void process() {
processExpressions(1); // <-- the init expression for x
}
void processExpressions(int x) {
int _x = x+1; // <- expression has processExpression is its logical
container, but is serialized "by hand" during generation
someProcessingMethod(_x);
}
processExpressions is assigned as the logical container for the
expression x+1, to make it scoped to parameter x
This examples works, but when introducing type parameters, the
serialization of the expressions gives an exception. E.g.
val T x = ... // T is a type parameter of enclosing "class"
process x
Should generate:
void process() { processExpressions(...); }
void processExpressions(T x) {
T _x = <<Exception when serializing x as an expression>>;
someProcessingMethod(_x);
}
By stepping through the serialization process in the debugger, I get the
impression that xbase tries to infer more specific type info, since the
type is a type argument. It looks at the expected type and ends up with
void as the type, which makes the serialization (as an expression)
break, since a void expression doesn't have value. What I believe xbase
has done, is look at the return type of the expression's logical
container, which is processExpression (to get the scoping right), and
infer that as the expected type, in practice assigning void to the type
parameter.
Am I using the logical container for the wrong reason (to get the
scoping right)? What can I do to avoid the faulty inference that void is
the expected type of the expression?