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 256c7d7 commit 32a1e82
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 111 deletions.
11 changes: 7 additions & 4 deletions experimental_epsilon/src/Declaration.egl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[%
var regionTemplate : Template = TemplateFactory.load("DeclarationRegion.egl");
%]

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

#pragma once
Expand All @@ -6,10 +10,9 @@ class [%=sm.name%] : public [%=sm.name%]Base
{
public:
static const StatePtr kInitialState;
[%var region = sm.regions.first;
var regionTemplate : Template = TemplateFactory.load("DeclarationRegion.egl");
regionTemplate.populate("region", region);
[%
regionTemplate.populate("region", sm.regions.first);
regionTemplate.populate("sm", sm);
%]
[%=regionTemplate.process()%]
[%=regionTemplate.process()%]
};
4 changes: 3 additions & 1 deletion experimental_epsilon/src/DeclarationRegion.egl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
%]

[%=stateTemplate.process()%]
[%}%]
[%
}
%]
35 changes: 22 additions & 13 deletions experimental_epsilon/src/DeclarationState.egl
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
[% import "Operations.egl"; %]
[%
import "Operations.egl";

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

// State [%=state.name%]
static Transition [%=state.name%]Handler(ImplPtr impl, Event event);
static const State k[%=state.name%];
[% for (outgoing_transition in state.getOutgoingTransitions()) {
var transitionTemplate : Template = TemplateFactory.load("DeclarationTransition.egl");
transitionTemplate.populate("start_transition", outgoing_transition);
transitionTemplate.populate("transition", outgoing_transition);
transitionTemplate.populate("state", state);
transitionTemplate.populate("sm", sm);
[%
for (outgoing_transition in state.getOutgoingTransitions()) {
transitionTemplate.populate("start_transition", outgoing_transition);
transitionTemplate.populate("transition", outgoing_transition);
transitionTemplate.populate("state", state);
transitionTemplate.populate("sm", sm);
%]
[%=transitionTemplate.process()%]
[%}%]
[% for (sub_region in state.regions) {
var regionTemplate : Template = TemplateFactory.load("DeclarationRegion.egl");
regionTemplate.populate("region", sub_region);
regionTemplate.populate("sm", sm);
[%
}
%]
[%
for (sub_region in state.regions) {
regionTemplate.populate("region", sub_region);
regionTemplate.populate("sm", sm);
%]
[%=regionTemplate.process()%]
[%}%]
[%
}
%]
18 changes: 11 additions & 7 deletions experimental_epsilon/src/DeclarationTransition.egl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
// Transition [%=start_transition.trigger.first.event.name%]: [%=start_transition.source.name%] -> [%=transition.target.name%]
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()) {
[%
} else if (transition.target.isChoiceState()) {
var transitionTemplate : Template = TemplateFactory.load("DeclarationTransition.egl");
transitionTemplate.populate("start_transition", start_transition);
transitionTemplate.populate("transition", choice_transition);
transitionTemplate.populate("state", state);
transitionTemplate.populate("sm", sm);
for (choice_transition in transition.target.getOutgoingTransitions()) {
transitionTemplate.populate("start_transition", start_transition);
transitionTemplate.populate("transition", choice_transition);
transitionTemplate.populate("state", state);
transitionTemplate.populate("sm", sm);
%]
[%=transitionTemplate.process()%]
[%}}%]
[%
}
}
%]
10 changes: 6 additions & 4 deletions experimental_epsilon/src/InstanceHandler.egl
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@

