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 /src/compiler | |
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.
Diffstat (limited to 'src/compiler')
21 files changed, 142 insertions, 93 deletions
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] = { |