Skip to content

Commit

Permalink
Did minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
clnhlzmn committed Mar 26, 2021
1 parent f182217 commit d25b6be
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions makina-compiler/src/xyz/colinholzman/makina/CodeGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Handler.Exit>()) {
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<Handler.Exit>()) {
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<Handler.Entry>()) {
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<Handler.Entry>()) {
println("\t\t\t${entry.action}(self, event);")
}
}
}
Expand Down

0 comments on commit d25b6be

Please sign in to comment.