diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-06-08 02:36:10 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-06-08 15:32:28 +0200 |
commit | 0b2f1bcf75d31c59b25e19eebcb80f39c155365b (patch) | |
tree | 8d9dfc50ef01ca48c068b232af7e67a723325388 /src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala | |
parent | 13213e3df0384b1fd815c0798758a22284572cdb (diff) | |
download | scala-0b2f1bcf75d31c59b25e19eebcb80f39c155365b.tar.gz scala-0b2f1bcf75d31c59b25e19eebcb80f39c155365b.tar.bz2 scala-0b2f1bcf75d31c59b25e19eebcb80f39c155365b.zip |
Introduces scala-reflect.jar
Diffstat (limited to 'src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala')
-rw-r--r-- | src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala b/src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala new file mode 100644 index 0000000000..f1fe4fc118 --- /dev/null +++ b/src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala @@ -0,0 +1,50 @@ +/* NSC -- new scala compiler + * Copyright 2005-2011 LAMP/EPFL + * @author Martin Odersky + */ + +package scala.reflect +package internal + +import scala.collection.{ mutable, immutable } +import util._ + +/** The name of this trait defines the eventual intent better than + * it does the initial contents. + */ +trait ExistentialsAndSkolems { + self: SymbolTable => + + /** Map a list of type parameter symbols to skolemized symbols, which + * can be deskolemized to the original type parameter. (A skolem is a + * representation of a bound variable when viewed inside its scope.) + * !!!Adriaan: this does not work for hk types. + */ + def deriveFreshSkolems(tparams: List[Symbol]): List[Symbol] = { + class Deskolemizer extends LazyType { + override val typeParams = tparams + val typeSkolems = typeParams map (_.newTypeSkolem setInfo this) + override def complete(sym: Symbol) { + // The info of a skolem is the skolemized info of the + // actual type parameter of the skolem + sym setInfo sym.deSkolemize.info.substSym(typeParams, typeSkolems) + } + } + (new Deskolemizer).typeSkolems + } + + /** Convert to corresponding type parameters all skolems of method + * parameters which appear in `tparams`. + */ + def deskolemizeTypeParams(tparams: List[Symbol])(tp: Type): Type = { + class DeSkolemizeMap extends TypeMap { + def apply(tp: Type): Type = tp match { + case TypeRef(pre, sym, args) if sym.isTypeSkolem && (tparams contains sym.deSkolemize) => + mapOver(typeRef(NoPrefix, sym.deSkolemize, args)) + case _ => + mapOver(tp) + } + } + new DeSkolemizeMap mapOver tp + } +} |