cleanup + little opt for object compare
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@8324 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
99f5a0225e
commit
946c024ebb
|
@ -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 ) =
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue