mirror of
https://github.com/irmen/prog8.git
synced 2025-02-21 10:29:03 +00:00
optimize redundant typecasts more
This commit is contained in:
parent
c9b16dcbd9
commit
12cb7d7abe
@ -38,7 +38,7 @@ enum class DataType {
|
|||||||
|
|
||||||
infix fun isAssignableTo(targetTypes: Set<DataType>) = targetTypes.any { this isAssignableTo it }
|
infix fun isAssignableTo(targetTypes: Set<DataType>) = targetTypes.any { this isAssignableTo it }
|
||||||
|
|
||||||
infix fun biggerThan(other: DataType) =
|
infix fun largerThan(other: DataType) =
|
||||||
when(this) {
|
when(this) {
|
||||||
in ByteDatatypes -> false
|
in ByteDatatypes -> false
|
||||||
in WordDatatypes -> other in ByteDatatypes
|
in WordDatatypes -> other in ByteDatatypes
|
||||||
|
@ -49,6 +49,15 @@ internal class SimplifyExpressions(private val program: Program) : IAstModifying
|
|||||||
return tc.expression
|
return tc.expression
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the previous typecast was casting to a 'bigger' type, just ignore that one
|
||||||
|
val subTc = tc.expression as? TypecastExpression
|
||||||
|
if(subTc!=null && subTc.type largerThan tc.type) {
|
||||||
|
subTc.type = tc.type
|
||||||
|
subTc.parent = tc.parent
|
||||||
|
optimizationsDone++
|
||||||
|
return subTc
|
||||||
|
}
|
||||||
return super.visit(tc)
|
return super.visit(tc)
|
||||||
}
|
}
|
||||||
optimizationsDone++
|
optimizationsDone++
|
||||||
@ -385,7 +394,7 @@ internal class SimplifyExpressions(private val program: Program) : IAstModifying
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(leftConstVal==null && rightConstVal!=null) {
|
if(leftConstVal==null && rightConstVal!=null) {
|
||||||
if(leftDt biggerThan rightDt) {
|
if(leftDt largerThan rightDt) {
|
||||||
val (adjusted, newValue) = adjust(rightConstVal, leftDt)
|
val (adjusted, newValue) = adjust(rightConstVal, leftDt)
|
||||||
if (adjusted) {
|
if (adjusted) {
|
||||||
expr.right = newValue
|
expr.right = newValue
|
||||||
@ -395,7 +404,7 @@ internal class SimplifyExpressions(private val program: Program) : IAstModifying
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
} else if(leftConstVal!=null && rightConstVal==null) {
|
} else if(leftConstVal!=null && rightConstVal==null) {
|
||||||
if(rightDt biggerThan leftDt) {
|
if(rightDt largerThan leftDt) {
|
||||||
val (adjusted, newValue) = adjust(leftConstVal, rightDt)
|
val (adjusted, newValue) = adjust(leftConstVal, rightDt)
|
||||||
if (adjusted) {
|
if (adjusted) {
|
||||||
expr.left = newValue
|
expr.left = newValue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user