summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2005-05-31 10:24:13 +0000
committerburaq <buraq@epfl.ch>2005-05-31 10:24:13 +0000
commitec2192987663a4e7cca89abdd644e72b55219187 (patch)
tree472a9bc6e0bfef1ceb5f1cb06d2b0277e3d59bbe /sources
parent8ae660b5ce33ef84ca4a4baf0c0cbcab432c7489 (diff)
downloadscala-ec2192987663a4e7cca89abdd644e72b55219187.tar.gz
scala-ec2192987663a4e7cca89abdd644e72b55219187.tar.bz2
scala-ec2192987663a4e7cca89abdd644e72b55219187.zip
more code cleanup
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala96
1 files changed, 47 insertions, 49 deletions
diff --git a/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala b/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala
index 0338c0b770..018053e148 100644
--- a/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala
+++ b/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala
@@ -590,58 +590,16 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) {
return gen.mkBlock(selector.pos, ts, res);
}
- /*protected*/ def toTree(node1: PatternNode): Tree = {
- var node = node1;
- var res = gen.mkBooleanLit(node.pos, false);
- while (node != null)
- node match {
- case _h:Header =>
- val selector = _h.selector;
- val next = _h.next;
- //res = cf.And(mkNegate(res), toTree(node.or, selector));
- //Console.println("HEADER TYPE = " + selector.type);
- if (optimize(node.getTpe(), node.or))
- res = cf.Or(res, toOptTree(node.or, selector));
- else
- res = cf.Or(res, toTree(node.or, selector));
- node = next;
-
- case _b:Body =>
- var bound = _b.bound;
- val guard = _b.guard;
- val body = _b.body;
- if ((bound.length == 0) &&
- (guard.length == 0) &&
- (body.length == 0)) {
- return gen.mkBooleanLit(node.pos, true); // cf.Or(res, gen.mkBooleanLit(node.pos, true));
- } else if (!doBinding)
- bound = Predef.Array[Array[ValDef]]( Predef.Array[ValDef]() );
- var i = guard.length - 1; while(i >= 0) {
- val ts = bound(i).asInstanceOf[Array[Tree]];
- var res0 = gen.mkBlock(gen.Assign(gen.Ident(body(i).pos, resultVar),
- body(i)),
- gen.mkBooleanLit(body(i).pos, true));
- if (guard(i) != Tree.Empty)
- res0 = cf.And(guard(i), res0);
- res = cf.Or(gen.mkBlock(body(i).pos, ts, res0), res);
- i = i - 1
- }
- return res;
- case _ =>
- throw new ApplicationError();
- }
- return res;
- }
-
- protected def optimize(selType:Type, alternatives1: PatternNode ): boolean = {
- var alternatives = alternatives1;
+ def toTree(node1: PatternNode): Tree = {
+ def optimize1(selType:Type, alternatives1: PatternNode ): boolean = {
+ var alts = alternatives1;
if (!optimize || !selType.isSubType(defs.SCALAOBJECT_TYPE()))
return false;
var cases = 0;
- while (alternatives != null) {
- alternatives match {
+ while (alts != null) {
+ alts match {
case ConstrPat(_) =>
- if (alternatives.getTpe().symbol().isCaseClass())
+ if (alts.getTpe().symbol().isCaseClass())
cases = cases +1;
else
return false;
@@ -651,11 +609,51 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) {
case _ =>
return false;
}
- alternatives = alternatives.or;
+ alts = alts.or;
}
return cases > 2;
}
+ var node = node1;
+ var res = gen.mkBooleanLit(node.pos, false);
+ while (node != null)
+ node match {
+ case _h:Header =>
+ val selector = _h.selector;
+ val next = _h.next;
+ //res = cf.And(mkNegate(res), toTree(node.or, selector));
+ //Console.println("HEADER TYPE = " + selector.type);
+ if (optimize1(node.getTpe(), node.or))
+ res = cf.Or(res, toOptTree(node.or, selector));
+ else
+ res = cf.Or(res, toTree(node.or, selector));
+ node = next;
+
+ case _b:Body =>
+ var bound = _b.bound;
+ val guard = _b.guard;
+ val body = _b.body;
+ if ((bound.length == 0) &&
+ (guard.length == 0) &&
+ (body.length == 0)) {
+ return gen.mkBooleanLit(node.pos, true); // cf.Or(res, gen.mkBooleanLit(node.pos, true));
+ } else if (!doBinding)
+ bound = Predef.Array[Array[ValDef]]( Predef.Array[ValDef]() );
+ var i = guard.length - 1; while(i >= 0) {
+ val ts = bound(i).asInstanceOf[Array[Tree]];
+ var res0 = gen.mkBlock(gen.Assign(gen.Ident(body(i).pos, resultVar),
+ body(i)),
+ gen.mkBooleanLit(body(i).pos, true));
+ if (guard(i) != Tree.Empty)
+ res0 = cf.And(guard(i), res0);
+ res = cf.Or(gen.mkBlock(body(i).pos, ts, res0), res);
+ i = i - 1
+ }
+ return res;
+ }
+ return res;
+ }
+
protected def toOptTree(node1: PatternNode, selector: Tree): Tree = {
class TagNodePair(tag1: int, node1: PatternNode, next1: TagNodePair) {