Model transformation: how to force the order of output elements based on the order of input elements [message #1022746] |
Fri, 22 March 2013 09:15  |
Eclipse User |
|
|
|
I'm using the IncQuery API for a model transformation; the source model is based on a DSL which describes a design space. The target model is a somewhat similar DSL, but which describes a concrete instance of a model that conforms to one of the combination of parameters in this design space.
The internal behavior of the elements is described by blocks of procedural expressions and the order of these expression is therefore crucial to the correctness.
When transforming one model into another, one can specify that the activations should be fired in a specific order, but this does not fully guarantee that when an expression 'appears' in between two others (e.g. by programmatically inserting one) that the order in the output model is consistent with the order in the input model.
As far as I have seen, there is no such construction in the EVM yet to enforce this kind of order. Although this may not necessarily be a motivating use-case in case of programmatically starting a transformation, this can become a problem for 'live' model transformations.
I'm thinking it may be possible to solve this by creating an additional pattern, which looks for the 'sibling' of such expressions, so that in the model transformation code the developer can 'see'/deduce what position the newly created element should be inserted.
Although I may not run into this problem in my current use-case (haven't found a case where it matters) it may become a problem in future use-cases. What are your thoughts on this?
|
|
|
|
|
Re: Model transformation: how to force the order of output elements based on the order of input elem [message #1028611 is a reply to message #1022768] |
Thu, 28 March 2013 09:46   |
Eclipse User |
|
|
|
Thanks to the RulePriorityActivationComparator (RPAC) I'm now able to specify:
1. rule ordering by priority
2. activation ordering (with same rule type) using the original order of containment (see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=403825)
Unfortunately, this is not yet enough for my use case; expression trees do not have a 'static' priority, as they can be nested arbitrarily. Such nesting occurs if you metamodel allows some kind of containment cycles (as is quite common with nested expressions).
Say that I have an abstract Primary element, which specializes into Expression and Literal. Expression specializes again into multiple types: e.g. a BinaryExpression (like add, multiply, etc). Any BinaryExpression has a left and right hand side, which is a containment reference to a Primary (e.g. either a Literal or an Expression).
Based on this, I would like to be able to extend/annotate/label an expression pattern with a 'depth' or 'transformationOrder'. By making all Expression rules the same priority in the RPAC, it would be possible to arrange the activations for the expression containment tree such that the container elements are created before the contained elements are created.
How can I make something like this possible? I've tried the following:
pattern depth(primary : Primary, depth) = {
Literal(primary);
depth == 1;
// Always a leaf element
} or {
BinaryExpression(primary);
BinaryExpression.left(primary, left);
BinaryExpression.right(primary, right);
find primaryExpressionDepth(left, ldepth);
find primaryExpressionDepth(right, rdepth);
// check(depth == Math::max(ldepth, rdepth) + 1); // No positive inference
// depth == Math::max(ldepth, rdepth) + 1; // Invalid syntax
}
Is it possible to write such a bottom-up (or top-down) labeling mechanism with the currently available pattern language?
If not, then I'll probably resort to writing a custom solution by modifying the comparison mechanism of the RPAC.
P.S. I'm aware the the RPAC will probably get refactored soon.
|
|
|
|
Re: Model transformation: how to force the order of output elements based on the order of input elem [message #1028781 is a reply to message #1028618] |
Thu, 28 March 2013 14:30  |
Eclipse User |
|
|
|
Hi,
to answer your question: indeed, what you wish to do doesn't seem currently possible purely with the query language. In fact, I also suspect that eval() (https://bugs.eclipse.org/bugs/show_bug.cgi?id=398722) would be necessary for your idea to work.
Note that those enhancements are in the "Future" milestone for a reason: they would require a significant conceptual extension / re-work of the evaluation strategy behind IncQuery's queries. While they could be implemented with the current incremental engine with some limitations, a more complete support would probably necessitate to develop a top-down search-based (i.e. non-incremental) evaluation strategy. This is in the works, but in an early research state at the moment.
cheers
Istvan
|
|
|
Powered by
FUDForum. Page generated in 0.05340 seconds