Wiki

Clone wiki

Model Generation / TBMGCS3

Case Study 3: Generating State Machine

#!dsl

model state

import <platform:/resource/ICSE-CS/statemachine/statemachine.ecore>

template TStateMachine {
    role (statemachine)
    node statemachine : StateMachine plays statemachine;
    node init : InitialState;
    node final : FinalState;
    node body @ TMultiTransOfStates,TRoundtripTransOfStates,TState;
    node t1 @ TTransition;
    node t2 @ TTransition;
    node set[0..-1] crosses @ TCross;
    edge e1 : Transition::source(t1,init);
    edge e2 : Transition::target(t1,body);
    edge e3 : Transition::source(t2,body);
    edge e4 : Transition::target(t2,final);
    edge e5 : StateContainer::states(statemachine,init);
    edge e6 : StateContainer::states(statemachine,final);
    binding e1 for source TTransition=>trans
    binding e2 for source TTransition=>trans for target TMultiTransOfStates=>in TRoundtripTransOfStates=>st TState=>state
    binding e3 for source TTransition=>trans for target TMultiTransOfStates=>out TRoundtripTransOfStates=>st TState=>state
    binding e4 for source TTransition=>trans
}

template TMultiTransOfStates {  
    role (in,out)
    node in @ TMultiTransOfStates, TRoundtripTransOfStates, TState plays in;
    node out @ TMultiTransOfStates, TRoundtripTransOfStates, TState plays out;
    node set[1..-1] inner @ TMultiTransOfStateInnerTrans,TMultiTransOfStateInnerStructure;
    edge e1 : Transition::source(inner,in);
    edge e2 : Transition::target(inner,out);
    binding e1 
        for source TMultiTransOfStateInnerTrans=>trans TMultiTransOfStateInnerStructure=>incoming TTransition=>trans
        for target TMultiTransOfStates=>out TRoundtripTransOfStates=>st TState=>state
    binding e2 
        for source TMultiTransOfStateInnerTrans=>trans TMultiTransOfStateInnerStructure=>outgoing TTransition=>trans
        for target TMultiTransOfStates=>in TRoundtripTransOfStates=>st TState=>state
}

template TMultiTransOfStateInnerTrans {
    role (trans)
    node trans @ TTransition plays trans;
}

template TMultiTransOfStateInnerStructure {
    role (incoming,outgoing)
    node incoming @ TTransition plays incoming;
    node inner @ TMultiTransOfStates, TRoundtripTransOfStates, TState;
    node outgoing @ TTransition plays outgoing;
    edge e1 : Transition::target(incoming,inner);
    edge e2 : Transition::source(outgoing,inner);
    binding e1 for source TTransition=>trans for target TMultiTransOfStates=>in TRoundtripTransOfStates=>st TState=>state
    binding e2 for source TTransition=>trans for target TMultiTransOfStates=>out TRoundtripTransOfStates=>st TState=>state
}
template TRoundtripTransOfStates {
    role (st)
    node st @ TState plays st;
    node body @ TMultiTransOfStates, TRoundtripTransOfStates, TState;
    node t1 @ TTransition;
    node t2 @ TTransition;
    edge e1 : Transition::source(t1,st);
    edge e2 : Transition::target(t1,body);
    edge e3 : Transition::source(t2,body);
    edge e4 : Transition::target(t2,st);
    binding e1 
        for source TTransition=>trans
        for target TState=>state
    binding e2 
        for source TTransition=>trans
        for target TState=>state TMultiTransOfStates=>in TRoundtripTransOfStates=>st
    binding e3
        for source TTransition=>trans
        for target TState=>state TMultiTransOfStates=>out TRoundtripTransOfStates=>st
    binding e4 
        for source TTransition=>trans
        for target TState=>state
}

template TTransition {
    role (trans)
    node trans : Transition[eventName : event, actionName : action] plays trans;
    node reversed container @ TStateMachine;
    edge e : StateContainer::transitions (container,trans);
    binding e for source TStateMachine => statemachine
}

template TState {
    role (state)
    node state : State [stateName : name] plays state;
    node reversed container @ TStateMachine;
    edge e : StateContainer::states (container,state);
    binding e for source TStateMachine => statemachine
}

template TCross {
    node shared s1 @ TState;
    node shared s2 @ TState;
    node t @ TTransition;
    edge e1 : Transition::source(t,s1);
    edge e2 : Transition::target(t,s2);
    binding e1 for source TTransition=>trans for target TState=>state
    binding e2 for source TTransition=>trans for target TState=>state
}

image.png

Updated