From 76675f6e9f20da569da47104954f82dd989f9700 Mon Sep 17 00:00:00 2001 From: Colin Holzman Date: Thu, 25 Mar 2021 12:23:17 -0400 Subject: [PATCH] Changed behavior of code generator and added test to verify default transition behaves as external type. --- .../xyz/colinholzman/makina/CodeGenerator.kt | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/makina-compiler/src/xyz/colinholzman/makina/CodeGenerator.kt b/makina-compiler/src/xyz/colinholzman/makina/CodeGenerator.kt index 7a49b2c..49830f9 100644 --- a/makina-compiler/src/xyz/colinholzman/makina/CodeGenerator.kt +++ b/makina-compiler/src/xyz/colinholzman/makina/CodeGenerator.kt @@ -53,17 +53,11 @@ class CodeGenerator(val machine: Machine, } } - private fun getTransition(handler: Handler.Event, sourceState: State, activeLeafState: State): Transition { - var target = handler.getTargetState(sourceState, machine) - if (!target.isLeafState()) - target = target.getStateConfiguration().getLeafState() - return Transition(activeLeafState, target) - } - private fun generateExitActions(handler: Handler.Event, sourceState: State, activeLeafState: State, output: PrintWriter) { output.apply { if (handler.target.isNotEmpty()) { - val transition = getTransition(handler, sourceState, activeLeafState) + val target = handler.getTargetState(sourceState, machine) + val transition = Transition(activeLeafState, target) val exitSet = transition.getExitSet() for (stateToExit in exitSet) { for (exit in stateToExit.handlers.filterIsInstance()) { @@ -78,9 +72,11 @@ class CodeGenerator(val machine: Machine, private fun generateEntryActions(handler: Handler.Event, sourceState: State, activeLeafState: State, output: PrintWriter) { output.apply { if (handler.target.isNotEmpty()) { - val transition = getTransition(handler, sourceState, activeLeafState) - val entrySet = transition.getEntrySet() - println("\t\t\tself->state = ${machine.id}_${transition.target.getFullyQualifiedIdString()};") + val target = handler.getTargetState(sourceState, machine) + val transition = Transition(activeLeafState, target) + val entrySet = transition.getEntrySet() + target.getDefaultEntrySet() + val leafStateTarget = if (target.isLeafState()) target else target.getDefaultEntrySet().last() + println("\t\t\tself->state = ${machine.id}_${leafStateTarget.getFullyQualifiedIdString()};") for (stateToEnter in entrySet) { for (entry in stateToEnter.handlers.filterIsInstance()) { println("\t\t\t${entry.action}(self, event);")