switch([%=sm.name%]_GET_INSTANCE_EVENT_ID(event))
{
[% for (an_event in all_events) {%]
[%
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.guardIsElse());
[%
var all_transitions = state.getOutgoingTransitions().select(t | t.trigger.first.event.name == an_event);
for (transition in all_transitions) {
transitionTemplate.populate("start_transition", transition);
transitionTemplate.populate("transition", transition);
transitionTemplate.populate("state", state);
transitionTemplate.populate("sm", sm);
%]
%]
[%=transitionTemplate.process()%]
[%
}
Expand Down
37 changes: 17 additions & 20 deletions experimental_epsilon/src/InstanceHandlerTransition.egl
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
[%
import "Operations.egl";

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

if (transition.target.isState()) {
if (transition.guardIsElse()) {
%]
return [%=transition.getVariableName(start_transition)%];
[% } else { %]
[%
} else {
%]
if (impl->[%=transition.guard.name%](event))
{
return [%=transition.getVariableName(start_transition)%];
}
[%
}
} else if (transition.target.isChoiceState()) {
if (not transition.guardIsElse()) {
if (transition.hasGuard()) {
%]
if (impl->[%=transition.guard.name%](event))
{
[% for (choice_transition in transition.target.getOutgoingTransitions()) {
transitionTemplate.populate("start_transition", transition);
transitionTemplate.populate("transition", choice_transition);
transitionTemplate.populate("state", state);
transitionTemplate.populate("sm", sm);
[%
}
var transitionTemplate : Template = TemplateFactory.load("InstanceHandlerTransition.egl");
for (choice_transition in transition.target.getOutgoingTransitions()) {
transitionTemplate.populate("start_transition", transition);
transitionTemplate.populate("transition", choice_transition);
transitionTemplate.populate("state", state);
transitionTemplate.populate("sm", sm);
%]
[%=transitionTemplate.process()%]
}
[% }
} else {
for (choice_transition in transition.target.getOutgoingTransitions()) {
transitionTemplate.populate("start_transition", transition);
transitionTemplate.populate("transition", choice_transition);
transitionTemplate.populate("state", state);
transitionTemplate.populate("sm", sm);
[%
}
if (transition.hasGuard()) {
%]
[%=transitionTemplate.process()%]
}
[%
}
}
}
}
%]
4 changes: 3 additions & 1 deletion experimental_epsilon/src/InstanceRegion.egl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
%]

[%=stateTemplate.process()%]
[%}%]
[%
}
%]
40 changes: 24 additions & 16 deletions experimental_epsilon/src/InstanceState.egl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import "Operations.egl";

var regionTemplate : Template = TemplateFactory.load("InstanceRegion.egl");
var transitionTemplate : Template = TemplateFactory.load("InstanceTransition.egl");
var transitionVariableTemplate : Template = TemplateFactory.load("InstanceTransitionVariable.egl");
var handlerTemplate : Template = TemplateFactory.load("InstanceHandler.egl");
handlerTemplate.populate("state", state);
handlerTemplate.populate("sm", sm);
Expand All @@ -14,10 +14,9 @@

var initial = "nullptr";
if (not state.regions.empty) {
var region = state.regions.first;
var initial_state = region.getInitialState();
var initial_state = state.regions.first.getInitialState();
if (initial_state != null) {
initial = "&k" + initial_state.outgoing.first.target.name;
initial = "&k" + initial_state.outgoing.first.target.name;
}
}

