Skip to content

Commit

Permalink
Store successors in List to retain the original order
Browse files Browse the repository at this point in the history
  • Loading branch information
Lipen committed Jun 20, 2024
1 parent 01e5e6f commit 6fb0240
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,16 @@ fun cfg2cfg(cfg: CfgDto, arkMethod: ArkMethod): ArkCfg {
}
}
}
val successorMap: MutableMap<ArkStmt, Set<ArkStmt>> = hashMapOf()
val successorMap: MutableMap<ArkStmt, List<ArkStmt>> = hashMapOf()
for (block in cfg.blocks) {
for (i in block.stmts.indices) {
val arkStmt = stmts[blockStart[block.id]!! + i]
if (i == block.stmts.lastIndex) {
successorMap[arkStmt] = block.successors.mapNotNullTo(hashSetOf()) { id ->
successorMap[arkStmt] = block.successors.mapNotNull { id ->
blockStart[id]?.let { stmts[it] }
}
} else {
successorMap[arkStmt] = setOf(stmts[i + 1])
successorMap[arkStmt] = listOf(stmts[i + 1])
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.jacodb.panda.dynamic.ark.base.ArkTerminatingStmt

class ArkCfg(
val stmts: List<ArkStmt>,
private val successorMap: Map<ArkStmt, Set<ArkStmt>>,
private val successorMap: Map<ArkStmt, List<ArkStmt>>,
) : ControlFlowGraph<ArkStmt> {

private val predecessorMap: Map<ArkStmt, Set<ArkStmt>> by lazy {
Expand All @@ -45,7 +45,7 @@ class ArkCfg(
get() = instructions.filterIsInstance<ArkTerminatingStmt>()

override fun successors(node: ArkStmt): Set<ArkStmt> {
return successorMap[node]!!
return successorMap[node]!!.toSet()
}

override fun predecessors(node: ArkStmt): Set<ArkStmt> {
Expand Down

0 comments on commit 6fb0240

Please sign in to comment.