diff --git a/compiler/test/TestCallgraph.kt b/compiler/test/TestCallgraph.kt index 9a351d214..b1526ae46 100644 --- a/compiler/test/TestCallgraph.kt +++ b/compiler/test/TestCallgraph.kt @@ -117,11 +117,12 @@ class TestCallgraph: FunSpec({ val result = compileText(C64Target(), false, sourcecode)!! val graph = CallGraph(result.compilerAst) graph.allIdentifiers.size shouldBeGreaterThanOrEqual 5 - val empties = graph.allIdentifiers.keys.filter { it.nameInSource==listOf("empty") } + val empties = graph.allIdentifiers.filter { it.first.nameInSource==listOf("empty") } + println(graph.allIdentifiers) empties.size shouldBe 3 - empties[0].position.line shouldBe 4 - empties[1].position.line shouldBe 5 - empties[2].position.line shouldBe 6 + empties[0].first.position.line shouldBe 4 + empties[1].first.position.line shouldBe 5 + empties[2].first.position.line shouldBe 6 } test("checking block and subroutine names usage in assembly code") { diff --git a/compilerAst/src/prog8/compiler/CallGraph.kt b/compilerAst/src/prog8/compiler/CallGraph.kt index e3a06e0de..a98c4e784 100644 --- a/compilerAst/src/prog8/compiler/CallGraph.kt +++ b/compilerAst/src/prog8/compiler/CallGraph.kt @@ -18,14 +18,14 @@ class CallGraph(private val program: Program) : IAstVisitor { val calls = mutableMapOf>().withDefault { setOf() } val calledBy = mutableMapOf>().withDefault { setOf() } val notCalledButReferenced = mutableSetOf() - private val allIdentifiersAndTargets = mutableMapOf() + private val allIdentifiersAndTargets = mutableListOf>() private val allAssemblyNodes = mutableListOf() init { visit(program) } - val allIdentifiers: Map = allIdentifiersAndTargets + val allIdentifiers: List> = allIdentifiersAndTargets private val usedSubroutines: Set by lazy { calledBy.keys + program.entrypoint + notCalledButReferenced @@ -36,7 +36,7 @@ class CallGraph(private val program: Program) : IAstVisitor { val used = mutableSetOf() allIdentifiersAndTargets.forEach { - val target = it.value.definingBlock + val target = it.second.definingBlock used.add(target) } @@ -108,7 +108,7 @@ class CallGraph(private val program: Program) : IAstVisitor { override fun visit(identifier: IdentifierReference) { val target = identifier.targetStatement(program) if(target!=null) - allIdentifiersAndTargets[identifier] = target + allIdentifiersAndTargets.add(identifier to target) // if it's a scoped identifier, the subroutines in the name are also referenced! val scope = identifier.definingScope @@ -196,7 +196,7 @@ class CallGraph(private val program: Program) : IAstVisitor { val assemblyBlocks = allAssemblyNodes.filter { decl.name in it.names || "p8v_" + decl.name in it.names } - return allIdentifiersAndTargets.filter { decl===it.value }.map{ it.key } + assemblyBlocks + return allIdentifiersAndTargets.filter { decl===it.second }.map{ it.first } + assemblyBlocks } private val prefixes = listOf("p8b_", "p8v_", "p8s_", "p8c_", "p8l_", "p8_", "")