Skip to content
Snippets Groups Projects
Commit e9e458f0 authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Top-level chooses have their spec extracted

parent d6a65563
No related branches found
No related tags found
No related merge requests found
...@@ -76,6 +76,18 @@ object ConversionPhase extends UnitPhase[Program] { ...@@ -76,6 +76,18 @@ object ConversionPhase extends UnitPhase[Program] {
* choose(x => post(x)) * choose(x => post(x))
* } * }
* *
* 4) Functions that have only a choose as body gets their spec from the choose.
*
* def foo(a: T) = {
* choose(x => post(a, x))
* }
*
* gets converted to:
*
* def foo(a: T) = {
* choose(x => post(a, x))
* } ensuring { x => post(a, x) }
*
*/ */
def convert(e : Expr, ctx : LeonContext) : Expr = { def convert(e : Expr, ctx : LeonContext) : Expr = {
...@@ -115,7 +127,7 @@ object ConversionPhase extends UnitPhase[Program] { ...@@ -115,7 +127,7 @@ object ConversionPhase extends UnitPhase[Program] {
} }
} }
body match { val fullBody = body match {
case Some(body) => case Some(body) =>
var holes = List[Identifier]() var holes = List[Identifier]()
...@@ -172,6 +184,14 @@ object ConversionPhase extends UnitPhase[Program] { ...@@ -172,6 +184,14 @@ object ConversionPhase extends UnitPhase[Program] {
val newPost = post getOrElse Lambda(Seq(ValDef(FreshIdentifier("res", e.getType))), BooleanLiteral(true)) val newPost = post getOrElse Lambda(Seq(ValDef(FreshIdentifier("res", e.getType))), BooleanLiteral(true))
withPrecondition(Choose(newPost), pre) withPrecondition(Choose(newPost), pre)
} }
// extract spec from chooses at the top-level
fullBody match {
case Choose(spec) =>
withPostcondition(fullBody, Some(spec))
case _ =>
fullBody
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment