[ATL] How to Clone/Copy source elements to multiple target elements [message #516524] |
Wed, 24 February 2010 10:58 |
Tim Messages: 7 Registered: December 2009 |
Junior Member |
|
|
Hi all,
In my ATL transformation I have a location class that contains a set of invariant expressions. I would like to transform the model in such a way that the new invariant set in the target model contains all the source invariant expressions AND a copy of each of the expressions. So {exp1} must be transformed to {exp1,exp1}.
Currently I've tried to transform the source to target expressions using match rules and tried to create the extra/copied expressions using lazy rules. This unfortunately didn't work.
What happens is that the lazy rule Number2 is executed first, whereafter the match rule Number1 is not executed once, but twice. Does anyone have an explanation for this? I know that it can be solved by placing the Number1 rule above the Location rule. So it probably is the case that the expression created by the lazy rule is seen as a source element by the matched rule.
I currently use both match and lazy rules. Does anybody know a better way to create the two instances in the target model? What I would like to have is just one match rule, and then something of a cloning rule/action, but I don't know if this is possible.
Any help would be greatly appreciated.
Best regards,
Tim
--copy location
rule Location{
from s : cif!Location
to t : cif!Location(
invariant <- s.invariant->union(s.invariant->collect(inv| inv.getExpression()))
)
}
--copy number
rule Number1{
from s : cif!Number
to t : cif!Number(
value <- s.value + 'new',
type <- s.type
)
}
--copy nat type
rule NatType1{
from s : cif!NatType
to t : cif!NatType()
}
helper context cif!Number def: getExpression() : cif!Expression =
thisModule.Number(self);
--copy number
lazy rule Number2{
from s : cif!Number
to t : cif!Number(
value <- s.value,
type <- s.type.getStaticType()
)
}
helper context cif!NatType def: getStaticType(): cif!StaticType =
thisModule.NatType(self);
--copy nat type
lazy rule NatType2{
from s : cif!NatType
to t : cif!NatType()
}
|
|
|
Re: [ATL] How to Clone/Copy source elements to multiple target elements [message #516621 is a reply to message #516524] |
Wed, 24 February 2010 15:39 |
Sylvain EVEILLARD Messages: 556 Registered: July 2009 |
Senior Member |
|
|
You can use multiple target elements in each rule and use resolveTemp to get both target elements instead of just the first one.
I'm afraid it's the only available solution in a declarative way.
That would be :
--copy location
rule Location{
from s : cif!Location
to t : cif!Location(
invariant <- s.invariant->collect(e | Sequence{thisModule.resolveTemp(e,'t'),thisModule.resolveTem p(e,'copy')})- >flatten()
)
}
--copy number
rule Number1{
from s : cif!Number
to t : cif!Number(
value <- s.value,
type <- s.type
),
copy : cif!Number(
value <- s.value + 'new',
type <- thisModule.resolveTemp(s.type,'copy')
)
}
--copy nat type
rule NatType1{
from s : cif!NatType
to t : cif!NatType(),
copy : cif!NatType(),
}
You could also use called rules.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03290 seconds