aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-04-29 10:36:16 +0200
committerMartin Odersky <odersky@gmail.com>2015-05-02 19:23:08 +0200
commit60ab9f8f525d319aa5b6d5052018c6781da036eb (patch)
treefbc5096a1f7193a4970226a7ad6f03fbf7670a4b /src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala
parentac46a0e4489bba4f76863cc1491bf2b8441ed1cb (diff)
downloaddotty-60ab9f8f525d319aa5b6d5052018c6781da036eb.tar.gz
dotty-60ab9f8f525d319aa5b6d5052018c6781da036eb.tar.bz2
dotty-60ab9f8f525d319aa5b6d5052018c6781da036eb.zip
Pickling modularization reorg
The pickling package got rather large and confusing with three separate tasks that each had their own conventions: read JVM classfiles, read Scala2 pickle info, read Tasty. The classes for each task are now in separate packages.
Diffstat (limited to 'src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala')
-rw-r--r--src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala b/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala
new file mode 100644
index 000000000..fa80a2769
--- /dev/null
+++ b/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala
@@ -0,0 +1,38 @@
+package dotty.tools
+package dotc
+package core
+package tasty
+
+
+import util.Positions._
+import collection.mutable
+import TastyBuffer.Addr
+
+object PositionUnpickler {
+ type AddrToPosition = mutable.HashMap[Addr, Position]
+}
+
+/** Unpickler for tree positions */
+class PositionUnpickler(reader: TastyReader) {
+ import PositionUnpickler._
+ import reader._
+
+ def unpickle(): (Position, AddrToPosition) = {
+ val positions = new mutable.HashMap[Addr, Position] // Dotty deviation: Can't use new AddrToPosition here. TODO: fix this!
+ val sourceLength = readNat()
+ def readDelta() = if (isAtEnd) 0 else readInt()
+ var curIndex: Addr = Addr(readDelta())
+ while (!isAtEnd) {
+ val delta1 = readDelta()
+ val delta2 = readDelta()
+ val (startDelta, endDelta, indexDelta) =
+ if (delta2 <= 0) (delta1, -delta2, readDelta())
+ else if (delta1 < 0) (0, -delta1, delta2)
+ else (delta1, 0, delta2)
+ positions(curIndex) = Position(startDelta, endDelta, startDelta)
+ // make non-synthetic position; will be made synthetic by normalization.
+ curIndex += indexDelta
+ }
+ (Position(0, sourceLength), positions)
+ }
+}