diff options
author | Antonio Cunei <antonio.cunei@epfl.ch> | 2009-04-22 22:18:06 +0000 |
---|---|---|
committer | Antonio Cunei <antonio.cunei@epfl.ch> | 2009-04-22 22:18:06 +0000 |
commit | 4ae08113a6a1708ac53bd84b938c2a233df80476 (patch) | |
tree | 71f469e8433abdfda5f7eeacd8e8a97691ccb587 /src | |
parent | c52b5c7df7b3274ce7e72dee7ef416edb037cff5 (diff) | |
download | scala-4ae08113a6a1708ac53bd84b938c2a233df80476.tar.gz scala-4ae08113a6a1708ac53bd84b938c2a233df80476.tar.bz2 scala-4ae08113a6a1708ac53bd84b938c2a233df80476.zip |
Backward-compatible extension of the signature
format, allows for more than 32 bits of flags
to be saved by the pickler if so required.
Diffstat (limited to 'src')
5 files changed, 24 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/PickleBuffer.scala b/src/compiler/scala/tools/nsc/symtab/classfile/PickleBuffer.scala index 23dc22e100..c09a2c797c 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/PickleBuffer.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/PickleBuffer.scala @@ -40,15 +40,25 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) { /** Write a natural number in big endian format, base 128. * All but the last digits have bit 0x80 set. */ - def writeNat(x: Int) { - def writeNatPrefix(x: Int) { + def writeNat(x: Int) = + writeLongNat(x.asInstanceOf[Long] & 0x00000000FFFFFFFFL) + + /** + * Like writeNat, but for longs. This is not the same as + * writeLong, which writes in base 256. Note that the + * binary representation of LongNat is identical to Nat + * if the long value is in the range Int.MIN_VALUE to + * Int.MAX_VALUE. + */ + def writeLongNat(x: Long) { + def writeNatPrefix(x: Long) { val y = x >>> 7 if (y != 0) writeNatPrefix(y) - writeByte((x & 0x7f) | 0x80) + writeByte(((x & 0x7f) | 0x80).asInstanceOf[Int]) } val y = x >>> 7 if (y != 0) writeNatPrefix(y) - writeByte(x & 0x7f) + writeByte((x & 0x7f).asInstanceOf[Int]) } /** Write a natural number <code>x</code> at position <code>pos</code>. @@ -93,9 +103,11 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) { /** Read a natural number in big endian format, base 128. * All but the last digits have bit 0x80 set.*/ - def readNat(): Int = { - var b = 0 - var x = 0 + def readNat(): Int = readLongNat().asInstanceOf[Int] + + def readLongNat(): Long = { + var b = 0L + var x = 0L do { b = readByte() x = (x << 7) + (b & 0x7f) diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/PickleFormat.scala b/src/compiler/scala/tools/nsc/symtab/classfile/PickleFormat.scala index db634f6092..0b74201a96 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/PickleFormat.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/PickleFormat.scala @@ -111,7 +111,7 @@ object PickleFormat { * | 70 PosCLASSsym len_Nat pos_Nat SymbolInfo [thistype_Ref] * | 71 PosMODULEsym len_Nat pos_Nat SymbolInfo * | 72 PosVALsym len_Nat pos_Nat SymbolInfo [alias_Ref] - * SymbolInfo = name_Ref owner_Ref flags_Nat [privateWithin_Ref] info_Ref + * SymbolInfo = name_Ref owner_Ref flags_LongNat [privateWithin_Ref] info_Ref * NameInfo = <character sequence of length len_Nat in Utf8 format> * NumInfo = <len_Nat-byte signed number in big endian format> * Ref = Nat diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala index 7a721c52de..eb23571053 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala @@ -471,7 +471,7 @@ abstract class Pickler extends SubComponent { var posOffset = 0 writeRef(sym.name) writeRef(normalizedOwner(sym)) - writeNat((rawFlagsToPickled(sym.flags & PickledFlags)).asInstanceOf[Int]) + writeLongNat((rawFlagsToPickled(sym.flags & PickledFlags))) if (sym.privateWithin != NoSymbol) writeRef(sym.privateWithin) writeRef(sym.info) posOffset diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala index 0b76104433..82df45dd2d 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala @@ -182,7 +182,7 @@ abstract class UnPickler { } val name = readNameRef() val owner = readSymbolRef() - val flags = pickledToRawFlags(readNat()) + val flags = pickledToRawFlags(readLongNat()) var privateWithin: Symbol = NoSymbol var inforef = readNat() if (isSymbolRef(inforef)) { diff --git a/src/compiler/scala/tools/nsc/util/ShowPickled.scala b/src/compiler/scala/tools/nsc/util/ShowPickled.scala index fa7c1b5941..633fa5adf5 100644 --- a/src/compiler/scala/tools/nsc/util/ShowPickled.scala +++ b/src/compiler/scala/tools/nsc/util/ShowPickled.scala @@ -7,7 +7,7 @@ package scala.tools.nsc.util import java.io.{File, FileInputStream, PrintStream, IOException} -import java.lang.Integer.toHexString +import java.lang.Long.toHexString import java.lang.Float.intBitsToFloat import java.lang.Double.longBitsToDouble @@ -84,7 +84,7 @@ object ShowPickled extends Names { def printSymInfo() { printNameRef() printSymbolRef() - val pflags = buf.readNat() + val pflags = buf.readLongNat() out.print(" " + toHexString(pflags) + "[" + Flags.flagsToString(Flags.pickledToRawFlags(pflags)) + "] ") printTypeRef() |