From dbb5281ee587f31b53505745a35451176b9f5889 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 17 Oct 2024 21:38:56 +0200 Subject: [PATCH] Change unique_id handling to produce smaller diffs on changes --- generator/src/generator/InstanceHandler.egl | 3 ++ .../generator/InstanceHandlerTransition.egl | 6 +-- .../InstanceHandlerTransitionRoot.egl | 1 + generator/src/generator/Transformations.egl | 2 - test/generated/IScXmlTestImpl.hxx | 2 +- test/generated/IXmiTestImpl.hxx | 3 +- test/generated/ScXmlTestDeclaration.hxx | 2 +- test/generated/ScXmlTestInstance.hxx | 2 +- test/generated/XmiTestDeclaration.hxx | 2 +- test/generated/XmiTestInstance.hxx | 30 +++++++---- test/xmi/XmiTest.notation | 50 +++++++++++++++++-- test/xmi/XmiTest.uml | 10 +++- 12 files changed, 89 insertions(+), 24 deletions(-) diff --git a/generator/src/generator/InstanceHandler.egl b/generator/src/generator/InstanceHandler.egl index ca01e7b..b66782b 100644 --- a/generator/src/generator/InstanceHandler.egl +++ b/generator/src/generator/InstanceHandler.egl @@ -4,6 +4,8 @@ static [%=statemachine.name%]::[%=statemachine.transition_type%] [%=state.scoped [% if (not state.all_events.isEmpty()) { + var unique_id = new Tuple(); + unique_id.id = 0; %] switch([%=statemachine.name%]_GET_INSTANCE_EVENT_ID(event)) { @@ -16,6 +18,7 @@ case [%=statemachine.name%]_GET_STATIC_EVENT_ID([%=trigger%]): var transitionRootTemplate : Template = TemplateFactory.load("InstanceHandlerTransitionRoot.egl"); transitionRootTemplate.populate("state", state); + transitionRootTemplate.populate("unique_id", unique_id); transitionRootTemplate.populate("statemachine", statemachine); transitionRootTemplate.populate("transition", transition); %] diff --git a/generator/src/generator/InstanceHandlerTransition.egl b/generator/src/generator/InstanceHandlerTransition.egl index def1c65..f09b94d 100644 --- a/generator/src/generator/InstanceHandlerTransition.egl +++ b/generator/src/generator/InstanceHandlerTransition.egl @@ -2,11 +2,11 @@ var actions = ""; var actions_with_comma = ""; if (transition.actions_list != null) { - statemachine.unique_id = statemachine.unique_id + 1; - actions = "kActions" + statemachine.unique_id; + unique_id.id = unique_id.id + 1; + actions = "kActions" + unique_id.id; actions_with_comma = ", " + actions; %] -static const auto kActions[%=statemachine.unique_id%] = std::to_array<[%=statemachine.name%]::[%=statemachine.transition_action_type%]>({[%=transition.actions_list%]}); +static const auto kActions[%=unique_id.id%] = std::to_array<[%=statemachine.name%]::[%=statemachine.transition_action_type%]>({[%=transition.actions_list%]}); [% } %] diff --git a/generator/src/generator/InstanceHandlerTransitionRoot.egl b/generator/src/generator/InstanceHandlerTransitionRoot.egl index e617a32..f38df3e 100644 --- a/generator/src/generator/InstanceHandlerTransitionRoot.egl +++ b/generator/src/generator/InstanceHandlerTransitionRoot.egl @@ -2,6 +2,7 @@ var transitionTemplate : Template = TemplateFactory.load("InstanceHandlerTransition.egl"); transitionTemplate.populate("state", state); transitionTemplate.populate("statemachine", statemachine); + transitionTemplate.populate("unique_id", unique_id); for (transition in transition.trans_conditional) { transitionTemplate.populate("transition", transition); diff --git a/generator/src/generator/Transformations.egl b/generator/src/generator/Transformations.egl index 763d263..5531a6c 100644 --- a/generator/src/generator/Transformations.egl +++ b/generator/src/generator/Transformations.egl @@ -7,8 +7,6 @@ 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/IScXmlTestImpl.hxx b/test/generated/IScXmlTestImpl.hxx index ba49a7a..75b14bd 100644 --- a/test/generated/IScXmlTestImpl.hxx +++ b/test/generated/IScXmlTestImpl.hxx @@ -1,5 +1,5 @@ // Statemachine ScXmlTest implementation interface -// Generated: 23.08.24, 20:41 +// Generated: 17.10.24, 21:37 #pragma once diff --git a/test/generated/IXmiTestImpl.hxx b/test/generated/IXmiTestImpl.hxx index eb87d0a..23b4ce8 100644 --- a/test/generated/IXmiTestImpl.hxx +++ b/test/generated/IXmiTestImpl.hxx @@ -1,5 +1,5 @@ // Statemachine XmiTest implementation interface -// Generated: 23.08.24, 20:41 +// Generated: 17.10.24, 21:37 #pragma once @@ -26,6 +26,7 @@ class IXmiTestImpl // Entry/Exit virtual void State1OnEntry() = 0; + virtual void State1OnExit() = 0; virtual void State2OnEntry() = 0; virtual void State3OnEntry() = 0; virtual void State3OnExit() = 0; diff --git a/test/generated/ScXmlTestDeclaration.hxx b/test/generated/ScXmlTestDeclaration.hxx index d85c2b7..7fdf60e 100644 --- a/test/generated/ScXmlTestDeclaration.hxx +++ b/test/generated/ScXmlTestDeclaration.hxx @@ -1,5 +1,5 @@ // Statemachine ScXmlTest declaration -// Generated: 23.08.24, 20:41 +// Generated: 17.10.24, 21:37 #pragma once diff --git a/test/generated/ScXmlTestInstance.hxx b/test/generated/ScXmlTestInstance.hxx index 1339d1f..25f132f 100644 --- a/test/generated/ScXmlTestInstance.hxx +++ b/test/generated/ScXmlTestInstance.hxx @@ -1,5 +1,5 @@ // Statemachine ScXmlTest instance -// Generated: 23.08.24, 20:41 +// Generated: 17.10.24, 21:37 #pragma once diff --git a/test/generated/XmiTestDeclaration.hxx b/test/generated/XmiTestDeclaration.hxx index 8c42416..31917e0 100644 --- a/test/generated/XmiTestDeclaration.hxx +++ b/test/generated/XmiTestDeclaration.hxx @@ -1,5 +1,5 @@ // Statemachine XmiTest declaration -// Generated: 23.08.24, 20:41 +// Generated: 17.10.24, 21:37 #pragma once diff --git a/test/generated/XmiTestInstance.hxx b/test/generated/XmiTestInstance.hxx index 784d552..9754ffa 100644 --- a/test/generated/XmiTestInstance.hxx +++ b/test/generated/XmiTestInstance.hxx @@ -1,5 +1,5 @@ // Statemachine XmiTest instance -// Generated: 23.08.24, 20:41 +// Generated: 17.10.24, 21:37 #pragma once @@ -19,10 +19,18 @@ static XmiTest::Transition State_1Handler(XmiTest::ImplPtr impl, XmiTest::Event { (void)impl; // impl parameter is unused when there is no guard function being called in here - (void) event; // No outgoing transitions + switch(XmiTest_GET_INSTANCE_EVENT_ID(event)) + { + case XmiTest_GET_STATIC_EVENT_ID(SelfTransition): + return XmiTest::TransitionTo(XmiTest::kState_1); + break; + + default: + break; + } return XmiTest::UnhandledEvent(); } -const XmiTest::State XmiTest::kState_1("State_1", &State_1Handler, nullptr, &XmiTest::kState_1State_2, &XmiTest::Impl::State1OnEntry, nullptr); +const XmiTest::State XmiTest::kState_1("State_1", &State_1Handler, nullptr, &XmiTest::kState_1State_2, &XmiTest::Impl::State1OnEntry, &XmiTest::Impl::State1OnExit); // State State_1::StateWithSameName static XmiTest::Transition State_1StateWithSameNameHandler(XmiTest::ImplPtr impl, XmiTest::Event event) @@ -80,6 +88,10 @@ static XmiTest::Transition State_1State_4Handler(XmiTest::ImplPtr impl, XmiTest: switch(XmiTest_GET_INSTANCE_EVENT_ID(event)) { + case XmiTest_GET_STATIC_EVENT_ID(SelfTransition): + return XmiTest::TransitionTo(XmiTest::kState_1State_4); + break; + case XmiTest_GET_STATIC_EVENT_ID(Transition_8): return XmiTest::TransitionTo(XmiTest::kState_1State_2); break; @@ -107,16 +119,16 @@ static XmiTest::Transition State_1State_4StateWithSameNameHandler(XmiTest::ImplP { if (impl->ChoiceGuard2(event)) { - static const auto kActions3 = std::to_array({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::CommaAction2, &XmiTest::Impl::ChoiceAction2}); - return XmiTest::TransitionTo(XmiTest::kState_1State_4State_5, kActions3); + static const auto kActions1 = std::to_array({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::CommaAction2, &XmiTest::Impl::ChoiceAction2}); + return XmiTest::TransitionTo(XmiTest::kState_1State_4State_5, kActions1); } if (impl->ChoiceGuard3(event)) { - static const auto kActions4 = std::to_array({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::CommaAction2, &XmiTest::Impl::ChoiceAction3, &XmiTest::Impl::ChoiceAction4}); - return XmiTest::TransitionTo(XmiTest::kState_1State_2, kActions4); + static const auto kActions2 = std::to_array({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::CommaAction2, &XmiTest::Impl::ChoiceAction3, &XmiTest::Impl::ChoiceAction4}); + return XmiTest::TransitionTo(XmiTest::kState_1State_2, kActions2); } - static const auto kActions5 = std::to_array({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::CommaAction2, &XmiTest::Impl::ChoiceAction3}); - return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions5); + static const auto kActions3 = std::to_array({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::CommaAction2, &XmiTest::Impl::ChoiceAction3}); + return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions3); } break; diff --git a/test/xmi/XmiTest.notation b/test/xmi/XmiTest.notation index b48cf29..1de488f 100644 --- a/test/xmi/XmiTest.notation +++ b/test/xmi/XmiTest.notation @@ -12,7 +12,7 @@ - + @@ -194,7 +194,7 @@ - + @@ -204,8 +204,12 @@ + + + + - + @@ -438,7 +442,7 @@ - + @@ -515,4 +519,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/xmi/XmiTest.uml b/test/xmi/XmiTest.uml index a442934..7ff361e 100644 --- a/test/xmi/XmiTest.uml +++ b/test/xmi/XmiTest.uml @@ -6,8 +6,12 @@ + + + - + + @@ -68,6 +72,9 @@ + + + @@ -87,4 +94,5 @@ +