diff options
author | Martin Odersky <odersky@gmail.com> | 2014-03-15 10:57:33 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-03-18 16:06:33 +0100 |
commit | 9c7cf4ee6196e0ec9ac7c7701de417bd9cb31c43 (patch) | |
tree | 3b5a3cc8c6046e29e2b0a0c64db60922b692efc9 /src | |
parent | 164ecb70593728ce218e04f4e316a32ae346e4b7 (diff) | |
download | dotty-9c7cf4ee6196e0ec9ac7c7701de417bd9cb31c43.tar.gz dotty-9c7cf4ee6196e0ec9ac7c7701de417bd9cb31c43.tar.bz2 dotty-9c7cf4ee6196e0ec9ac7c7701de417bd9cb31c43.zip |
Renamings TreeTransformer -> TreeMap, TreeMapper -> TreeTypeMap
This makes naming uniform between trees and types, and also avoids the clash with
transform.TreeTransformer. The idea is that transformers are parts of phases, and
have logic that is phase-specific. In particular, a context is passed around when
transforming a tree. Maps are simpler, they only have a T -> T apply method.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/ast/Trees.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/tpd.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/untpd.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Symbols.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/PostTyperTransformers.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/TreeTransform.scala | 6 |
7 files changed, 11 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala index e0e64f06a..5eb9a6409 100644 --- a/src/dotty/tools/dotc/ast/Trees.scala +++ b/src/dotty/tools/dotc/ast/Trees.scala @@ -1077,7 +1077,7 @@ object Trees { } } - abstract class TreeTransformer(val cpy: TreeCopier = inst.cpy) { + abstract class TreeMap(val cpy: TreeCopier = inst.cpy) { def transform(tree: Tree)(implicit ctx: Context): Tree = tree match { case Ident(name) => diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index 4de98d8f8..9d4ec21de 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -334,10 +334,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { shallowFold[Option[tpd.Tree]](None)((accum, tree) => if (pred(tree)) Some(tree) else accum) def subst(from: List[Symbol], to: List[Symbol])(implicit ctx: Context): ThisTree = - new TreeMapper(typeMap = new ctx.SubstSymMap(from, to)).apply(tree) + new TreeTypeMap(typeMap = new ctx.SubstSymMap(from, to)).apply(tree) def changeOwner(from: Symbol, to: Symbol)(implicit ctx: Context): ThisTree = - new TreeMapper(ownerMap = (sym => if (sym == from) to else sym)).apply(tree) + new TreeTypeMap(ownerMap = (sym => if (sym == from) to else sym)).apply(tree) def appliedToTypes(targs: List[Type])(implicit ctx: Context): Tree = if (targs.isEmpty) tree else TypeApply(tree, targs map (TypeTree(_))) @@ -347,7 +347,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def tpes: List[Type] = xs map (_.tpe) } - class TreeMapper(val typeMap: TypeMap = IdentityTypeMap, val ownerMap: Symbol => Symbol = identity _)(implicit ctx: Context) extends TreeTransformer { + class TreeTypeMap(val typeMap: TypeMap = IdentityTypeMap, val ownerMap: Symbol => Symbol = identity _)(implicit ctx: Context) extends TreeMap { override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = super.transform { tree.withType(typeMap(tree.tpe)) match { case bind: tpd.Bind => @@ -378,7 +378,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { /** The current tree map composed with a substitution [from -> to] */ def withSubstitution(from: List[Symbol], to: List[Symbol]) = - new TreeMapper( + new TreeTypeMap( typeMap andThen ((tp: Type) => tp.substSym(from, to)), ownerMap andThen (from zip to).toMap) } diff --git a/src/dotty/tools/dotc/ast/untpd.scala b/src/dotty/tools/dotc/ast/untpd.scala index aea34e08a..4e55fe868 100644 --- a/src/dotty/tools/dotc/ast/untpd.scala +++ b/src/dotty/tools/dotc/ast/untpd.scala @@ -285,7 +285,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { } } - abstract class UntypedTreeTransformer(cpy: UntypedTreeCopier = untpd.cpy) extends TreeTransformer(cpy) { + abstract class UntypedTreeMap(cpy: UntypedTreeCopier = untpd.cpy) extends TreeMap(cpy) { override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match { case ModuleDef(mods, name, impl) => cpy.ModuleDef(tree, mods, name, transformSub(impl)) diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala index aa0cbb5a9..3fc8a4f2c 100644 --- a/src/dotty/tools/dotc/core/Symbols.scala +++ b/src/dotty/tools/dotc/core/Symbols.scala @@ -19,7 +19,7 @@ import Annotations._ import util.Positions._ import StdNames._ import NameOps._ -import ast.tpd.{TreeMapper, Tree} +import ast.tpd.{TreeTypeMap, Tree} import Denotations.{ Denotation, SingleDenotation, MultiDenotation } import collection.mutable import io.AbstractFile @@ -278,7 +278,7 @@ trait Symbols { this: Context => else { val copies: List[Symbol] = for (original <- originals) yield newNakedSymbol[original.ThisName](original.coord) - val treeMap = new TreeMapper(typeMap, ownerMap) + val treeMap = new TreeTypeMap(typeMap, ownerMap) .withSubstitution(originals, copies) (originals, copies).zipped foreach {(original, copy) => val odenot = original.denot diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 9714f7eae..6dda937d2 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -2169,7 +2169,7 @@ object Types { annot.derivedAnnotation(mapOver(annot.tree)) def mapOver(tree: Tree): Tree = - new TreeMapper(this).apply(tree) + new TreeTypeMap(this).apply(tree) /** Can be overridden. By default, only the prefix is mapped. */ protected def mapClassInfo(tp: ClassInfo): ClassInfo = diff --git a/src/dotty/tools/dotc/transform/PostTyperTransformers.scala b/src/dotty/tools/dotc/transform/PostTyperTransformers.scala index 066a733f9..14e2cf35d 100644 --- a/src/dotty/tools/dotc/transform/PostTyperTransformers.scala +++ b/src/dotty/tools/dotc/transform/PostTyperTransformers.scala @@ -12,7 +12,7 @@ import NameOps._ object PostTyperTransformers { - import tpd.{TreeTransformer => _, _} + import tpd._ /** A trait that's assumed by the transformers that run right after typer. diff --git a/src/dotty/tools/dotc/transform/TreeTransform.scala b/src/dotty/tools/dotc/transform/TreeTransform.scala index 6cee17589..ecbe8daaf 100644 --- a/src/dotty/tools/dotc/transform/TreeTransform.scala +++ b/src/dotty/tools/dotc/transform/TreeTransform.scala @@ -7,6 +7,7 @@ import dotty.tools.dotc.ast.Trees._ import scala.annotation.tailrec object TreeTransforms { + import tpd._ /** The base class of tree transforms. For each kind of tree K, there are * two methods which can be overridden: @@ -47,8 +48,6 @@ object TreeTransforms { */ class TreeTransform(group: TreeTransformer, idx: Int) { - import tpd._ - def prepareForIdent(tree: Ident) = this def prepareForSelect(tree: Select) = this def prepareForThis(tree: This) = this @@ -390,11 +389,8 @@ object TreeTransforms { /** A group of tree transforms that are applied in sequence during the same phase */ abstract class TreeTransformer extends Phase { - import tpd.{TreeTransformer => _, _} - protected def transformations: Array[(TreeTransformer, Int) => TreeTransform] - override def run(implicit ctx: Context): Unit = { val curTree = ctx.compilationUnit.tpdTree val newTree = transform(curTree) |