From d25b6be889e940954340f71612f445c0efcb3025 Mon Sep 17 00:00:00 2001 From: Colin Holzman Date: Fri, 26 Mar 2021 12:30:45 -0400 Subject: [PATCH] Did minor refactoring. --- .../xyz/colinholzman/makina/CodeGenerator.kt | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/makina-compiler/src/xyz/colinholzman/makina/CodeGenerator.kt b/makina-compiler/src/xyz/colinholzman/makina/CodeGenerator.kt index 3a93f40..4a7e354 100644 --- a/makina-compiler/src/xyz/colinholzman/makina/CodeGenerator.kt +++ b/makina-compiler/src/xyz/colinholzman/makina/CodeGenerator.kt @@ -54,33 +54,29 @@ class CodeGenerator(val machine: Machine, } private fun generateExitActions(handler: Handler.Event, sourceState: State, activeLeafState: State, output: PrintWriter) { - output.apply { - if (handler.target != null) { - 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()) { - println("\t\t\t${exit.action}(self, event);") - } + if (handler.target != null) output.apply { + 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()) { + println("\t\t\t${exit.action}(self, event);") } - println("\t\t\tself->state = NULL;") } + println("\t\t\tself->state = NULL;") } } private fun generateEntryActions(handler: Handler.Event, sourceState: State, activeLeafState: State, output: PrintWriter) { - output.apply { - if (handler.target != null) { - 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);") - } + if (handler.target != null) output.apply { + 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);") } } }