From da2288db93dc6825e64badeb0e323983340dcfa4 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 19 Oct 2026 22:16:53 +0200 Subject: [PATCH] improved variable source line position --- .../src/prog8/codegen/intermediate/StConvert.kt | 3 ++- .../src/prog8/codegen/intermediate/StackFrameLayout.kt | 2 +- intermediate/src/prog8/intermediate/IRSymbolTable.kt | 8 +++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/StConvert.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/StConvert.kt index 9fe09f05b..be0ad8958 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/StConvert.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/StConvert.kt @@ -2,6 +2,7 @@ package prog8.codegen.intermediate import prog8.code.* import prog8.code.ast.PtStructField +import prog8.code.core.Position import prog8.intermediate.* /** @@ -78,7 +79,7 @@ private class StToIrConverter(val romable: Boolean) { val hasInit = initValue != null val inBss = !hasInit || romable val readonly = romable && hasInit - return IRStStaticVariable(name, variable.dt, initValue, variable.length, variable.zpwish, variable.align, variable.dirty, inBss, readonly, variable.shared) + return IRStStaticVariable(name, variable.dt, initValue, variable.length, variable.zpwish, variable.align, variable.dirty, inBss, readonly, variable.shared, variable.astNode?.position ?: Position.DUMMY) } fun convert(variable: StMemVar): IRStMemVar { diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/StackFrameLayout.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/StackFrameLayout.kt index f831328ff..afe7000c3 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/StackFrameLayout.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/StackFrameLayout.kt @@ -516,7 +516,7 @@ class StackFrameLayout(private val program: IRProgram, private val errors: IErro locals += LocalLayout(name, elemDt, count, size, alignment, v.dirty, initialized, isFloat) if (v.length != null && size > 8 && !v.dirty && v.initializationValue == null) { val shortName = name.substringAfterLast('.').removePrefix("p8v_") - errors.warn("local array '$shortName' ($size bytes) in subroutine '${userName(sub)}' is zero-initialized on every call which can be costly; consider @dirty if you assign it before use", sub.position) + errors.warn("local array '$shortName' ($size bytes) in subroutine '${userName(sub)}' is zero-initialized on every call which can be costly; consider @dirty if you assign it before use", v.position) } } diff --git a/intermediate/src/prog8/intermediate/IRSymbolTable.kt b/intermediate/src/prog8/intermediate/IRSymbolTable.kt index c12fbaf73..41d5f5913 100644 --- a/intermediate/src/prog8/intermediate/IRSymbolTable.kt +++ b/intermediate/src/prog8/intermediate/IRSymbolTable.kt @@ -2,10 +2,7 @@ package prog8.intermediate import prog8.code.PROG8_CONTAINER_MODULES import prog8.code.SymbolNames -import prog8.code.core.BaseDataType -import prog8.code.core.DataType -import prog8.code.core.Encoding -import prog8.code.core.ZeropageWish +import prog8.code.core.* // In the Intermediate Representation, all nesting has been removed. @@ -132,7 +129,8 @@ class IRStStaticVariable(name: String, val dirty: Boolean, val inBss: Boolean = false, // variable should be placed in BSS (RAM), not inline with code val readonly: Boolean = false, // variable should be treated as read-only - val shared: Boolean = false // the @shared tag: keep the variable in program-static storage + val shared: Boolean = false, // the @shared tag: keep the variable in program-static storage + val position: Position = Position.DUMMY ) : IRStNode(name, IRStNodeType.STATICVAR) { init { if(align > 0u) {