diff options
author | Paul Phillips <paulp@improving.org> | 2009-09-22 06:24:34 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-09-22 06:24:34 +0000 |
commit | efc9abd507efc4a1847459a3523dbd95d1e0acb3 (patch) | |
tree | 965a24814c8546972cddf718988e7ab41cce1cb4 | |
parent | d094b4ac4dfc3822129562921d801a2ae7616605 (diff) | |
download | scala-efc9abd507efc4a1847459a3523dbd95d1e0acb3.tar.gz scala-efc9abd507efc4a1847459a3523dbd95d1e0acb3.tar.bz2 scala-efc9abd507efc4a1847459a3523dbd95d1e0acb3.zip |
Attempting to widen the field of possibilities ...
Attempting to widen the field of possibilities for equality, a proof
by construction that a large codebase doesn't need to perform equality
checks between different primitives types if it is not so inclined.
31 files changed, 243 insertions, 148 deletions
diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala index 3467b65738..92111d6bf8 100644 --- a/src/actors/scala/actors/Actor.scala +++ b/src/actors/scala/actors/Actor.scala @@ -511,7 +511,7 @@ trait Actor extends AbstractActor with ReplyReactor with ReplyableActor { drainSendBuffer(mailbox) // keep going () => {} - } else if (msec == 0) { + } else if (msec == 0L) { done = true receiveTimeout } else { @@ -601,7 +601,7 @@ trait Actor extends AbstractActor with ReplyReactor with ReplyableActor { drainSendBuffer(mailbox) // keep going () => {} - } else if (msec == 0) { + } else if (msec == 0L) { done = true receiveTimeout } else { diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index be358d28cc..f9c12ce10a 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -105,7 +105,10 @@ class Settings(errorFn: String => Unit) extends ScalacSettings { ): Option[List[String]] = lookupSetting(cmd) match { case None => errorFn("Parameter '" + cmd + "' is not recognised by Scalac.") ; None - case Some(cmd) => setter(cmd)(args) + case Some(cmd) => + val res = setter(cmd)(args) + cmd.postSetHook() + res } // if arg is of form -Xfoo:bar,baz,quux @@ -358,6 +361,12 @@ object Settings { def errorFn(msg: String) = _errorFn(msg) def errorAndValue[T](msg: String, x: T): T = { errorFn(msg) ; x } + /** Will be called after this Setting is set, for any cases where the + * Setting wants to perform extra work. */ + private var _postSetHook: () => Unit = () => () + def postSetHook(): Unit = _postSetHook() + def withPostSetHook(f: () => Unit): this.type = { _postSetHook = f ; this } + /** After correct Setting has been selected, tryToSet is called with the * remainder of the command line. It consumes any applicable arguments and * returns the unconsumed ones. @@ -807,6 +816,8 @@ trait ScalacSettings { withHelpSyntax("-Ysqueeze:<enabled>") val Ystatistics = BooleanSetting ("-Ystatistics", "Print compiler statistics") val stop = PhasesSetting ("-Ystop", "Stop after phase") + val logEquality = BooleanSetting ("-Ylog-equality", "Log all noteworthy equality tests (hardcoded to /tmp/scala-equality-log.txt)") . + withPostSetHook(() => scala.runtime.BoxesRunTime.setEqEqLogging(true)) val refinementMethodDispatch = ChoiceSetting ("-Ystruct-dispatch", "Selects dispatch method for structural refinement method calls", List("no-cache", "mono-cache", "poly-cache", "invoke-dynamic"), "poly-cache") . diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 9d5cf7125b..945df94e91 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -69,7 +69,7 @@ trait Trees { def isTrait = hasFlag(TRAIT | notDEFERRED) // (part of DEVIRTUALIZE) def isImplicit = hasFlag(IMPLICIT ) def isPublic = !isPrivate && !isProtected - def hasFlag(flag: Long) = (flag & flags) != 0 + def hasFlag(flag: Long) = (flag & flags) != 0L def & (flag: Long): Modifiers = { val flags1 = flags & flag if (flags1 == flags) this @@ -334,7 +334,7 @@ trait Trees { case ValDef(mods, _, _, _) => if (mods.isVariable) "var" else "val" case _ => "" } - final def hasFlag(mask: Long): Boolean = (mods.flags & mask) != 0 + final def hasFlag(mask: Long): Boolean = (mods.flags & mask) != 0L } /** Package clause @@ -624,7 +624,7 @@ trait Trees { } else { // convert (implicit ... ) to ()(implicit ... ) if its the only parameter section if (vparamss1.isEmpty || - !vparamss1.head.isEmpty && (vparamss1.head.head.mods.flags & IMPLICIT) != 0) + !vparamss1.head.isEmpty && (vparamss1.head.head.mods.flags & IMPLICIT) != 0L) vparamss1 = List() :: vparamss1; val superRef: Tree = atPos(superPos) { Select(Super(nme.EMPTY.toTypeName, nme.EMPTY.toTypeName), nme.CONSTRUCTOR) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 63ec09e8cf..80b22dd28f 100755 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -854,7 +854,7 @@ trait Scanners { def isSpecial(c: Char) = { val chtp = Character.getType(c) - chtp == Character.MATH_SYMBOL || chtp == Character.OTHER_SYMBOL + chtp == Character.MATH_SYMBOL.toInt || chtp == Character.OTHER_SYMBOL.toInt } def isOperatorPart(c : Char) : Boolean = (c: @switch) match { diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index d7b6c16041..5919351614 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -1349,6 +1349,36 @@ abstract class GenICode extends SubComponent { ctx1.bb.close } + /** Log equality tests to file if they are playing with typefire */ + def logEqEq(l: Tree, r: Tree, op: String) { + def mayBeNumericComparison: Boolean = { + def isPossiblyBoxed(sym: Symbol): Boolean = { + import definitions._ + + // good enough for now + (sym == ObjectClass) || + (sym isNonBottomSubClass BoxedNumberClass) || + (sym isNonBottomSubClass BoxedCharacterClass) + } + + val lsym = l.tpe.typeSymbol + val rsym = r.tpe.typeSymbol + + (lsym != rsym) && (isPossiblyBoxed(lsym) && isPossiblyBoxed(rsym)) + } + + val tkl = toTypeKind(l.tpe) + val tkr = toTypeKind(r.tpe) + lazy val whereAreWe = tree.pos.source + ":" + tree.pos.line + def logit(preface: String) = + runtime.BoxesRunTime.log("[%s] %s %s %s (%s)".format(preface, l.tpe, op, r.tpe, whereAreWe)) + + if (tkl.isNumericType && tkr.isNumericType && tkl != tkr) + logit(" KNOWN ") + else if (mayBeNumericComparison) + logit("UNKNOWN") + } + if (settings.debug.value) log("Entering genCond with tree: " + tree); @@ -1363,6 +1393,9 @@ abstract class GenICode extends SubComponent { } else if ((code == scalaPrimitives.EQ || code == scalaPrimitives.NE)) { val Select(leftArg, _) = fun; + if (settings.logEquality.value) + logEqEq(leftArg, args.head, (if (code == scalaPrimitives.EQ) "==" else "!=")) + if (toTypeKind(leftArg.tpe).isReferenceType) { if (code == scalaPrimitives.EQ) genEqEqPrimitive(leftArg, args.head, ctx, thenCtx, elseCtx) @@ -1393,9 +1426,6 @@ abstract class GenICode extends SubComponent { genCond(args.head, ctxInterm, thenCtx, elseCtx) case _ => - // TODO (maybe): deal with the equals case here - // Current semantics: rich equals (from runtime.Comparator) only when == is used - // See genEqEqPrimitive for implementation var ctx1 = genLoad(tree, ctx, BOOL) ctx1.bb.emit(CZJUMP(thenCtx.bb, elseCtx.bb, NE, BOOL), tree.pos) ctx1.bb.close @@ -1510,9 +1540,7 @@ abstract class GenICode extends SubComponent { nonNullCtx.bb.emit(CZJUMP(thenCtx.bb, elseCtx.bb, NE, BOOL)) nonNullCtx.bb.close } - } - } /** diff --git a/src/compiler/scala/tools/nsc/dependencies/Changes.scala b/src/compiler/scala/tools/nsc/dependencies/Changes.scala index 6ebf6f8fa6..5dabe45c10 100644 --- a/src/compiler/scala/tools/nsc/dependencies/Changes.scala +++ b/src/compiler/scala/tools/nsc/dependencies/Changes.scala @@ -20,9 +20,8 @@ abstract class Changes { /** Are the new modifiers more restrictive than the old ones? */ private def moreRestrictive(from: Long, to: Long): Boolean = - ((((to & PRIVATE) != 0) && (from & PRIVATE) == 0) - || (((to & PROTECTED) != 0) && (from & PROTECTED) == 0)) - + ((((to & PRIVATE) != 0L) && (from & PRIVATE) == 0L) + || (((to & PROTECTED) != 0L) && (from & PROTECTED) == 0L)) /** An entity in source code, either a class or a member definition. * Name is fully-qualified. diff --git a/src/compiler/scala/tools/nsc/io/ZipArchive.scala b/src/compiler/scala/tools/nsc/io/ZipArchive.scala index a3c3c85a15..9f7e02ab6c 100644 --- a/src/compiler/scala/tools/nsc/io/ZipArchive.scala +++ b/src/compiler/scala/tools/nsc/io/ZipArchive.scala @@ -299,8 +299,9 @@ final class URLZipArchive(url: URL) extends AbstractFile with ZipContainer /** Private methods **/ private def byteInputStream(in: InputStream): InputStream = { + val minusOne = (-1).toByte val buf = new BufferedInputStream(in) - val bytes = Iterator continually in.read().toByte takeWhile (_ != -1) + val bytes = Iterator continually in.read().toByte takeWhile (_ != minusOne) new ByteArrayInputStream(bytes.toSequence.toArray) } } diff --git a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala index 50c166c38e..c1bedd8d95 100755 --- a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala @@ -700,7 +700,7 @@ trait JavaScanners { def isSpecial(c: Char) = { val chtp = Character.getType(c) - chtp == Character.MATH_SYMBOL || chtp == Character.OTHER_SYMBOL + chtp == Character.MATH_SYMBOL.toInt || chtp == Character.OTHER_SYMBOL.toInt } private def getIdentRest { diff --git a/src/compiler/scala/tools/nsc/symtab/Flags.scala b/src/compiler/scala/tools/nsc/symtab/Flags.scala index 270c5820fe..dabdd32e69 100644 --- a/src/compiler/scala/tools/nsc/symtab/Flags.scala +++ b/src/compiler/scala/tools/nsc/symtab/Flags.scala @@ -192,7 +192,7 @@ object Flags { var mask=m var i=0 while (i <= 62) { - if ((mask&1) == 1) return i + if ((mask&1) == 1L) return i mask >>= 1 i += 1 } @@ -255,16 +255,16 @@ object Flags { var f = flags val pw = if (privateWithin == "") { - if ((flags & (PRIVATE | LOCAL)) == (PRIVATE | LOCAL)) { + if ((flags & (PRIVATE | LOCAL)) == (PRIVATE | LOCAL).toLong) { f = f & ~(PRIVATE | LOCAL) "private[this]" - } else if ((flags & (PROTECTED | LOCAL)) == (PROTECTED | LOCAL)) { + } else if ((flags & (PROTECTED | LOCAL)) == (PROTECTED | LOCAL).toLong) { f = f & ~(PROTECTED | LOCAL) "protected[this]" } else { "" } - } else if ((f & PROTECTED) != 0) { + } else if ((f & PROTECTED) != 0L) { f = f & ~PROTECTED "protected[" + privateWithin + "]" } else { @@ -327,9 +327,9 @@ object Flags { } class Flag(mods: Long) { - def isPrivate = (mods & PRIVATE ) != 0 - def isProtected = (mods & PROTECTED) != 0 - def isVariable = (mods & MUTABLE) != 0 + def isPrivate = (mods & PRIVATE ) != 0L + def isProtected = (mods & PROTECTED) != 0L + def isVariable = (mods & MUTABLE) != 0L def isPublic = !isPrivate && !isProtected } } diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala index 94fc787e76..fa7f088ef2 100644 --- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala +++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala @@ -113,7 +113,7 @@ trait StdNames { '|' | '\\'| '/' => true case _ => val chtp = Character.getType(c) - chtp == Character.MATH_SYMBOL || chtp == Character.OTHER_SYMBOL + chtp == Character.MATH_SYMBOL.toInt || chtp == Character.OTHER_SYMBOL.toInt } /** If `name' is an expandedName name, the original name. diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 5f9a2b6bd3..e10ddb26d6 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -306,7 +306,7 @@ trait Symbols { // True if the symbol is locked but still below the allowed recursion depth. // False otherwise def lockOK: Boolean = { - ((rawflags & LOCKED) == 0) || + ((rawflags & LOCKED) == 0L) || ((settings.Yrecursion.value != 0) && (recursionTable get this match { case Some(n) => (n <= settings.Yrecursion.value) @@ -315,7 +315,7 @@ trait Symbols { // Lock a symbol, using the handler if the recursion depth becomes too great. def lock(handler: => Unit) = { - if ((rawflags & LOCKED) != 0) { + if ((rawflags & LOCKED) != 0L) { if (settings.Yrecursion.value != 0) { recursionTable get this match { case Some(n) => @@ -336,7 +336,7 @@ trait Symbols { // Unlock a symbol def unlock() = { - if ((rawflags & LOCKED) != 0) { + if ((rawflags & LOCKED) != 0L) { activeLocks -= 1 rawflags = rawflags & ~LOCKED if (settings.Yrecursion.value != 0) @@ -373,7 +373,7 @@ trait Symbols { final def isValueParameter = isTerm && hasFlag(PARAM) final def isLocalDummy = isTerm && nme.isLocalDummyName(name) final def isMethod = isTerm && hasFlag(METHOD) - final def isSourceMethod = isTerm && (flags & (METHOD | STABLE)) == METHOD // ??? + final def isSourceMethod = isTerm && (flags & (METHOD | STABLE)) == METHOD.toLong // ??? final def isLabel = isMethod && !hasFlag(ACCESSOR) && hasFlag(LABEL) final def isInitializedToDefault = !isType && (getFlag(DEFAULTINIT | ACCESSOR) == (DEFAULTINIT | ACCESSOR)) final def isClassConstructor = isTerm && (name == nme.CONSTRUCTOR) @@ -673,7 +673,7 @@ trait Symbols { final def setFlag(mask: Long): this.type = { rawflags = rawflags | mask; this } final def resetFlag(mask: Long): this.type = { rawflags = rawflags & ~mask; this } final def getFlag(mask: Long): Long = flags & mask - final def hasFlag(mask: Long): Boolean = (flags & mask) != 0 + final def hasFlag(mask: Long): Boolean = (flags & mask) != 0L final def resetFlags { rawflags = rawflags & TopLevelCreationFlags } /** The class or term up to which this symbol is accessible, @@ -1777,7 +1777,7 @@ trait Symbols { else rawowner override def name: Name = - if ((rawflags & notDEFERRED) != 0 && phase.devirtualized && !phase.erasedTypes) { + if ((rawflags & notDEFERRED) != 0L && phase.devirtualized && !phase.erasedTypes) { newTypeName(rawname+"$trait") // (part of DEVIRTUALIZE) } else if (phase.flatClasses && rawowner != NoSymbol && !rawowner.isPackageClass) { if (flatname == nme.EMPTY) { @@ -1806,7 +1806,7 @@ trait Symbols { /** the self type of an object foo is foo.type, not class<foo>.this.type */ override def typeOfThis: Type = - if (getFlag(MODULE | IMPLCLASS) == MODULE && owner != NoSymbol) + if (getFlag(MODULE | IMPLCLASS) == MODULE.toLong && owner != NoSymbol) singleType(owner.thisType, sourceModule) else thissym.tpe diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 10723f285a..39e6a7869c 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -717,10 +717,10 @@ trait Types { val sym = entry.sym if (sym.getFlag(requiredFlags) == requiredFlags) { val excl = sym.getFlag(excluded) - if (excl == 0 && + if (excl == 0L && (// omit PRIVATE LOCALS unless selector class is contained in class owning the def. (bcs eq bcs0) || - sym.getFlag(PRIVATE | LOCAL) != (PRIVATE | LOCAL) || + sym.getFlag(PRIVATE | LOCAL) != (PRIVATE | LOCAL).toLong || (bcs0.head.hasTransOwner(bcs.head)))) { if (name.isTypeName || stableOnly && sym.isStable) { // if (util.Statistics.enabled) findMemberNanos += System.nanoTime() - startTime @@ -752,7 +752,7 @@ trait Types { members enter sym } } - } else if (excl == DEFERRED) { + } else if (excl == DEFERRED.toLong) { continue = true } } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index ab7dd877c7..6f264b3c13 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -106,8 +106,8 @@ abstract class ClassfileParser { throw new IOException("class file '" + in.file + "' " + "has wrong magic number 0x" + toHexString(magic) + ", should be 0x" + toHexString(JAVA_MAGIC)) - val minorVersion = in.nextChar - val majorVersion = in.nextChar + val minorVersion = in.nextChar.toInt + val majorVersion = in.nextChar.toInt if ((majorVersion < JAVA_MAJOR_VERSION) || ((majorVersion == JAVA_MAJOR_VERSION) && (minorVersion < JAVA_MINOR_VERSION))) @@ -151,7 +151,7 @@ abstract class ClassfileParser { var name = values(index).asInstanceOf[Name] if (name eq null) { val start = starts(index) - if (in.buf(start) != CONSTANT_UTF8) errorBadTag(start) + if (in.buf(start).toInt != CONSTANT_UTF8) errorBadTag(start) name = newTermName(in.buf, start + 3, in.getChar(start + 1)) values(index) = name } @@ -172,7 +172,7 @@ abstract class ClassfileParser { var c = values(index).asInstanceOf[Symbol] if (c eq null) { val start = starts(index) - if (in.buf(start) != CONSTANT_CLASS) errorBadTag(start) + if (in.buf(start).toInt != CONSTANT_CLASS) errorBadTag(start) val name = getExternalName(in.getChar(start + 1)) if (name.endsWith("$")) c = definitions.getModule(name.subName(0, name.length - 1)) @@ -188,7 +188,7 @@ abstract class ClassfileParser { */ def getClassName(index: Int): Name = { val start = starts(index) - if (in.buf(start) != CONSTANT_CLASS) errorBadTag(start) + if (in.buf(start).toInt != CONSTANT_CLASS) errorBadTag(start) getExternalName(in.getChar(start + 1)) } @@ -206,9 +206,10 @@ abstract class ClassfileParser { var f = values(index).asInstanceOf[Symbol] if (f eq null) { val start = starts(index) - if (in.buf(start) != CONSTANT_FIELDREF && - in.buf(start) != CONSTANT_METHODREF && - in.buf(start) != CONSTANT_INTFMETHODREF) errorBadTag(start) + val first = in.buf(start).toInt + if (first != CONSTANT_FIELDREF && + first != CONSTANT_METHODREF && + first != CONSTANT_INTFMETHODREF) errorBadTag(start) val ownerTpe = getClassOrArrayType(in.getChar(start + 1)) if (settings.debug.value) log("getMemberSymbol(static: " + static + "): owner type: " + ownerTpe + " " + ownerTpe.typeSymbol.originalName) @@ -260,11 +261,11 @@ abstract class ClassfileParser { var p = values(index).asInstanceOf[(Name, Type)] if (p eq null) { val start = starts(index) - if (in.buf(start) != CONSTANT_NAMEANDTYPE) errorBadTag(start) - val name = getName(in.getChar(start + 1)) + if (in.buf(start).toInt != CONSTANT_NAMEANDTYPE) errorBadTag(start) + val name = getName(in.getChar(start + 1).toInt) // create a dummy symbol for method types val dummySym = ownerTpe.typeSymbol.newMethod(ownerTpe.typeSymbol.pos, name) - var tpe = getType(dummySym, in.getChar(start + 3)) + var tpe = getType(dummySym, in.getChar(start + 3).toInt) // fix the return type, which is blindly set to the class currently parsed if (name == nme.CONSTRUCTOR) @@ -288,7 +289,7 @@ abstract class ClassfileParser { var c: Type = null if (value eq null) { val start = starts(index) - if (in.buf(start) != CONSTANT_CLASS) errorBadTag(start) + if (in.buf(start).toInt != CONSTANT_CLASS) errorBadTag(start) val name = getExternalName(in.getChar(start + 1)) if (name(0) == ARRAY_TAG) { c = sigToType(null, name) @@ -321,9 +322,9 @@ abstract class ClassfileParser { var value = values(index) if (value eq null) { val start = starts(index) - value = in.buf(start) match { + value = (in.buf(start).toInt: @switch) match { case CONSTANT_STRING => - Constant(getName(in.getChar(start + 1)).toString()) + Constant(getName(in.getChar(start + 1).toInt).toString()) case CONSTANT_INTEGER => Constant(in.getInt(start + 1)) case CONSTANT_FLOAT => @@ -399,7 +400,7 @@ abstract class ClassfileParser { def parseClass() { val jflags = in.nextChar - val isAnnotation = (jflags & JAVA_ACC_ANNOTATION) != 0 + val isAnnotation = hasAnnotation(jflags) var sflags = transFlags(jflags, true) var nameIdx = in.nextChar externalName = pool.getClassName(nameIdx) @@ -452,7 +453,7 @@ abstract class ClassfileParser { for (i <- 0 until methodCount) parseMethod() if (!sawPrivateConstructor && (instanceDefs.lookup(nme.CONSTRUCTOR) == NoSymbol && - (sflags & INTERFACE) == 0)) + (sflags & INTERFACE) == 0L)) { //Console.println("adding constructor to " + clazz);//DEBUG instanceDefs.enter( @@ -480,8 +481,8 @@ abstract class ClassfileParser { def parseField() { val jflags = in.nextChar var sflags = transFlags(jflags, false) - if ((sflags & FINAL) == 0) sflags = sflags | MUTABLE - if ((sflags & PRIVATE) != 0 && !global.settings.XO.value) { + if ((sflags & FINAL) == 0L) sflags = sflags | MUTABLE + if ((sflags & PRIVATE) != 0L && !global.settings.XO.value) { in.skip(4); skipAttributes() } else { val name = pool.getName(in.nextChar) @@ -496,9 +497,9 @@ abstract class ClassfileParser { } def parseMethod() { - val jflags = in.nextChar + val jflags = in.nextChar.toInt var sflags = transFlags(jflags, false) - if ((jflags & JAVA_ACC_PRIVATE) != 0 && !global.settings.XO.value) { + if (isPrivate(jflags) && !global.settings.XO.value) { val name = pool.getName(in.nextChar) if (name == nme.CONSTRUCTOR) sawPrivateConstructor = true @@ -506,7 +507,7 @@ abstract class ClassfileParser { } else { if ((jflags & JAVA_ACC_BRIDGE) != 0) sflags |= BRIDGE - if ((sflags & PRIVATE) != 0 && global.settings.XO.value) { + if ((sflags & PRIVATE) != 0L && global.settings.XO.value) { in.skip(4); skipAttributes() } else { val name = pool.getName(in.nextChar) @@ -517,7 +518,7 @@ abstract class ClassfileParser { case MethodType(params, restpe) => // if this is a non-static inner class, remove the explicit outer parameter val newParams = innerClasses.get(externalName) match { - case Some(entry) if !isScalaRaw && (entry.jflags & JAVA_ACC_STATIC) == 0 => + case Some(entry) if !isScalaRaw && !isStatic(entry.jflags) => assert(params.head.tpe.typeSymbol == clazz.owner, params.head.tpe.typeSymbol + ": " + clazz.owner) params.tail case _ => @@ -944,10 +945,10 @@ abstract class ClassfileParser { case nme.InnerClassesATTR if !isScala => val entries = in.nextChar.toInt for (i <- 0 until entries) { - val innerIndex = in.nextChar - val outerIndex = in.nextChar - val nameIndex = in.nextChar - val jflags = in.nextChar + val innerIndex = in.nextChar.toInt + val outerIndex = in.nextChar.toInt + val nameIndex = in.nextChar.toInt + val jflags = in.nextChar.toInt if (innerIndex != 0 && outerIndex != 0 && nameIndex != 0) { val entry = InnerClassEntry(innerIndex, outerIndex, nameIndex, jflags) innerClasses += (pool.getClassName(innerIndex) -> entry) @@ -1020,7 +1021,7 @@ abstract class ClassfileParser { get(externalName) match { case Some(entry) => - val clazz = innerSymbol(entry.externalName, entry.originalName, (entry.jflags & JAVA_ACC_STATIC) != 0) + val clazz = innerSymbol(entry.externalName, entry.originalName, isStatic(entry.jflags)) clazz case None => classNameToSymbol(externalName) @@ -1057,10 +1058,10 @@ abstract class ClassfileParser { } protected def getOwner(flags: Int): Symbol = - if ((flags & JAVA_ACC_STATIC) != 0) statics else clazz + if (isStatic(flags)) statics else clazz protected def getScope(flags: Int): Scope = - if ((flags & JAVA_ACC_STATIC) != 0) staticDefs else instanceDefs + if (isStatic(flags)) staticDefs else instanceDefs protected def transFlags(flags: Int, isClass: Boolean): Long = { var res = 0l @@ -1079,7 +1080,7 @@ abstract class ClassfileParser { res = res | SYNTHETIC if ((flags & JAVA_ACC_STATIC) != 0) res = res | STATIC - if (isClass && ((res & DEFERRED) != 0)) + if (isClass && ((res & DEFERRED) != 0L)) res = res & ~DEFERRED | ABSTRACT res | JAVA @@ -1089,4 +1090,11 @@ abstract class ClassfileParser { if ((jflags & (JAVA_ACC_PRIVATE | JAVA_ACC_PROTECTED | JAVA_ACC_PUBLIC)) == 0) sym.privateWithin = sym.toplevelClass.owner } + + @inline final private def isPrivate(flags: Int) = + (flags & JAVA_ACC_PRIVATE) != 0 + @inline final private def isStatic(flags: Int) = + (flags & JAVA_ACC_STATIC) != 0 + @inline final private def hasAnnotation(flags: Int) = + (flags & JAVA_ACC_ANNOTATION) != 0 } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala index 47ab0328f3..298a577200 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala @@ -79,7 +79,7 @@ abstract class ICodeReader extends ClassfileParser { val jflags = in.nextChar val isAttribute = (jflags & JAVA_ACC_ANNOTATION) != 0 var sflags = transFlags(jflags, true) - if ((sflags & DEFERRED) != 0) sflags = sflags & ~DEFERRED | ABSTRACT + if ((sflags & DEFERRED) != 0L) sflags = sflags & ~DEFERRED | ABSTRACT val c = pool.getClassSymbol(in.nextChar) parseInnerClasses() @@ -278,7 +278,7 @@ abstract class ICodeReader extends ClassfileParser { case JVM.fload => code.emit(LOAD_LOCAL(code.getLocal(in.nextByte, FLOAT))); size += 1 case JVM.dload => code.emit(LOAD_LOCAL(code.getLocal(in.nextByte, DOUBLE))); size += 1 case JVM.aload => - val local = in.nextByte; size += 1 + val local = in.nextByte.toInt; size += 1 if (local == 0 && !method.isStatic) code.emit(THIS(method.symbol.owner)); else diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/PickleBuffer.scala b/src/compiler/scala/tools/nsc/symtab/classfile/PickleBuffer.scala index b02ae0b4b5..76ac3d4e1f 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/PickleBuffer.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/PickleBuffer.scala @@ -55,11 +55,11 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) { def writeLongNat(x: Long) { def writeNatPrefix(x: Long) { val y = x >>> 7 - if (y != 0) writeNatPrefix(y) + if (y != 0L) writeNatPrefix(y) writeByte(((x & 0x7f) | 0x80).asInstanceOf[Int]) } val y = x >>> 7 - if (y != 0) writeNatPrefix(y) + if (y != 0L) writeNatPrefix(y) writeByte((x & 0x7f).asInstanceOf[Int]) } @@ -113,7 +113,7 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) { do { b = readByte() x = (x << 7) + (b & 0x7f) - } while ((b & 0x80) != 0); + } while ((b & 0x80) != 0L); x } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala index d5e69d20d8..fccc5d7def 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala @@ -16,6 +16,7 @@ import scala.tools.nsc.util.{Position, NoPosition} import Flags._ import PickleFormat._ import collection.mutable.{HashMap, ListBuffer} +import annotation.switch /** This abstract class implements .. * @@ -101,7 +102,7 @@ abstract class UnPickler { /** Does entry represent an (internal) symbol */ private def isSymbolEntry(i: Int): Boolean = { - val tag = bytes(index(i)) + val tag = bytes(index(i)).toInt (firstSymTag <= tag && tag <= lastSymTag && (tag != CLASSsym || !isRefinementSymbolEntry(i))) } @@ -114,19 +115,19 @@ abstract class UnPickler { /** Does entry represent a name? */ private def isNameEntry(i: Int): Boolean = { - val tag = bytes(index(i)) + val tag = bytes(index(i)).toInt tag == TERMname || tag == TYPEname } /** Does entry represent a symbol annotation? */ private def isSymbolAnnotationEntry(i: Int): Boolean = { - val tag = bytes(index(i)) + val tag = bytes(index(i)).toInt tag == SYMANNOT } /** Does the entry represent children of a symbol? */ private def isChildrenEntry(i: Int): Boolean = { - val tag = bytes(index(i)) + val tag = bytes(index(i)).toInt tag == CHILDREN } @@ -136,7 +137,7 @@ abstract class UnPickler { private def isRefinementSymbolEntry(i: Int): Boolean = { val savedIndex = readIndex readIndex = index(i) - val tag = readByte() + val tag = readByte().toInt if (tag != CLASSsym) assert(false) readNat(); // read length val result = readNameRef() == nme.REFINE_CLASS_NAME.toTypeName @@ -230,10 +231,10 @@ abstract class UnPickler { case CLASSsym => sym = if (name == classRoot.name && owner == classRoot.owner) - (if ((flags & MODULE) != 0) moduleRoot.moduleClass + (if ((flags & MODULE) != 0L) moduleRoot.moduleClass else classRoot) else - if ((flags & MODULE) != 0) owner.newModuleClass(NoPosition, name) + if ((flags & MODULE) != 0L) owner.newModuleClass(NoPosition, name) else owner.newClass(NoPosition, name) if (readIndex != end) sym.typeOfThis = new LazyTypeRef(readNat()) case MODULEsym => @@ -351,11 +352,11 @@ abstract class UnPickler { /** Read a constant */ private def readConstant(): Constant = { - val tag = readByte() + val tag = readByte().toInt val len = readNat() - tag match { + (tag: @switch) match { case LITERALunit => Constant(()) - case LITERALboolean => Constant(if (readLong(len) == 0) false else true) + case LITERALboolean => Constant(if (readLong(len) == 0L) false else true) case LITERALbyte => Constant(readLong(len).asInstanceOf[Byte]) case LITERALshort => Constant(readLong(len).asInstanceOf[Short]) case LITERALchar => Constant(readLong(len).asInstanceOf[Char]) diff --git a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala index 2eb63cd52d..cad86ea024 100644 --- a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala +++ b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala @@ -84,7 +84,7 @@ abstract class OverridingPairs { fillDecls(bcs.tail, deferredflag) var e = bcs.head.info.decls.elems; while (e ne null) { - if (e.sym.getFlag(DEFERRED) == deferredflag && !exclude(e.sym)) + if (e.sym.getFlag(DEFERRED) == deferredflag.toLong && !exclude(e.sym)) decls enter e.sym; e = e.next } diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index d7c5ed2b33..9efc9827c2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -338,7 +338,7 @@ trait Namers { self: Analyzer => case tree @ ClassDef(mods, name, tparams, impl) => tree.symbol = enterClassSymbol(tree) finishWith(tparams) - if ((mods.flags & CASE) != 0) { + if ((mods.flags & CASE) != 0L) { val m = ensureCompanionObject(tree, caseModuleDef(tree)) caseClassOfModuleClass(m.moduleClass) = tree } @@ -364,24 +364,24 @@ trait Namers { self: Analyzer => case vd @ ValDef(mods, name, tp, rhs) => if ((!context.owner.isClass || - (mods.flags & (PRIVATE | LOCAL)) == (PRIVATE | LOCAL) || + (mods.flags & (PRIVATE | LOCAL)) == (PRIVATE | LOCAL).toLong || name.endsWith(nme.OUTER, nme.OUTER.length) || context.unit.isJava) && - (mods.flags & LAZY) == 0) { + (mods.flags & LAZY) == 0L) { tree.symbol = enterInScope(owner.newValue(tree.pos, name) .setFlag(mods.flags)) finish } else { // add getter and possibly also setter val accflags: Long = ACCESSOR | - (if ((mods.flags & MUTABLE) != 0) mods.flags & ~MUTABLE & ~PRESUPER + (if ((mods.flags & MUTABLE) != 0L) mods.flags & ~MUTABLE & ~PRESUPER else mods.flags & ~PRESUPER | STABLE) if (nme.isSetterName(name)) context.error(tree.pos, "Names of vals or vars may not end in `_='") // .isInstanceOf[..]: probably for (old) IDE hook. is this obsolete? val getter = enterAliasMethod(tree, name, accflags, mods) setInfo(getter)(namerOf(getter).getterTypeCompleter(vd)) - if ((mods.flags & MUTABLE) != 0) { + if ((mods.flags & MUTABLE) != 0L) { val setter = enterAliasMethod(tree, nme.getterToSetter(name), accflags & ~STABLE & ~CASEACCESSOR, mods) @@ -393,7 +393,7 @@ trait Namers { self: Analyzer => } else { var vsym = if (!context.owner.isClass) { - assert((mods.flags & LAZY) != 0) // if not a field, it has to be a lazy val + assert((mods.flags & LAZY) != 0L) // if not a field, it has to be a lazy val owner.newValue(tree.pos, name + "$lzy" ).setFlag(mods.flags | MUTABLE) } else { owner.newValue(tree.pos, nme.getterToLocal(name)) @@ -402,7 +402,7 @@ trait Namers { self: Analyzer => } enterInScope(vsym) setInfo(vsym)(namerOf(vsym).typeCompleter(tree)) - if ((mods.flags & LAZY) != 0) + if ((mods.flags & LAZY) != 0L) vsym.setLazyAccessor(getter) vsym } @@ -418,7 +418,7 @@ trait Namers { self: Analyzer => finishWith(tparams) case TypeDef(mods, name, tparams, _) => var flags: Long = mods.flags - if ((flags & PARAM) != 0) flags |= DEFERRED + if ((flags & PARAM) != 0L) flags |= DEFERRED var sym = new TypeSymbol(owner, tree.pos, name).setFlag(flags) setPrivateWithin(tree, sym, mods) tree.symbol = enterInScope(sym) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index f7e5e51a1f..6a1bdc5ce1 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1259,7 +1259,7 @@ trait Typers { self: Analyzer => */ def addGetterSetter(stat: Tree): List[Tree] = stat match { case ValDef(mods, name, tpt, rhs) - if (mods.flags & (PRIVATE | LOCAL)) != (PRIVATE | LOCAL) && !stat.symbol.isModuleVar => + if (mods.flags & (PRIVATE | LOCAL)) != (PRIVATE | LOCAL).toLong && !stat.symbol.isModuleVar => val isDeferred = mods hasFlag DEFERRED val value = stat.symbol val getter = if (isDeferred) value else value.getter(value.owner) diff --git a/src/compiler/scala/tools/nsc/util/BitSet.scala b/src/compiler/scala/tools/nsc/util/BitSet.scala index 52856afb82..59d6d51219 100644 --- a/src/compiler/scala/tools/nsc/util/BitSet.scala +++ b/src/compiler/scala/tools/nsc/util/BitSet.scala @@ -59,7 +59,7 @@ abstract class BitSet { } def contains(elem: Int): Boolean = - 0 <= elem && (word(elem >> LogWL) & (1L << elem)) != 0 + 0 <= elem && (word(elem >> LogWL) & (1L << elem)) != 0L def subSet(other: BitSet): Boolean = (0 until nwords) forall (idx => (this.word(idx) & ~ other.word(idx)) == 0L) diff --git a/src/compiler/scala/tools/nsc/util/ShowPickled.scala b/src/compiler/scala/tools/nsc/util/ShowPickled.scala index 98ed06a778..c89e16ac72 100644 --- a/src/compiler/scala/tools/nsc/util/ShowPickled.scala +++ b/src/compiler/scala/tools/nsc/util/ShowPickled.scala @@ -127,7 +127,7 @@ object ShowPickled extends Names { case POLYtpe => printTypeRef(); buf.until(end, printSymbolRef) case LITERALboolean => - out.print(if (buf.readLong(len) == 0) " false" else " true") + out.print(if (buf.readLong(len) == 0L) " false" else " true") case LITERALbyte => out.print(" " + buf.readLong(len).asInstanceOf[Byte]) case LITERALshort => diff --git a/src/compiler/scala/tools/nsc/util/SourceFile.scala b/src/compiler/scala/tools/nsc/util/SourceFile.scala index 92cb3b44ed..9df275fa2f 100644 --- a/src/compiler/scala/tools/nsc/util/SourceFile.scala +++ b/src/compiler/scala/tools/nsc/util/SourceFile.scala @@ -94,10 +94,11 @@ class BatchSourceFile(val file : AbstractFile, val content: Array[Char]) extends } def isLineBreak(idx: Int) = - if (idx >= length) false else content(idx) match { + if (idx >= length) false else { + val ch = content(idx) // don't identify the CR in CR LF as a line break, since LF will do. - case CR => (idx + 1 == length) || (content(idx + 1) != LF) - case x => isLineBreakChar(x.toChar) + if (ch == CR) (idx + 1 == length) || (content(idx + 1) != LF) + else isLineBreakChar(ch) } private lazy val lineIndices: Array[Int] = { diff --git a/src/library/scala/collection/generic/BitSetTemplate.scala b/src/library/scala/collection/generic/BitSetTemplate.scala index 501a388b4d..670109a874 100644 --- a/src/library/scala/collection/generic/BitSetTemplate.scala +++ b/src/library/scala/collection/generic/BitSetTemplate.scala @@ -61,7 +61,7 @@ trait BitSetTemplate[+This <: BitSetTemplate[This] with Set[Int]] extends SetTem for (i <- 0 until nwords) { val w = word(i) for (j <- i * WordLength until (i + 1) * WordLength) { - if ((w & (1L << j)) != 0) f(j) + if ((w & (1L << j)) != 0L) f(j) } } } @@ -109,7 +109,7 @@ trait BitSetTemplate[+This <: BitSetTemplate[This] with Set[Int]] extends SetTem /** Does the set contain the given element? */ def contains(elem: Int): Boolean = - 0 <= elem && (word(elem >> LogWL) & (1L << elem)) != 0 + 0 <= elem && (word(elem >> LogWL) & (1L << elem)) != 0L /** Is the set a subset of the given bitset */ @@ -154,6 +154,6 @@ object BitSetTemplate { private def popCount(w: Long): Int = { def pc2(w: Int) = if (w == 0) 0 else pc1(w & 0xff) + pc1(w >>> 8) def pc4(w: Int) = if (w == 0) 0 else pc2(w & 0xffff) + pc2(w >>> 16) - if (w == 0) 0 else pc4(w.toInt) + pc4((w >>> 32).toInt) + if (w == 0L) 0 else pc4(w.toInt) + pc4((w >>> 32).toInt) } } diff --git a/src/library/scala/collection/immutable/LongMap.scala b/src/library/scala/collection/immutable/LongMap.scala index 2be51e7577..d553329114 100644 --- a/src/library/scala/collection/immutable/LongMap.scala +++ b/src/library/scala/collection/immutable/LongMap.scala @@ -4,7 +4,7 @@ package scala.collection.immutable; * @author David MacIver */ private[immutable] object LongMapUtils{ - def zero(i : Long, mask : Long) = (i & mask) == 0; + def zero(i : Long, mask : Long) = (i & mask) == 0L; def mask(i : Long, mask : Long) = i & (complement(mask - 1) ^ mask) def hasMatch(key : Long, prefix : Long, m : Long) = mask(key, m) == prefix; def unsignedCompare(i : Long, j : Long) = (i < j) ^ (i < 0) ^ (j < 0) diff --git a/src/library/scala/io/BytePickle.scala b/src/library/scala/io/BytePickle.scala index 558a299399..7e5628e207 100644 --- a/src/library/scala/io/BytePickle.scala +++ b/src/library/scala/io/BytePickle.scala @@ -69,7 +69,7 @@ object BytePickle { case Def() => Array.concat(s, Array[Byte](1)) }; def appU(s: Array[Byte]): (RefDef, Array[Byte]) = - if (s(0) == 0) (Ref(), s.slice(1, s.length)) + if (s(0) == (0: Byte)) (Ref(), s.slice(1, s.length)) else (Def(), s.slice(1, s.length)); } diff --git a/src/library/scala/io/UTF8Codec.scala b/src/library/scala/io/UTF8Codec.scala index 21d3b3bb31..6bbe6263ee 100644 --- a/src/library/scala/io/UTF8Codec.scala +++ b/src/library/scala/io/UTF8Codec.scala @@ -33,7 +33,7 @@ object UTF8Codec @deprecated("""Use new String(Array(ch), 0, 1).getBytes("UTF-8") instead""") def encode(ch: Int): Array[Byte] = - if ((Character getType ch) == Character.SURROGATE) UNI_REPLACEMENT_BYTES + if ((Character getType ch) == Character.SURROGATE.toInt) UNI_REPLACEMENT_BYTES else try new String(Array(ch), 0, 1) getBytes "UTF-8" catch { case _: IllegalArgumentException => UNI_REPLACEMENT_BYTES } diff --git a/src/library/scala/runtime/BoxesRunTime.java b/src/library/scala/runtime/BoxesRunTime.java index 3f71bb9409..885022c01c 100644 --- a/src/library/scala/runtime/BoxesRunTime.java +++ b/src/library/scala/runtime/BoxesRunTime.java @@ -11,6 +11,8 @@ package scala.runtime; +import java.io.*; + /** An object (static class) that defines methods used for creating, * reverting, and calculating with, boxed values. There are four classes * of methods in this object: @@ -25,7 +27,44 @@ package scala.runtime; * @author Martin Odersky * @contributor Stepan Koltsov * @version 2.0 */ -public class BoxesRunTime { +public class BoxesRunTime +{ + /**** Temporary code to support logging all equality comparisons. ****/ + private static boolean eqeqLogging = false; + private static String eqeqLogName = "/tmp/trunk-eqeq.log"; + private static FileWriter eqeqLog; + public static void setEqEqLogging(boolean state) { + eqeqLogging = state; + if (state) { + try { eqeqLog = new FileWriter(eqeqLogName, true); } + catch (IOException e) { eqeqLog = null; } + + log("Started eqeq log at " + (new java.util.Date())); + } + } + private static String obToString(Object o) { + String s = o.toString() + " (" + o.getClass().getSimpleName() + ")"; + return s.replaceAll("\\n", " "); + } + private static void logInternal(String msg, Object a, Object b, String where) { + log(msg + obToString(a) + " == " + obToString(b) + " " + where); + } + + public static String whereAreWe() { + StackTraceElement e = Thread.currentThread().getStackTrace()[3]; + return"(" + e.getClassName() + "." + e.getMethodName() + e.getFileName() + ":" + e.getLineNumber() + ")"; + } + public static void log(String msg) { + if (eqeqLogging && eqeqLog != null) { + try { + eqeqLog.write(msg + "\n"); + eqeqLog.flush(); + } + catch (IOException e) { } + } + } + + /**** End temporary logging section. ****/ private static final int CHAR = 0, BYTE = 1, SHORT = 2, INT = 3, LONG = 4, FLOAT = 5, DOUBLE = 6, OTHER = 7; @@ -121,16 +160,15 @@ public class BoxesRunTime { return d == null ? 0.0d : ((Double)d).doubleValue(); } -/* COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON */ + /**************************************/ - /** A rich implementation of the <code>equals</code> method that overrides the - * default equals because Java's boxed primitives are utterly broken. This equals - * is inserted instead of a normal equals by the Scala compiler (in the - * ICode phase, method <code>genEqEqPrimitive</code>) only when either - * side of the comparison is a subclass of <code>AnyVal</code>, of - * <code>java.lang.Number</code>, of <code>java.lang.Character</code> or - * is exactly <code>Any</code> or <code>AnyRef</code>. */ public static boolean equals(Object a, Object b) { + if ((a instanceof Number || a instanceof Character) && (b instanceof Number || b instanceof Character)) { + if (a.getClass() != b.getClass()) { + logInternal("[ BOXED ] Comparing: ", a, b, whereAreWe()); + } + } + if (a == null || b == null) return a == b; if (a.equals(b)) @@ -139,32 +177,41 @@ public class BoxesRunTime { int acode = typeCode(a); int bcode = typeCode(b); int maxcode = (acode < bcode) ? bcode : acode; + boolean res = false; if (maxcode <= INT) { int aa = (acode == CHAR) ? ((Character) a).charValue() : ((Number) a).intValue(); int bb = (bcode == CHAR) ? ((Character) b).charValue() : ((Number) b).intValue(); - return aa == bb; + res = (aa == bb); } if (maxcode <= LONG) { long aa = (acode == CHAR) ? ((Character) a).charValue() : ((Number) a).longValue(); long bb = (bcode == CHAR) ? ((Character) b).charValue() : ((Number) b).longValue(); - return aa == bb; + res = (aa == bb); } if (maxcode <= FLOAT) { float aa = (acode == CHAR) ? ((Character) a).charValue() : ((Number) a).floatValue(); float bb = (bcode == CHAR) ? ((Character) b).charValue() : ((Number) b).floatValue(); - return aa == bb; + res = (aa == bb); } if (maxcode <= DOUBLE) { double aa = (acode == CHAR) ? ((Character) a).charValue() : ((Number) a).doubleValue(); double bb = (bcode == CHAR) ? ((Character) b).charValue() : ((Number) b).doubleValue(); - return aa == bb; + res = (aa == bb); } - return b.equals(a); + if (res || b.equals(a)) { + String msg; + if (res) msg = "[ BOXED ] Overriding equals between different types: "; + else msg = "[ BOXED ] Overriding equals because b.equals(a): "; + logInternal(msg, a, b, whereAreWe()); + return true; + } + return false; } return false; } + /* OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS */ /** arg1 + arg2 */ diff --git a/src/library/scala/xml/Utility.scala b/src/library/scala/xml/Utility.scala index 39e594eb05..302f77d07c 100644 --- a/src/library/scala/xml/Utility.scala +++ b/src/library/scala/xml/Utility.scala @@ -331,44 +331,43 @@ object Utility extends AnyRef with parsing.TokenTests * @return ... */ def parseAttributeValue(value: String): Seq[Node] = { - val zs: Seq[Char] = value val sb = new StringBuilder var rfb: StringBuilder = null val nb = new NodeBuffer() - val it = zs.iterator + + val it = value.iterator while (it.hasNext) { var c = it.next - c match { - case '&' => // entity! flush buffer into text node - it.next match { - case '#' => - c = it.next - val theChar = parseCharRef ({ ()=> c },{ () => c = it.next },{s => throw new RuntimeException(s)}) - sb.append(theChar) - - case x => - if (rfb eq null) rfb = new StringBuilder() - rfb.append(x) - c = it.next - while (c != ';') { - rfb.append(c) - c = it.next - } - val ref = rfb.toString() - rfb.setLength(0) - unescape(ref,sb) match { - case null => - if (sb.length > 0) { // flush buffer - nb += Text(sb.toString()) - sb.setLength(0) - } - nb += EntityRef(sb.toString()) // add entityref - case _ => + // entity! flush buffer into text node + if (c == '&') { + c = it.next + if (c == '#') { + c = it.next + val theChar = parseCharRef ({ ()=> c },{ () => c = it.next },{s => throw new RuntimeException(s)}) + sb.append(theChar) + } + else { + if (rfb eq null) rfb = new StringBuilder() + rfb append c + c = it.next + while (c != ';') { + rfb.append(c) + c = it.next + } + val ref = rfb.toString() + rfb.setLength(0) + unescape(ref,sb) match { + case null => + if (sb.length > 0) { // flush buffer + nb += Text(sb.toString()) + sb.setLength(0) } + nb += EntityRef(sb.toString()) // add entityref + case _ => } - case x => - sb.append(x) + } } + else sb append c } if (sb.length > 0) { // flush buffer val x = Text(sb.toString()) diff --git a/src/library/scala/xml/parsing/TokenTests.scala b/src/library/scala/xml/parsing/TokenTests.scala index e4d9b371f8..608a715d15 100644 --- a/src/library/scala/xml/parsing/TokenTests.scala +++ b/src/library/scala/xml/parsing/TokenTests.scala @@ -37,7 +37,7 @@ trait TokenTests { */ def isNameChar(ch: Char) = isNameStart(ch) || (ch match { case '.' | '-' | ':' => true; - case _ => java.lang.Character.getType( ch ).asInstanceOf[Byte] match { + case _ => java.lang.Character.getType( ch ).toByte match { case java.lang.Character.COMBINING_SPACING_MARK => true; // Mc case java.lang.Character.ENCLOSING_MARK => true; // Me case java.lang.Character.NON_SPACING_MARK => true; // Mn diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala index 146fc5ce05..0fbea9a125 100644 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala +++ b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala @@ -237,7 +237,7 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { lazy val literal = oneOf( 24 -^ (), - 25 -~ longValue ^^ (_ != 0), + 25 -~ longValue ^^ (_ != 0L), 26 -~ longValue ^^ (_.asInstanceOf[Byte]), 27 -~ longValue ^^ (_.asInstanceOf[Short]), 28 -~ longValue ^^ (_.asInstanceOf[Char]), diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Symbol.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Symbol.scala index 47fb39ae0f..dee1cf84ac 100644 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Symbol.scala +++ b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Symbol.scala @@ -54,7 +54,7 @@ abstract class SymbolInfoSymbol extends ScalaSigSymbol { def entry = symbolInfo.entry def name = symbolInfo.name def parent = Some(symbolInfo.owner) - def hasFlag(flag : Long) = (symbolInfo.flags & flag) != 0 + def hasFlag(flag : Long) = (symbolInfo.flags & flag) != 0L lazy val infoType = applyRule(parseEntry(typeEntry)(symbolInfo.info)) } |