Created
November 9, 2008 00:42
-
-
Save paulp/23165 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait PatternNodes { self: transform.ExplicitOuter => | |
import global._ | |
import symtab.Flags | |
final def DBG(x: => String) = if (settings.debug.value) Console.println(x) | |
final def getDummies(i: Int): List[Tree] = List.make(i, EmptyTree) | |
def makeBind(vs:List[Symbol], pat:Tree): Tree = | |
if (vs eq Nil) pat else Bind(vs.head, makeBind(vs.tail, pat)) setType pat.tpe | |
def normalizedListPattern(pats:List[Tree], tptArg:Type): Tree = pats match { | |
case Nil => gen.mkAttributedRef(definitions.NilModule) | |
case (sp @ Strip(_, _: Star)) :: xs => makeBind(definedVars(sp), Ident(nme.WILDCARD) setType sp.tpe) | |
// case sp::xs if strip2(sp).isInstanceOf[Star] => | |
// makeBind(definedVars(sp), Ident(nme.WILDCARD) setType sp.tpe) | |
case x::xs => | |
var resType: Type = null; | |
val consType: Type = definitions.ConsClass.primaryConstructor.tpe match { | |
case mt @ MethodType(args, res @ TypeRef(pre,sym,origArgs)) => | |
val listType = TypeRef(pre, definitions.ListClass, List(tptArg)) | |
resType = TypeRef(pre, sym , List(tptArg)) | |
MethodType(List(tptArg, listType), resType) | |
} | |
Apply(TypeTree(consType),List(x,normalizedListPattern(xs,tptArg))).setType(resType) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment