Skip to content
Snippets Groups Projects
Commit 13dca114 authored by Ali Sinan Köksal's avatar Ali Sinan Köksal
Browse files

Extract the body of a predicate in purescala

parent e2c59a06
No related branches found
No related tags found
No related merge requests found
......@@ -275,6 +275,30 @@ trait CodeExtraction extends Extractors {
Program(programName, topLevelObjDef)
}
def extractPredicate(unit: CompilationUnit, params: Seq[ValDef], body: Tree) : FunDef = {
def s2ps(tree: Tree): Expr = toPureScala(unit)(tree) match {
case Some(ex) => ex
case None => stopIfErrors; scala.Predef.error("unreachable error.")
}
def st2ps(tree: Type): purescala.TypeTrees.TypeTree = toPureScalaType(unit)(tree) match {
case Some(tt) => tt
case None => stopIfErrors; scala.Predef.error("unreachable error.")
}
val newParams = params.map(p => {
val ptpe = st2ps(p.tpt.tpe)
val newID = FreshIdentifier(p.name.toString).setType(ptpe)
varSubsts(p.symbol) = (() => Variable(newID))
VarDecl(newID, ptpe)
})
val fd = new FunDef(FreshIdentifier("predicate"), BooleanType, newParams)
val bodyAttempt = toPureScala(unit)(body)
fd.body = bodyAttempt
fd
}
/** An exception thrown when non-purescala compatible code is encountered. */
sealed case class ImpureCodeEncounteredException(tree: Tree) extends Exception
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment