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

Allow adding definitions within a program

parent 179845b0
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,12 @@ object DefOps { ...@@ -18,6 +18,12 @@ object DefOps {
case u : UnitDef => Some(u) case u : UnitDef => Some(u)
case other => other.owner flatMap inUnit case other => other.owner flatMap inUnit
} }
def inModule(df : Definition) : Option[ModuleDef] = df match {
case p : Program => None
case m : ModuleDef => Some(m)
case other => other.owner flatMap inModule
}
def inProgram(df : Definition) : Option[Program] = { def inProgram(df : Definition) : Option[Program] = {
df match { df match {
......
...@@ -10,6 +10,7 @@ object Definitions { ...@@ -10,6 +10,7 @@ object Definitions {
import Common._ import Common._
import Trees._ import Trees._
import TreeOps._ import TreeOps._
import DefOps._
import Extractors._ import Extractors._
import TypeTrees._ import TypeTrees._
import TypeTreeOps._ import TypeTreeOps._
...@@ -80,6 +81,26 @@ object Definitions { ...@@ -80,6 +81,26 @@ object Definitions {
copy(units = units.map{_.duplicate}) copy(units = units.map{_.duplicate})
} }
// Use only to add functions around functions
def addDefinition(d: Definition, around: Definition): Program = {
val Some(m) = inModule(around)
val nm = m.copy(defs = d +: m.defs)
m.owner match {
case Some(u: UnitDef) =>
val nu = u.copy(modules = u.modules.filterNot(_ == m) :+ nm)
u.owner match {
case Some(p: Program) =>
p.copy(units = p.units.filterNot(_ == u) :+ nu)
case _ =>
this
}
case _ =>
this
}
}
lazy val library = Library(this) lazy val library = Library(this)
def writeScalaFile(filename: String) { def writeScalaFile(filename: String) {
......
...@@ -23,9 +23,11 @@ import synthesis.rules._ ...@@ -23,9 +23,11 @@ import synthesis.rules._
import synthesis.heuristics._ import synthesis.heuristics._
import graph.DotGenerator import graph.DotGenerator
class Repairman(ctx: LeonContext, program: Program, fd: FunDef, verifTimeout: Option[Long]) { class Repairman(ctx: LeonContext, initProgram: Program, fd: FunDef, verifTimeout: Option[Long]) {
val reporter = ctx.reporter val reporter = ctx.reporter
var program = initProgram
implicit val debugSection = DebugSectionRepair implicit val debugSection = DebugSectionRepair
def getSynthesizer(tests: List[Example]): Synthesizer = { def getSynthesizer(tests: List[Example]): Synthesizer = {
...@@ -69,6 +71,8 @@ class Repairman(ctx: LeonContext, program: Program, fd: FunDef, verifTimeout: Op ...@@ -69,6 +71,8 @@ class Repairman(ctx: LeonContext, program: Program, fd: FunDef, verifTimeout: Op
passes passes
) )
program = program.addDefinition(nfd, fd)
val p = focusRepair(tests, nfd, spec, out) val p = focusRepair(tests, nfd, spec, out)
val soptions0 = SynthesisPhase.processOptions(ctx); val soptions0 = SynthesisPhase.processOptions(ctx);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment