module ATL2WTracer; | |
create OUT : ATL refining IN : ATL; | |
helper def: _module : ATL!Module = | |
ATL!Module.allInstancesFrom('IN')->asSequence()->first(); | |
helper context ATL!Module def: models : Sequence(ATL!OclModel) = | |
self.inModels->union(self.outModels); | |
rule Module { | |
from | |
s : ATL!Module | |
to | |
t : ATL!Module ( | |
name <- s.name, | |
libraries <- s.libraries, | |
isRefining <- s.isRefining, | |
inModels <- s.inModels, | |
outModels <- s.outModels->including(traceModel), | |
elements <- s.models->collect(e | | |
thisModule.ModelHelper(e) | |
)->prepend( | |
traceHelper | |
)->append( | |
initTrace | |
)->union(s.elements), | |
location <- s.location, | |
commentsBefore <- s.commentsBefore, | |
commentsAfter <- s.commentsAfter | |
), | |
traceModel : ATL!OclModel ( | |
name <- 'trace', | |
metamodel <- traceMetamodel | |
), | |
traceMetamodel : ATL!OclModel ( | |
name <- 'Trace' | |
), | |
-- entrypoint rule InitTrace | |
initTrace : ATL!CalledRule ( | |
name <- 'InitTrace', | |
parameters <- Sequence {}, | |
isEntrypoint <- true, | |
outPattern <- initTraceOutPattern, | |
actionBlock <- actionBlock | |
), | |
-- to | |
initTraceOutPattern : ATL!OutPattern ( | |
elements <- Sequence {wmodel}->union( | |
s.models->collect(e | | |
thisModule.TraceModelRef(e) | |
) | |
) | |
), | |
-- wmodel : Trace:TraceModel | |
wmodel : ATL!SimpleOutPatternElement ( | |
varName <- 'wmodel', | |
type <- wmodelType, | |
bindings <- Sequence {wovenModels} | |
), | |
wmodelType : ATL!OclModelElement ( | |
name <- 'TraceModel', | |
model <- traceMetamodel | |
), | |
wovenModels : ATL!Binding ( | |
propertyName <- 'wovenModels', | |
value <- wovenSeq | |
), | |
wovenSeq : ATL!SequenceExp ( | |
elements <- s.models->collect(e | thisModule.TraceModelVar(e)) | |
), | |
-- do | |
actionBlock : ATL!ActionBlock ( | |
statements <- s.models->collect(e | thisModule.ModelHelperInit(e))->prepend(traceInit) | |
), | |
-- helper def: __wmodel : Trace!TraceModel | |
traceHelper : ATL!Helper ( | |
definition <- fdef | |
), | |
fdef : ATL!OclFeatureDefinition ( | |
feature <- feature | |
), | |
feature : ATL!Attribute ( | |
name <- '__wmodel', | |
type <- type, | |
initExpression <- init | |
), | |
type : ATL!OclModelElement ( | |
name <- 'TraceModel', | |
model <- traceMetamodel | |
), | |
init : ATL!OclUndefinedExp, | |
-- thisModule.__wmodel <- wmodel | |
traceInit : ATL!BindingStat ( | |
source <- nav, | |
value <- modelVar | |
), | |
nav : ATL!NavigationOrAttributeCallExp ( | |
name <- '__wmodel', | |
source <- thisModuleVar | |
), | |
modelVar : ATL!VariableExp ( | |
referredVariable <- wmodel | |
), | |
thisModuleVar : ATL!VariableExp ( | |
referredVariable <- thisModuleVarDecl | |
), | |
thisModuleVarDecl : ATL!VariableDeclaration ( | |
varName <- 'thisModule' | |
) | |
} | |
unique lazy rule TraceModelRef { | |
from | |
s : ATL!OclModel | |
to | |
t : ATL!SimpleOutPatternElement ( | |
varName <- 'model_' + s.name, | |
type <- type, | |
bindings <- Sequence {setName} | |
), | |
type : ATL!OclModelElement ( | |
name <- 'TraceModelRef', | |
model <- thisModule.resolveTemp(s.refImmediateComposite(), 'traceMetamodel') | |
), | |
setName : ATL!Binding ( | |
propertyName <- 'name', | |
value <- name | |
), | |
name : ATL!StringExp ( | |
stringSymbol <- s.name | |
) | |
} | |
-- model_<name> : Trace:TraceModelRef | |
unique lazy rule TraceModelVar { | |
from | |
s : ATL!OclModel | |
to | |
wovenVars : ATL!VariableExp ( | |
referredVariable <- thisModule.TraceModelRef(s) | |
) | |
} | |
-- thisModule.__model_<name> <- __model_<name> | |
unique lazy rule ModelHelperInit { | |
from | |
s : ATL!OclModel | |
to | |
t : ATL!BindingStat ( | |
source <- nav, | |
value <- modelVar | |
), | |
nav : ATL!NavigationOrAttributeCallExp ( | |
name <- '__model_' + s.name, | |
source <- thisModuleVar | |
), | |
modelVar : ATL!VariableExp ( | |
referredVariable <- thisModule.TraceModelRef(s) | |
), | |
thisModuleVar : ATL!VariableExp ( | |
referredVariable <- thisModuleVarDecl | |
), | |
thisModuleVarDecl : ATL!VariableDeclaration ( | |
varName <- 'thisModule' | |
) | |
} | |
unique lazy rule ModelHelper { | |
from | |
s : ATL!OclModel | |
to | |
t : ATL!Helper ( | |
definition <- fdef | |
), | |
fdef : ATL!OclFeatureDefinition ( | |
feature <- feature | |
), | |
feature : ATL!Attribute ( | |
name <- '__model_' + s.name, | |
type <- type, | |
initExpression <- init | |
), | |
type : ATL!OclModelElement ( | |
name <- 'TraceModelRef', | |
model <- thisModule.resolveTemp(s.refImmediateComposite(), 'traceMetamodel') | |
), | |
init : ATL!OclUndefinedExp | |
} | |
rule OutPattern { | |
from | |
s : ATL!OutPattern | |
to | |
t : ATL!OutPattern ( | |
elements <- s.elements->including(traceLink)->union( | |
s."rule".inPattern.elements->union(s.elements)->collect(e | | |
Sequence {thisModule.LinkEnd(e), thisModule.ElementRef(e)} | |
)->flatten() | |
) | |
), | |
traceLink : ATL!SimpleOutPatternElement ( | |
varName <- '__traceLink', | |
type <- traceType, | |
bindings <- Sequence {ruleName, sourceElements, targetElements, model} | |
), | |
model : ATL!Binding ( | |
propertyName <- 'model', | |
value <- getModel | |
), | |
getModel : ATL!NavigationOrAttributeCallExp ( | |
name <- '__wmodel', | |
source <- getModelVar | |
), | |
getModelVar : ATL!VariableExp ( | |
referredVariable <- getModelVarDecl | |
), | |
getModelVarDecl : ATL!VariableDeclaration ( | |
varName <- 'thisModule' | |
), | |
traceType : ATL!OclModelElement ( | |
name <- 'TraceLink', | |
model <- thisModule.resolveTemp(s."rule"."module", 'traceMetamodel') | |
), | |
ruleName : ATL!Binding ( | |
propertyName <- 'name', | |
value <- nameString | |
), | |
nameString : ATL!StringExp ( | |
stringSymbol <- s."rule".name | |
), | |
-- sourceElements <- Sequence {%sourceLinkEnds} | |
sourceElements : ATL!Binding ( | |
propertyName <- 'sourceElements', | |
value <- sourceSeq | |
), | |
sourceSeq : ATL!SequenceExp ( | |
elements <- sourceVars | |
), | |
sourceVars : distinct ATL!VariableExp foreach(e in s."rule".inPattern.elements) ( | |
referredVariable <- thisModule.LinkEnd(e) | |
), | |
-- targetElements <- Sequence {%targetLinkEnds} | |
targetElements : ATL!Binding ( | |
propertyName <- 'targetElements', | |
value <- targetSeq | |
), | |
targetSeq : ATL!SequenceExp ( | |
elements <- targetVars | |
), | |
targetVars : distinct ATL!VariableExp foreach(e in s.elements) ( | |
referredVariable <- thisModule.LinkEnd(e) | |
) | |
} | |
unique lazy rule LinkEnd { | |
from | |
s : ATL!PatternElement | |
to | |
linkEnd : ATL!SimpleOutPatternElement ( | |
varName <- '__LinkEnd_' + s.varName, | |
type <- linkEndType, | |
bindings <- Sequence {elementBinding} | |
), | |
linkEndType : ATL!OclModelElement ( | |
name <- 'TraceLinkEnd', | |
model <- thisModule.resolveTemp(s.refImmediateComposite()."rule"."module", 'traceMetamodel') | |
), | |
elementBinding : ATL!Binding ( | |
propertyName <- 'element', | |
value <- elementVar | |
), | |
elementVar : ATL!VariableExp ( | |
referredVariable <- thisModule.ElementRef(s) | |
) | |
} | |
unique lazy rule ElementRef { | |
from | |
s : ATL!PatternElement | |
to | |
elementRef : ATL!SimpleOutPatternElement ( | |
varName <- '__elementRef_' + s.varName, | |
type <- elementRefType, | |
bindings <- Sequence {refBinding, modelRef} | |
), | |
elementRefType : ATL!OclModelElement ( | |
name <- 'ElementRef', | |
model <- thisModule.resolveTemp(s.refImmediateComposite()."rule"."module", 'traceMetamodel') | |
), | |
-- ref <- s.__xmiID | |
refBinding : ATL!Binding ( | |
propertyName <- 'ref', | |
value <- xmiID | |
), | |
xmiID : ATL!NavigationOrAttributeCallExp ( | |
name <- '__xmiID__', | |
source <- refVar | |
), | |
refVar : ATL!VariableExp ( | |
referredVariable <- s | |
), | |
modelRef : ATL!Binding ( | |
propertyName <- 'modelRef', | |
value <- getModelRef | |
), | |
getModelRef : ATL!NavigationOrAttributeCallExp ( | |
name <- '__model_' + | |
s.type.model.model->select(e | | |
if s.oclIsKindOf(ATL!InPatternElement) then | |
thisModule._module.inModels | |
else | |
thisModule._module.outModels | |
endif->includes(e) | |
)->first().name, | |
source <- getModelRefVar | |
), | |
getModelRefVar : ATL!VariableExp ( | |
referredVariable <- getModelRefVarDecl | |
), | |
getModelRefVarDecl : ATL!VariableDeclaration ( | |
varName <- 'thisModule' | |
) | |
} | |