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 27, 2023
1 parent cde8030 commit 256c7d7
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 216 deletions.
10 changes: 7 additions & 3 deletions experimental_epsilon/src/DeclarationRegion.egl
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[% for (state in region.subvertices.select(s|s.type.name == "State")) {
[%
import "Operations.egl";

var stateTemplate : Template = TemplateFactory.load("DeclarationState.egl");
stateTemplate.populate("state", state);
stateTemplate.populate("sm", sm);

for (state in region.getStates()) {
stateTemplate.populate("state", state);
stateTemplate.populate("sm", sm);
%]

[%=stateTemplate.process()%]
Expand Down
4 changes: 3 additions & 1 deletion experimental_epsilon/src/DeclarationState.egl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[% import "Operations.egl"; %]

// State [%=state.name%]
static Transition [%=state.name%]Handler(ImplPtr impl, Event event);
static const State k[%=state.name%];
[% for (outgoing_transition in state.outgoing) {
[% for (outgoing_transition in state.getOutgoingTransitions()) {
var transitionTemplate : Template = TemplateFactory.load("DeclarationTransition.egl");
transitionTemplate.populate("start_transition", outgoing_transition);
transitionTemplate.populate("transition", outgoing_transition);
Expand Down
13 changes: 8 additions & 5 deletions experimental_epsilon/src/DeclarationTransition.egl
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[%if (transition.target.type.name == "State") {%]
[%
import "Operations.egl";

if (transition.target.isState()) {%]
// Transition [%=start_transition.trigger.first.event.name%]: [%=start_transition.source.name%] -> [%=transition.target.name%]
static const Transition::ActionType k[%=start_transition.source.name%]To[%=transition.target.name%]By[%=start_transition.trigger.first.event.name%]Actions[];
static const Transition k[%=start_transition.source.name%]To[%=transition.target.name%]By[%=start_transition.trigger.first.event.name%];
[%} else if ((transition.target.type.name == "Pseudostate") and (transition.target.kind.name == "choice")) {
for (choice_transition in transition.target.outgoing) {
static const Transition::ActionType [%=transition.getVariableName(start_transition)%]Actions[];
static const Transition [%=transition.getVariableName(start_transition)%];
[%} else if (transition.target.isChoiceState()) {
for (choice_transition in transition.target.getOutgoingTransitions()) {
var transitionTemplate : Template = TemplateFactory.load("DeclarationTransition.egl");
transitionTemplate.populate("start_transition", start_transition);
transitionTemplate.populate("transition", choice_transition);
Expand Down
5 changes: 3 additions & 2 deletions experimental_epsilon/src/Instance.egl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[% import "Operations.egl"; %]
// Statemachine [%=sm.name%] instance

// Override the following defines according to your needs if you are not using cpp_event_framework:
Expand All @@ -12,12 +13,12 @@

[%
var region = sm.regions.first;
var intitalstate = region.subvertices.select(s|(s.type.name == "Pseudostate") and (s.kind.name == "initial")).first;
var intital_state = region.getInitialState();

var regionTemplate : Template = TemplateFactory.load("InstanceRegion.egl");
regionTemplate.populate("region", region);
regionTemplate.populate("sm", sm);
%]
// Initial state
const [%=sm.name%]::StatePtr [%=sm.name%]::kInitialState = &[%=sm.name%]::k[%=intitalstate.outgoing.first.target.name%];
const [%=sm.name%]::StatePtr [%=sm.name%]::kInitialState = &[%=sm.name%]::k[%=intital_state.outgoing.first.target.name%];
[%=regionTemplate.process()%]
21 changes: 13 additions & 8 deletions experimental_epsilon/src/InstanceHandler.egl
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[%
import "Operations.egl";

var transitionTemplate : Template = TemplateFactory.load("InstanceHandlerTransition.egl");

var all_events = new List();
for (transition in state.outgoing) {
all_events.add(transition.trigger.first.event.name);
}
all_events = all_events.sortBy(e | e); // sort by event name
%]
[%=sm.name%]::Transition [%=sm.name%]::[%=state.name%]Handler(ImplPtr impl, Event event)
{
Expand All @@ -15,16 +18,18 @@
[% for (an_event in all_events) {%]
case [%=sm.name%]_GET_STATIC_EVENT_ID([%=an_event%]):
[%
var all_transitions = state.outgoing.select(t | t.trigger.first.event.name == an_event).sortBy(t | (t.guard == null) or (t.guard.name == "else"));
for (transition in all_transitions) {
transitionTemplate.populate("start_transition", transition);
transitionTemplate.populate("transition", transition);
transitionTemplate.populate("state", state);
transitionTemplate.populate("sm", sm);
var all_transitions = state.outgoing.select(t | t.trigger.first.event.name == an_event).sortBy(t | t.guardIsElse());
for (transition in all_transitions) {
transitionTemplate.populate("start_transition", transition);
transitionTemplate.populate("transition", transition);
transitionTemplate.populate("state", state);
transitionTemplate.populate("sm", sm);
%]
[%=transitionTemplate.process()%]
[%}%]
[%}%]
[%
}
}
%]
default:
return UnhandledEvent();
}
Expand Down
26 changes: 8 additions & 18 deletions experimental_epsilon/src/InstanceHandlerTransition.egl
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
[%
import "Operations.egl";

var transitionTemplate : Template = TemplateFactory.load("InstanceHandlerTransition.egl");

if (transition.target.type.name = "State") {
if (transition.target.isState()) {
if (transition.guardIsElse()) {
%]
return k[%=start_transition.source.name%]To[%=transition.target.name%]By[%=start_transition.trigger.first.event.name%];
return [%=transition.getVariableName(start_transition)%];
[% } else { %]
if (impl->[%=transition.guard.name%](event))
{
return k[%=start_transition.source.name%]To[%=transition.target.name%]By[%=start_transition.trigger.first.event.name%];
return [%=transition.getVariableName(start_transition)%];
}
[%
}
} else if (transition.targetIsChoiceState()) {
} else if (transition.target.isChoiceState()) {
if (not transition.guardIsElse()) {
%]
if (impl->[%=transition.guard.name%](event))
{
[% for (choice_transition in transition.getChoiceTransitions()) {
[% for (choice_transition in transition.target.getOutgoingTransitions()) {
transitionTemplate.populate("start_transition", transition);
transitionTemplate.populate("transition", choice_transition);
transitionTemplate.populate("state", state);
Expand All @@ -27,7 +29,7 @@ if (impl->[%=transition.guard.name%](event))
}
[% }
} else {
for (choice_transition in transition.getChoiceTransitions()) {
for (choice_transition in transition.target.getOutgoingTransitions()) {
transitionTemplate.populate("start_transition", transition);
transitionTemplate.populate("transition", choice_transition);
transitionTemplate.populate("state", state);
Expand All @@ -38,16 +40,4 @@ if (impl->[%=transition.guard.name%](event))
}
}
}

operation Transition getChoiceTransitions() : List {
return self.target.outgoing.sortBy(t | (t.guard = null) or (t.guard.name = "else"));
}

operation Transition targetIsChoiceState() : Boolean {
return (self.target.type.name = "Pseudostate") and (self.target.kind.name = "choice");
}

operation Transition guardIsElse() : Boolean {
return (self.guard = null) or (self.guard.name = 'else');
}
%]
10 changes: 7 additions & 3 deletions experimental_epsilon/src/InstanceRegion.egl
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[% for (state in region.subvertices.select(s|s.type.name == "State")) {
[%
import "Operations.egl";

var stateTemplate : Template = TemplateFactory.load("InstanceState.egl");
stateTemplate.populate("state", state);
stateTemplate.populate("sm", sm);

for (state in region.getStates()) {
stateTemplate.populate("state", state);
stateTemplate.populate("sm", sm);
%]

[%=stateTemplate.process()%]
Expand Down
6 changes: 4 additions & 2 deletions experimental_epsilon/src/InstanceState.egl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[%
import "Operations.egl";

var regionTemplate : Template = TemplateFactory.load("InstanceRegion.egl");
var transitionTemplate : Template = TemplateFactory.load("InstanceTransition.egl");
var handlerTemplate : Template = TemplateFactory.load("InstanceHandler.egl");
Expand All @@ -13,7 +15,7 @@
var initial = "nullptr";
if (not state.regions.empty) {
var region = state.regions.first;
var initial_state = region.subvertices.select(s|(s.type.name == "Pseudostate") and ((s.kind.name == "initial") or (s.kind.name == "shallowHistory"))).first;
var initial_state = region.getInitialState();
if (initial_state != null) {
initial = "&k" + initial_state.outgoing.first.target.name;
}
Expand All @@ -36,7 +38,7 @@ const [%=sm.name%]::State [%=sm.name%]::k[%=state.name%]("[%=state.name%]",
[%=initial%], // Initial
[%=entry%], // Entry
[%=exit%]); // Exit
[% for (outgoing_transition in state.outgoing) {
[% for (outgoing_transition in state.getOutgoingTransitions()) {
transitionTemplate.populate("start_transition", outgoing_transition);
transitionTemplate.populate("transition", outgoing_transition);
transitionTemplate.populate("state", state);
Expand Down
29 changes: 29 additions & 0 deletions experimental_epsilon/src/Operations.egl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[%
operation Vertex getOutgoingTransitions() : List {
return self.outgoing.sortBy(t | t.guardIsElse());
}

operation Vertex isChoiceState() : Boolean {
return (self.type.name = "Pseudostate") and (self.kind.name = "choice");
}

operation Vertex isState() : Boolean {
return (self.type.name = "State");
}

operation Transition guardIsElse() : Boolean {
return (self.guard = null) or (self.guard.name = 'else');
}

operation Transition getVariableName(start_transition : Transition) : String {
return "k" + start_transition.source.name + "To" + self.target.name + "By"+ start_transition.trigger.first.event.name;
}

operation Region getInitialState() : Pseudostate {
return self.subvertices.select(s|(s.type.name == "Pseudostate") and ((s.kind.name == "initial") or (s.kind.name == "shallowHistory"))).first;
}

operation Region getStates() : List {
return self.subvertices.select(s|s.type.name == "State").sortBy(s | s.name);
}
%]
Loading

0 comments on commit 256c7d7

Please sign in to comment.