aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-11-28 21:55:31 +0100
committerMartin Odersky <odersky@gmail.com>2013-11-28 21:55:31 +0100
commit98160c43002907b2784d1031c476cd46b912e752 (patch)
tree719b240fff2f060f13c1c950ddb87978a8ee3777 /src/dotty/tools/dotc/core/Types.scala
parent4dadbda073422eba3745866737f438aa772169df (diff)
downloaddotty-98160c43002907b2784d1031c476cd46b912e752.tar.gz
dotty-98160c43002907b2784d1031c476cd46b912e752.tar.bz2
dotty-98160c43002907b2784d1031c476cd46b912e752.zip
Making substitutions deep type maps that also map parents and self type of a class info.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index bfe19c859..8ef7edf24 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -1989,11 +1989,6 @@ object Types {
abstract class TypeMap(implicit ctx: Context) extends (Type => Type) { thisMap =>
- /** Unset by default. If set also map parents and self type of a ClassInfo.
- * By default, only the prefix is mapped.
- */
- def mapClassInfosDeeply = false
-
def apply(tp: Type): Type
/** Map this function over given type */
@@ -2028,17 +2023,8 @@ object Types {
tp.derivedTypeBounds(this(lo), this(hi))
}
- case tp @ ClassInfo(prefix, _, _, _, _) =>
- if (mapClassInfosDeeply) {
- val prefix1 = this(prefix)
- val parents1 = (tp.parents mapConserve this).asInstanceOf[List[TypeRef]]
- val self1 = tp.self match {
- case self: Type => this(self)
- case _ => tp.self
- }
- tp.derivedClassInfo(prefix1, parents1, self1)
- }
- else tp.derivedClassInfo(this(prefix))
+ case tp: ClassInfo =>
+ mapClassInfo(tp)
case tp: TypeVar =>
val inst = tp.instanceOpt
@@ -2076,11 +2062,28 @@ object Types {
def mapOver(tree: Tree): Tree =
new TreeMapper(this).apply(tree)
+ /** Can be overridden. By default, only the prefix is mapped. */
+ protected def mapClassInfo(tp: ClassInfo): ClassInfo =
+ tp.derivedClassInfo(this(tp.prefix))
+
def andThen(f: Type => Type): TypeMap = new TypeMap {
def apply(tp: Type) = f(thisMap(tp))
}
}
+ /** A type map that maps also parents and self type of a ClassInfo */
+ abstract class DeepTypeMap(implicit ctx: Context) extends TypeMap {
+ override def mapClassInfo(tp: ClassInfo) = {
+ val prefix1 = this(tp.prefix)
+ val parents1 = (tp.parents mapConserve this).asInstanceOf[List[TypeRef]]
+ val self1 = tp.self match {
+ case self: Type => this(self)
+ case _ => tp.self
+ }
+ tp.derivedClassInfo(prefix1, parents1, self1)
+ }
+ }
+
object IdentityTypeMap extends TypeMap()(NoContext) {
def apply(tp: Type) = tp
}