Skip to content

Instantly share code, notes, and snippets.

@paulp
Created November 9, 2008 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulp/23165 to your computer and use it in GitHub Desktop.
Save paulp/23165 to your computer and use it in GitHub Desktop.
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