Skip to content
Snippets Groups Projects
Commit 2caaa959 authored by Manos Koukoutos's avatar Manos Koukoutos
Browse files

Refactor TypedFunDef

parent 2edb6f85
No related branches found
No related tags found
No related merge requests found
...@@ -59,8 +59,7 @@ object Definitions { ...@@ -59,8 +59,7 @@ object Definitions {
def toVariable : Variable = Variable(id) def toVariable : Variable = Variable(id)
} }
/** A wrapper for a program. For now a program is simply a single object. The /** A wrapper for a program. For now a program is simply a single object. */
* name is meaningless and we just use the package name as id. */
case class Program(units: List[UnitDef]) extends Definition { case class Program(units: List[UnitDef]) extends Definition {
val id = FreshIdentifier("program") val id = FreshIdentifier("program")
...@@ -481,43 +480,19 @@ object Definitions { ...@@ -481,43 +480,19 @@ object Definitions {
lazy val returnType: TypeTree = translated(fd.returnType) lazy val returnType: TypeTree = translated(fd.returnType)
private var trCache = Map[Expr, Expr]() private var trCache = Map[Expr, Expr]()
private var postCache = Map[Expr, Expr]()
def fullBody = { private def cached(e: Expr): Expr = {
val fb = fd.fullBody trCache.getOrElse(e, {
trCache.getOrElse(fb, { val res = translated(e)
val res = translated(fb) trCache += e -> res
trCache += fb -> res
res res
}) })
} }
def body = fd.body.map { b => def fullBody = cached(fd.fullBody)
trCache.getOrElse(b, { def body = fd.body map cached
val res = translated(b) def precondition = fd.precondition map cached
trCache += b -> res def postcondition = fd.postcondition map cached
res
})
}
def precondition = fd.precondition.map { pre =>
trCache.getOrElse(pre, {
val res = translated(pre)
trCache += pre -> res
res
})
}
def postcondition = fd.postcondition.map {
case post if typesMap.nonEmpty =>
postCache.getOrElse(post, {
val res = instantiateType(post, typesMap, paramsMap)
postCache += (post -> res)
res
})
case p => p
}
def hasImplementation = body.isDefined def hasImplementation = body.isDefined
def hasBody = hasImplementation def hasBody = hasImplementation
......
...@@ -35,7 +35,7 @@ trait StructuralSize { ...@@ -35,7 +35,7 @@ trait StructuralSize {
Variable(x), Variable(x),
uminus(Variable(x)) uminus(Variable(x))
)) ))
TypedFunDef(absFun, Seq()) // Seq() because no generic type params absFun.typed
} }
def size(expr: Expr) : Expr = { def size(expr: Expr) : Expr = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment