Skip to content

Commit

Permalink
Changed behavior of code generator and added test to verify default t…
Browse files Browse the repository at this point in the history
…ransition behaves as external type.
  • Loading branch information
clnhlzmn committed Mar 25, 2021
1 parent 4cce8bd commit 76675f6
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions makina-compiler/src/xyz/colinholzman/makina/CodeGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Handler.Exit>()) {
Expand All @@ -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<Handler.Entry>()) {
println("\t\t\t${entry.action}(self, event);")
Expand Down

0 comments on commit 76675f6

Please sign in to comment.