Skip to content

Commit

Permalink
Change unique_id handling to produce smaller diffs on changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dziegel committed Oct 17, 2024
1 parent 8541c42 commit dbb5281
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 24 deletions.
3 changes: 3 additions & 0 deletions generator/src/generator/InstanceHandler.egl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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);
%]
Expand Down
6 changes: 3 additions & 3 deletions generator/src/generator/InstanceHandlerTransition.egl
Original file line number Diff line number Diff line change
Expand Up @@ -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%]});
[%
}
%]
Expand Down
1 change: 1 addition & 0 deletions generator/src/generator/InstanceHandlerTransitionRoot.egl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions generator/src/generator/Transformations.egl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
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: 23.08.24, 20:41
// Generated: 17.10.24, 21:37

#pragma once

Expand Down
3 changes: 2 additions & 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: 23.08.24, 20:41
// Generated: 17.10.24, 21:37

#pragma once

Expand All @@ -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;
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: 23.08.24, 20:41
// Generated: 17.10.24, 21:37

#pragma once

Expand Down
2 changes: 1 addition & 1 deletion test/generated/ScXmlTestInstance.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine ScXmlTest instance
// Generated: 23.08.24, 20:41
// Generated: 17.10.24, 21:37

#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: 23.08.24, 20:41
// Generated: 17.10.24, 21:37

#pragma once

Expand Down
30 changes: 21 additions & 9 deletions test/generated/XmiTestInstance.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine XmiTest instance
// Generated: 23.08.24, 20:41
// Generated: 17.10.24, 21:37

