From 42fe052f9f4ec48253749389d2f3ce4606a4e0e3 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 26 Nov 2021 21:09:29 +0100 Subject: [PATCH] got rid of old getScopedSymbolNameForTarget routine --- .../compiler/target/cpu6502/codegen/AsmGen.kt | 23 +++++-------------- .../src/prog8/ast/statements/AstStatements.kt | 2 +- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt index 9e7936737..7a50550b9 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt @@ -522,13 +522,15 @@ class AsmGen(private val program: Program, val targetScope = target.definingSubroutine val identScope = identifier.definingSubroutine return if (targetScope !== identScope) { - val scopedName = getScopedSymbolNameForTarget(identifier.nameInSource.last(), target) + val scopedName = (target as INamedStatement).scopedName if (target is Label) { // make labels locally scoped in the asm. Is slightly problematic, see GitHub issue #62 - val last = scopedName.removeLast() - scopedName.add("_$last") + val newName = scopedName.dropLast(1) + ("_${scopedName.last()}") + fixNameSymbols(newName.joinToString(".")) + } + else { + fixNameSymbols(scopedName.joinToString(".")) } - fixNameSymbols(scopedName.joinToString(".")) } else { if (target is Label) { // make labels locally scoped in the asm. Is slightly problematic, see GitHub issue #62 @@ -546,19 +548,6 @@ class AsmGen(private val program: Program, fun asmVariableName(identifier: IdentifierReference) = fixNameSymbols(identifier.nameInSource.joinToString(".")) - // TODO use INamedStatement.scopedName - private fun getScopedSymbolNameForTarget(actualName: String, target: Statement): MutableList { - val scopedName = mutableListOf(actualName) - var node: Node = target - while (node !is Block) { - node = node.parent - if(node is INameScope) { - scopedName.add(0, node.name) - } - } - return scopedName - } - internal fun asmSymbolName(regs: RegisterOrPair): String = if (regs in Cx16VirtualRegisters) "cx16." + regs.toString().lowercase() diff --git a/compilerAst/src/prog8/ast/statements/AstStatements.kt b/compilerAst/src/prog8/ast/statements/AstStatements.kt index 09b03fcd6..1a9981ccc 100644 --- a/compilerAst/src/prog8/ast/statements/AstStatements.kt +++ b/compilerAst/src/prog8/ast/statements/AstStatements.kt @@ -29,7 +29,7 @@ sealed class Statement : Node { abstract fun accept(visitor: IAstVisitor) abstract fun accept(visitor: AstWalker, parent: Node) -` fun nextSibling(): Statement? { + fun nextSibling(): Statement? { val statements = (parent as? IStatementContainer)?.statements ?: return null val nextIdx = statements.indexOfFirst { it===this } + 1 return if(nextIdx < statements.size)