mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
no longer do return value optimization with tempvar, this caused invalid code sometimes.
This commit is contained in:
parent
8ab47d3321
commit
ca7932c4f0
@ -374,31 +374,4 @@ class StatementOptimizer(private val program: Program,
|
|||||||
|
|
||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun after(returnStmt: Return, parent: Node): Iterable<IAstModification> {
|
|
||||||
|
|
||||||
if(compTarget.name==VMTarget.NAME)
|
|
||||||
return noModifications
|
|
||||||
|
|
||||||
val returnvalue = returnStmt.value
|
|
||||||
if (returnvalue!=null) {
|
|
||||||
val dt = returnvalue.inferType(program).getOr(DataType.UNDEFINED)
|
|
||||||
if(dt!=DataType.UNDEFINED) {
|
|
||||||
if (returnvalue is BinaryExpression || (returnvalue is TypecastExpression && !returnvalue.expression.isSimple)) {
|
|
||||||
// first assign to intermediary variable, then return that
|
|
||||||
val (returnVarName, _) = program.getTempVar(dt)
|
|
||||||
val returnValueIntermediary = IdentifierReference(returnVarName, returnStmt.position)
|
|
||||||
val tgt = AssignTarget(returnValueIntermediary, null, null, returnStmt.position)
|
|
||||||
val assign = Assignment(tgt, returnvalue, AssignmentOrigin.OPTIMIZER, returnStmt.position)
|
|
||||||
val returnReplacement = Return(returnValueIntermediary.copy(), returnStmt.position)
|
|
||||||
return listOf(
|
|
||||||
IAstModification.InsertBefore(returnStmt, assign, parent as IStatementContainer),
|
|
||||||
IAstModification.ReplaceNode(returnStmt, returnReplacement, parent)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return noModifications
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user