aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/tpd.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-11-08 18:44:30 +0100
committerMartin Odersky <odersky@gmail.com>2014-11-09 19:09:52 +0100
commitb07c30b09851334c40298725daa5503e97ae305a (patch)
tree459e52ce1d0f35afdcc84e17aa089b900952808b /src/dotty/tools/dotc/ast/tpd.scala
parent0ad4dea891701b8ca14014549056806a41d2f385 (diff)
downloaddotty-b07c30b09851334c40298725daa5503e97ae305a.tar.gz
dotty-b07c30b09851334c40298725daa5503e97ae305a.tar.bz2
dotty-b07c30b09851334c40298725daa5503e97ae305a.zip
New functionality: changeOwnerAfter
Changes owners after a phase without copying the tree. This should be more suitable for the changeOwner operations used in the tree transforms so far, which are linear, i.e. no tree duplication is needed.
Diffstat (limited to 'src/dotty/tools/dotc/ast/tpd.scala')
-rw-r--r--src/dotty/tools/dotc/ast/tpd.scala24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala
index 6aa715c8e..5aebbd6fe 100644
--- a/src/dotty/tools/dotc/ast/tpd.scala
+++ b/src/dotty/tools/dotc/ast/tpd.scala
@@ -6,7 +6,7 @@ import transform.SymUtils._
import core._
import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Symbols._
-import Denotations._, Decorators._
+import Denotations._, Decorators._, DenotTransformers._
import config.Printers._
import typer.Mode
import collection.mutable
@@ -537,6 +537,28 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
loop(from, Nil, to :: Nil)
}
+ /** After phase `trans`, set the owner of every definition in this tree that was formerly
+ * owner by `from` to `to`.
+ */
+ def changeOwnerAfter(from: Symbol, to: Symbol, trans: DenotTransformer)(implicit ctx: Context): ThisTree = {
+ assert(ctx.phase == trans.next)
+ val traverser = new TreeTraverser {
+ def traverse(tree: Tree) = tree match {
+ case tree: DefTree =>
+ val sym = tree.symbol
+ if (sym.denot(ctx.withPhase(trans)).owner == from) {
+ println(i"change owner $from -> $to of $sym")
+ sym.copySymDenotation(owner = to).installAfter(trans)
+ }
+ if (sym.isWeakOwner) traverseChildren(tree)
+ case _ =>
+ traverseChildren(tree)
+ }
+ }
+ traverser.traverse(tree)
+ tree
+ }
+
def select(name: Name)(implicit ctx: Context): Select =
Select(tree, name)