Skip to content

Commit

Permalink
More cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
dziegel committed Aug 22, 2024
1 parent a3daa34 commit ec2dde2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 68 deletions.
36 changes: 18 additions & 18 deletions generator/src/generator/InstanceHandler.egl
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
static [%=statemachine.name%]::[%=statemachine.transition_type%] [%=state.scoped_name%]Handler([%=statemachine.name%]::ImplPtr impl, [%=statemachine.name%]::Event event)
{
(void)impl; // impl parameter is unused when there is no guard function being called in here
(void)impl; // impl parameter is unused when there is no guard function being called in here

[%
if (not state.all_events.isEmpty()) {
if (not state.all_events.isEmpty()) {
%]
switch([%=statemachine.name%]_GET_INSTANCE_EVENT_ID(event))
{
switch([%=statemachine.name%]_GET_INSTANCE_EVENT_ID(event))
{
[%
for (trigger in state.all_events) {
%]
case [%=statemachine.name%]_GET_STATIC_EVENT_ID([%=trigger%]):
case [%=statemachine.name%]_GET_STATIC_EVENT_ID([%=trigger%]):
[%
var transition = state.transitions_for_trigger_transformed.get(trigger);
var transition = state.transitions_for_trigger_transformed.get(trigger);

var transitionRootTemplate : Template = TemplateFactory.load("InstanceHandlerTransitionRoot.egl");
transitionRootTemplate.populate("state", state);
transitionRootTemplate.populate("statemachine", statemachine);
transitionRootTemplate.populate("transition", transition);
var transitionRootTemplate : Template = TemplateFactory.load("InstanceHandlerTransitionRoot.egl");
transitionRootTemplate.populate("state", state);
transitionRootTemplate.populate("statemachine", statemachine);
transitionRootTemplate.populate("transition", transition);
%]
[%=transitionRootTemplate.process()%]
break;
break;

[%
}
%]
default:
break;
}
default:
break;
}
[%
} else {
} else {
%]
(void) event; // No outgoing transitions
(void) event; // No outgoing transitions
[%
}
}
%]
return [%=statemachine.name%]::UnhandledEvent();
return [%=statemachine.name%]::UnhandledEvent();
}
32 changes: 16 additions & 16 deletions generator/src/generator/InstanceHandlerTransition.egl
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
[%
var actions = "";
if (transition.actions_list != null) {
statemachine.unique_id = statemachine.unique_id + 1;
actions = ", kActions" + statemachine.unique_id;
var actions = "";
if (transition.actions_list != null) {
statemachine.unique_id = statemachine.unique_id + 1;
actions = ", kActions" + statemachine.unique_id;
%]
static const auto kActions[%=statemachine.unique_id%] = std::to_array<[%=statemachine.name%]::[%=statemachine.transition_action_type%]>({[%=transition.actions_list%]});
static const auto kActions[%=statemachine.unique_id%] = std::to_array<[%=statemachine.name%]::[%=statemachine.transition_action_type%]>({[%=transition.actions_list%]});
[%
}
}
%]
[%
if (transition.internal) {
if (transition.internal) {
%]
return [%=statemachine.name%]::TransitionTo([%=statemachine.name%]::kNone[%=actions%]);
return [%=statemachine.name%]::TransitionTo([%=statemachine.name%]::kNone[%=actions%]);
[%
}
if (transition.target_variable_name != null) {
}
if (transition.target_variable_name != null) {
%]
return [%=statemachine.name%]::TransitionTo([%=statemachine.name%]::[%=transition.target_variable_name%][%=actions%]);
return [%=statemachine.name%]::TransitionTo([%=statemachine.name%]::[%=transition.target_variable_name%][%=actions%]);
[%
}
}

var transitionRootTemplate : Template = TemplateFactory.load("InstanceHandlerTransitionRoot.egl");
transitionRootTemplate.populate("state", state);
transitionRootTemplate.populate("statemachine", statemachine);
transitionRootTemplate.populate("transition", transition);
var transitionRootTemplate : Template = TemplateFactory.load("InstanceHandlerTransitionRoot.egl");
transitionRootTemplate.populate("state", state);
transitionRootTemplate.populate("statemachine", statemachine);
transitionRootTemplate.populate("transition", transition);
%]
[%=transitionRootTemplate.process()%]
24 changes: 12 additions & 12 deletions generator/src/generator/InstanceHandlerTransitionRoot.egl
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
[%
var transitionTemplate : Template = TemplateFactory.load("InstanceHandlerTransition.egl");
transitionTemplate.populate("state", state);
transitionTemplate.populate("statemachine", statemachine);
var transitionTemplate : Template = TemplateFactory.load("InstanceHandlerTransition.egl");
transitionTemplate.populate("state", state);
transitionTemplate.populate("statemachine", statemachine);

for (transition in transition.trans_conditional) {
transitionTemplate.populate("transition", transition);
for (transition in transition.trans_conditional) {
transitionTemplate.populate("transition", transition);
%]
if ([%=transition.guards_list%])
{
if ([%=transition.guards_list%])
{
[%=transitionTemplate.process()%]
}
}
[%
}
}
%]
[%
for (transition in transition.trans_unconditional) {
transitionTemplate.populate("transition", transition);
for (transition in transition.trans_unconditional) {
transitionTemplate.populate("transition", transition);
%]
[%=transitionTemplate.process()%]
[%
}
}
%]
2 changes: 1 addition & 1 deletion test/generated/IScXmlTestImpl.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine ScXmlTest implementation interface
// Generated: 21.08.24, 21:44
// Generated: 22.08.24, 11:29

