mirror of
https://github.com/irmen/prog8.git
synced 2026-04-21 17:16:33 +00:00
fix detection of string comparisons (make it aware of new pointer types equivalent to STR)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
--------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user