Skip to content

Commit

Permalink
Work on eclipse epsilon
Browse files Browse the repository at this point in the history
  • Loading branch information
dziegel committed Dec 29, 2023
1 parent 08eb2ac commit bf19c0b
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 155 deletions.
8 changes: 1 addition & 7 deletions experimental_epsilon/src/Declaration.egl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
[%
import "Model.egl";
var statemachine = sm.getModel();

var regionTemplate : Template = TemplateFactory.load("DeclarationRegion.egl");
%]

// Statemachine [%=statemachine.name%] declaration

#pragma once
Expand All @@ -14,6 +7,7 @@ class [%=statemachine.name%] : public [%=statemachine.name%]Base
public:
static const StatePtr kInitialState;
[%
var regionTemplate : Template = TemplateFactory.load("DeclarationRegion.egl");
regionTemplate.populate("region", statemachine.region);
regionTemplate.populate("statemachine", statemachine);
%]
Expand Down
6 changes: 6 additions & 0 deletions experimental_epsilon/src/DeclarationState.egl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ static const [%=statemachine.state_type%] [%=state.variable_name%];
for (transition in state.transitions) {
%]
// Transition [%=transition.trigger%]: [%=transition.start%] -> [%=transition.target%]
[%
if (not transition.actions.isEmpty()) {
%]
static const [%=statemachine.transition_action_type%] [%=transition.variable_name%]Actions[];
[%
}
%]
static const [%=statemachine.transition_type%] [%=transition.variable_name%];
[%
}
Expand Down
6 changes: 1 addition & 5 deletions experimental_epsilon/src/Instance.egl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[%
import "Model.egl";
var statemachine = sm.getModel();
%]
// Statemachine [%=statemachine.name%] instance

// Override the following defines according to your needs if you are not using cpp_event_framework:
Expand All @@ -21,4 +17,4 @@
%]
// Initial state
const [%=statemachine.name%]::StatePtr [%=statemachine.name%]::kInitialState = &[%=statemachine.name%]::[%=statemachine.region.initial_variable_name%];
[%=regionTemplate.process()%]
[%=regionTemplate.process()%]
47 changes: 0 additions & 47 deletions experimental_epsilon/src/Operations.egl

This file was deleted.

4 changes: 2 additions & 2 deletions experimental_epsilon/src/Program.egx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rule StatemachineDeclaration
var java = new Native("org.eclipse.epsilon.egl.formatter.language.JavaFormatter");
}

template : "Declaration.egl"
template : "XmiDeclaration.egl"

formatter : java

Expand All @@ -19,7 +19,7 @@ rule StatemachineInstance
var java = new Native("org.eclipse.epsilon.egl.formatter.language.JavaFormatter");
}

template : "Instance.egl"
template : "XmiInstance.egl"

formatter : java

Expand Down
76 changes: 76 additions & 0 deletions experimental_epsilon/src/Transformations.egl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[%
operation Tuple transformStatemachine() {
self.transition_type = "Transition";
self.transition_action_type = "Transition::Action";
self.state_type = "State";
self.event_type = "Event";
self.impl_type = "Impl";
self.impl_ptr_type = "ImplPtr";

self.region.transformRegion(self);
}

operation Tuple transformRegion(statemachine : Tuple) {
self.initial_variable_name = "k" + self.initial;

self.states = self.states.sortBy(s | s.name);
for (state in self.states) {
state.transformState(statemachine);
}
}

operation Tuple transformState(statemachine : Tuple) {
self.variable_name = "k" + self.name;

self.parent_variable_pointer = "nullptr";
if (self.parent.isDefined()) {
self.parent_variable_pointer = "&k" + self.parent;
}

self.entry_pointer = "nullptr";
if (self.entry.isDefined()) {
self.entry_pointer = "&" + self.entry;
}

self.exit_pointer = "nullptr";
if (self.exit.isDefined()) {
self.exit_pointer = "&" + self.exit;
}

self.transitions = self.transitions.sortBy(t | t.trigger + t.start + t.target);
for (transition in self.transitions) {
transition.transformTransition(statemachine);
}

self.initial_variable_pointer = "nullptr";
if (self.region.isDefined()) {
self.region.transformRegion(statemachine);
self.initial_variable_pointer = "&" + self.region.initial_variable_name;
}

self.all_events = new List();
for (transition in self.transitions) {
if (not self.all_events.includes(transition.trigger)) {
self.all_events.add(transition.trigger);
}
}
self.all_events = self.all_events.sortBy(e | e);

self.all_event_transitions = new Map();
for (event in self.all_events) {
self.all_event_transitions.put(event, self.transitions.select(t | t.trigger = event));
}
}

operation Tuple transformTransition(statemachine : Tuple) {
self.target_variable_name = "k" + self.target;
self.variable_name = "k" + self.start + "To" + self.target + "By"+ self.trigger;
self.actions_variable_name = self.variable_name + "Actions";

var actions = new List();
for (action in self.actions) {
actions.add("&" + statemachine.name + "::" + statemachine.impl_type + "::" + action);
}
self.actions_list = actions.concat(", ");
}
%]
11 changes: 11 additions & 0 deletions experimental_epsilon/src/XmiDeclaration.egl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[%
import "XmiModel.egl";
import "Transformations.egl";

var statemachine = sm.getModel();
statemachine.transformStatemachine();

var declarationTemplate : Template = TemplateFactory.load("Declaration.egl");
declarationTemplate.populate("statemachine", statemachine);
%]
[%=declarationTemplate.process()%]
11 changes: 11 additions & 0 deletions experimental_epsilon/src/XmiInstance.egl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[%
import "XmiModel.egl";
import "Transformations.egl";

var statemachine = sm.getModel();
statemachine.transformStatemachine();

var instanceTemplate : Template = TemplateFactory.load("Instance.egl");
instanceTemplate.populate("statemachine", statemachine);
%]
[%=instanceTemplate.process()%]
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ operation StateMachine getModel() : Tuple {
var result = new Tuple();
result.name = self.name;
result.region = sm.regions.first.getModel(result);

result.transformStatemachine();
return result;
}

