Pseudocode: Fix depth-first pseudocode traversal

This commit is contained in:
Alexey Sedunov
2014-06-19 16:17:41 +04:00
parent 0968ea6914
commit d01d186130
@@ -181,18 +181,10 @@ fun traverseFollowingInstructions(
while (!stack.isEmpty()) {
val instruction = stack.pop()
visited.add(instruction)
if (!visited.add(instruction)) continue
if (handler != null && !handler(instruction)) return false
val followingInstructions = instruction.getNextInstructions(order)
for (followingInstruction in followingInstructions) {
if (!visited.contains(followingInstruction)) {
if (handler != null && !handler(instruction)) {
return false
}
stack.push(followingInstruction)
}
}
instruction.getNextInstructions(order).forEach { stack.push(it) }
}
return true
}