diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/Interpreter.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/matching/PatternMatchers.scala | 5 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 6 | ||||
-rw-r--r-- | src/library/scala/Array.scala | 108 | ||||
-rw-r--r-- | src/library/scala/Predef.scala | 87 | ||||
-rw-r--r-- | src/library/scala/mobile/Code.scala | 42 | ||||
-rw-r--r-- | src/library/scala/mobile/Location.scala | 2 | ||||
-rw-r--r-- | src/library/scala/xml/Utility.scala | 2 | ||||
-rw-r--r-- | test/files/jvm/xml01.scala | 2 |
11 files changed, 129 insertions, 134 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala index 30d71d438f..d715da5efb 100644 --- a/src/compiler/scala/tools/nsc/Interpreter.scala +++ b/src/compiler/scala/tools/nsc/Interpreter.scala @@ -99,9 +99,9 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) */ private val classLoader = { if (parentClassLoader == null) - new java.net.URLClassLoader(Predef.Array(classfilePath.toURL)) + new java.net.URLClassLoader(Array(classfilePath.toURL)) else - new java.net.URLClassLoader(Predef.Array(classfilePath.toURL), parentClassLoader) + new java.net.URLClassLoader(Array(classfilePath.toURL), parentClassLoader) } protected def parentClassLoader : ClassLoader = { new java.net.URLClassLoader( diff --git a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala index 1d99e5c402..c2667443ce 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala @@ -199,7 +199,7 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean } nextch; } - new String(Predef.Array(i.asInstanceOf[char])) + new String(Array(i.asInstanceOf[char])) } /** Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' * diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index d8be10771f..b0069cdfa8 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -1060,8 +1060,7 @@ abstract class GenJVM extends SubComponent { } jcode.emitINVOKEVIRTUAL(JAVA_LANG_STRINGBUFFER, "append", - new JMethodType(stringBufferType, - Predef.Array(jtype))); + new JMethodType(stringBufferType, Array(jtype))); case EndConcat => jcode.emitINVOKEVIRTUAL(JAVA_LANG_STRINGBUFFER, "toString", diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala index 69354f9b62..12e179c5df 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala @@ -199,9 +199,8 @@ trait PatternMatchers requires (transform.ExplicitOuter with PatternNodes) { } def pBody(pos: PositionType, bound: Array[ValDef], guard: Tree, body: Tree) = { - val node = new Body(Predef.Array[Array[ValDef]](bound), - Predef.Array[Tree](guard), - Predef.Array[Tree](body)) + val node = + new Body(Array[Array[ValDef]](bound), Array[Tree](guard), Array[Tree](body)) node.pos = pos node } diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index c50e90bcd9..599ece4c7c 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -300,7 +300,7 @@ trait Types requires SymbolTable { * * Sorting is with respect to Symbol.isLess() on type symbols. */ - def closure: Array[Type] = Predef.Array(this) + def closure: Array[Type] = Array(this) def baseClasses: List[Symbol] = List() @@ -1909,7 +1909,7 @@ trait Types requires SymbolTable { var i = 0 for (val x <- glbs.elements) { result(i) = x; i = i + 1; } result - // Predef.Array(glbs: _*); + // Array(glbs: _*); } /** The least sorted upwards closed upper bound of a non-empty list @@ -1940,7 +1940,7 @@ trait Types requires SymbolTable { lubs = lubs.tail } arr - // todo: replace by Predef.Array(lubs: _* ) + // todo: replace by Array(lubs: _* ) } /** The minimal symbol (wrt Symbol.isLess) of a list of types */ diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala index 22872d1b39..b64df80406 100644 --- a/src/library/scala/Array.scala +++ b/src/library/scala/Array.scala @@ -69,23 +69,107 @@ object Array { for (val i <- Iterator.range(start, end)) result(i - start) = i result } + + /** Create an array with given elements. + * + * @param xs the elements to put in the array + * @return the array containing elements xs. + */ + def apply[A <: AnyRef](xs: A*): Array[A] = { + val array = new Array[A](xs.length) + var i = 0 + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array + } + + +/* The following metod clashes with the previous one, and has therefore been + * removed. Note that this is a choice between efficiency and generality. + * The previous factory method is more efficient than the one that has been + * commented out. Since it is anyway possible to create a polymorphic array + * using + * new Array[T] + * it was preferred to restrict the definition of the factory method. + + def Array[A](xs: A*): Array[A] = { + val array = new Array[A](xs.length) + var i = 0 + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array + } +*/ + + def apply(xs: Boolean*): Array[Boolean] = { + val array = new Array[Boolean](xs.length) + var i = 0 + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array + } + def apply(xs: Byte*): Array[Byte] = { + val array = new Array[Byte](xs.length) + var i = 0 + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array + } + def apply(xs: Short*): Array[Short] = { + val array = new Array[Short](xs.length) + var i = 0 + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array + } + def apply(xs: Char*): Array[Char] = { + val array = new Array[Char](xs.length) + var i = 0 + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array + } + def apply(xs: Int*): Array[Int] = { + val array = new Array[Int](xs.length) + var i = 0 + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array + } + def apply(xs: Long*): Array[Long] = { + val array = new Array[Long](xs.length) + var i = 0 + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array + } + def apply(xs: Float*): Array[Float] = { + val array = new Array[Float](xs.length) + var i = 0 + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array + } + def apply(xs: Double*): Array[Double] = { + val array = new Array[Double](xs.length) + var i = 0 + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array + } + def apply(xs: Unit*): Array[Unit] = { + val array = new Array[Unit](xs.length) + var i = 0 + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array + } + } -/** This class ... +/** This class represents polymorphic arrays. It is never instantiated. * * @author Martin Odersky * @version 1.0 */ -[cloneable,serializable] -final class Array[a](_length: Int) extends Seq[a] { +final class Array[A](_length: Int) extends Seq[A] { def length: Int = throw new Error() - def apply(i: Int): a = throw new Error() - def update(i: Int, x: a): Unit = throw new Error() - def elements: Iterator[a] = throw new Error() - def subArray(from: Int, end: Int): Array[a] = throw new Error() - def filter(p: a => Boolean): Array[a] = throw new Error() - def map[b](f: a => b): Array[b] = throw new Error() - def flatMap[b](f: a => Array[b]): Array[b] = throw new Error() - def zip[b](that: Array[b]): Array[Tuple2[a,b]] = throw new Error() - def zipWithIndex: Array[Tuple2[a,Int]] = throw new Error() + def apply(i: Int): A = throw new Error() + def update(i: Int, x: A): Unit = throw new Error() + def elements: Iterator[A] = throw new Error() + def subArray(from: Int, end: Int): Array[A] = throw new Error() + def filter(p: A => Boolean): Array[A] = throw new Error() + def map[B](f: A => B): Array[B] = throw new Error() + def flatMap[B](f: A => Array[B]): Array[B] = throw new Error() + def zip[B](that: Array[B]): Array[Tuple2[A,B]] = throw new Error() + def zipWithIndex: Array[Tuple2[A,Int]] = throw new Error() } diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala index 785546624a..dcb67d2900 100644 --- a/src/library/scala/Predef.scala +++ b/src/library/scala/Predef.scala @@ -74,93 +74,6 @@ object Predef { type Function[-a,+b] = Function1[a,b] - // arrays ----------------------------------------------------------- - - /** Create an array with given elements. - * - * @param xs the elements to put in the array - * @return the array containing elements xs. - */ - def Array[A <: AnyRef](xs: A*): Array[A] = { - val array = new Array[A](xs.length) - var i = 0 - for (val x <- xs.elements) { array(i) = x; i = i + 1; } - array - } - - val Array = scala.Array - -/* The following metod clashes with the previous one, and has therefore been - * removed. Note that this is a choice between efficiency and generality. - * The previous factory method is more efficient than the one that has been - * commented out. Since it is anyway possible to create a polymorphic array - * using - * new Array[T] - * it was preferred to restrict the definition of the factory method. - - def Array[A](xs: A*): Array[A] = { - val array = new Array[A](xs.length) - var i = 0 - for (val x <- xs.elements) { array(i) = x; i = i + 1; } - array - } -*/ - - def Array(xs: boolean*): Array[boolean] = { - val array = new Array[boolean](xs.length) - var i = 0 - for (val x <- xs.elements) { array(i) = x; i = i + 1; } - array - } - def Array(xs: byte*): Array[byte] = { - val array = new Array[byte](xs.length) - var i = 0 - for (val x <- xs.elements) { array(i) = x; i = i + 1; } - array - } - def Array(xs: short*): Array[short] = { - val array = new Array[short](xs.length) - var i = 0 - for (val x <- xs.elements) { array(i) = x; i = i + 1; } - array - } - def Array(xs: char*): Array[char] = { - val array = new Array[char](xs.length) - var i = 0 - for (val x <- xs.elements) { array(i) = x; i = i + 1; } - array - } - def Array(xs: int*): Array[int] = { - val array = new Array[int](xs.length) - var i = 0 - for (val x <- xs.elements) { array(i) = x; i = i + 1; } - array - } - def Array(xs: long*): Array[long] = { - val array = new Array[long](xs.length) - var i = 0 - for (val x <- xs.elements) { array(i) = x; i = i + 1; } - array - } - def Array(xs: float*): Array[float] = { - val array = new Array[float](xs.length) - var i = 0 - for (val x <- xs.elements) { array(i) = x; i = i + 1; } - array - } - def Array(xs: double*): Array[double] = { - val array = new Array[double](xs.length) - var i = 0 - for (val x <- xs.elements) { array(i) = x; i = i + 1; } - array - } - def Array(xs: unit*): Array[unit] = { - val array = new Array[unit](xs.length) - var i = 0 - for (val x <- xs.elements) { array(i) = x; i = i + 1; } - array - } - // errors and asserts ------------------------------------------------- def error(message: String): Nothing = throw new Error(message) diff --git a/src/library/scala/mobile/Code.scala b/src/library/scala/mobile/Code.scala index 27de533b83..c15db16f01 100644 --- a/src/library/scala/mobile/Code.scala +++ b/src/library/scala/mobile/Code.scala @@ -44,16 +44,16 @@ class Code(clazz: java.lang.Class) { def apply[R](funName: String) = () => { - val args = Predef.Array[JObject](); - val types = Predef.Array[Class](); + val args = Array[JObject](); + val types = Array[Class](); applyFun(funName, args, types).asInstanceOf[R]; }; def apply[A0, R](funName: String) = (_0: A0) => { val p = boxValue(_0); - val args = Predef.Array(p._1); - val types = Predef.Array(p._2); + val args = Array(p._1); + val types = Array(p._2); applyFun(funName, args, types).asInstanceOf[R]; }; @@ -61,8 +61,8 @@ class Code(clazz: java.lang.Class) { (_0: A0, _1: A1) => { val p0 = boxValue(_0); val p1 = boxValue(_1); - val args = Predef.Array(p0._1, p1._1); - val types = Predef.Array(p0._2, p1._2); + val args = Array(p0._1, p1._1); + val types = Array(p0._2, p1._2); applyFun(funName, args, types).asInstanceOf[R]; }; @@ -71,8 +71,8 @@ class Code(clazz: java.lang.Class) { val p0 = boxValue(_0); val p1 = boxValue(_1); val p2 = boxValue(_2); - val args = Predef.Array(p0._1, p1._1, p2._1); - val types = Predef.Array(p0._2, p1._2, p2._2); + val args = Array(p0._1, p1._1, p2._1); + val types = Array(p0._2, p1._2, p2._2); applyFun(funName, args, types).asInstanceOf[R]; }; @@ -82,8 +82,8 @@ class Code(clazz: java.lang.Class) { val p1 = boxValue(_1); val p2 = boxValue(_2); val p3 = boxValue(_3); - val args = Predef.Array(p0._1, p1._1, p2._1, p3._1); - val types = Predef.Array(p0._2, p1._2, p2._2, p3._2); + val args = Array(p0._1, p1._1, p2._1, p3._1); + val types = Array(p0._2, p1._2, p2._2, p3._2); applyFun(funName, args, types).asInstanceOf[R]; }; @@ -94,8 +94,8 @@ class Code(clazz: java.lang.Class) { val p2 = boxValue(_2); val p3 = boxValue(_3); val p4 = boxValue(_4); - val args = Predef.Array(p0._1, p1._1, p2._1, p3._1, p4._1); - val types = Predef.Array(p0._2, p1._2, p2._2, p3._2, p4._2); + val args = Array(p0._1, p1._1, p2._1, p3._1, p4._1); + val types = Array(p0._2, p1._2, p2._2, p3._2, p4._2); applyFun(funName, args, types).asInstanceOf[R]; }; @@ -107,8 +107,8 @@ class Code(clazz: java.lang.Class) { val p3 = boxValue(_3); val p4 = boxValue(_4); val p5 = boxValue(_5); - val args = Predef.Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1); - val types = Predef.Array(p0._2, p1._2, p2._2, p3._2, p4._2, p5._2); + val args = Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1); + val types = Array(p0._2, p1._2, p2._2, p3._2, p4._2, p5._2); applyFun(funName, args, types).asInstanceOf[R]; }; @@ -121,8 +121,8 @@ class Code(clazz: java.lang.Class) { val p4 = boxValue(_4); val p5 = boxValue(_5); val p6 = boxValue(_6); - val args = Predef.Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1, p6._1); - val types = Predef.Array(p0._2, p1._2, p2._2, p3._2, p4._2, p5._2, p6._2); + val args = Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1, p6._1); + val types = Array(p0._2, p1._2, p2._2, p3._2, p4._2, p5._2, p6._2); applyFun(funName, args, types).asInstanceOf[R]; }; @@ -136,8 +136,8 @@ class Code(clazz: java.lang.Class) { val p5 = boxValue(_5); val p6 = boxValue(_6); val p7 = boxValue(_7); - val args = Predef.Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1, p6._1, p7._1); - val types = Predef.Array(p0._2, p1._2, p2._2, p3._2, p4._2, p5._2, p6._2, p7._2); + val args = Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1, p6._1, p7._1); + val types = Array(p0._2, p1._2, p2._2, p3._2, p4._2, p5._2, p6._2, p7._2); applyFun(funName, args, types).asInstanceOf[R]; }; @@ -152,8 +152,8 @@ class Code(clazz: java.lang.Class) { val p6 = boxValue(_6); val p7 = boxValue(_7); val p8 = boxValue(_8); - val args = Predef.Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1, p6._1, p7._1, p8._1); - val types = Predef.Array(p0._2, p1._2, p2._2, p3._2, p4._2, p5._2, p6._2, p7._2, p8._2); + val args = Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1, p6._1, p7._1, p8._1); + val types = Array(p0._2, p1._2, p2._2, p3._2, p4._2, p5._2, p6._2, p7._2, p8._2); applyFun(funName, args, types).asInstanceOf[R]; }; @@ -194,7 +194,7 @@ class Code(clazz: java.lang.Class) { val cs = clazz.getConstructors(); //Console.println("cs.length=" + cs.length); if (cs.length > 0) { - cs(0).newInstance(Predef.Array("")) + cs(0).newInstance(Array("")) } else { error("class " + clazz.getName() + " has no public constructor"); null diff --git a/src/library/scala/mobile/Location.scala b/src/library/scala/mobile/Location.scala index 816edd9dcb..388cc2d415 100644 --- a/src/library/scala/mobile/Location.scala +++ b/src/library/scala/mobile/Location.scala @@ -48,7 +48,7 @@ class Location(url: URL) { case Some(cl) => cl case _ => - val cl = new URLClassLoader(Predef.Array(url)); + val cl = new URLClassLoader(Array(url)); lcache(url) = cl; cl }; diff --git a/src/library/scala/xml/Utility.scala b/src/library/scala/xml/Utility.scala index dd3afc61a0..4bdb480483 100644 --- a/src/library/scala/xml/Utility.scala +++ b/src/library/scala/xml/Utility.scala @@ -316,7 +316,7 @@ object Utility extends AnyRef with parsing.TokenTests { } nextch(); } - new String(Predef.Array(i.asInstanceOf[char])) + new String(Array(i.asInstanceOf[char])) } } diff --git a/test/files/jvm/xml01.scala b/test/files/jvm/xml01.scala index 3ba0bbd193..3558d95100 100644 --- a/test/files/jvm/xml01.scala +++ b/test/files/jvm/xml01.scala @@ -31,7 +31,7 @@ object Test { assertEquals(c, parsedxml11); assertEquals(parsedxml1, parsedxml11); assertSameElements( List(parsedxml1), List(parsedxml11)); - assertSameElements( Iterator.fromArray(Predef.Array(parsedxml1)).toList, List(parsedxml11)); + assertSameElements( Iterator.fromArray(Array(parsedxml1)).toList, List(parsedxml11)); val x2 = "<book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book>"; |