aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/core/classfile/AbstractFileReader.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-02 11:08:28 +0100
committerGuillaume Martres <smarter@ubuntu.com>2016-11-22 01:35:07 +0100
commit8a61ff432543a29234193cd1f7c14abd3f3d31a0 (patch)
treea8147561d307af862c295cfc8100d271063bb0dd /compiler/src/dotty/tools/dotc/core/classfile/AbstractFileReader.scala
parent6a455fe6da5ff9c741d91279a2dc6fe2fb1b472f (diff)
downloaddotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.tar.gz
dotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.tar.bz2
dotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.zip
Move compiler and compiler tests to compiler dir
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core/classfile/AbstractFileReader.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/core/classfile/AbstractFileReader.scala88
1 files changed, 88 insertions, 0 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/classfile/AbstractFileReader.scala b/compiler/src/dotty/tools/dotc/core/classfile/AbstractFileReader.scala
new file mode 100644
index 000000000..cad3a4132
--- /dev/null
+++ b/compiler/src/dotty/tools/dotc/core/classfile/AbstractFileReader.scala
@@ -0,0 +1,88 @@
+package dotty.tools
+package dotc
+package core
+package classfile
+
+import java.lang.Float.intBitsToFloat
+import java.lang.Double.longBitsToDouble
+
+import io.AbstractFile
+
+/**
+ * This class reads files byte per byte. Only used by ClassFileParser
+ *
+ * @author Philippe Altherr
+ * @version 1.0, 23/03/2004
+ */
+class AbstractFileReader(val file: AbstractFile) {
+
+ /** the buffer containing the file
+ */
+ val buf: Array[Byte] = file.toByteArray
+
+ /** the current input pointer
+ */
+ var bp: Int = 0
+
+ /** return byte at offset 'pos'
+ */
+ @throws(classOf[IndexOutOfBoundsException])
+ def byteAt(pos: Int): Byte = buf(pos)
+
+ /** read a byte
+ */
+ @throws(classOf[IndexOutOfBoundsException])
+ def nextByte: Byte = {
+ val b = buf(bp)
+ bp += 1
+ b
+ }
+
+ /** read some bytes
+ */
+ def nextBytes(len: Int): Array[Byte] = {
+ bp += len
+ buf.slice(bp - len, bp)
+ }
+
+ /** read a character
+ */
+ def nextChar: Char =
+ (((nextByte & 0xff) << 8) + (nextByte & 0xff)).toChar
+
+ /** read an integer
+ */
+ def nextInt: Int =
+ ((nextByte & 0xff) << 24) + ((nextByte & 0xff) << 16) +
+ ((nextByte & 0xff) << 8) + (nextByte & 0xff)
+
+
+ /** extract a character at position bp from buf
+ */
+ def getChar(mybp: Int): Char =
+ (((buf(mybp) & 0xff) << 8) + (buf(mybp + 1) & 0xff)).toChar
+
+ /** extract an integer at position bp from buf
+ */
+ def getInt(mybp: Int): Int =
+ ((buf(mybp ) & 0xff) << 24) + ((buf(mybp + 1) & 0xff) << 16) +
+ ((buf(mybp + 2) & 0xff) << 8) + (buf(mybp + 3) & 0xff)
+
+ /** extract a long integer at position bp from buf
+ */
+ def getLong(mybp: Int): Long =
+ (getInt(mybp).toLong << 32) + (getInt(mybp + 4) & 0xffffffffL)
+
+ /** extract a float at position bp from buf
+ */
+ def getFloat(mybp: Int): Float = intBitsToFloat(getInt(mybp))
+
+ /** extract a double at position bp from buf
+ */
+ def getDouble(mybp: Int): Double = longBitsToDouble(getLong(mybp))
+
+ /** skip next 'n' bytes
+ */
+ def skip(n: Int): Unit = { bp += n }
+
+}