Expand All @@ -32,24 +31,33 @@
}
%]
// State [%=state.name%]
const [%=sm.name%]::State [%=sm.name%]::k[%=state.name%]("[%=state.name%]",
const [%=state.getStateType(sm)%] [%=sm.name%]::k[%=state.name%]("[%=state.name%]",
&[%=state.name%]Handler, // Handler
[%=parent%], // Parent
[%=initial%], // Initial
[%=entry%], // Entry
[%=exit%]); // Exit
[% for (outgoing_transition in state.getOutgoingTransitions()) {
transitionTemplate.populate("start_transition", outgoing_transition);
transitionTemplate.populate("transition", outgoing_transition);
transitionTemplate.populate("state", state);
transitionTemplate.populate("sm", sm);

[%
for (outgoing_transition in state.getOutgoingTransitions()) {
transitionVariableTemplate.populate("actions", new List());
transitionVariableTemplate.populate("start_transition", outgoing_transition);
transitionVariableTemplate.populate("transition", outgoing_transition);
transitionVariableTemplate.populate("state", state);
transitionVariableTemplate.populate("sm", sm);
%]
[%=transitionVariableTemplate.process()%]
[%
}
%]
[%=transitionTemplate.process()%]
[%}%]

[%=handlerTemplate.process()%]
[% for (sub_region in state.regions) {
regionTemplate.populate("region", sub_region);
regionTemplate.populate("sm", sm);
[%
for (sub_region in state.regions) {
regionTemplate.populate("region", sub_region);
regionTemplate.populate("sm", sm);
%]
[%=regionTemplate.process()%]
[%}%]
[%
}
%]
1 change: 0 additions & 1 deletion experimental_epsilon/src/InstanceTransition.egl

This file was deleted.

33 changes: 33 additions & 0 deletions experimental_epsilon/src/InstanceTransitionVariable.egl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[%
import "Operations.egl";

var transitionVariableTemplate : Template = TemplateFactory.load("InstanceTransitionVariable.egl");

if (transition.effect != null) {
actions.add("&" + sm.name + "::Impl::" + transition.effect.name);
}

if (transition.target.isState()) {
if (not actions.isEmpty()) {
%]
const [%=sm.name%]::Transition::ActionType [%=sm.name%]::[%=transition.getVariableName(start_transition)%]Actions[] = {[%=actions.concat(", ")%]};
const [%=sm.name%]::Transition [%=sm.name%]::[%=transition.getVariableName(start_transition)%]([%=transition.target.getVariableName()%], [%=transition.getVariableName(start_transition)%]Actions);
[%
} else {
%]
const [%=sm.name%]::Transition [%=sm.name%]::[%=transition.getVariableName(start_transition)%]([%=transition.target.getVariableName()%]);
[%
}
} else if (transition.target.isChoiceState()) {
for (outgoing_transition in transition.target.getOutgoingTransitions()) {
transitionVariableTemplate.populate("actions", actions);
transitionVariableTemplate.populate("start_transition", start_transition);
transitionVariableTemplate.populate("transition", outgoing_transition);
transitionVariableTemplate.populate("state", state);
transitionVariableTemplate.populate("sm", sm);
%]
[%=transitionVariableTemplate.process()%]
[%
}
}
%]
24 changes: 21 additions & 3 deletions experimental_epsilon/src/Operations.egl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

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

operation Vertex isState() : Boolean {
Expand All @@ -15,15 +15,33 @@
return (self.guard = null) or (self.guard.name = 'else');
}

operation Transition hasGuard() : Boolean {
return (self.guard != null) and (self.guard.name != 'else');
}

operation State getVariableName() : String {
return "k" + self.name;
}

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;
return self.subvertices.select(s|(s.type.name = "Pseudostate") and ((s.kind = PseudostateKind#initial) or (s.kind = PseudostateKind#shallowHistory))).first;
}

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

operation Vertex getStateType(sm : StateMachine) : String {
if (not self.regions.isEmpty()) {
var initial = self.regions.first.getInitialState();
if ((initial != null) and (initial.kind = PseudostateKind#shallowHistory)) {
return sm.name + "::HistoryState";
}
}
return sm.name + "::State";
}
%]
12 changes: 12 additions & 0 deletions experimental_epsilon/src/Program.egx
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
rule StatemachineDeclaration
transform sm : UML!StateMachine {

pre {
var java = new Native("org.eclipse.epsilon.egl.formatter.language.JavaFormatter");
}

template : "Declaration.egl"

formatter : java

target : "gen/" + sm.name + "Declaration.hxx"
}

rule StatemachineInstance
transform sm : UML!StateMachine {

pre {
var java = new Native("org.eclipse.epsilon.egl.formatter.language.JavaFormatter");
}

template : "Instance.egl"

formatter : java

target : "gen/" + sm.name + "Instance.hxx"
}
Loading

0 comments on commit 32a1e82

Please sign in to comment.