diff options
author | Martin Odersky <odersky@gmail.com> | 2013-02-22 19:00:12 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-02-22 19:00:12 +0100 |
commit | 184dcbfdb37f20a43ebe68787f6fbeab1ac4cb56 (patch) | |
tree | 46fe06f0ce90c307ceb33117cd85fde0d59b4ad7 /src/dotty/tools/dotc/core/Types.scala | |
parent | a0bbaa8f42b16274071b30a8f1d6ad23a4ee9584 (diff) | |
download | dotty-184dcbfdb37f20a43ebe68787f6fbeab1ac4cb56.tar.gz dotty-184dcbfdb37f20a43ebe68787f6fbeab1ac4cb56.tar.bz2 dotty-184dcbfdb37f20a43ebe68787f6fbeab1ac4cb56.zip |
Added methods to substitute trees and change their owners.
Required also some better integration with TypeMaps.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 4b3271ed2..09a2585d0 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -209,7 +209,7 @@ object Types { final def forall(p: Type => Boolean): Boolean = !exists(!p(_)) /** Substitute all types that refer in their symbol attribute to - * one of the symbols in `from` by the corresponding types in `to` + * one of the symbols in `from` by the corresponding types in `to`. */ final def subst(from: List[Symbol], to: List[Type])(implicit ctx: Context): Type = if (from.isEmpty) this @@ -237,6 +237,11 @@ object Types { final def substThis(rt: RefinedType, tp: Type)(implicit ctx: Context): Type = ctx.substThis(this, rt, tp, null) + /** Substitute all occurrences symbols in `from` by references to corresponding symbols in `to` + */ + final def substSym(from: List[Symbol], to: List[Symbol])(implicit ctx: Context): Type = + ctx.substSym(this, from, to, null) + /** For a ClassInfo type, its parents, * Inherited by all type proxies. Empty for all other types. * Overwritten in ClassInfo, where parents is cached. @@ -963,6 +968,8 @@ object Types { abstract class GenericMethodType { def apply(paramNames: List[TermName], paramTypes: List[Type])(resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType + def apply(paramNames: List[TermName], paramTypes: List[Type], resultType: Type)(implicit ctx: Context): MethodType = + apply(paramNames, paramTypes)(_ => resultType) def fromSymbols(params: List[Symbol], resultType: Type)(implicit ctx: Context) = { def transResult(mt: MethodType) = resultType.subst(params, (0 until params.length).toList map (MethodParam(mt, _))) @@ -1172,7 +1179,7 @@ object Types { // ----- TypeMaps -------------------------------------------------------------------- - abstract class TypeMap(implicit ctx: Context) extends (Type => Type) { + abstract class TypeMap(implicit ctx: Context) extends (Type => Type) { thisMap => def apply(tp: Type): Type def applyToBounds(tp: TypeBounds): TypeBounds = @@ -1217,8 +1224,25 @@ object Types { tp } + def mapOver(syms: List[Symbol]): List[Symbol] = + ctx.mapSymbols(syms, this) + + def mapOver(scope: Scope): Scope = { + val elems = scope.toList + val elems1 = mapOver(elems) + if (elems1 eq elems) scope + else newScopeWith(elems1: _*) + } + def mapOverAnnotations(annots: List[Annotation]): List[Annotation] = ??? + def andThen(f: Type => Type): TypeMap = new TypeMap { + def apply(tp: Type) = f(thisMap.apply(tp)) + } + } + + object IdentityTypeMap extends TypeMap()(NoContext) { + def apply(tp: Type) = tp } class InstMethodMap(mt: MethodType, argtypes: List[Type])(implicit ctx: Context) extends TypeMap { |