fix detection of string comparisons (make it aware of new pointer types equivalent to STR)

This commit is contained in:
Irmen de Jong
2025-08-16 17:04:59 +02:00
parent 0cc36ed6e4
commit a3d7b8a899
4 changed files with 23 additions and 9 deletions
@@ -295,11 +295,25 @@ _after:
}
override fun after(expr: BinaryExpression, parent: Node): Iterable<IAstModification> {
fun isStringComparison(leftDt: InferredTypes.InferredType, rightDt: InferredTypes.InferredType): Boolean =
if(leftDt issimpletype BaseDataType.STR && rightDt issimpletype BaseDataType.STR)
true
else
leftDt issimpletype BaseDataType.UWORD && rightDt issimpletype BaseDataType.STR || leftDt issimpletype BaseDataType.STR && rightDt issimpletype BaseDataType.UWORD
fun isStringComparison(leftDt: InferredTypes.InferredType, rightDt: InferredTypes.InferredType): Boolean {
if (leftDt issimpletype BaseDataType.STR && rightDt issimpletype BaseDataType.STR)
return true
if (leftDt issimpletype BaseDataType.UWORD && rightDt issimpletype BaseDataType.STR || leftDt issimpletype BaseDataType.STR && rightDt issimpletype BaseDataType.UWORD)
return true
if(leftDt.isPointer && leftDt.getOrUndef().sub==BaseDataType.UBYTE) {
return if(rightDt issimpletype BaseDataType.STR || rightDt.issimpletype(BaseDataType.UWORD))
true
else
rightDt.isPointer && rightDt.getOrUndef().sub==BaseDataType.UBYTE
}
if(rightDt.isPointer && rightDt.getOrUndef().sub==BaseDataType.UBYTE) {
return if(leftDt issimpletype BaseDataType.STR || leftDt.issimpletype(BaseDataType.UWORD))
true
else
leftDt.isPointer && leftDt.getOrUndef().sub==BaseDataType.UBYTE
}
return false
}
if(expr.operator=="in") {
val containment = ContainmentCheck(expr.left, expr.right, expr.position)
@@ -104,6 +104,9 @@ internal class VerifyFunctionArgTypes(val program: Program, val options: Compila
if(paramDt.isUnsignedWord && argDt.isPointer)
return true
if(paramDt.isString && (argDt.isPointer && argDt.sub==BaseDataType.UBYTE))
return true
return false
}
+1 -1
View File
@@ -491,7 +491,6 @@ main {
val result = compileText(VMTarget(), false, src, outputDir, writeAssembly = false)!!
val main = result.compilerAst.allBlocks.first {it.name=="main"}
val st = main.statements.filterIsInstance<Subroutine>().first {it.name=="start"}.statements
st.size shouldBe 8
fun assertIsStringCompare(expr: BinaryExpression) {
expr.operator shouldBe "=="
@@ -499,6 +498,7 @@ main {
(expr.left as FunctionCallExpression).target.nameInSource shouldBe listOf("prog8_lib_stringcompare")
}
st.size shouldBe 9
val av1 = (st[0] as Assignment).value as BinaryExpression
val av2 = (st[1] as Assignment).value as BinaryExpression
val av3 = (st[2] as Assignment).value as BinaryExpression
-3
View File
@@ -1,9 +1,6 @@
TODO
====
fix pointer arith type error (shell fails to compile) if diskio.list_filename==filename where filename is a str parameter
STRUCTS and TYPED POINTERS (6502 codegen specific)
--------------------------------------------------