Skip to content
Snippets Groups Projects
Commit 43c307c5 authored by Regis Blanc's avatar Regis Blanc
Browse files

pre and post of nested functions can refer local variables

parent f28ace68
Branches
Tags
No related merge requests found
...@@ -299,6 +299,21 @@ object ImperativeCodeElimination extends UnitPhase[Program] { ...@@ -299,6 +299,21 @@ object ImperativeCodeElimination extends UnitPhase[Program] {
val newBody = fdScope(newRes) val newBody = fdScope(newRes)
newFd.body = Some(newBody) newFd.body = Some(newBody)
newFd.precondition = fd.precondition.map(prec => {
replace(modifiedVars.zip(freshNames).map(p => (p._1.toVariable, p._2.toVariable)).toMap, prec)
})
newFd.postcondition = fd.postcondition.map(post => {
val Lambda(Seq(res), postBody) = post
val newRes = ValDef(FreshIdentifier(res.id.name, newFd.returnType))
val newBody =
replace(
modifiedVars.zipWithIndex.map{ case (v, i) =>
(v.toVariable, TupleSelect(newRes.toVariable, i+2)): (Expr, Expr)}.toMap +
(res.toVariable -> TupleSelect(newRes.toVariable, 1)),
postBody)
Lambda(Seq(newRes), newBody)
})
val (bodyRes, bodyScope, bodyFun) = toFunction(b)(state.withFunDef(fd, newFd, modifiedVars)) val (bodyRes, bodyScope, bodyFun) = toFunction(b)(state.withFunDef(fd, newFd, modifiedVars))
(bodyRes, (b2: Expr) => LetDef(newFd, bodyScope(b2)).copiedFrom(expr), bodyFun) (bodyRes, (b2: Expr) => LetDef(newFd, bodyScope(b2)).copiedFrom(expr), bodyFun)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment