Skip to content
Snippets Groups Projects
Commit 7c34f26f authored by Emmanouil (Manos) Koukoutos's avatar Emmanouil (Manos) Koukoutos
Browse files

Imports show to fresh Modules during MethodLifting

parent 7fedcb8b
No related branches found
No related tags found
No related merge requests found
...@@ -116,7 +116,7 @@ object Definitions { ...@@ -116,7 +116,7 @@ object Definitions {
abstract class Import extends Definition { abstract class Import extends Definition {
def subDefinitions = Nil def subDefinitions = Nil
lazy val importedDefs = this match { def importedDefs = this match {
case PackageImport(pack) => { case PackageImport(pack) => {
import DefOps._ import DefOps._
// Ignore standalone modules, assume there are extra imports for them // Ignore standalone modules, assume there are extra imports for them
......
...@@ -75,39 +75,48 @@ object MethodLifting extends TransformationPhase { ...@@ -75,39 +75,48 @@ object MethodLifting extends TransformationPhase {
}(e) }(e)
} }
val newUnits = program.units map { u => u.copy ( val modsToMods = ( for {
u <- program.units
m <- u.modules
} yield (m, {
// We remove methods from class definitions and add corresponding functions
val newDefs = m.defs.flatMap {
case acd: AbstractClassDef if acd.methods.nonEmpty =>
acd +: acd.methods.map(translateMethod(_))
case ccd: CaseClassDef if ccd.methods.nonEmpty =>
ccd +: ccd.methods.map(translateMethod(_))
case fd: FunDef =>
List(translateMethod(fd))
case d =>
List(d)
}
// finally, we clear methods from classes
m.defs.foreach {
case cd: ClassDef =>
cd.clearMethods()
case _ =>
}
ModuleDef(m.id, newDefs, m.isStandalone )
})).toMap
val newUnits = program.units map { u => u.copy(
imports = u.imports flatMap { imports = u.imports flatMap {
case s@SingleImport(c : ClassDef) => case s@SingleImport(c : ClassDef) =>
// If a class is imported, also add the "methods" of this class // If a class is imported, also add the "methods" of this class
s :: ( c.methods map { md => SingleImport(mdToFds(md))}) s :: ( c.methods map { md => SingleImport(mdToFds(md))})
// If importing a ModuleDef, update to new ModuleDef
case SingleImport(m : ModuleDef) => List(SingleImport(modsToMods(m)))
case WildcardImport(m : ModuleDef) => List(WildcardImport(modsToMods(m)))
case other => List(other) case other => List(other)
}, },
modules = u.modules map { m => modules = u.modules map modsToMods
// We remove methods from class definitions and add corresponding functions
val newDefs = m.defs.flatMap {
case acd: AbstractClassDef if acd.methods.nonEmpty =>
acd +: acd.methods.map(translateMethod(_))
case ccd: CaseClassDef if ccd.methods.nonEmpty =>
ccd +: ccd.methods.map(translateMethod(_))
case fd: FunDef =>
List(translateMethod(fd))
case d =>
List(d)
}
// finally, we clear methods from classes
m.defs.foreach {
case cd: ClassDef =>
cd.clearMethods()
case _ =>
}
ModuleDef(m.id, newDefs, m.isStandalone )
}
)} )}
Program(program.id, newUnits) Program(program.id, newUnits)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment