diff options
author | Martin Odersky <odersky@gmail.com> | 2016-09-04 15:01:05 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-10-02 16:11:21 +0200 |
commit | 333ec27c9e503f428c86a155351d11f332f2892d (patch) | |
tree | 99c9c9638de688e4a3369cedb61d9046427cc4b8 /src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala | |
parent | 688cc890ceadb42f742579494a560159334c85aa (diff) | |
download | dotty-333ec27c9e503f428c86a155351d11f332f2892d.tar.gz dotty-333ec27c9e503f428c86a155351d11f332f2892d.tar.bz2 dotty-333ec27c9e503f428c86a155351d11f332f2892d.zip |
Set the positions of inlined trees wehn read form Tasty
This required a major change in the way positions are handled, as the
previous scheme did not allow to read the positions of arbitrary subtrees
selectively.
Fortunately, it's altogether a major simplification.
Also, this fixed a bug in the previous scheme, where positions were
generated before compactification, resulting in addresses being wrong.
Diffstat (limited to 'src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala b/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala index fa80a2769..c29aeba70 100644 --- a/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala +++ b/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala @@ -6,33 +6,31 @@ package tasty import util.Positions._ import collection.mutable -import TastyBuffer.Addr - -object PositionUnpickler { - type AddrToPosition = mutable.HashMap[Addr, Position] -} +import TastyBuffer.{Addr, NoAddr} /** 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()) + private[tasty] lazy val positions = { + val positions = new mutable.HashMap[Addr, Position] + var curIndex = 0 + var curStart = 0 + var curEnd = 0 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 + val header = readInt() + val addrDelta = header >> 2 + val hasStart = (header & 2) != 0 + val hasEnd = (header & 1) != 0 + curIndex += addrDelta + assert(curIndex >= 0) + if (hasStart) curStart += readInt() + if (hasEnd) curEnd += readInt() + positions(Addr(curIndex)) = Position(curStart, curEnd) } - (Position(0, sourceLength), positions) + positions } + + def posAt(addr: Addr) = positions.getOrElse(addr, NoPosition) } + |