#pragma once

Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -107,16 +119,16 @@ static XmiTest::Transition State_1State_4StateWithSameNameHandler(XmiTest::ImplP
{
if (impl->ChoiceGuard2(event))
{
static const auto kActions3 = std::to_array<XmiTest::ActionType>({&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::ActionType>({&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::ActionType>({&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::ActionType>({&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::ActionType>({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::CommaAction2, &XmiTest::Impl::ChoiceAction3});
return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions5);
static const auto kActions3 = std::to_array<XmiTest::ActionType>({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::CommaAction2, &XmiTest::Impl::ChoiceAction3});
return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions3);
}
break;

Expand Down
50 changes: 46 additions & 4 deletions test/xmi/XmiTest.notation
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<children xmi:type="notation:BasicCompartment" xmi:id="_j2Q8qLr8Ee60g8u59OCKgQ" type="Region_SubvertexCompartment">
<children xmi:type="notation:Shape" xmi:id="_yxJAgLr8Ee60g8u59OCKgQ" type="State_Shape">
<children xmi:type="notation:DecorationNode" xmi:id="_yxJnkLr8Ee60g8u59OCKgQ" type="State_NameLabel">
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_Z54WkLr9Ee6r94MfzN2GzQ" width="701" height="40"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_Z54WkLr9Ee6r94MfzN2GzQ" width="701" height="58"/>
</children>
<children xmi:type="notation:DecorationNode" xmi:id="_yxJnkbr8Ee60g8u59OCKgQ" type="State_FloatingNameLabel">
<layoutConstraint xmi:type="notation:Location" xmi:id="_yxJnkrr8Ee60g8u59OCKgQ" x="40"/>
Expand Down Expand Up @@ -194,7 +194,7 @@
<element xmi:type="uml:Region" href="XmiTest.uml#_a14r0Lr9Ee6r94MfzN2GzQ"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_a2Jxkbr9Ee6r94MfzN2GzQ" width="701" height="601"/>
</children>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_yxKOobr8Ee60g8u59OCKgQ" y="40" width="701" height="601"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_yxKOobr8Ee60g8u59OCKgQ" y="58" width="701" height="601"/>
</children>
<children xmi:type="notation:BasicCompartment" xmi:id="_K5BmgLr9Ee6r94MfzN2GzQ" type="compartment_shape_display">
<styles xmi:type="notation:TitleStyle" xmi:id="_K5Bmgbr9Ee6r94MfzN2GzQ"/>
Expand All @@ -204,8 +204,12 @@
<element xmi:type="uml:FunctionBehavior" href="XmiTest.uml#_hzxlALs_Ee6r94MfzN2GzQ"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_h0YpAbs_Ee6r94MfzN2GzQ" x="-10" y="-2"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_Yy5_8G7BEe-Hrv9TL11c5Q" type="Behavior_ExitBehaviorLabel">
<element xmi:type="uml:FunctionBehavior" href="XmiTest.uml#_Yya3wG7BEe-Hrv9TL11c5Q"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_Yy5_8W7BEe-Hrv9TL11c5Q" x="-10" y="-4"/>
</children>
<element xmi:type="uml:State" href="XmiTest.uml#_yxCS0Lr8Ee60g8u59OCKgQ"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_yxJAgbr8Ee60g8u59OCKgQ" x="79" y="18" width="701" height="641"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_yxJAgbr8Ee60g8u59OCKgQ" x="79" y="18" width="701" height="659"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_2cssQLr8Ee60g8u59OCKgQ" type="Pseudostate_InitialShape">
<children xmi:type="notation:DecorationNode" xmi:id="_2ctTULr8Ee60g8u59OCKgQ" type="Pseudostate_InitialFloatingNameLabel">
Expand Down Expand Up @@ -438,7 +442,7 @@
</children>
<styles xmi:type="notation:FontStyle" xmi:id="_ldv94bxnEe6cZuHlyUXtcQ"/>
<element xmi:type="uml:Transition" href="XmiTest.uml#_ldKIALxnEe6cZuHlyUXtcQ"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_ldv94rxnEe6cZuHlyUXtcQ" points="[640, 610, -643984, -643984]$[240, 600, -643984, -643984]$[240, 486, -643984, -643984]"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_ldv94rxnEe6cZuHlyUXtcQ" points="[640, 628, -643984, -643984]$[240, 620, -643984, -643984]$[240, 504, -643984, -643984]"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_le50cLxnEe6cZuHlyUXtcQ" id="(0.0,0.5)"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_le50cbxnEe6cZuHlyUXtcQ" id="(0.7547169811320755,1.0)"/>
</edges>
Expand Down Expand Up @@ -515,4 +519,42 @@
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_ucpLgF_6Ee-nkouQL1JVbw" id="(0.15,0.6)"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_ucpLgV_6Ee-nkouQL1JVbw" id="(0.9667774086378738,1.0)"/>
</edges>
<edges xmi:type="notation:Connector" xmi:id="_Obp4QG7BEe-Hrv9TL11c5Q" type="Transition_Edge" source="_yxJAgLr8Ee60g8u59OCKgQ" target="_yxJAgLr8Ee60g8u59OCKgQ">
<children xmi:type="notation:DecorationNode" xmi:id="_Obwl8G7BEe-Hrv9TL11c5Q" type="Transition_NameLabel">
<styles xmi:type="notation:BooleanValueStyle" xmi:id="_PWqH8G7BEe-Hrv9TL11c5Q" name="IS_UPDATED_POSITION" booleanValue="true"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_Obwl8W7BEe-Hrv9TL11c5Q" y="19"/>
</children>
<children xmi:type="notation:DecorationNode" xmi:id="_Obwl8m7BEe-Hrv9TL11c5Q" type="Transition_GuardLabel">
<styles xmi:type="notation:BooleanValueStyle" xmi:id="_PXi4wG7BEe-Hrv9TL11c5Q" name="IS_UPDATED_POSITION" booleanValue="true"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_Obwl827BEe-Hrv9TL11c5Q" x="-3" y="14"/>
</children>
<children xmi:type="notation:DecorationNode" xmi:id="_ObxNAG7BEe-Hrv9TL11c5Q" type="Transition_StereotypeLabel">
<styles xmi:type="notation:BooleanValueStyle" xmi:id="_PYX_MG7BEe-Hrv9TL11c5Q" name="IS_UPDATED_POSITION" booleanValue="true"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_ObxNAW7BEe-Hrv9TL11c5Q" y="59"/>
</children>
<styles xmi:type="notation:FontStyle" xmi:id="_Obp4QW7BEe-Hrv9TL11c5Q"/>
<element xmi:type="uml:Transition" href="XmiTest.uml#_OWhgoG7BEe-Hrv9TL11c5Q"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_Obp4Qm7BEe-Hrv9TL11c5Q" points="[100, 121, -643984, -643984]$[60, 120, -643984, -643984]$[60, 183, -643984, -643984]$[100, 183, -643984, -643984]"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_OeRHYG7BEe-Hrv9TL11c5Q" id="(0.0,0.09256449165402124)"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_OeRHYW7BEe-Hrv9TL11c5Q" id="(0.0,0.18664643399089528)"/>
</edges>
<edges xmi:type="notation:Connector" xmi:id="_nq02cG7BEe-Hrv9TL11c5Q" type="Transition_Edge" source="_vK6rQLr9Ee6r94MfzN2GzQ" target="_vK6rQLr9Ee6r94MfzN2GzQ">
<children xmi:type="notation:DecorationNode" xmi:id="_nq1dgG7BEe-Hrv9TL11c5Q" type="Transition_NameLabel">
<styles xmi:type="notation:BooleanValueStyle" xmi:id="_oKLE4G7BEe-Hrv9TL11c5Q" name="IS_UPDATED_POSITION" booleanValue="true"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_nq1dgW7BEe-Hrv9TL11c5Q" x="-1" y="18"/>
</children>
<children xmi:type="notation:DecorationNode" xmi:id="_nq1dgm7BEe-Hrv9TL11c5Q" type="Transition_GuardLabel">
<styles xmi:type="notation:BooleanValueStyle" xmi:id="_oKo-8G7BEe-Hrv9TL11c5Q" name="IS_UPDATED_POSITION" booleanValue="true"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_nq2EkG7BEe-Hrv9TL11c5Q" x="2" y="-8"/>
</children>
<children xmi:type="notation:DecorationNode" xmi:id="_nq2EkW7BEe-Hrv9TL11c5Q" type="Transition_StereotypeLabel">
<styles xmi:type="notation:BooleanValueStyle" xmi:id="_oLONwG7BEe-Hrv9TL11c5Q" name="IS_UPDATED_POSITION" booleanValue="true"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_nq2Ekm7BEe-Hrv9TL11c5Q" x="-1" y="58"/>
</children>
<styles xmi:type="notation:FontStyle" xmi:id="_nq02cW7BEe-Hrv9TL11c5Q"/>
<element xmi:type="uml:Transition" href="XmiTest.uml#_nqPnoG7BEe-Hrv9TL11c5Q"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_nq02cm7BEe-Hrv9TL11c5Q" points="[480, 318, -643984, -643984]$[480, 280, -643984, -643984]$[400, 280, -643984, -643984]$[400, 318, -643984, -643984]"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_nsMIYG7BEe-Hrv9TL11c5Q" id="(0.5446293494704992,0.0)"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_nsMIYW7BEe-Hrv9TL11c5Q" id="(0.4236006051437216,0.0)"/>
</edges>
</notation:Diagram>
10 changes: 9 additions & 1 deletion test/xmi/XmiTest.uml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
<packagedElement xmi:type="uml:StateMachine" xmi:id="_jJpHMLr8Ee60g8u59OCKgQ" name="XmiTest">
<region xmi:type="uml:Region" xmi:id="_j2PHcLr8Ee60g8u59OCKgQ" name="Region1">
<transition xmi:type="uml:Transition" xmi:id="_4iNAMLr8Ee60g8u59OCKgQ" source="_2ciUMLr8Ee60g8u59OCKgQ" target="_yxCS0Lr8Ee60g8u59OCKgQ"/>
<transition xmi:type="uml:Transition" xmi:id="_OWhgoG7BEe-Hrv9TL11c5Q" source="_yxCS0Lr8Ee60g8u59OCKgQ" target="_yxCS0Lr8Ee60g8u59OCKgQ">
<trigger xmi:type="uml:Trigger" xmi:id="_d0BJYG7BEe-Hrv9TL11c5Q" name="SelfTransition" event="_1d9PIG7BEe-Hrv9TL11c5Q"/>
</transition>
<subvertex xmi:type="uml:State" xmi:id="_yxCS0Lr8Ee60g8u59OCKgQ" name="State_1">
<entry xmi:type="uml:FunctionBehavior" xmi:id="_hzxlALs_Ee6r94MfzN2GzQ" name="State1OnEntry"/>
<entry xmi:type="uml:FunctionBehavior" xmi:id="_hzxlALs_Ee6r94MfzN2GzQ" name="State1OnEntry" visibility="public"/>
<exit xmi:type="uml:FunctionBehavior" xmi:id="_Yya3wG7BEe-Hrv9TL11c5Q" name="State1OnExit"/>
<region xmi:type="uml:Region" xmi:id="_a14r0Lr9Ee6r94MfzN2GzQ" name="Region1">
<transition xmi:type="uml:Transition" xmi:id="_6EdnsLr9Ee6r94MfzN2GzQ" source="_ehpy8Lr9Ee6r94MfzN2GzQ" target="_a2OqELr9Ee6r94MfzN2GzQ"/>
<transition xmi:type="uml:Transition" xmi:id="_BVwEALr-Ee6r94MfzN2GzQ" guard="_POxYwLs_Ee6r94MfzN2GzQ" source="_a2OqELr9Ee6r94MfzN2GzQ" target="_tPkY4Lr9Ee6r94MfzN2GzQ">
Expand Down Expand Up @@ -68,6 +72,9 @@
<ownedRule xmi:type="uml:Constraint" xmi:id="_ukWWALxnEe6cZuHlyUXtcQ" name="else"/>
<effect xmi:type="uml:FunctionBehavior" xmi:id="_BXnAsLxoEe6cZuHlyUXtcQ" name="ChoiceAction3"/>
</transition>
<transition xmi:type="uml:Transition" xmi:id="_nqPnoG7BEe-Hrv9TL11c5Q" source="_vKf0gLr9Ee6r94MfzN2GzQ" target="_vKf0gLr9Ee6r94MfzN2GzQ">
<trigger xmi:type="uml:Trigger" xmi:id="_3yzmoG7BEe-Hrv9TL11c5Q" event="_1d9PIG7BEe-Hrv9TL11c5Q"/>
</transition>
<subvertex xmi:type="uml:State" xmi:id="_0PA3QLr9Ee6r94MfzN2GzQ" name="State_5"/>
<subvertex xmi:type="uml:State" xmi:id="_27rR0Lr9Ee6r94MfzN2GzQ" name="StateWithSameName"/>
<subvertex xmi:type="uml:Pseudostate" xmi:id="_7dXUULr9Ee6r94MfzN2GzQ" name="" kind="shallowHistory"/>
Expand All @@ -87,4 +94,5 @@
<packagedElement xmi:type="uml:SignalEvent" xmi:id="_xc7rMLs_Ee6r94MfzN2GzQ" name="Transition_6"/>
<packagedElement xmi:type="uml:SignalEvent" xmi:id="_SA33gLtAEe6r94MfzN2GzQ" name="Internal"/>
<packagedElement xmi:type="uml:SignalEvent" xmi:id="_FZ2QILtBEe6r94MfzN2GzQ" name="Transition_4"/>
<packagedElement xmi:type="uml:SignalEvent" xmi:id="_1d9PIG7BEe-Hrv9TL11c5Q" name="SelfTransition"/>
</uml:Model>

0 comments on commit dbb5281

Please sign in to comment.