diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-01-05 00:34:39 +0300 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-01-09 08:10:47 +0100 |
commit | 5660b7af199ae02a014fb200f199b58d42addde9 (patch) | |
tree | 9910170dfc504e953bbc7dc26e59ee8230b67cc9 | |
parent | 75507997c79e46018e3e77a8b89d7bd72a5fac15 (diff) | |
download | scala-5660b7af199ae02a014fb200f199b58d42addde9.tar.gz scala-5660b7af199ae02a014fb200f199b58d42addde9.tar.bz2 scala-5660b7af199ae02a014fb200f199b58d42addde9.zip |
adds Trees.replace(Tree, Tree)
Currently dead code. Has proven to be useful to implement type macros,
therefore I'm moving it to scala.reflect.internal.Trees.
-rw-r--r-- | src/compiler/scala/tools/nsc/interactive/Global.scala | 9 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Trees.scala | 13 |
2 files changed, 13 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala index 07ffe9e437..e3d59d83ea 100644 --- a/src/compiler/scala/tools/nsc/interactive/Global.scala +++ b/src/compiler/scala/tools/nsc/interactive/Global.scala @@ -1031,15 +1031,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") // ---------------- Helper classes --------------------------- - /** A transformer that replaces tree `from` with tree `to` in a given tree */ - class TreeReplacer(from: Tree, to: Tree) extends Transformer { - override def transform(t: Tree): Tree = { - if (t == from) to - else if ((t.pos includes from.pos) || t.pos.isTransparent) super.transform(t) - else t - } - } - /** The typer run */ class TyperRun extends Run { // units is always empty diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index 308ab93c07..3c2249bfb5 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -164,6 +164,9 @@ trait Trees extends api.Trees { self: SymbolTable => override def substituteThis(clazz: Symbol, to: Tree): Tree = new ThisSubstituter(clazz, to) transform this + def replace(from: Tree, to: Tree): Tree = + new TreeReplacer(from, to, positionAware = false) transform this + def hasSymbolWhich(f: Symbol => Boolean) = (symbol ne null) && (symbol ne NoSymbol) && f(symbol) @@ -1381,6 +1384,16 @@ trait Trees extends api.Trees { self: SymbolTable => if (tree eq orig) super.transform(tree) else tree } + + /** A transformer that replaces tree `from` with tree `to` in a given tree */ + class TreeReplacer(from: Tree, to: Tree, positionAware: Boolean) extends Transformer { + override def transform(t: Tree): Tree = { + if (t == from) to + else if (!positionAware || (t.pos includes from.pos) || t.pos.isTransparent) super.transform(t) + else t + } + } + // Create a readable string describing a substitution. private def substituterString(fromStr: String, toStr: String, from: List[Any], to: List[Any]): String = { "subst[%s, %s](%s)".format(fromStr, toStr, (from, to).zipped map (_ + " -> " + _) mkString ", ") |