Permalink
Browse files

Incorporated changes suggested in code review

  • Loading branch information...
1 parent a52bd2c commit a3c5427fa0b1347d932b2e2f2bf4c357b67604f1 @hubertp hubertp committed Sep 27, 2012
@@ -297,7 +297,7 @@ trait Reshape {
val vdef1 = ValDef(mods2, name1, tpt, rhs)
if (reifyDebug) println("resetting visibility of field: %s => %s".format(vdef, vdef1))
Some(vdef1) // no copyAttrs here, because new ValDef and old symbols are now out of sync
- case ddef @ DefDef(mods, name, tparams, vparamss, tpt, rhs) if !ddef.mods.isLazy =>
+ case ddef: DefDef if !ddef.mods.isLazy =>
// lazy val accessors are removed in reshapeLazyVals
// as they are needed to recreate lazy vals
if (accessors.values.exists(_.contains(ddef))) {
@@ -319,7 +319,7 @@ trait Reshape {
// lazy valdef and defdef are in the same block.
// only that valdef needs to have its rhs rebuilt from defdef
stats flatMap (stat => stat match {
- case vdef @ ValDef(mods0, name0, tpt0, rhs0) if vdef.symbol.isLazy =>
+ case vdef: ValDef if vdef.symbol.isLazy =>
if (reifyDebug) println(s"reconstructing original lazy value for $vdef")
val ddefSym = vdef.symbol.lazyAccessor
val vdef1 = lazyvaldefs.get(ddefSym) match {
@@ -331,7 +331,7 @@ trait Reshape {
}
if (reifyDebug) println(s"reconstructed lazy val is $vdef1")
vdef1::Nil
- case ddef @ DefDef(mods0, name0, _, _, tpt0, rhs0) if ddef.symbol.isLazy =>
+ case ddef: DefDef if ddef.symbol.isLazy =>
def hasUnitType(sym: Symbol) = (sym.tpe.typeSymbol == UnitClass) && sym.tpe.annotations.isEmpty
if (hasUnitType(ddef.symbol)) {
// since lazy values of type Unit don't have val's
@@ -231,9 +231,8 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure =>
extends ChangeOwnerTraverser(oldowner, newowner) {
override def traverse(tree: Tree) {
tree match {
- case Return(expr) =>
- if (tree.symbol == oldowner) tree.symbol = newowner
- case _ =>
+ case _: Return => change(tree.symbol)
+ case _ =>
}
super.traverse(tree)
}
@@ -454,21 +454,30 @@ trait MethodSynthesis {
* { z = <rhs>; z } where z can be an identifier or a field.
*/
case class LazyValGetter(tree: ValDef) extends BaseGetter(tree) {
+ class ChangeOwnerAndModuleClassTraverser(oldowner: Symbol, newowner: Symbol)
+ extends ChangeOwnerTraverser(oldowner, newowner) {
+
+ override def traverse(tree: Tree) {
+ tree match {
+ case _: DefTree => change(tree.symbol.moduleClass)
+ case _ =>
+ }
+ super.traverse(tree)
+ }
+ }
+
// todo: in future this should be enabled but now other phases still depend on the flag for various reasons
//override def flagsMask = (super.flagsMask & ~LAZY)
override def derivedSym = basisSym.lazyAccessor
override def derivedTree: DefDef = {
val ValDef(_, _, tpt0, rhs0) = tree
- val rhs1 = transformed.get(rhs0) match {
- case Some(rhs) => rhs
- case None => rhs0
- }
+ val rhs1 = transformed.getOrElse(rhs0, rhs0)
val body = (
if (tree.symbol.owner.isTrait || hasUnitType(basisSym)) rhs1
else gen.mkAssignAndReturn(basisSym, rhs1)
)
derivedSym.setPos(tree.pos) // cannot set it at createAndEnterSymbol because basisSym can possible stil have NoPosition
- val ddefRes = atPos(tree.pos)(DefDef(derivedSym, body.changeOwner(followModuleClass = true, basisSym -> derivedSym)))
+ val ddefRes = atPos(tree.pos)(DefDef(derivedSym, new ChangeOwnerAndModuleClassTraverser(basisSym, derivedSym)(body)))
// ValDef will have its position focused whereas DefDef will have original correct rangepos
// ideally positions would be correct at the creation time but lazy vals are really a special case
// here so for the sake of keeping api clean we fix positions manually in LazyValGetter
@@ -178,12 +178,9 @@ trait Trees extends api.Trees { self: SymbolTable =>
new ForeachPartialTreeTraverser(pf).traverse(this)
}
- def changeOwner(pairs: (Symbol, Symbol)*): Tree =
- changeOwner(false, pairs: _*)
-
- def changeOwner(followModuleClass: Boolean, pairs: (Symbol, Symbol)*): Tree = {
+ def changeOwner(pairs: (Symbol, Symbol)*): Tree = {
pairs.foldLeft(this) { case (t, (oldOwner, newOwner)) =>
- new ChangeOwnerTraverser(oldOwner, newOwner, followModuleClass) apply t
+ new ChangeOwnerTraverser(oldOwner, newOwner) apply t
}
}
@@ -1302,29 +1299,27 @@ trait Trees extends api.Trees { self: SymbolTable =>
}
}
- class ChangeOwnerTraverser(val oldowner: Symbol, val newowner: Symbol, followModuleClass: Boolean = false) extends Traverser {
- def changeSymboOwnerIfCorrect(sym: Symbol) = {
+ class ChangeOwnerTraverser(val oldowner: Symbol, val newowner: Symbol) extends Traverser {
+ final def change(sym: Symbol) = {
if (sym != NoSymbol && sym.owner == oldowner)
sym.owner = newowner
}
- def changeOwner(tree: Tree) = tree match {
- case Return(expr) =>
- if (tree.symbol == oldowner) {
- // SI-5612
- if (newowner hasTransOwner oldowner)
- log("NOT changing owner of %s because %s is nested in %s".format(tree, newowner, oldowner))
- else {
- log("changing owner of %s: %s => %s".format(tree, oldowner, newowner))
- tree.symbol = newowner
- }
- }
- case _: DefTree | _: Function =>
- changeSymboOwnerIfCorrect(tree.symbol)
- if (followModuleClass) changeSymboOwnerIfCorrect(tree.symbol.moduleClass)
- case _ =>
- }
override def traverse(tree: Tree) {
- changeOwner(tree)
+ tree match {
+ case _: Return =>
+ if (tree.symbol == oldowner) {
+ // SI-5612
+ if (newowner hasTransOwner oldowner)
+ log("NOT changing owner of %s because %s is nested in %s".format(tree, newowner, oldowner))
+ else {
+ log("changing owner of %s: %s => %s".format(tree, oldowner, newowner))
+ tree.symbol = newowner
+ }
+ }
+ case _: DefTree | _: Function =>
+ change(tree.symbol)
+ case _ =>
+ }
super.traverse(tree)
}
}

0 comments on commit a3c5427

Please sign in to comment.