diff options
author | Burak Emir <emir@epfl.ch> | 2006-11-06 14:55:38 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2006-11-06 14:55:38 +0000 |
commit | e2e0a9488d1c97ff7095d63996ef131c4bcf8eb3 (patch) | |
tree | 7050f1768a2cf13a1ba6e395577f1280b1055a18 /src | |
parent | 516f06d7bd48509f4baeff069b5113e3005ed631 (diff) | |
download | scala-e2e0a9488d1c97ff7095d63996ef131c4bcf8eb3.tar.gz scala-e2e0a9488d1c97ff7095d63996ef131c4bcf8eb3.tar.bz2 scala-e2e0a9488d1c97ff7095d63996ef131c4bcf8eb3.zip |
removed CaseClass
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/Trees.scala | 14 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/LiftCode.scala | 6 | ||||
-rw-r--r-- | src/library/scala/Iterator.scala | 9 | ||||
-rw-r--r-- | src/library/scala/List.scala | 5 | ||||
-rw-r--r-- | src/library/scala/Product.scala | 6 | ||||
-rw-r--r-- | src/library/scala/Seq.scala | 3 | ||||
-rw-r--r-- | src/library/scala/runtime/ScalaRunTime.scala | 56 |
7 files changed, 30 insertions, 69 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 54f8a8bc76..1958099e31 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -93,15 +93,15 @@ trait Trees requires Global { } def equalsStructure(that: Tree): Boolean = if (this == that) true else (this:Any) match { - case thiz : CaseClass if (that != null && thiz.getClass == that.getClass) => - val that0 = that.asInstanceOf[CaseClass] + case thiz : Product if (that != null && thiz.getClass == that.getClass) => + val that0 = that.asInstanceOf[Product] val result: Iterator[Boolean] = - for (val i <- 0.until(thiz.caseArity)) yield thiz.caseElement(i) match { + for (val i <- 0.until(thiz.arity)) yield thiz.element(i) match { case tree: Tree => - val b = tree.equalsStructure(that0.caseElement(i).asInstanceOf[Tree]) + val b = tree.equalsStructure(that0.element(i).asInstanceOf[Tree]) b - case list: List[_] if (that0.caseElement(i).isInstanceOf[List[Any]]) => - val listThat = that0.caseElement(i).asInstanceOf[List[Any]] + case list: List[_] if (that0.element(i).isInstanceOf[List[Any]]) => + val listThat = that0.element(i).asInstanceOf[List[Any]] if (list.length == listThat.length) (for (val x <- list.zip(listThat)) yield { if (x._1 != null && x._1.isInstanceOf[Tree] && x._2.isInstanceOf[Tree]) { val b = x._1.asInstanceOf[Tree] equalsStructure x._2.asInstanceOf[Tree] @@ -110,7 +110,7 @@ trait Trees requires Global { }).foldLeft(true)((x,y) => x && y) else false case elem => - val b = elem == that0.caseElement(i) + val b = elem == that0.element(i) b } val b = result.foldLeft(true)((x,y) => x && y) diff --git a/src/compiler/scala/tools/nsc/transform/LiftCode.scala b/src/compiler/scala/tools/nsc/transform/LiftCode.scala index bc010f8236..581d115071 100644 --- a/src/compiler/scala/tools/nsc/transform/LiftCode.scala +++ b/src/compiler/scala/tools/nsc/transform/LiftCode.scala @@ -233,8 +233,6 @@ abstract class LiftCode extends Transform { "scala.reflect.MethodType" case x:Product => "scala.reflect."+x.productPrefix //caseName - case x:CaseClass => - "scala.reflect."+x.caseName //case _ => // bq:unreachable code // "" } @@ -275,10 +273,6 @@ abstract class LiftCode extends Transform { case x: Float => Literal(Constant(x)) case x: Double => Literal(Constant(x)) case c: Product => treatProduct(c) - case c: CaseClass => treatProduct(new Product { - override def productPrefix = c.caseName; - def element(i:Int) = c.caseElement(i) - def arity = c.caseArity }) case null => gen.mkAttributedRef(definitions.getModule("scala.reflect.NoType")) case _ => diff --git a/src/library/scala/Iterator.scala b/src/library/scala/Iterator.scala index 3e9dbdb957..a7dd7c6aad 100644 --- a/src/library/scala/Iterator.scala +++ b/src/library/scala/Iterator.scala @@ -67,13 +67,16 @@ object Iterator { def head = str charAt i } - def fromCaseClass(n:CaseClass): Iterator[Any] = new Iterator[Any] { + def fromProduct(n:Product): Iterator[Any] = new Iterator[Any] { private var c: Int = 0 - private val cmax = n.caseArity + private val cmax = n.arity def hasNext = c < cmax - def next = { val a = n caseElement c; c = c + 1; a } + def next = { val a = n element c; c = c + 1; a } } + /** deprecated */ + def fromCaseClass(n:Product) = fromProduct(n) + /** Create an iterator with elements * <code>e<sub>n+1</sub> = e<sub>n</sub> + 1</code> * where <code>e<sub>0</sub> = lo</code> diff --git a/src/library/scala/List.scala b/src/library/scala/List.scala index 3d622bd68c..581122448c 100644 --- a/src/library/scala/List.scala +++ b/src/library/scala/List.scala @@ -29,6 +29,11 @@ object List { */ def apply[A](xs: A*): List[A] = xs.toList + /** for unapply matching + */ + def unapplySeq[A](x:Any):Option[Tuple1[List[A]]] = + if(x.isInstanceOf[List[A]]) Some(Tuple1(x.asInstanceOf[List[A]])) else None + /** Create a sorted list of all integers in a range. * * @param from the start value of the list diff --git a/src/library/scala/Product.scala b/src/library/scala/Product.scala index 07bc5b045c..929f6c2591 100644 --- a/src/library/scala/Product.scala +++ b/src/library/scala/Product.scala @@ -6,13 +6,13 @@ ** |/ ** \* */ -// $Id: CaseClass.scala 8756 2006-09-22 16:00:23Z michelou $ +// $Id$ package scala -/** The trait <code>CaseClass</code> defines access functions for instances - * of case classes. +/** The trait <code>Product</code> defines access functions for instances + * of products, in particular case classes. * * @author Burak Emir * @version 1.0 diff --git a/src/library/scala/Seq.scala b/src/library/scala/Seq.scala index 8879422969..264d1122dc 100644 --- a/src/library/scala/Seq.scala +++ b/src/library/scala/Seq.scala @@ -16,6 +16,9 @@ import Predef.IllegalArgumentException object Seq { + def unapplySeq[A](x:Any): Option[Tuple1[Seq[A]]] = + if(x.isInstanceOf[Seq[A]]) Some(Tuple1(x.asInstanceOf[Seq[A]])) else None + /** builds a singleton sequence * @author buraq */ diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala index f20f6106fa..7173253316 100644 --- a/src/library/scala/runtime/ScalaRunTime.scala +++ b/src/library/scala/runtime/ScalaRunTime.scala @@ -68,13 +68,6 @@ object ScalaRunTime { throw exception; } - def caseFields(x: CaseClass): List[Any] = { - val arity = x.caseArity; - def fields(from: Int): List[Any] = - if (from >= arity) List() - else x.caseElement(from) :: fields(from + 1); - fields(0) - } def caseFields(x: Product): List[Any] = { val arity = x.arity; def fields(from: Int): List[Any] = @@ -82,28 +75,12 @@ object ScalaRunTime { else x.element(from) :: fields(from + 1); fields(1) } - def _toStringCaseClass(x: CaseClass): String = { - caseFields(x).mkString(x.caseName + "(", ",", ")") - } - def _toStringProduct(x: Product): String = { + + def _toString(x: Product): String = { caseFields(x).mkString(x.productPrefix + "(", ",", ")") } - /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */ - def _toString(x: AnyRef): String = x match { - case xc: CaseClass => _toStringCaseClass(xc) - case xp: Product => _toStringProduct(xp) - } - def _hashCodeCaseClass(x: CaseClass): Int = { - var code = x.getClass().hashCode(); - val arr = x.caseArity - var i = 0; - while (i < arr) { - code = code * 41 + x.caseElement(i).hashCode(); - i = i + 1 - } - code - } - def _hashCodeProduct(x: Product): Int = { + + def _hashCode(x: Product): Int = { var code = x.getClass().hashCode(); val arr = x.arity var i = 1; @@ -113,24 +90,8 @@ object ScalaRunTime { } code } - /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */ - def _hashCode(x: AnyRef): Int = x match { - case xc: CaseClass => _hashCodeCaseClass(xc) - case xp: Product => _hashCodeProduct(xp) - } - def _equalsCaseClass(x: CaseClass, y: Any): Boolean = y match { - case y1: CaseClass => - /*(x.getClass() eq y1.getClass() &&*/ { - val arity = x.caseArity; - var i = 0; - while (i < arity && x.caseElement(i) == y1.caseElement(i)) - i = i + 1; - i == arity - } - case _ => - false - } - def _equalsProduct(x: Product, y: Any): Boolean = y match { + + def _equals(x: Product, y: Any): Boolean = y match { case y1: Product if x.arity == y1.arity => /*(x.getClass() eq y1.getClass() &&*/ { val arity = x.arity; @@ -142,11 +103,6 @@ object ScalaRunTime { case _ => false } - /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */ - def _equals(x: AnyRef, y: Any): Boolean = x match { - case xc: CaseClass => _equalsCaseClass(xc, y) - case xp: Product => _equalsProduct(xp, y) - } //def checkDefined[T >: Null](x: T): T = // if (x == null) throw new UndefinedException else x |