diff options
20 files changed, 76 insertions, 62 deletions
diff --git a/newsources/scala/Array.scala b/newsources/scala/Array.scala index 068d4813d0..7e3b0e225e 100755 --- a/newsources/scala/Array.scala +++ b/newsources/scala/Array.scala @@ -10,8 +10,7 @@ package scala; -/** @meta class [?T] extends scala.AnyRef with java.lang.Cloneable with java.io.Serializable; */ -abstract class Array[T](val length: Int) extends Cloneable with java.io.Serializable with Seq[T] { +final class Array[T](val length: Int) extends Cloneable with java.io.Serializable with Seq[T] { def apply(i: Int): T; def update(i: Int, x: T): Unit; diff --git a/sources/scala/runtime/BoxedAnyArray.scala b/sources/scala/runtime/BoxedAnyArray.scala index 5b7ff7528d..9d783805a2 100755 --- a/sources/scala/runtime/BoxedAnyArray.scala +++ b/sources/scala/runtime/BoxedAnyArray.scala @@ -14,26 +14,26 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray { private var boxed = new Array[Object](length); private val hash = boxed.hashCode(); private var unboxed: Object = null; - private var elemClass: Class = null; + private var elemTag: String = null; def apply(index: Int): Object = synchronized { if (unboxed == null) boxed(index); - else if (elemClass == java.lang.Integer.TYPE) + else if (elemTag == ScalaRunTime.IntTag) BoxedInt.box(unboxed.asInstanceOf[Array[Int]](index)) - else if (elemClass == java.lang.Double.TYPE) + else if (elemTag == ScalaRunRime.DoubleTag) BoxedDouble.box(unboxed.asInstanceOf[Array[Double]](index)) - else if (elemClass == java.lang.Float.TYPE) + else if (elemTag == ScalaRunRime.FloatTag) BoxedFloat.box(unboxed.asInstanceOf[Array[Float]](index)) - else if (elemClass == java.lang.Long.TYPE) + else if (elemTag == ScalaRunRime.LongTag) BoxedLong.box(unboxed.asInstanceOf[Array[Long]](index)) - else if (elemClass == java.lang.Character.TYPE) + else if (elemTag == ScalaRunRime.CharTag) BoxedChar.box(unboxed.asInstanceOf[Array[Char]](index)) - else if (elemClass == java.lang.Byte.TYPE) + else if (elemTag == ScalaRunRime.ByteTag) BoxedByte.box(unboxed.asInstanceOf[Array[Byte]](index)) - else if (elemClass == java.lang.Short.TYPE) + else if (elemTag == ScalaRunRime.ShortTag) BoxedShort.box(unboxed.asInstanceOf[Array[Short]](index)) - else if (elemClass == java.lang.Boolean.TYPE) + else if (elemTag == ScalaRunRime.BooleanTag) BoxedBoolean.box(unboxed.asInstanceOf[Array[Boolean]](index)) else unboxed.asInstanceOf[Array[Object]](index) @@ -42,30 +42,30 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray { def update(index: Int, elem: Object): Unit = synchronized { if (unboxed == null) boxed(index) = elem; - else if (elemClass == java.lang.Integer.TYPE) + else if (elemTag == ScalaRunRime.IntTag) unboxed.asInstanceOf[Array[Int]](index) = elem.asInstanceOf[BoxedNumber].intValue() - else if (elemClass == java.lang.Double.TYPE) + else if (elemTag == ScalaRunRime.DoubleTag) unboxed.asInstanceOf[Array[Double]](index) = elem.asInstanceOf[BoxedNumber].doubleValue() - else if (elemClass == java.lang.Float.TYPE) + else if (elemTag == ScalaRunRime.FloatTag) unboxed.asInstanceOf[Array[Float]](index) = elem.asInstanceOf[BoxedNumber].floatValue() - else if (elemClass == java.lang.Long.TYPE) + else if (elemTag == ScalaRunRime.LongTag) unboxed.asInstanceOf[Array[Long]](index) = elem.asInstanceOf[BoxedNumber].longValue() - else if (elemClass == java.lang.Character.TYPE) + else if (elemTag == ScalaRunRime.CharTag) unboxed.asInstanceOf[Array[Char]](index) = elem.asInstanceOf[BoxedNumber].charValue() - else if (elemClass == java.lang.Byte.TYPE) + else if (elemTag == ScalaRunRime.ByteTag) unboxed.asInstanceOf[Array[Byte]](index) = elem.asInstanceOf[BoxedNumber].byteValue() - else if (elemClass == java.lang.Short.TYPE) + else if (elemTag == ScalaRunRime.ShortTag) unboxed.asInstanceOf[Array[Short]](index) = elem.asInstanceOf[BoxedNumber].shortValue() - else if (elemClass == java.lang.Boolean.TYPE) + else if (elemTag == ScalaRunRime.BooleanTag) unboxed.asInstanceOf[Array[Boolean]](index) = elem.asInstanceOf[BoxedBoolean].value else unboxed.asInstanceOf[Array[Object]](index) = elem } - def unbox(elemClass: Class): Object = synchronized { + def unbox(elemTag: String): Object = synchronized { if (unboxed == null) { - this.elemClass = elemClass; - if (elemClass == java.lang.Integer.TYPE) { + this.elemTag = elemTag; + if (elemTag == ScalaRunRime.IntTag) { val newvalue = new Array[Int](length); var i = 0; while (i < length) { @@ -73,7 +73,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray { i = i + 1 } unboxed = newvalue; - } else if (elemClass == java.lang.Double.TYPE) { + } else if (elemTag == ScalaRunRime.DoubleTag) { val newvalue = new Array[Double](length); var i = 0; while (i < length) { @@ -81,7 +81,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray { i = i + 1 } unboxed = newvalue; - } else if (elemClass == java.lang.Float.TYPE) { + } else if (elemTag == ScalaRunRime.FloatTag) { val newvalue = new Array[Float](length); var i = 0; while (i < length) { @@ -89,7 +89,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray { i = i + 1 } unboxed = newvalue; - } else if (elemClass == java.lang.Long.TYPE) { + } else if (elemTag == ScalaRunRime.LongTag) { val newvalue = new Array[Long](length); var i = 0; while (i < length) { @@ -97,7 +97,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray { i = i + 1 } unboxed = newvalue; - } else if (elemClass == java.lang.Character.TYPE) { + } else if (elemTag == ScalaRunRime.CharTag) { val newvalue = new Array[Char](length); var i = 0; while (i < length) { @@ -105,7 +105,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray { i = i + 1 } unboxed = newvalue; - } else if (elemClass == java.lang.Byte.TYPE) { + } else if (elemTag == ScalaRunRime.ByteTag) { val newvalue = new Array[Byte](length); var i = 0; while (i < length) { @@ -113,7 +113,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray { i = i + 1 } unboxed = newvalue; - } else if (elemClass == java.lang.Short.TYPE) { + } else if (elemTag == ScalaRunRime.ShortTag) { val newvalue = new Array[Short](length); var i = 0; while (i < length) { @@ -121,7 +121,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray { i = i + 1 } unboxed = newvalue; - } else if (elemClass == java.lang.Boolean.TYPE) { + } else if (elemTag == ScalaRunRime.BooleanTag) { val newvalue = new Array[Boolean](length); var i = 0; while (i < length) { @@ -129,10 +129,10 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray { i = i + 1 } unboxed = newvalue; - } else if (elemClass == boxed.getClass().getComponentType()) { + } else if (elemTag == boxed.getClass().getComponentType()) { unboxed = boxed; } else { - unboxed = java.lang.reflect.Array.newInstance(elemClass, length); + unboxed = java.lang.reflect.Array.newInstance(Class.forName(elemTag), length); System.arraycopy(boxed, 0, unboxed, 0, length); } boxed = null diff --git a/sources/scala/runtime/BoxedArray.scala b/sources/scala/runtime/BoxedArray.scala index d3376e9a15..08a5220a32 100755 --- a/sources/scala/runtime/BoxedArray.scala +++ b/sources/scala/runtime/BoxedArray.scala @@ -10,10 +10,20 @@ package scala.runtime; /** A class representing Array[T] */ abstract class BoxedArray() extends PartialFunction[Int, Object] with Seq[Object] { + /** The length of the array */ def length: Int; + + /** The element at given index */ def apply(index: Int): Object; + + /** Update element at given index */ def update(index: Int, elem: Object): Unit; - def unbox(elemClass: Class): Object; + + /** Convert to Java array. + * @param elemTag Either one of the tags ".N" where N is the name of a primitive type + * (@see ScalaRunTime), or a full class name. + */ + def unbox(elemTag: String): Object; override def isDefinedAt(x: Int): Boolean = 0 <= x && x < length; diff --git a/sources/scala/runtime/BoxedBooleanArray.scala b/sources/scala/runtime/BoxedBooleanArray.scala index c4804ce6ac..7ebc328fbb 100755 --- a/sources/scala/runtime/BoxedBooleanArray.scala +++ b/sources/scala/runtime/BoxedBooleanArray.scala @@ -17,7 +17,7 @@ final class BoxedBooleanArray(val value: Array[Boolean]) extends BoxedArray { value(index) = elem.asInstanceOf[BoxedBoolean].value } - def unbox(elemClass: Class): Object = value; + def unbox(elemTag: String): Object = value; override def equals(other: Any) = value == other || diff --git a/sources/scala/runtime/BoxedByteArray.scala b/sources/scala/runtime/BoxedByteArray.scala index ea96c7600d..34b4f919b0 100755 --- a/sources/scala/runtime/BoxedByteArray.scala +++ b/sources/scala/runtime/BoxedByteArray.scala @@ -17,7 +17,7 @@ final class BoxedByteArray(val value: Array[Byte]) extends BoxedArray { value(index) = elem.asInstanceOf[BoxedNumber].byteValue() } - def unbox(elemClass: Class): Object = value; + def unbox(elemTag: String): Object = value; override def equals(other: Any) = value == other || diff --git a/sources/scala/runtime/BoxedCharArray.scala b/sources/scala/runtime/BoxedCharArray.scala index c91efbd38e..2a09ca43d3 100755 --- a/sources/scala/runtime/BoxedCharArray.scala +++ b/sources/scala/runtime/BoxedCharArray.scala @@ -17,7 +17,7 @@ final class BoxedCharArray(val value: Array[Char]) extends BoxedArray { value(index) = elem.asInstanceOf[BoxedNumber].charValue() } - def unbox(elemClass: Class): Object = value; + def unbox(elemTag: String): Object = value; override def equals(other: Any) = value == other || diff --git a/sources/scala/runtime/BoxedDoubleArray.scala b/sources/scala/runtime/BoxedDoubleArray.scala index e93a47c42d..d55ffc3d5a 100755 --- a/sources/scala/runtime/BoxedDoubleArray.scala +++ b/sources/scala/runtime/BoxedDoubleArray.scala @@ -17,7 +17,7 @@ final class BoxedDoubleArray(val value: Array[Double]) extends BoxedArray { value(index) = elem.asInstanceOf[BoxedNumber].doubleValue() } - def unbox(elemClass: Class): Object = value; + def unbox(elemTag: String): Object = value; override def equals(other: Any) = value == other || diff --git a/sources/scala/runtime/BoxedFloatArray.scala b/sources/scala/runtime/BoxedFloatArray.scala index 2ca4f2e54d..95ef72a799 100755 --- a/sources/scala/runtime/BoxedFloatArray.scala +++ b/sources/scala/runtime/BoxedFloatArray.scala @@ -17,7 +17,7 @@ final class BoxedFloatArray(val value: Array[Float]) extends BoxedArray { value(index) = elem.asInstanceOf[BoxedNumber].floatValue() } - def unbox(elemClass: Class): Object = value; + def unbox(elemTag: String): Object = value; override def equals(other: Any) = value == other || diff --git a/sources/scala/runtime/BoxedIntArray.scala b/sources/scala/runtime/BoxedIntArray.scala index bf46e33846..fcb6598839 100755 --- a/sources/scala/runtime/BoxedIntArray.scala +++ b/sources/scala/runtime/BoxedIntArray.scala @@ -17,7 +17,7 @@ final class BoxedIntArray(val value: Array[Int]) extends BoxedArray { value(index) = elem.asInstanceOf[BoxedNumber].intValue() } - def unbox(elemClass: Class): Object = value; + def unbox(elemTag: String): Object = value; override def equals(other: Any) = value == other || diff --git a/sources/scala/runtime/BoxedLongArray.scala b/sources/scala/runtime/BoxedLongArray.scala index 23506a4783..20f4de6183 100755 --- a/sources/scala/runtime/BoxedLongArray.scala +++ b/sources/scala/runtime/BoxedLongArray.scala @@ -17,7 +17,7 @@ final class BoxedLongArray(val value: Array[Long]) extends BoxedArray { value(index) = elem.asInstanceOf[BoxedNumber].longValue() } - def unbox(elemClass: Class): Object = value; + def unbox(elemTag: String): Object = value; override def equals(other: Any) = value == other || diff --git a/sources/scala/runtime/BoxedObjectArray.scala b/sources/scala/runtime/BoxedObjectArray.scala index 747888afaf..65efbde4ab 100755 --- a/sources/scala/runtime/BoxedObjectArray.scala +++ b/sources/scala/runtime/BoxedObjectArray.scala @@ -15,7 +15,7 @@ final class BoxedObjectArray(val value: Array[Object]) extends BoxedArray { def update(index: Int, elem: Object): Unit = { value(index) = elem } - def unbox(elemClass: Class): Object = value; + def unbox(elemTag: String): Object = value; override def equals(other: Any): Boolean = value == other || diff --git a/sources/scala/runtime/BoxedShortArray.scala b/sources/scala/runtime/BoxedShortArray.scala index 464b238ed3..d25505610e 100755 --- a/sources/scala/runtime/BoxedShortArray.scala +++ b/sources/scala/runtime/BoxedShortArray.scala @@ -17,7 +17,7 @@ final class BoxedShortArray(val value: Array[Short]) extends BoxedArray { value(index) = elem.asInstanceOf[BoxedNumber].shortValue() } - def unbox(elemClass: Class): Object = value; + def unbox(elemTag: String): Object = value; override def equals(other: Any) = value == other || diff --git a/sources/scala/runtime/ScalaRunTime.scala b/sources/scala/runtime/ScalaRunTime.scala index 9dc7649269..f4ac7a18cb 100644 --- a/sources/scala/runtime/ScalaRunTime.scala +++ b/sources/scala/runtime/ScalaRunTime.scala @@ -10,8 +10,19 @@ package scala.runtime; + object ScalaRunTime { + /** Names for primitive typesm, used by array unboxing */ + val ByteTag = ".Byte"; + val ShortTag = ".Short"; + val CharTag = ".Char"; + val IntTag = ".Int"; + val LongTag = ".Long"; + val FloatTag = ".Float"; + val DoubleTag = ".Double"; + val BooleanTag = ".Boolean"; + import compat.Platform.getClass; trait Try[a] { diff --git a/sources/scala/tools/nsc/Global.scala b/sources/scala/tools/nsc/Global.scala index 154a1ab84b..2b74fa67dd 100755 --- a/sources/scala/tools/nsc/Global.scala +++ b/sources/scala/tools/nsc/Global.scala @@ -176,7 +176,6 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable } val tailCallPhase = new tailCalls.Phase(uncurryPhase); - object transmatcher extends TransMatcher { val global: Global.this.type = Global.this; diff --git a/sources/scala/tools/nsc/matching/DetWordAutoms.scala b/sources/scala/tools/nsc/matching/DetWordAutoms.scala index 7870458a44..b250877d87 100644 --- a/sources/scala/tools/nsc/matching/DetWordAutoms.scala +++ b/sources/scala/tools/nsc/matching/DetWordAutoms.scala @@ -10,7 +10,7 @@ import java.util._ ; trait DetWordAutoms: TransMatcher { import global._; -class DetWordAutom { +class DetWordAutom { /** determinization -- standard algorithm considering only * reachable states @@ -150,7 +150,7 @@ class DetWordAutom { // TEMPORARY VAR used only during determinization and debug printing // Q -> (Label -> Q ) - var delta: HashMap = _; + var deltaMap: HashMap = _; // Q -> Integer; var indexMap: HashMap = _; @@ -183,7 +183,7 @@ class DetWordAutom { this._labels = nfa.labels; ////System.out.println("Labels: "+labels); - this.delta = new HashMap(); + this.deltaMap = new HashMap(); //this.dead = -1; states = new TreeSet( new StateSetComparator() ); @@ -222,7 +222,7 @@ class DetWordAutom { invIndexMap.put( new Integer( ix ), P1 ); indexMap.put( P1, new Integer( ix )); ix = ix + 1; - delta.put( P1, {trans = new HashMap(); trans}); + deltaMap.put( P1, {trans = new HashMap(); trans}); //Console.println("...beginning 4" ); // labelled transitions @@ -310,7 +310,7 @@ class DetWordAutom { ////System.out.print(state.toString() + " --> " + state_x); //System.out.println(" deftarget " + defTarget + " --> "+defTarget_x); - trans = delta.get( state ).asInstanceOf[HashMap]; + trans = deltaMap.get( state ).asInstanceOf[HashMap]; val newTrans = new HashMap(); val labs = _labels.iterator(); while(labs.hasNext()) { @@ -333,7 +333,7 @@ class DetWordAutom { _deltaq( state_x.intValue() ) = newTrans; _defaultq( state_x.intValue() ) = defTarget_x; - delta.remove( state ); + deltaMap.remove( state ); deftrans.remove( state ); } @@ -866,7 +866,7 @@ class DetWordAutom { while (it.hasNext()) { val state = it.next().asInstanceOf[TreeSet]; Console.print("state:" + state.toString() + " transitions "); - trans = delta.get( state ).asInstanceOf[HashMap]; + trans = deltaMap.get( state ).asInstanceOf[HashMap]; val labs = _labels.iterator(); while(labs.hasNext()) { val label = labs.next(); diff --git a/sources/scala/tools/nsc/matching/PatternMatchers.scala b/sources/scala/tools/nsc/matching/PatternMatchers.scala index 33e28627d4..aac86f1fe5 100644 --- a/sources/scala/tools/nsc/matching/PatternMatchers.scala +++ b/sources/scala/tools/nsc/matching/PatternMatchers.scala @@ -8,7 +8,7 @@ package scala.tools.nsc.matching ; import scala.tools.util.Position; -trait PatternMatchers: (TransMatcher with PatternNodes) with PatternNodeCreator { +trait PatternMatchers: (TransMatcher with PatternNodes) extends AnyRef with PatternNodeCreator { import global._; diff --git a/sources/scala/tools/nsc/symtab/Definitions.scala b/sources/scala/tools/nsc/symtab/Definitions.scala index f12bc799f5..f82a74dba1 100755 --- a/sources/scala/tools/nsc/symtab/Definitions.scala +++ b/sources/scala/tools/nsc/symtab/Definitions.scala @@ -145,6 +145,7 @@ abstract class Definitions: SymbolTable { // boxed classes var BoxedArrayClass: Symbol = _; + var BoxedObjectArrayClass: Symbol = _; var BoxedUnitClass: Symbol = _; def getModule(fullname: Name): Symbol = @@ -318,6 +319,7 @@ abstract class Definitions: SymbolTable { PatternWildcard = NoSymbol.newValue(Position.NOPOS, "_").setInfo(AllClass.typeConstructor); BoxedArrayClass = getClass("scala.runtime.BoxedArray"); + BoxedObjectArrayClass = getClass("scala.runtime.BoxedObjectArray"); BoxedUnitClass = getClass("scala.runtime.BoxedUnit"); } } diff --git a/sources/scala/tools/nsc/symtab/Types.scala b/sources/scala/tools/nsc/symtab/Types.scala index d5cf7102d6..69b49890ef 100755 --- a/sources/scala/tools/nsc/symtab/Types.scala +++ b/sources/scala/tools/nsc/symtab/Types.scala @@ -840,11 +840,8 @@ abstract class Types: SymbolTable { /** A creator for type applications */ def appliedType(tycon: Type, args: List[Type]): Type = tycon match { case TypeRef(pre, sym, _) => typeRef(pre, sym, args) - case _ => - tycon match { - case PolyType(tparams, restpe) => restpe.subst(tparams, args) - case ErrorType => tycon - } + case PolyType(tparams, restpe) => restpe.subst(tparams, args) + case ErrorType => tycon } // Helper Classes --------------------------------------------------------- diff --git a/sources/scala/tools/nsc/transform/UnCurry.scala b/sources/scala/tools/nsc/transform/UnCurry.scala index db819a799f..8392454607 100755 --- a/sources/scala/tools/nsc/transform/UnCurry.scala +++ b/sources/scala/tools/nsc/transform/UnCurry.scala @@ -91,12 +91,7 @@ abstract class UnCurry extends InfoTransform { formals.last match { case TypeRef(pre, sym, List(elempt)) if (sym == RepeatedParamClass) => def mkSequence(args: List[Tree]) = - if(inPattern) /* buraq adds TEMPORARILY */ - atPos(pos)(Sequence(args) setType formals.last); /* eventually */ - else /* recognize ArrayValue*/ - atPos(pos)( - ArrayValue(TypeTree(elempt), args) setType formals.last); - + atPos(pos)(ArrayValue(TypeTree(elempt), args) setType formals.last); if (args.isEmpty) List(mkSequence(args)) else { val suffix = args.last match { diff --git a/sources/scala/tools/nsc/typechecker/Typers.scala b/sources/scala/tools/nsc/typechecker/Typers.scala index f8bb0a40bb..0034f08679 100755 --- a/sources/scala/tools/nsc/typechecker/Typers.scala +++ b/sources/scala/tools/nsc/typechecker/Typers.scala @@ -459,6 +459,7 @@ abstract class Typers: Analyzer { val getter: DefDef = { val sym = vdef.symbol; val getter = sym.owner.info.decls.lookup(name).suchThat(.hasFlag(ACCESSOR)); + assert(getter != NoSymbol, vdef); val result = atPos(vdef.pos)( DefDef(getter, vparamss => if ((mods & DEFERRED) != 0) EmptyTree else typed(gen.mkRef(sym), EXPRmode, sym.tpe))); @@ -1012,7 +1013,7 @@ abstract class Typers: Analyzer { val elems1 = List.mapConserve(elems)(elem => typed(elem, mode, elemtpt1.tpe)); copy.ArrayValue(tree, elemtpt1, elems1) setType (if (isFullyDefined(pt)) pt - else appliedType(ArrayClass.tpe, List(elemtpt1.tpe))) + else appliedType(ArrayClass.typeConstructor, List(elemtpt1.tpe))) case fun @ Function(_, _) => newTyper(context.makeNewScope(tree, context.owner)).typedFunction(fun, mode, pt) |