Expand Down Expand Up @@ -87,81 +85,4 @@ operation Transition getTarget(sm : Tuple, transition : Tuple, transitions : Lis
}
}
}

// Transformations

operation Tuple transformStatemachine() {
self.transition_type = "Transition";
self.transition_action_type = "Transition::Action";
self.state_type = "State";
self.event_type = "Event";
self.impl_type = "Impl";
self.impl_ptr_type = "ImplPtr";

self.region.transformRegion(self);
}

operation Tuple transformRegion(statemachine : Tuple) {
self.initial_variable_name = "k" + self.initial;

self.states = self.states.sortBy(s | s.name);
for (state in self.states) {
state.transformState(statemachine);
}
}

operation Tuple transformState(statemachine : Tuple) {
self.variable_name = "k" + self.name;

self.parent_variable_pointer = "nullptr";
if (self.parent.isDefined()) {
self.parent_variable_pointer = "&k" + self.parent;
}

self.entry_pointer = "nullptr";
if (self.entry.isDefined()) {
self.entry_pointer = "&" + self.entry;
}

self.exit_pointer = "nullptr";
if (self.exit.isDefined()) {
self.exit_pointer = "&" + self.exit;
}

self.transitions = self.transitions.sortBy(t | t.trigger + t.start + t.target);
for (transition in self.transitions) {
transition.transformTransition(statemachine);
}

self.initial_variable_pointer = "nullptr";
if (self.region.isDefined()) {
self.region.transformRegion(statemachine);
self.initial_variable_pointer = "&" + self.region.initial_variable_name;
}

self.all_events = new List();
for (transition in self.transitions) {
if (not self.all_events.includes(transition.trigger)) {
self.all_events.add(transition.trigger);
}
}
self.all_events = self.all_events.sortBy(e | e);

self.all_event_transitions = new Map();
for (event in self.all_events) {
self.all_event_transitions.put(event, self.transitions.select(t | t.trigger = event));
}
}

operation Tuple transformTransition(statemachine : Tuple) {
self.target_variable_name = "k" + self.target;
self.variable_name = "k" + self.start + "To" + self.target + "By"+ self.trigger;
self.actions_variable_name = self.variable_name + "Actions";

var actions = new List();
for (action in self.actions) {
actions.add("&" + statemachine.name + "::" + statemachine.impl_type + "::" + action);
}
self.actions_list = actions.concat(", ");
}
%]
15 changes: 1 addition & 14 deletions experimental_epsilon/src/gen/IoArHandlerMainDeclaration.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Statemachine IoArHandlerMain declaration

#pragma once
Expand All @@ -12,19 +11,14 @@ class IoArHandlerMain : public IoArHandlerMainBase
static Transition ClosedHandler(ImplPtr impl, Event event);
static const State kClosed;
// Transition S_PNS_ArOpend_ind: Closed -> Open
static const Transition::Action kClosedToOpenByS_PNS_ArOpend_indActions[];
static const Transition kClosedToOpenByS_PNS_ArOpend_ind;
// Transition S_PNS_ReadReq: Closed -> Closed
static const Transition::Action kClosedToClosedByS_PNS_ReadReqActions[];
static const Transition kClosedToClosedByS_PNS_ReadReq;
// Transition S_PNS_SwitchoverRequestBackup: Closed -> Closed
static const Transition::Action kClosedToClosedByS_PNS_SwitchoverRequestBackupActions[];
static const Transition kClosedToClosedByS_PNS_SwitchoverRequestBackup;
// Transition S_PNS_SwitchoverRequestPrimary: Closed -> Closed
static const Transition::Action kClosedToClosedByS_PNS_SwitchoverRequestPrimaryActions[];
static const Transition kClosedToClosedByS_PNS_SwitchoverRequestPrimary;
// Transition S_PNS_WriteReq: Closed -> Closed
static const Transition::Action kClosedToClosedByS_PNS_WriteReqActions[];
static const Transition kClosedToClosedByS_PNS_WriteReq;

