diff options
author | Geoffrey Washburn <geoffrey.washburn@epfl.ch> | 2008-05-26 13:34:36 +0000 |
---|---|---|
committer | Geoffrey Washburn <geoffrey.washburn@epfl.ch> | 2008-05-26 13:34:36 +0000 |
commit | 1b1425c63b054b52dc97e2a8cbaf54662a870492 (patch) | |
tree | 436d3427b954137d280cb2f12105fd3eb110226b /src | |
parent | c8882cea3ca77aa55d19430c53e49e75aecabebf (diff) | |
download | scala-1b1425c63b054b52dc97e2a8cbaf54662a870492.tar.gz scala-1b1425c63b054b52dc97e2a8cbaf54662a870492.tar.bz2 scala-1b1425c63b054b52dc97e2a8cbaf54662a870492.zip |
Hooked in the DeVirtualize phase again, though ...
Hooked in the DeVirtualize phase again, though it only runs with
-Xexperimental, and even then it does not work yet.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala | 36 |
3 files changed, 30 insertions, 20 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 4d00907934..75a57a3ff4 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -291,6 +291,10 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable val global: Global.this.type = Global.this } + object devirtualize extends DeVirtualize { + val global: Global.this.type = Global.this + } + object liftcode extends LiftCode { val global: Global.this.type = Global.this } @@ -396,7 +400,11 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable analyzer.namerFactory: SubComponent, // note: types are there because otherwise analyzer.typerFactory: SubComponent, // consistency check after refchecks would fail. superAccessors, // add super accessors - pickler, // serialize symbol tables + pickler // serialize symbol tables + ) ::: ( + // Desugar virtual classes + if (settings.Xexperimental.value) List(devirtualize) else List() + ) ::: List( refchecks // perform reference and override checking, translate nested objects ) ::: ( if (forJVM) List(liftcode) else List() // generate reified trees diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 340f403f9f..c2e1bd1e7e 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -2163,7 +2163,9 @@ trait Parsers extends NewScanners with MarkupParsers { else (accessModifierOpt(), paramClauses(name, implicitClassViews, mods.hasFlag(Flags.CASE))) val thistpe = requiresTypeOpt() var mods1 = mods - if (inToken == SUBTYPE) mods1 = mods | Flags.DEFERRED + if (settings.Xexperimental.value) { + if (inToken == SUBTYPE) mods1 = mods | Flags.DEFERRED + } var template = templateOpt(mods1, name, constrMods withAnnotations constrAnnots, vparamss) if (!thistpe.isEmpty) { if (template.self.isEmpty) { diff --git a/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala b/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala index b46464646f..e88ba6f194 100644 --- a/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala +++ b/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala @@ -69,10 +69,10 @@ abstract class DeVirtualize extends InfoTransform with TypingTransformers { */ object devirtualizeMap extends TypeMap { def apply(tp: Type): Type = { - println("devirtualizeMap on " + tp) +// println("devirtualizeMap on " + tp) mapOver(tp) match { case tp1 @ ClassInfoType(parents, decls, clazz) if containsVirtuals(clazz) => - println(clazz + " contains virtuals") +// println(clazz + " contains virtuals") transformOwnerInfo(clazz) // we might need to do this in two phases: enter/resolve val ds = decls.toList val decls1 = newScope(ds) @@ -80,7 +80,7 @@ abstract class DeVirtualize extends InfoTransform with TypingTransformers { if (m.isVirtualClass) devirtualize(m, decls1) for (m <- classesInNeedOfFactories(clazz)) addFactory(m, clazz, decls1) - println("Built ourselves a " + ClassInfoType(parents, decls1, clazz)) +// println("Built ourselves a " + ClassInfoType(parents, decls1, clazz)) ClassInfoType(parents, decls1, clazz) case tp1 @ ThisType(clazz) if clazz.isVirtualClass => ThisType(workerTrait(clazz)) @@ -126,10 +126,10 @@ abstract class DeVirtualize extends InfoTransform with TypingTransformers { /** The abstract type corresponding to a virtual class. */ protected def abstractType(clazz: Symbol): Symbol = atPhase(ownPhase.next) { - println("Looking up the abstract type for " + clazz) +// println("Looking up the abstract type for " + clazz) val tsym = clazz.owner.info.member(clazz.name) assert(tsym.isAbstractType, clazz) - println("Found " + tsym) +// println("Found " + tsym) tsym } @@ -249,7 +249,7 @@ abstract class DeVirtualize extends InfoTransform with TypingTransformers { * @param scope The scope into which factory is entered */ def addFactory(clazz: Symbol, owner: Symbol, scope: Scope) { - println("Adding a factory to " + clazz.owner + "." + clazz) +// println("Adding a factory to " + clazz.owner + "." + clazz) val pos = if (clazz.owner == owner) clazz.pos else owner.pos val factory = owner.newMethod(pos, factoryName(clazz.name)) .setFlag(clazz.flags & factoryFlagMask) @@ -310,7 +310,7 @@ abstract class DeVirtualize extends InfoTransform with TypingTransformers { * to template body `stats' */ override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = { - println("QUX!") +// println("QUX!") val stats1 = stats flatMap transformStat map transform val newDefs = new ListBuffer[Tree] if (currentOwner.isClass && containsVirtuals(currentOwner)) { @@ -373,28 +373,28 @@ abstract class DeVirtualize extends InfoTransform with TypingTransformers { * abstract type and worker traits. */ protected def transformStat(tree: Tree): List[Tree] = { - println("QUZZ!") +// println("QUZZ!") tree match { case ClassDef(mods, name, tparams, templ @ Template(parents, self, body)) if (tree.symbol.isVirtualClass) => - println("QUXX!") +// println("QUXX!") val clazz = tree.symbol - println("QUXY!") +// println("QUXY!") val absTypeSym = abstractType(clazz) - println("QUXY2!") +// println("QUXY2!") val workerTraitSym = workerTrait(clazz) - println("QUXY3!") +// println("QUXY3!") val abstypeDef = TypeDef(abstractType(clazz)) - println("QUXY4!") +// println("QUXY4!") val workerTraitDef = ClassDef( workerTraitSym, Modifiers(0), List(List()), List(List()), body) - println("QUXY5!") +// println("QUXY5!") new ChangeOwnerTraverser(clazz, workerTraitSym)( new ChangeOwnerTraverser(templ.symbol, workerTraitDef.impl.symbol)(workerTraitDef.impl)) - println("QUXY6!") +// println("QUXY6!") List(abstypeDef, workerTraitDef) map localTyper.typed case _ => List(tree) @@ -402,12 +402,12 @@ abstract class DeVirtualize extends InfoTransform with TypingTransformers { } override def transform(tree: Tree): Tree = { - println("FOOB!") +// println("FOOB!") tree match { // Replace references to VC.this and VC.super where VC is a virtual class // with VC$trait.this and VC$trait.super case This(_) | Super(_, _) if tree.symbol.isVirtualClass => - println("BARB!") +// println("BARB!") tree setSymbol workerTrait(tree.symbol) // Replace a new VC().init() where VC is a virtual class with new$VC @@ -424,7 +424,7 @@ abstract class DeVirtualize extends InfoTransform with TypingTransformers { } case _ => - println("BAZ!") +// println("BAZ!") super.transform(tree) } } setType devirtualizeMap(tree.tpe) |