summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2010-04-09 15:43:27 +0000
committerIulian Dragos <jaguarul@gmail.com>2010-04-09 15:43:27 +0000
commit2209c911ce5f2a8a3f2115d83dcac400227aba6e (patch)
treeeb6dfbb016ef2fb869374e97ea40729b773662c0 /src/compiler
parent04e60a56e945f760dee3813e4ce2972a4c812844 (diff)
downloadscala-2209c911ce5f2a8a3f2115d83dcac400227aba6e.tar.gz
scala-2209c911ce5f2a8a3f2115d83dcac400227aba6e.tar.bz2
scala-2209c911ce5f2a8a3f2115d83dcac400227aba6e.zip
Changed TreeSymSubstituter from a traverser to
transformer. It now aligns tree nodes that contain names to the symbol name that was substituted. Before this change identifiers may refer to one symbol, while the name they carry would resovlve to another one.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala25
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala3
2 files changed, 21 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index 9097dd460e..3640b6825b 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -935,19 +935,34 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
lazy val EmptyTreeTypeSubstituter = new TreeTypeSubstituter(List(), List())
- class TreeSymSubstituter(from: List[Symbol], to: List[Symbol]) extends Traverser {
+ /** Substitute symbols in 'from' with symbols in 'to'. Returns a new
+ * tree using the new symbols and whose Ident and Select nodes are
+ * name-consistent with the new symbols.
+ */
+ class TreeSymSubstituter(from: List[Symbol], to: List[Symbol]) extends Transformer {
val symSubst = new SubstSymMap(from, to)
- override def traverse(tree: Tree) {
+ override def transform(tree: Tree): Tree = {
def subst(from: List[Symbol], to: List[Symbol]) {
if (!from.isEmpty)
if (tree.symbol == from.head) tree setSymbol to.head
else subst(from.tail, to.tail)
}
+
if (tree.tpe ne null) tree.tpe = symSubst(tree.tpe)
- if (tree.hasSymbol) subst(from, to)
- super.traverse(tree)
+ if (tree.hasSymbol) {
+ subst(from, to)
+ tree match {
+ case Ident(name0) if tree.symbol != NoSymbol =>
+ treeCopy.Ident(tree, tree.symbol.name)
+ case Select(qual, name0) =>
+ treeCopy.Select(tree, transform(qual), tree.symbol.name)
+ case _ =>
+ super.transform(tree)
+ }
+ } else
+ super.transform(tree)
}
- override def apply[T <: Tree](tree: T): T = super.apply(tree.duplicate)
+ def apply[T <: Tree](tree: T): T = transform(tree).asInstanceOf[T]
override def toString() = "TreeSymSubstituter("+from+","+to+")"
}
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index dad654c967..f2b896dc96 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -354,8 +354,7 @@ abstract class ExplicitOuter extends InfoTransform
localTyper typed (DEF(method) === {
new ChangeOwnerTraverser(currentOwner, method) traverse guard
- new TreeSymSubstituter(vs, method.paramss.head) traverse guard
- guard
+ new TreeSymSubstituter(vs, method.paramss.head) transform (guard)
})
}