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/transform/UnCurry.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/transform/UnCurry.scala')
-rw-r--r-- | src/reflect/scala/reflect/internal/transform/UnCurry.scala | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/internal/transform/UnCurry.scala b/src/reflect/scala/reflect/internal/transform/UnCurry.scala new file mode 100644 index 0000000000..0c1640ceb9 --- /dev/null +++ b/src/reflect/scala/reflect/internal/transform/UnCurry.scala @@ -0,0 +1,64 @@ +package scala.reflect +package internal +package transform + +import Flags._ + +trait UnCurry { + + val global: SymbolTable + import global._ + import definitions._ + + private def expandAlias(tp: Type): Type = if (!tp.isHigherKinded) tp.normalize else tp + + val uncurry: TypeMap = new TypeMap { + def apply(tp0: Type): Type = { + val tp = expandAlias(tp0) + tp match { + case MethodType(params, MethodType(params1, restpe)) => + apply(MethodType(params ::: params1, restpe)) + case MethodType(params, ExistentialType(tparams, restpe @ MethodType(_, _))) => + assert(false, "unexpected curried method types with intervening existential") + tp0 + case MethodType(h :: t, restpe) if h.isImplicit => + apply(MethodType(h.cloneSymbol.resetFlag(IMPLICIT) :: t, restpe)) + case NullaryMethodType(restpe) => + apply(MethodType(List(), restpe)) + case TypeRef(pre, ByNameParamClass, arg :: Nil) => + apply(functionType(List(), arg)) + case TypeRef(pre, RepeatedParamClass, arg :: Nil) => + apply(seqType(arg)) + case TypeRef(pre, JavaRepeatedParamClass, arg :: Nil) => + apply(arrayType( + if (isUnboundedGeneric(arg)) ObjectClass.tpe else arg)) + case _ => + expandAlias(mapOver(tp)) + } + } + } + + private val uncurryType = new TypeMap { + def apply(tp0: Type): Type = { + val tp = expandAlias(tp0) + tp match { + case ClassInfoType(parents, decls, clazz) => + val parents1 = parents mapConserve uncurry + if (parents1 eq parents) tp + else ClassInfoType(parents1, decls, clazz) // @MAT normalize in decls?? + case PolyType(_, _) => + mapOver(tp) + case _ => + tp + } + } + } + + /** - return symbol's transformed type, + * - if symbol is a def parameter with transformed type T, return () => T + * + * @MAT: starting with this phase, the info of every symbol will be normalized + */ + def transformInfo(sym: Symbol, tp: Type): Type = + if (sym.isType) uncurryType(tp) else uncurry(tp) +}
\ No newline at end of file |