#pragma once

Expand Down
2 changes: 1 addition & 1 deletion test/generated/ScXmlTestDeclaration.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine ScXmlTest declaration
// Generated: 21.08.24, 21:44
// Generated: 22.08.24, 11:29

#pragma once

Expand Down
32 changes: 12 additions & 20 deletions test/generated/ScXmlTestInstance.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine ScXmlTest instance
// Generated: 21.08.24, 21:44
// Generated: 22.08.24, 11:29

#pragma once

Expand All @@ -17,38 +17,30 @@
// State State_1
static ScXmlTest::Transition State_1Handler(ScXmlTest::ImplPtr impl, ScXmlTest::Event event)
{
(void)impl; // impl parameter is unused when there is no guard function or action being called in here
(void)impl; // impl parameter is unused when there is no guard function being called in here

switch(ScXmlTest_GET_INSTANCE_EVENT_ID(event))
{
default:
break;
}
(void) event; // No outgoing transitions
return ScXmlTest::UnhandledEvent();
}
const ScXmlTest::State ScXmlTest::kState_1("State_1", &State_1Handler, nullptr, &ScXmlTest::kState_1State_2, &ScXmlTest::Impl::State1OnEntry, nullptr);

// State State_1::State_2
static ScXmlTest::Transition State_1State_2Handler(ScXmlTest::ImplPtr impl, ScXmlTest::Event event)
{
(void)impl; // impl parameter is unused when there is no guard function or action being called in here
(void)impl; // impl parameter is unused when there is no guard function being called in here

switch(ScXmlTest_GET_INSTANCE_EVENT_ID(event))
{
case ScXmlTest_GET_STATIC_EVENT_ID(Internal):
{
static const auto kActions = std::to_array<ScXmlTest::Transition::ActionType>({&ScXmlTest::Impl::State2InternalAction});
return ScXmlTest::TransitionTo(ScXmlTest::kNone, kActions);
}
static const auto kActions1 = std::to_array<ScXmlTest::Transition::ActionType>({&ScXmlTest::Impl::State2InternalAction});
return ScXmlTest::TransitionTo(ScXmlTest::kNone, kActions1);
break;

case ScXmlTest_GET_STATIC_EVENT_ID(Transition_3):
if (impl->State2Transition3Guard(event))
{
{
static const auto kActions = std::to_array<ScXmlTest::Transition::ActionType>({&ScXmlTest::Impl::Transition3Action1, &ScXmlTest::Impl::Transition3Action2});
return ScXmlTest::TransitionTo(ScXmlTest::kState_1State_3, kActions);
}
static const auto kActions2 = std::to_array<ScXmlTest::Transition::ActionType>({&ScXmlTest::Impl::Transition3Action1, &ScXmlTest::Impl::Transition3Action2});
return ScXmlTest::TransitionTo(ScXmlTest::kState_1State_3, kActions2);
}
break;

Expand All @@ -66,7 +58,7 @@ const ScXmlTest::State ScXmlTest::kState_1State_2("State_1::State_2", &State_1St
// State State_1::State_3
static ScXmlTest::Transition State_1State_3Handler(ScXmlTest::ImplPtr impl, ScXmlTest::Event event)
{
(void)impl; // impl parameter is unused when there is no guard function or action being called in here
(void)impl; // impl parameter is unused when there is no guard function being called in here

switch(ScXmlTest_GET_INSTANCE_EVENT_ID(event))
{
Expand All @@ -84,7 +76,7 @@ const ScXmlTest::State ScXmlTest::kState_1State_3("State_1::State_3", &State_1St
// State State_1::State_4
static ScXmlTest::Transition State_1State_4Handler(ScXmlTest::ImplPtr impl, ScXmlTest::Event event)
{
(void)impl; // impl parameter is unused when there is no guard function or action being called in here
(void)impl; // impl parameter is unused when there is no guard function being called in here

switch(ScXmlTest_GET_INSTANCE_EVENT_ID(event))
{
Expand All @@ -102,7 +94,7 @@ const ScXmlTest::HistoryState ScXmlTest::kState_1State_4("State_1::State_4", &St
// State State_1::State_4::State_5
static ScXmlTest::Transition State_1State_4State_5Handler(ScXmlTest::ImplPtr impl, ScXmlTest::Event event)
{
(void)impl; // impl parameter is unused when there is no guard function or action being called in here
(void)impl; // impl parameter is unused when there is no guard function being called in here

switch(ScXmlTest_GET_INSTANCE_EVENT_ID(event))
{
Expand All @@ -120,7 +112,7 @@ const ScXmlTest::State ScXmlTest::kState_1State_4State_5("State_1::State_4::Stat
// State State_1::State_4::State_6
static ScXmlTest::Transition State_1State_4State_6Handler(ScXmlTest::ImplPtr impl, ScXmlTest::Event event)
{
(void)impl; // impl parameter is unused when there is no guard function or action being called in here
(void)impl; // impl parameter is unused when there is no guard function being called in here

switch(ScXmlTest_GET_INSTANCE_EVENT_ID(event))
{
Expand Down

0 comments on commit ec2dde2

Please sign in to comment.