aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/pickling/TastyReader.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-02-23 13:34:12 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-03-18 11:14:09 +0100
commit89c00f601678f58d0ddb424ffe680940f760eaeb (patch)
treeb0771f335a117aee334301da28b52def59b08ac9 /src/dotty/tools/dotc/core/pickling/TastyReader.scala
parent1daa94f860e8b80624d6ab397e3673abb6cb4cfa (diff)
downloaddotty-89c00f601678f58d0ddb424ffe680940f760eaeb.tar.gz
dotty-89c00f601678f58d0ddb424ffe680940f760eaeb.tar.bz2
dotty-89c00f601678f58d0ddb424ffe680940f760eaeb.zip
Add signed ints in Tasty format.
- will be needed for position deltas - also simplify format in that negative constants are no longer needed.
Diffstat (limited to 'src/dotty/tools/dotc/core/pickling/TastyReader.scala')
-rw-r--r--src/dotty/tools/dotc/core/pickling/TastyReader.scala32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/pickling/TastyReader.scala b/src/dotty/tools/dotc/core/pickling/TastyReader.scala
index 4e1acf9a9..1b3c82f79 100644
--- a/src/dotty/tools/dotc/core/pickling/TastyReader.scala
+++ b/src/dotty/tools/dotc/core/pickling/TastyReader.scala
@@ -65,6 +65,11 @@ class TastyReader(val bytes: Array[Byte], start: Int, end: Int, val base: Int =
* All but the last digits have bit 0x80 set.
*/
def readNat(): Int = readLongNat.toInt
+
+ /** Read an integer number in 2's complement big endian format, base 128.
+ * All but the last digits have bit 0x80 set.
+ */
+ def readInt(): Int = readLongInt.toInt
/** Read a natural number fitting in a Long in big endian format, base 128.
* All but the last digits have bit 0x80 set.
@@ -79,7 +84,28 @@ class TastyReader(val bytes: Array[Byte], start: Int, end: Int, val base: Int =
} while ((b & 0x80) == 0)
x
}
-
+
+ /** Read a long integer number in 2's complement big endian format, base 128. */
+ def readLongInt(): Long = {
+ var b = bytes(bp)
+ var x = (b << 1).toByte >> 1 // sign extend with bit 6.
+ bp += 1
+ while ((b & 0x80) == 0) {
+ b = bytes(bp)
+ x = (x << 7) | (b & 0x7f)
+ bp += 1
+ }
+ x
+ }
+
+ /** Read an uncompressed Long stored in 8 bytes in big endian format */
+ def readUncompressedLong(): Long = {
+ var x = 0
+ for (i <- 0 to 7)
+ x = (x << 8) | (readByte() & 0xff)
+ x
+ }
+
/** Read a natural number and return as a NameRef */
def readNameRef() = NameRef(readNat())
@@ -103,6 +129,10 @@ class TastyReader(val bytes: Array[Byte], start: Int, end: Int, val base: Int =
buf.toList
}
+ /** If before given `end` address, the result of `op`, otherwise `default` */
+ def ifBefore[T](end: Addr)(op: => T, default: T): T =
+ if (bp < index(end)) op else default
+
/** Perform `op` while cindition `cond` holds and collect results in a list. */
def collectWhile[T](cond: => Boolean)(op: => T): List[T] = {
val buf = new mutable.ListBuffer[T]