// State Open
Expand Down Expand Up @@ -78,17 +72,14 @@ class IoArHandlerMain : public IoArHandlerMainBase
static Transition DrWaitApplicationReadyPlugSubmoduleHandler(ImplPtr impl, Event event);
static const State kDrWaitApplicationReadyPlugSubmodule;
// Transition SPnpbAppTimeout: DrWaitApplicationReadyPlugSubmodule -> DrWaitApplicationReadyCnfPlugSubmodule
static const Transition::Action kDrWaitApplicationReadyPlugSubmoduleToDrWaitApplicationReadyCnfPlugSubmoduleBySPnpbAppTimeoutActions[];
static const Transition kDrWaitApplicationReadyPlugSubmoduleToDrWaitApplicationReadyCnfPlugSubmoduleBySPnpbAppTimeout;
// Transition SPnpbAppTimeout: DrWaitApplicationReadyPlugSubmodule -> DrWaitApplicationReadyPlugSubmodule
static const Transition::Action kDrWaitApplicationReadyPlugSubmoduleToDrWaitApplicationReadyPlugSubmoduleBySPnpbAppTimeoutActions[];
static const Transition kDrWaitApplicationReadyPlugSubmoduleToDrWaitApplicationReadyPlugSubmoduleBySPnpbAppTimeout;

// State DrWaitPlugCnf
static Transition DrWaitPlugCnfHandler(ImplPtr impl, Event event);
static const State kDrWaitPlugCnf;
// Transition S_PNS_PlugSubmodule_cnf: DrWaitPlugCnf -> DrPlugPrmSequence
static const Transition::Action kDrWaitPlugCnfToDrPlugPrmSequenceByS_PNS_PlugSubmodule_cnfActions[];
static const Transition kDrWaitPlugCnfToDrPlugPrmSequenceByS_PNS_PlugSubmodule_cnf;

// State DrWaitPullCnf
Expand All @@ -115,26 +106,22 @@ class IoArHandlerMain : public IoArHandlerMainBase
static const Transition::Action kParameterizingToWaitApplicationReadyByS_PNS_ParamEndIndActions[];
static const Transition kParameterizingToWaitApplicationReadyByS_PNS_ParamEndInd;
// Transition S_PNS_ParamEndInd: Parameterizing -> WaitApplicationReadyCnf
static const Transition::Action kParameterizingToWaitApplicationReadyCnfByS_PNS_ParamEndIndActions[];
static const Transition kParameterizingToWaitApplicationReadyCnfByS_PNS_ParamEndInd;

// State WaitApplicationReady
static Transition WaitApplicationReadyHandler(ImplPtr impl, Event event);
static const State kWaitApplicationReady;
// Transition SPnpbAppTimeout: WaitApplicationReady -> WaitApplicationReady
static const Transition::Action kWaitApplicationReadyToWaitApplicationReadyBySPnpbAppTimeoutActions[];
static const Transition kWaitApplicationReadyToWaitApplicationReadyBySPnpbAppTimeout;
// Transition SPnpbAppTimeout: WaitApplicationReady -> WaitApplicationReadyCnf
static const Transition::Action kWaitApplicationReadyToWaitApplicationReadyCnfBySPnpbAppTimeoutActions[];
static const Transition kWaitApplicationReadyToWaitApplicationReadyCnfBySPnpbAppTimeout;

// State WaitApplicationReadyCnf
static Transition WaitApplicationReadyCnfHandler(ImplPtr impl, Event event);
static const State kWaitApplicationReadyCnf;
// Transition S_PNS_ApplicationReady_cnf: WaitApplicationReadyCnf -> ApplicationReady
static const Transition::Action kWaitApplicationReadyCnfToApplicationReadyByS_PNS_ApplicationReady_cnfActions[];
static const Transition kWaitApplicationReadyCnfToApplicationReadyByS_PNS_ApplicationReady_cnf;
// Transition S_PNS_ApplicationReady_cnf: WaitApplicationReadyCnf -> WaitApplicationReadyCnf
static const Transition::Action kWaitApplicationReadyCnfToWaitApplicationReadyCnfByS_PNS_ApplicationReady_cnfActions[];
static const Transition kWaitApplicationReadyCnfToWaitApplicationReadyCnfByS_PNS_ApplicationReady_cnf;
};
};
2 changes: 1 addition & 1 deletion experimental_epsilon/src/gen/IoArHandlerMainInstance.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,4 @@ IoArHandlerMain::Transition IoArHandlerMain::WaitApplicationReadyCnfHandler(Impl
default:
return UnhandledEvent();
}
}
}

0 comments on commit bf19c0b

Please sign in to comment.