summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/matching
diff options
context:
space:
mode:
authorDavid MacIver <david.maciver@gmail.com>2008-10-27 09:30:29 +0000
committerDavid MacIver <david.maciver@gmail.com>2008-10-27 09:30:29 +0000
commit0964a593ec081980744520b002f5475f7072d17b (patch)
treef2ed5b27f419e86cc8e28089ea402dc9bd78a11c /src/compiler/scala/tools/nsc/matching
parent2d6d18662dd2d9fe9e055be9fcbacbdbf018363e (diff)
downloadscala-0964a593ec081980744520b002f5475f7072d17b.tar.gz
scala-0964a593ec081980744520b002f5475f7072d17b.tar.bz2
scala-0964a593ec081980744520b002f5475f7072d17b.zip
More code shrinkage.
Diffstat (limited to 'src/compiler/scala/tools/nsc/matching')
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala9
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternNodes.scala28
-rw-r--r--src/compiler/scala/tools/nsc/matching/TransMatcher.scala13
3 files changed, 12 insertions, 38 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index 28942a093e..9e8c7e1978 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -597,14 +597,7 @@ trait ParallelMatching {
val fail = typed { repToTree(frep) }
fLabel setInfo (new MethodType(Nil, fail.tpe))
val succ = repToTree(srep)
- try {
- typed{ If(cond2, succ, LabelDef(fLabel, Nil, fail)) }
- } catch {
- case e =>
- Console.println("failed to type-check If")
- Console.println("cond2: "+cond2)
- throw e
- }
+ typed{ If(cond2, succ, LabelDef(fLabel, Nil, fail)) }
}
}
diff --git a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
index 8658d8ba37..98fbd8994f 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
@@ -29,35 +29,23 @@ trait PatternNodes { self: transform.ExplicitOuter =>
/** sorted, null-terminated list of (int,int) pairs */
class TagIndexPair(val tag: Int, val index: Int, val next: TagIndexPair) {
-
def find(tag: Int): Int =
if (this.tag == tag) index
else next.find(tag) // assumes argument can always be found
-
}
// --- misc methods
- private val dummy1 = EmptyTree :: Nil
- private val dummy2 = EmptyTree :: dummy1
- private val dummy3 = EmptyTree :: dummy2
- private val dummy4 = EmptyTree :: dummy3
- private val dummy5 = EmptyTree :: dummy4
- private val dummy6 = EmptyTree :: dummy5
- private val dummy7 = EmptyTree :: dummy6
-
- final def getDummies(i:Int): List[Tree] = i match {
- case 0 => Nil
- case 1 => dummy1
- case 2 => dummy2
- case 3 => dummy3
- case 4 => dummy4
- case 5 => dummy5
- case 6 => dummy6
- case 7 => dummy7
- case n => EmptyTree::getDummies(i-1)
+ private val dummies = new Array[List[Tree]](8);
+ dummies(0) = Nil;
+ for (i <- 1 until dummies.length){
+ dummies(i) = EmptyTree :: dummies(i - 1);
}
+ final def getDummies(i:Int): List[Tree] =
+ if (i < dummies.length) dummies(i);
+ else EmptyTree::getDummies(i-1)
+
def makeBind(vs:SymList, pat:Tree): Tree =
if(vs eq Nil) pat else Bind(vs.head, makeBind(vs.tail, pat)) setType pat.tpe
diff --git a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
index ce31e50f07..fe59ce47b6 100644
--- a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
+++ b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
@@ -70,17 +70,12 @@ trait TransMatcher { self: transform.ExplicitOuter with PatternNodes with Parall
case CaseDef(Ident(nme.WILDCARD),_,_) => true ;
case _ => false
}}) =>
- var i = 0
- var as = args
- while(as ne Nil) {
- val ti = as.head
+ for ((ti, i) <- args.zipWithIndex){
val v = newVar(ti.pos, cunit.fresh.newName(ti.pos, "tp"), selector.tpe.typeArgs(i))
if (!doCheckExhaustive)
v.setFlag(symtab.Flags.TRANS_FLAG)
vds += typedValDef(v, ti)
tmps += v
- i = i + 1
- as = as.tail
}
theFailTree = ThrowMatchError(selector.pos, copy.Apply(app, fn, tmps.toList map mkIdent))
case _ =>
@@ -97,12 +92,10 @@ trait TransMatcher { self: transform.ExplicitOuter with PatternNodes with Parall
val mch = typed{ repToTree(irep)}
var dfatree = typed{Block(vds.toList, mch)}
// cannot use squeezedBlock because of side-effects, see t275
- var bx = 0; var cs = cases; while(cs ne Nil) {
+ for ((cs, bx) <- cases.zipWithIndex){
if (!rep.isReached(bx)) {
- cunit.error(cs.head.asInstanceOf[CaseDef].body.pos, "unreachable code")
+ cunit.error(cs.body.pos, "unreachable code")
}
- cs = cs.tail
- bx += 1
}
dfatree = rep.cleanup(dfatree)
resetTrav.traverse(dfatree)