Skip to content

Commit c699932

Browse files
committed
Merge determineForwardPath functions
1 parent 7d0f4fd commit c699932

1 file changed

Lines changed: 15 additions & 38 deletions

File tree

src/main/kotlin/be/ugent/topl/mio/debugger/MultiverseDebugger.kt

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -310,23 +310,26 @@ class MultiverseDebugger(
310310
return null
311311
}
312312

313-
fun determineForwardPathNonDescendant(targetNode: MultiverseNode, targetInstructionOffset: Int): List<MultiverseNode> {
314-
// rCMD policy:
315-
/*reset() // The current node is earlier in time or in a different branch so we reset the execution.
316-
return graph.rootNode.findPath(targetNode)*/
313+
fun determineForwardPath(stopNode: MultiverseNode, targetNode: MultiverseNode, targetInstructionOffset: Int): List<MultiverseNode> {
314+
if (stopNode != graph.currentNode && stopNode != graph.rootNode) {
315+
throw IllegalArgumentException("stopNode should be the root node or the current node!")
316+
}
317317

318318
val path = mutableListOf<MultiverseNode>() // visited path, should be inverted to go forwards
319319
var currentNode = targetNode
320320
var restorePoint = findValidSnapshot(currentNode, targetNode, targetInstructionOffset)
321-
while (restorePoint == null && currentNode.parent != null) {
321+
while (restorePoint == null && currentNode != stopNode) {
322322
path.addFirst(currentNode)
323323
currentNode = currentNode.parent!!
324324
restorePoint = findValidSnapshot(currentNode, targetNode, targetInstructionOffset)
325325
}
326326
path.addFirst(currentNode)
327-
if (currentNode.parent == null) {
328-
// We went all the way to the rootnode and found no snapshots -> reset!
329-
reset()
327+
if (currentNode == stopNode) {
328+
// We went all the way to the current node, now we just need to walk forward.
329+
if (currentNode != graph.currentNode) {
330+
// We will restart from the root -> reset first.
331+
reset()
332+
}
330333
}
331334
else {
332335
// We found a valid snapshot to restore on the path back.
@@ -340,32 +343,6 @@ class MultiverseDebugger(
340343
return path
341344
}
342345

343-
fun determineForwardPathDescendant(cNode: MultiverseNode, targetNode: MultiverseNode, targetInstructionOffset: Int): List<MultiverseNode> {
344-
// rCMD policy:
345-
/*reset() // The current node is earlier in time or in a different branch so we reset the execution.
346-
return graph.rootNode.findPath(targetNode)*/
347-
348-
val path = mutableListOf<MultiverseNode>() // visited path, should be inverted to go forwards
349-
var currentNode = targetNode
350-
var restorePoint = findValidSnapshot(currentNode, targetNode, targetInstructionOffset)
351-
while (restorePoint == null && currentNode != cNode) {
352-
path.addFirst(currentNode)
353-
currentNode = currentNode.parent!!
354-
restorePoint = findValidSnapshot(currentNode, targetNode, targetInstructionOffset)
355-
}
356-
path.addFirst(currentNode)
357-
if (currentNode == cNode) {
358-
// We went all the way to the current node, now we just need to walk forward.
359-
}
360-
else {
361-
// We found a valid snapshot to restore on the path back.
362-
loadSnapshot(restorePoint!!.first)
363-
graph.currentNode = currentNode
364-
graph.instructionOffset = restorePoint.second
365-
}
366-
return path
367-
}
368-
369346
/**
370347
* Navigate to [targetNode] at [targetInstructionOffset] in the multiverse graph. If this state is earlier in time
371348
* or in a different branch, the execution will first reset and then re-execute from the root node.
@@ -377,14 +354,14 @@ class MultiverseDebugger(
377354
val forwardPath = if (graph.currentNode.findPath(targetNode).isEmpty() ||
378355
(graph.currentNode == targetNode && graph.instructionOffset > targetInstructionOffset)) {
379356
logger.info("Target is not a descendant of the current node")
380-
// In this path we first restore or reset and then go forward/
381-
determineForwardPathNonDescendant(targetNode, targetInstructionOffset)
357+
// In this path we first restore or reset and then go forward.
358+
determineForwardPath(graph.rootNode, targetNode, targetInstructionOffset)
382359
}
383360
else {
384361
logger.info("Target is a descendant of the current node")
385-
// In this path we could go forward from the current node or we restore a closer snapshot and then go forward.
362+
// In this path we could go forward from the current node, or we restore a closer snapshot and then go forward.
386363
//graph.currentNode.findPath(targetNode)
387-
determineForwardPathDescendant(graph.currentNode, targetNode, targetInstructionOffset)
364+
determineForwardPath(graph.currentNode, targetNode, targetInstructionOffset)
388365
}
389366
logger.info("Forward path (len = ${forwardPath.size}) = $forwardPath")
390367
logger.info("Current node = ${graph.currentNode}, offset = ${graph.instructionOffset}")

0 commit comments

Comments
 (0)