summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2006-06-19 09:05:44 +0000
committerBurak Emir <emir@epfl.ch>2006-06-19 09:05:44 +0000
commit7718b24e9d0de8782f52b87cee88378feec2f3fa (patch)
tree280396de901166927d051e0952ccec0c916646a6
parent001ce2371bb9f2812c8ab5cda3faf8e21b548b8a (diff)
downloadscala-7718b24e9d0de8782f52b87cee88378feec2f3fa.tar.gz
scala-7718b24e9d0de8782f52b87cee88378feec2f3fa.tar.bz2
scala-7718b24e9d0de8782f52b87cee88378feec2f3fa.zip
cleanup
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternMatchers.scala70
-rw-r--r--src/compiler/scala/tools/nsc/matching/TransMatcher.scala5
2 files changed, 24 insertions, 51 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
index 5669cf3292..0d72df5626 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
@@ -42,7 +42,6 @@ trait PatternMatchers requires (TransMatcher with PatternNodes) extends AnyRef w
protected var optimize = true;
- protected var delegateSequenceMatching = false;
protected var doBinding = true;
/** the owner of the pattern matching expression
@@ -155,34 +154,22 @@ trait PatternMatchers requires (TransMatcher with PatternNodes) extends AnyRef w
val res = tree match {
case Bind(_, pat) =>
patternArgs(pat);
+
+ case a @ Apply(_, List(av @ ArrayValue(_, ts))) if isRightIgnoring(av) =>
+ ts.reverse.drop(1).reverse
+
+ case a @ Apply(_, List(av @ ArrayValue(_, ts))) =>
+ ts
+
case a @ Apply(_, args) =>
- //Console.println(" isSeqApply? "+isSeqApply(a));
- //Console.println(" isExtendedSeqApply? "+isExtendedSeqApply(a));
+ args;
+
+ case av @ ArrayValue(_, ts) if isRightIgnoring(av) =>
+ ts.reverse.drop(1).reverse
+
+ case av @ ArrayValue(_, ts) =>
+ ts;
- if ( isSeqApply( a ) && !delegateSequenceMatching)
- args(0) match {
- case av @ ArrayValue(_, ts) => // test array values
- if(isRightIgnoring(av)) {
- //Console.println(" is RIGHT IGNORING");
- ts.reverse.drop(1).reverse
- } else {
- //Console.println(" is N O T RIGHT IGNORING");
- ts;
- }
- //case Sequence(ts) =>
- // ts;
- case _ =>
- args;
- }
- else args
- // Sequence nodes should not appear here anymore, they are ArrayValue now
- //case Sequence(ts) if (!delegateSequenceMatching) =>
- // ts;
- case av @ ArrayValue(_, ts) => // test array values
- if(isRightIgnoring(av))
- ts.reverse.drop(1).reverse
- else
- ts;
case _ =>
List();
}
@@ -269,10 +256,8 @@ trait PatternMatchers requires (TransMatcher with PatternNodes) extends AnyRef w
case t @ Apply(fn, args) => // pattern with args
//Console.println("Apply node: "+t);
//Console.println("isSeqApply "+isSeqApply(t));
- //Console.println("delegateSequenceMatching "+delegateSequenceMatching);
if (isSeqApply(t)) {
- if (!delegateSequenceMatching) {
- args(0) match {
+ args(0) match {
// case Sequence(ts)=>
case av @ ArrayValue(_, ts)=>
if(isRightIgnoring(av)) {
@@ -285,29 +270,21 @@ trait PatternMatchers requires (TransMatcher with PatternNodes) extends AnyRef w
} else
//Console.println(av.toString()+" IS N O T RIGHTIGNORING");
pSequencePat(tree.pos, tree.tpe, ts.length);
- }
- } else {
- //Console.println("delegating ... ");
- val res = pConstrPat(tree.pos, tree.tpe);
- res.and = pHeader(tree.pos, header.getTpe(), header.selector);
- //res.and.and = pSeqContainerPat(tree.pos, tree.tpe, args(0));
- res.and.and = pSeqContainerPat(tree.pos, tree.tpe, Sequence(args(0).asInstanceOf[ArrayValue].elems));
- res;
}
- } else if ((fn.symbol != null) &&
+ } else if ((fn.symbol != null) &&
fn.symbol.isStable &&
!(fn.symbol.isModule &&
((fn.symbol.flags & Flags.CASE) != 0))) {
pVariablePat(tree.pos, tree);
}
- else {
+ else {
/*
Console.println("apply but not seqApply");
Console.println("tree.tpe="+tree.tpe);
Console.println("tree.symbol="+tree.symbol);
*/
pConstrPat(tree.pos, tree.tpe);
- }
+ }
case Typed(Ident( nme.WILDCARD ), tpe) => // x@_:Type
val doTest = isSubType(header.getTpe(),tpe.tpe);
if(doTest)
@@ -391,13 +368,10 @@ trait PatternMatchers requires (TransMatcher with PatternNodes) extends AnyRef w
pRightIgnoringSequencePat(tree.pos, tree.tpe, castedRest, ts.length-1);
} else {
//Console.println("array value "+av+" is not considered right ignoring")
- if ( !delegateSequenceMatching ) {
- //lastSequencePat =
- pSequencePat(tree.pos, tree.tpe, ts.length);
- //lastSequencePat
- } else {
- pSeqContainerPat(tree.pos, tree.tpe, tree);
- }
+ //lastSequencePat =
+ pSequencePat(tree.pos, tree.tpe, ts.length);
+ //lastSequencePat
+
}
case Alternative(ts) =>
if(ts.length < 2)
diff --git a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
index 54187e02f8..6a2347ea95 100644
--- a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
+++ b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
@@ -166,13 +166,12 @@ with RightTracers {
};
// @todo: this should be isNotRegular :-/ premature opt src of all evil
- // check special case Seq(_,...,_,_*)
+ // check special case Seq(p1,...,pk,_*) where pi not regular
protected def isRightIgnoring(p:ArrayValue): Boolean = p match {
case ArrayValue(s,trees) =>
val it = trees.elements;
var c: Tree = null;
- while(it.hasNext && {c = it.next; //Console.println("isReg?("+c+" = "+isRegularPattern(c)); // DEBUG
-!isRegularPattern(c)}) {}
+ while(it.hasNext && {c = it.next; !isRegularPattern(c)}) {}
(!it.hasNext) && isDefaultStar(c)
}