diff --git a/generator/src/generator/InstanceHandler.egl b/generator/src/generator/InstanceHandler.egl index 5b36089..221120d 100644 --- a/generator/src/generator/InstanceHandler.egl +++ b/generator/src/generator/InstanceHandler.egl @@ -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)) { [% @@ -25,5 +28,12 @@ static [%=statemachine.name%]::[%=statemachine.transition_type%] [%=state.scoped default: break; } +[% + } else { +%] + (void) event; // No outgoing transitions +[% + } +%] return [%=statemachine.name%]::UnhandledEvent(); } diff --git a/generator/src/generator/InstanceHandlerTransition.egl b/generator/src/generator/InstanceHandlerTransition.egl index b243841..5757cbe 100644 --- a/generator/src/generator/InstanceHandlerTransition.egl +++ b/generator/src/generator/InstanceHandlerTransition.egl @@ -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%]}); [% } %] @@ -27,5 +25,4 @@ transitionRootTemplate.populate("statemachine", statemachine); transitionRootTemplate.populate("transition", transition); %] -[%=closing_bracket%] [%=transitionRootTemplate.process()%] \ No newline at end of file diff --git a/generator/src/generator/Transformations.egl b/generator/src/generator/Transformations.egl index fe1ec45..6f83f4d 100644 --- a/generator/src/generator/Transformations.egl +++ b/generator/src/generator/Transformations.egl @@ -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(); diff --git a/test/generated/IXmiTestImpl.hxx b/test/generated/IXmiTestImpl.hxx index 3520f29..487b6f6 100644 --- a/test/generated/IXmiTestImpl.hxx +++ b/test/generated/IXmiTestImpl.hxx @@ -1,5 +1,5 @@ // Statemachine XmiTest implementation interface -// Generated: 21.08.24, 22:20 +// Generated: 22.08.24, 08:27 #pragma once diff --git a/test/generated/XmiTestDeclaration.hxx b/test/generated/XmiTestDeclaration.hxx index 87f1bf4..45cb19d 100644 --- a/test/generated/XmiTestDeclaration.hxx +++ b/test/generated/XmiTestDeclaration.hxx @@ -1,5 +1,5 @@ // Statemachine XmiTest declaration -// Generated: 21.08.24, 22:20 +// Generated: 22.08.24, 08:27 #pragma once diff --git a/test/generated/XmiTestInstance.hxx b/test/generated/XmiTestInstance.hxx index 7a25c6c..fab1b00 100644 --- a/test/generated/XmiTestInstance.hxx +++ b/test/generated/XmiTestInstance.hxx @@ -1,5 +1,5 @@ // Statemachine XmiTest instance -// Generated: 21.08.24, 22:20 +// Generated: 22.08.24, 08:27 #pragma once @@ -17,13 +17,9 @@ // 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); @@ -31,7 +27,7 @@ const XmiTest::State XmiTest::kState_1("State_1", &State_1Handler, nullptr, &Xmi // 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)) { @@ -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::Impl::State2InternalAction}); - return XmiTest::TransitionTo(XmiTest::kNone, kActions); - } + static const auto kActions1 = std::to_array({&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::Impl::Transition3Action1}); - return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions); - } + static const auto kActions2 = std::to_array({&XmiTest::Impl::Transition3Action1}); + return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions2); } break; @@ -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)) { @@ -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)) { @@ -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::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction2}); - return XmiTest::TransitionTo(XmiTest::kState_1State_4State_5, kActions); - } + static const auto kActions3 = std::to_array({&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::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction3, &XmiTest::Impl::ChoiceAction4}); - return XmiTest::TransitionTo(XmiTest::kState_1State_2, kActions); - } - } - { - static const auto kActions = std::to_array({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction3}); - return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions); + static const auto kActions4 = std::to_array({&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::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction3}); + return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions5); } break; @@ -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)) { diff --git a/test/xmi/XmiTest.notation b/test/xmi/XmiTest.notation index 5136123..b48cf29 100644 --- a/test/xmi/XmiTest.notation +++ b/test/xmi/XmiTest.notation @@ -487,7 +487,7 @@ - +