Skip to content

Commit

Permalink
Beautify generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
dziegel committed Aug 22, 2024
1 parent 4102f58 commit d4fee2e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 45 deletions.
12 changes: 11 additions & 1 deletion generator/src/generator/InstanceHandler.egl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
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 or action 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()) {
%]
switch([%=statemachine.name%]_GET_INSTANCE_EVENT_ID(event))
{
[%
Expand All @@ -25,5 +28,12 @@ static [%=statemachine.name%]::[%=statemachine.transition_type%] [%=state.scoped
default:
break;
}
[%
} else {
%]
(void) event; // No outgoing transitions
[%
}
%]
return [%=statemachine.name%]::UnhandledEvent();
}
9 changes: 3 additions & 6 deletions generator/src/generator/InstanceHandlerTransition.egl
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[%
var actions = "";
var closing_bracket = "";
if (transition.actions_list != null) {
actions = ", kActions";
closing_bracket = "}";
statemachine.unique_id = statemachine.unique_id + 1;
actions = ", kActions" + statemachine.unique_id;
%]
{
static const auto kActions = 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%]});
[%
}
%]
Expand All @@ -27,5 +25,4 @@
transitionRootTemplate.populate("statemachine", statemachine);
transitionRootTemplate.populate("transition", transition);
%]
[%=closing_bracket%]
[%=transitionRootTemplate.process()%]
2 changes: 2 additions & 0 deletions generator/src/generator/Transformations.egl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ operation Tuple transformStatemachine() {
self.event_type = "Event";
self.impl_type = "Impl";
self.impl_ptr_type = "ImplPtr";

self.unique_id = 0;

self.all_states = new Map();
self.all_actions = new List();
Expand Down
2 changes: 1 addition & 1 deletion test/generated/IXmiTestImpl.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine XmiTest implementation interface
// Generated: 21.08.24, 22:20
// Generated: 22.08.24, 08:27

#pragma once

Expand Down
2 changes: 1 addition & 1 deletion test/generated/XmiTestDeclaration.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine XmiTest declaration
// Generated: 21.08.24, 22:20
// Generated: 22.08.24, 08:27

#pragma once

Expand Down
53 changes: 18 additions & 35 deletions test/generated/XmiTestInstance.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine XmiTest instance
// Generated: 21.08.24, 22:20
// Generated: 22.08.24, 08:27

#pragma once

Expand All @@ -17,21 +17,17 @@
// State State_1
static XmiTest::Transition State_1Handler(XmiTest::ImplPtr impl, XmiTest::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(XmiTest_GET_INSTANCE_EVENT_ID(event))
{
default:
break;
}
(void) event; // No outgoing transitions
return XmiTest::UnhandledEvent();
}
const XmiTest::State XmiTest::kState_1("State_1", &State_1Handler, nullptr, &XmiTest::kState_1State_2, &XmiTest::Impl::State1OnEntry, nullptr);

// State State_1::StateWithSameName
static XmiTest::Transition State_1StateWithSameNameHandler(XmiTest::ImplPtr impl, XmiTest::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(XmiTest_GET_INSTANCE_EVENT_ID(event))
{
Expand All @@ -49,24 +45,20 @@ const XmiTest::State XmiTest::kState_1StateWithSameName("State_1::StateWithSameN
// State State_1::State_2
static XmiTest::Transition State_1State_2Handler(XmiTest::ImplPtr impl, XmiTest::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(XmiTest_GET_INSTANCE_EVENT_ID(event))
{
case XmiTest_GET_STATIC_EVENT_ID(Internal):
{
static const auto kActions = std::to_array<XmiTest::Transition::ActionType>({&XmiTest::Impl::State2InternalAction});
return XmiTest::TransitionTo(XmiTest::kNone, kActions);
}
static const auto kActions1 = std::to_array<XmiTest::Transition::ActionType>({&XmiTest::Impl::State2InternalAction});
return XmiTest::TransitionTo(XmiTest::kNone, kActions1);
break;

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

Expand All @@ -84,7 +76,7 @@ const XmiTest::State XmiTest::kState_1State_2("State_1::State_2", &State_1State_
// State State_1::State_4
static XmiTest::Transition State_1State_4Handler(XmiTest::ImplPtr impl, XmiTest::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(XmiTest_GET_INSTANCE_EVENT_ID(event))
{
Expand All @@ -102,7 +94,7 @@ const XmiTest::HistoryState XmiTest::kState_1State_4("State_1::State_4", &State_
// State State_1::State_4::StateWithSameName
static XmiTest::Transition State_1State_4StateWithSameNameHandler(XmiTest::ImplPtr impl, XmiTest::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(XmiTest_GET_INSTANCE_EVENT_ID(event))
{
Expand All @@ -113,27 +105,18 @@ static XmiTest::Transition State_1State_4StateWithSameNameHandler(XmiTest::ImplP
case XmiTest_GET_STATIC_EVENT_ID(Transition_7):
if (impl->ChoiceGuard1(event))
{

if (impl->ChoiceGuard2(event))
{
{
static const auto kActions = std::to_array<XmiTest::Transition::ActionType>({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction2});
return XmiTest::TransitionTo(XmiTest::kState_1State_4State_5, kActions);
}
static const auto kActions3 = std::to_array<XmiTest::Transition::ActionType>({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction2});
return XmiTest::TransitionTo(XmiTest::kState_1State_4State_5, kActions3);
}

if (impl->ChoiceGuard3(event))
{

{
static const auto kActions = std::to_array<XmiTest::Transition::ActionType>({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction3, &XmiTest::Impl::ChoiceAction4});
return XmiTest::TransitionTo(XmiTest::kState_1State_2, kActions);
}
}
{
static const auto kActions = std::to_array<XmiTest::Transition::ActionType>({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction3});
return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions);
static const auto kActions4 = std::to_array<XmiTest::Transition::ActionType>({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction3, &XmiTest::Impl::ChoiceAction4});
return XmiTest::TransitionTo(XmiTest::kState_1State_2, kActions4);
}
static const auto kActions5 = std::to_array<XmiTest::Transition::ActionType>({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction3});
return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions5);
}
break;

Expand All @@ -147,7 +130,7 @@ const XmiTest::State XmiTest::kState_1State_4StateWithSameName("State_1::State_4
// State State_1::State_4::State_5
static XmiTest::Transition State_1State_4State_5Handler(XmiTest::ImplPtr impl, XmiTest::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(XmiTest_GET_INSTANCE_EVENT_ID(event))
{
Expand Down
2 changes: 1 addition & 1 deletion test/xmi/XmiTest.notation
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@
</children>
<children xmi:type="notation:DecorationNode" xmi:id="_aG1a4l_4Ee-nkouQL1JVbw" type="Transition_GuardLabel">
<styles xmi:type="notation:BooleanValueStyle" xmi:id="_NAbI0F_5Ee-nkouQL1JVbw" name="IS_UPDATED_POSITION" booleanValue="true"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_aG1a41_4Ee-nkouQL1JVbw" x="22" y="-111"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_aG1a41_4Ee-nkouQL1JVbw" x="7" y="-161"/>
</children>
<children xmi:type="notation:DecorationNode" xmi:id="_aG1a5F_4Ee-nkouQL1JVbw" type="Transition_StereotypeLabel">
<styles xmi:type="notation:BooleanValueStyle" xmi:id="_NAyVMF_5Ee-nkouQL1JVbw" name="IS_UPDATED_POSITION" booleanValue="true"/>
Expand Down

0 comments on commit d4fee2e

Please sign in to comment.