mirror of
https://github.com/irmen/prog8.git
synced 2024-08-19 14:29:17 +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 biggerThan(other: DataType) =
|
||||
infix fun largerThan(other: DataType) =
|
||||
when(this) {
|
||||
in ByteDatatypes -> false
|
||||
in WordDatatypes -> other in ByteDatatypes
|
||||
|
@ -49,6 +49,15 @@ internal class SimplifyExpressions(private val program: Program) : IAstModifying
|
||||
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)
|
||||
}
|
||||
optimizationsDone++
|
||||
@ -385,7 +394,7 @@ internal class SimplifyExpressions(private val program: Program) : IAstModifying
|
||||
}
|
||||
|
||||
if(leftConstVal==null && rightConstVal!=null) {
|
||||
if(leftDt biggerThan rightDt) {
|
||||
if(leftDt largerThan rightDt) {
|
||||
val (adjusted, newValue) = adjust(rightConstVal, leftDt)
|
||||
if (adjusted) {
|
||||
expr.right = newValue
|
||||
@ -395,7 +404,7 @@ internal class SimplifyExpressions(private val program: Program) : IAstModifying
|
||||
}
|
||||
return false
|
||||
} else if(leftConstVal!=null && rightConstVal==null) {
|
||||
if(rightDt biggerThan leftDt) {
|
||||
if(rightDt largerThan leftDt) {
|
||||
val (adjusted, newValue) = adjust(leftConstVal, rightDt)
|
||||
if (adjusted) {
|
||||
expr.left = newValue
|
||||
|
Loading…
Reference in New Issue
Block a user