summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2007-09-07 23:52:48 +0000
committerBurak Emir <emir@epfl.ch>2007-09-07 23:52:48 +0000
commitc9e92bfc89083227aa18f88b07688afd625970af (patch)
tree6c9019b58e916df02976cc5f6431ca39035bb359
parent49d86b0f877895375b36bf1752f445d81a47d97a (diff)
downloadscala-c9e92bfc89083227aa18f88b07688afd625970af.tar.gz
scala-c9e92bfc89083227aa18f88b07688afd625970af.tar.bz2
scala-c9e92bfc89083227aa18f88b07688afd625970af.zip
fixed v@unapp problem (merged changes from bran...
fixed v@unapp problem (merged changes from branch 2.6.0)
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala80
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternMatchers.scala2
2 files changed, 34 insertions, 48 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index 39783eab08..ad43caad4a 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -422,10 +422,11 @@ trait ParallelMatching {
private def bindToScrutinee(x:Symbol) = typedValDef(x,mkIdent(scrutinee))
- val unapp = strip2(column.head)
- /** returns the (un)apply and two continuations */
- var rootvdefs:List[Tree] = Nil // later, via bindToScrutinee
+ val (vs,unapp) = strip(column.head)
+ //DBG("\n\n?? vs = "+vs)
+ //DBG("?? unapp = "+unapp)
+ /** returns (unapply-call, success-rep, optional fail-rep*/
final def getTransition(implicit theOwner: Symbol): (Tree, List[Tree], Rep, Option[Rep]) = {
unapp match {
case ua @ UnApply(app @ Apply(fn, appargs), args) =>
@@ -436,7 +437,7 @@ trait ParallelMatching {
val nrowsOther = column.tail.zip(rest.row.tail) flatMap { case (pat, Row(ps, subst, g, bx)) => strip2(pat) match {
case UnApply(app @ Apply(fn1,_),args) if fn.symbol==fn1.symbol => Nil
- case p => List(Row(pat::ps, subst, g, bx))
+ case _ => List(Row(pat::ps, subst, g, bx))
}}
val nrepFail = if(nrowsOther.isEmpty) None else Some(rep.make(scrutinee::rest.temp, nrowsOther))
//Console.println("active = "+column.head+" / nrepFail = "+nrepFail)
@@ -445,12 +446,12 @@ trait ParallelMatching {
val ntemps = scrutinee :: rest.temp
val nrows = column.zip(rest.row) map { case (pat, Row(ps, subst, g, bx)) => strip2(pat) match {
case UnApply(Apply(fn1,_),args) if (fn.symbol == fn1.symbol) =>
- rootvdefs = (strip1(pat).toList map bindToScrutinee) ::: rootvdefs
- Row(EmptyTree::ps, subst, g, bx)
+ val nsubst = subst.add(strip1(pat).elements, scrutinee)
+ Row(EmptyTree::ps, nsubst /*subst*/ , g, bx)
case _ =>
Row( pat ::ps, subst, g, bx)
}}
- (uacall, rootvdefs, rep.make(ntemps, nrows), nrepFail)
+ (uacall, Nil, rep.make(ntemps, nrows), nrepFail)
case 1 => //special case for unapply(p), app.tpe is Option[T]
val vtpe = app.tpe.typeArgs(0)
@@ -458,48 +459,48 @@ trait ParallelMatching {
val ntemps = vsym :: scrutinee :: rest.temp
val nrows = column.zip(rest.row) map { case (pat, Row(ps, subst, g, bx)) => strip2(pat) match {
case UnApply(Apply(fn1,_),args) if (fn.symbol == fn1.symbol) =>
- rootvdefs = (strip1(pat).toList map bindToScrutinee) ::: rootvdefs
- Row(args(0) :: EmptyTree :: ps, subst, g, bx)
+ val nsubst = subst.add(strip1(pat).elements, scrutinee)
+ Row(args(0) :: EmptyTree :: ps, nsubst /*subst*/ , g, bx)
case _ =>
Row(EmptyTree :: pat :: ps, subst, g, bx)
}}
- (uacall, rootvdefs:::List( typedValDef(vsym, Select(mkIdent(ures), nme.get))), rep.make(ntemps, nrows), nrepFail)
+ val vdef = typedValDef(vsym, Select(mkIdent(ures), nme.get))
+ (uacall, List(vdef), rep.make(ntemps, nrows), nrepFail)
case _ => // app.tpe is Option[? <: ProductN[T1,...,Tn]]
val uresGet = newVarCapture(ua.pos, app.tpe.typeArgs(0))
- var vdefs = typedValDef(uresGet, Select(mkIdent(ures), nme.get))::Nil
+ val vdefs = new ListBuffer[Tree]
+ vdefs += typedValDef(uresGet, Select(mkIdent(ures), nme.get))
var ts = definitions.getProductArgs(uresGet.tpe).get
var i = 1;
//Console.println("typeargs"+ts)
- var vsyms:List[Symbol] = Nil
- var dummies:List[Tree] = Nil
+ val vsyms = new ListBuffer[Symbol]
while(ts ne Nil) {
val vtpe = ts.head
val vchild = newVarCapture(ua.pos, vtpe)
val accSym = definitions.productProj(uresGet, i)
val rhs = typed(Apply(Select(mkIdent(uresGet), accSym), List())) // nsc !
- vdefs = typedValDef(vchild, rhs)::vdefs
- vsyms = vchild :: vsyms
- dummies = EmptyTree::dummies
+ vdefs += typedValDef(vchild, rhs)
+ vsyms += vchild
ts = ts.tail
i += 1
}
- val ntemps = vsyms.reverse ::: scrutinee :: rest.temp
- dummies = dummies.reverse
+ val ntemps = vsyms.toList ::: scrutinee :: rest.temp
+ val dummies = getDummies(i - 1)
val nrows = column.zip(rest.row) map { case (pat,Row(ps, subst, g, bx)) => strip2(pat) match {
case UnApply(Apply(fn1,_),args) if (fn.symbol == fn1.symbol) =>
- rootvdefs = (strip1(pat).toList map bindToScrutinee) ::: rootvdefs
- Row( args::: EmptyTree ::ps, subst, g, bx)
+ val nsubst = subst.add(strip1(pat).elements, scrutinee)
+ Row( args::: EmptyTree ::ps, nsubst /*subst*/ , g, bx)
case _ =>
Row(dummies::: pat ::ps, subst, g, bx)
}}
- (uacall, rootvdefs:::vdefs.reverse, rep.make(ntemps, nrows), nrepFail)
+ (uacall, vdefs.toList, rep.make(ntemps, nrows), nrepFail)
}}
} /* def getTransition(...) */
final def tree(implicit theOwner: Symbol, failTree: Tree) = {
val (uacall/*:ValDef*/ , vdefs,srep,frep) = this.getTransition // uacall is a Valdef
- //Console.println("getTransition"+(uacall,vdefs,srep,frep))
+ DBG("getTransition"+(uacall,vdefs,srep,frep))
val succ = repToTree(srep)
val fail = if(frep.isEmpty) failTree else repToTree(frep.get)
val cond =
@@ -655,9 +656,9 @@ trait ParallelMatching {
private val isCaseHead = isCaseClass(headPatternType)
private val dummies = if(!isCaseHead) Nil else getDummies(headPatternType.typeSymbol.caseFieldAccessors.length)
- //Console.println("headPatternType "+headPatternType)
- //Console.println("isCaseHead = "+isCaseHead)
- //Console.println("dummies = "+dummies)
+ DBG("headPatternType "+headPatternType)
+ DBG("isCaseHead = "+isCaseHead)
+ DBG("dummies = "+dummies)
private def subpatterns(pat:Tree): List[Tree] = {
//Console.print("subpatterns("+pat+")=")
@@ -972,16 +973,16 @@ trait ParallelMatching {
//Console.println(jumpT)
return jump
}
- //DBG("requestbody("+bx+", "+subst+") isReached(bx)?"+isReached(bx)+" labels:"); // {for(s<-labels) Console.print({if(s ne null) {s} else "_"}+",")}
- //DBG("vss(bx) = "+vss(bx))
+ DBG("requestbody("+bx+", "+subst+") isReached(bx)?"+isReached(bx)+" labels:");
+ //{for(s<-labels) Console.print({if(s ne null) {s} else "_"}+",")}
+ DBG("vss(bx) = "+vss(bx))
if(!isReached(bx)) { // first time this bx is requested
val argts = new ListBuffer[Type] // types of
var vrev: List[Symbol] = Nil
var vdefs:List[Tree] = Nil
- //Console.println("vss = "+vss(bx))
val it = vss(bx).elements; while(it.hasNext) {
val v = it.next
- //Console.println("v = "+v)
+ DBG("v = "+v)
val substv = subst(v)
if(substv ne null) {// might be bound elsewhere ( see `x @ unapply' )
vrev = v :: vrev
@@ -1067,10 +1068,9 @@ trait ParallelMatching {
var indexOfAlternative = -1
var j = 0; while(opats ne Nil) {
var opat = opats.head // original pattern
- //DBG("opat = "+opat)
+ DBG("opat = "+opat)
val (vars,strippedPat) = strip(opat)
val vs = vars.toList
- //Console.println("strippedPat = "+strippedPat)
def handle(prepat:Tree): Unit = prepat match {
/* annotations do not make sense on pattern
@@ -1088,16 +1088,12 @@ trait ParallelMatching {
}
pats = opat :: pats
- case typat @ Typed(p:UnApply,tpt) =>
+ case typat @ Typed(p,tpt) if strip2(p).isInstanceOf[UnApply]=>
pats = (if (temp(j).tpe <:< tpt.tpe) p else typat)::pats // what about the null-check?
case Ident(nme.WILDCARD) | EmptyTree | _:Literal | _:Typed =>
pats = opat :: pats
- //case _ if !vs.isEmpty =>
- // pats = opat :: pats // strange but true: Bind node is deferred
-
-
case o @ Ident(n) => // n != nme.WILDCARD
/*
Console.println("/'''''''''''' 1"+o.tpe)
@@ -1156,18 +1152,12 @@ trait ParallelMatching {
case ua @ UnApply(Apply(fn, _), _) =>
- //Console.println("found unapply! "+ua)
fn.tpe match {
case MethodType(List(argtpe,_*),_) =>
val npat = (if (temp(j).tpe <:< argtpe) ua else Typed(ua,TypeTree(argtpe)).setType(argtpe))
- // npat setType argtpe
- //Console.println("coucou!")
pats = (makeBind(vs, npat) setType argtpe)::pats
}
- case ua @ UnApply(xyz, _) =>
- assert(false, xyz.toString)
-
/** something too tricky is going on if the outer types don't match
*/
case o @ Apply(fn, List()) if !isCaseClass(o.tpe) =>
@@ -1230,13 +1220,9 @@ trait ParallelMatching {
case ArrayValue(_,xs) =>
assert(false) // inactive, @see PatternMatchers::isImplemented
- //case _ if !vs.isEmpty =>
- // pats = opat :: pats // strange but true: Bind node is deferred
-
-
}
handle(strippedPat)
- //Console.println("!!added "+pats.head+":"+pats.head.tpe)
+ DBG("!!added "+pats.head+":"+pats.head.tpe)
opats = opats.tail
j += 1
}
diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
index 5d7fc44e9a..3a5868369f 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
@@ -219,7 +219,7 @@ trait PatternMatchers { self: transform.ExplicitOuter with PatternNodes with Par
//non-fallback:
case e: CantHandle => rep.cleanup(); return e
- case e => throw e
+ case e => e.printStackTrace(); throw new FatalError(e.getMessage())
}
}