summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2006-08-04 21:15:28 +0000
committerBurak Emir <emir@epfl.ch>2006-08-04 21:15:28 +0000
commit4f25b17e9f3c624e32522db1b79f64314870dad6 (patch)
treec0aa0f854f1b86f9dba682f8a8ca7ad08032fcf2
parentc5c18aa57a61ea9f40a3a8883f6e267bb21850c1 (diff)
downloadscala-4f25b17e9f3c624e32522db1b79f64314870dad6.tar.gz
scala-4f25b17e9f3c624e32522db1b79f64314870dad6.tar.bz2
scala-4f25b17e9f3c624e32522db1b79f64314870dad6.zip
cleanup + little opt for object compare
-rw-r--r--src/compiler/scala/tools/nsc/matching/CodeFactory.scala2
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternMatchers.scala43
2 files changed, 16 insertions, 29 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
index 943df9571e..8486ff36a0 100644
--- a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
+++ b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
@@ -186,6 +186,8 @@ trait CodeFactory requires TransMatcher {
*/
def Equals(left: Tree , right: Tree ): Tree = Apply(Select(left, nme.EQEQ), List(right));
+ def Eq(left: Tree , right: Tree ): Tree = Apply(Select(left, nme.eq), List(right));
+
def GreaterThanOrEquals(left: Tree , right: Tree ): Tree = Apply(Select(left, nme.GE), List(right));
def ThrowMatchError(pos: Int, obj: Tree ) =
diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
index d234f46c3d..72272faf82 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
@@ -261,7 +261,7 @@ trait PatternMatchers requires (TransMatcher with PatternNodes) extends AnyRef w
pConstrPat(tree.pos, tree.tpe);
}
case Typed(Ident( nme.WILDCARD ), tpe) => // x@_:Type
- val doTest = isSubType(header.getTpe(),tpe.tpe);
+ val doTest = isSubType(header.getTpe(),tpe.tpe); // this is already an optimization
if(doTest)
pDefaultPat(tree.pos, tpe.tpe)
else
@@ -296,32 +296,15 @@ trait PatternMatchers requires (TransMatcher with PatternNodes) extends AnyRef w
case Ident(nme.WILDCARD) => pDefaultPat(tree.pos, header.getTpe());
- case Ident(name) => // pattern without args or variable, nsc: wildcard's have no symbols
- //if (tree.symbol == defs.PatternWildcard)
- // pDefaultPat(tree.pos, header.getTpe());
- //else
-
- if (tree.symbol.isPrimaryConstructor) {
+ case Ident(name) => // pattern without args or named constant
+ if (tree.symbol.isPrimaryConstructor)
scala.Predef.error("error may not happen: ident is primary constructor"+tree.symbol); // Burak
+ else if (treeInfo.isVariableName(name))
+ scala.Predef.error("this may not happen"); // because id => id @ _
+ else
+ pVariablePat(tree.pos, tree); // named constant (capitalized variable Foo)
- } else if (treeInfo.isVariableName(name)) {// Burak
- //old scalac
- scala.Predef.error("this may not happen"); // Burak
-
- //nsc: desugarize (in case nsc does not do it)
- /*
- Console.println("Ident("+name+") in unit"+cunit);
- Console.println("tree.symbol = "+tree.symbol);
- // = treat the same as Bind(name, _)
- val node = pDefaultPat(tree.pos, header.getTpe());
- if ((env != null) && (tree.symbol != defs.PatternWildcard))
- env.newBoundVar( tree.symbol, tree.tpe, header.selector);
- node;
- */
- } else
- pVariablePat(tree.pos, tree); // a named constant Foo
-
- case Select(_, name) => // variable
+ case Select(_, name) => // named constant
if (tree.symbol.isPrimaryConstructor)
pConstrPat(tree.pos, tree.tpe);
else
@@ -330,9 +313,6 @@ trait PatternMatchers requires (TransMatcher with PatternNodes) extends AnyRef w
case Literal(Constant(value)) =>
pConstantPat(tree.pos, tree.tpe, value);
- //case Sequence(ts) =>
-
-
case av @ ArrayValue(_, ts) =>
if(isRightIgnoring(av)) {
val castedRest = ts.last match {
@@ -1077,9 +1057,14 @@ trait PatternMatchers requires (TransMatcher with PatternNodes) extends AnyRef w
toTree(node.and),
toTree(node.or, selector.duplicate));
case VariablePat(tree) =>
- return myIf(Equals(selector.duplicate, tree),
+ val cmp = if(tree.tpe.symbol.isModuleClass) // objects are compared by eq, not == (avoids unnecessary null-magic)
+ Eq(selector.duplicate, tree)
+ else
+ Equals(selector.duplicate, tree)
+ return myIf( cmp,
toTree(node.and),
toTree(node.or, selector.duplicate));
+
case AltPat(header) =>
return myIf(toTree(header),
toTree(node.and),