aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/ast/Positioned.scala2
-rw-r--r--src/dotty/tools/dotc/core/tasty/PositionPickler.scala24
-rw-r--r--src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala11
-rw-r--r--src/dotty/tools/dotc/printing/RefinedPrinter.scala8
4 files changed, 27 insertions, 18 deletions
diff --git a/src/dotty/tools/dotc/ast/Positioned.scala b/src/dotty/tools/dotc/ast/Positioned.scala
index f6793a309..bb6817603 100644
--- a/src/dotty/tools/dotc/ast/Positioned.scala
+++ b/src/dotty/tools/dotc/ast/Positioned.scala
@@ -24,7 +24,7 @@ abstract class Positioned extends DotClass with Product {
* positions in children.
*/
protected def setPos(pos: Position): Unit = {
- curPos = pos
+ setPosUnchecked(pos)
if (pos.exists) setChildPositions(pos.toSynthetic)
}
diff --git a/src/dotty/tools/dotc/core/tasty/PositionPickler.scala b/src/dotty/tools/dotc/core/tasty/PositionPickler.scala
index 78c15eae2..24a6c998e 100644
--- a/src/dotty/tools/dotc/core/tasty/PositionPickler.scala
+++ b/src/dotty/tools/dotc/core/tasty/PositionPickler.scala
@@ -36,9 +36,9 @@ class PositionPickler(pickler: TastyPickler, addrsOfTree: tpd.Tree => List[Addr]
if (it.hasNext) Some(it.next) else None
}
- def header(addrDelta: Int, hasStartDelta: Boolean, hasEndDelta: Boolean) = {
+ def header(addrDelta: Int, hasStartDelta: Boolean, hasEndDelta: Boolean, hasPoint: Boolean) = {
def toInt(b: Boolean) = if (b) 1 else 0
- (addrDelta << 2) | (toInt(hasStartDelta) << 1) | toInt(hasEndDelta)
+ (addrDelta << 3) | (toInt(hasStartDelta) << 2) | (toInt(hasEndDelta) << 1) | toInt(hasPoint)
}
def picklePositions(roots: List[Tree])(implicit ctx: Context) = {
@@ -48,26 +48,30 @@ class PositionPickler(pickler: TastyPickler, addrsOfTree: tpd.Tree => List[Addr]
val addrDelta = index - lastIndex
val startDelta = pos.start - lastPos.start
val endDelta = pos.end - lastPos.end
- buf.writeInt(header(addrDelta, startDelta != 0, endDelta != 0))
+ buf.writeInt(header(addrDelta, startDelta != 0, endDelta != 0, !pos.isSynthetic))
if (startDelta != 0) buf.writeInt(startDelta)
if (endDelta != 0) buf.writeInt(endDelta)
+ if (!pos.isSynthetic) buf.writeInt(pos.pointDelta)
lastIndex = index
lastPos = pos
}
/** True if x's position cannot be reconstructed automatically from its initialPos
*/
- def needsPosition(x: Positioned) =
- x.pos.toSynthetic != x.initialPos.toSynthetic ||
- x.isInstanceOf[WithLazyField[_]] || // initialPos is inaccurate for trees with lazy fields
- x.isInstanceOf[Trees.PackageDef[_]] // package defs might be split into several Tasty files
+ def alwaysNeedsPos(x: Positioned) = x match {
+ case _: WithLazyField[_] // initialPos is inaccurate for trees with lazy field
+ | _: Trees.PackageDef[_] => true // package defs might be split into several Tasty files
+ case _ => false
+ }
+
def traverse(x: Any): Unit = x match {
case x: Tree @unchecked =>
- if (x.pos.exists && needsPosition(x)) {
+ val pos = if (x.isInstanceOf[MemberDef]) x.pos else x.pos.toSynthetic
+ if (pos.exists && (pos != x.initialPos.toSynthetic || alwaysNeedsPos(x))) {
nextTreeAddr(x) match {
case Some(addr) =>
- //println(i"pickling $x at $addr")
- pickleDeltas(addr.index, x.pos)
+ //println(i"pickling $x with $pos at $addr")
+ pickleDeltas(addr.index, pos)
case _ =>
//println(i"no address for $x")
}
diff --git a/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala b/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala
index c29aeba70..cbe213d89 100644
--- a/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala
+++ b/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala
@@ -19,14 +19,17 @@ class PositionUnpickler(reader: TastyReader) {
var curEnd = 0
while (!isAtEnd) {
val header = readInt()
- val addrDelta = header >> 2
- val hasStart = (header & 2) != 0
- val hasEnd = (header & 1) != 0
+ val addrDelta = header >> 3
+ val hasStart = (header & 4) != 0
+ val hasEnd = (header & 2) != 0
+ val hasPoint = (header & 1) != 0
curIndex += addrDelta
assert(curIndex >= 0)
if (hasStart) curStart += readInt()
if (hasEnd) curEnd += readInt()
- positions(Addr(curIndex)) = Position(curStart, curEnd)
+ positions(Addr(curIndex)) =
+ if (hasPoint) Position(curStart, curEnd, curStart + readInt())
+ else Position(curStart, curEnd)
}
positions
}
diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
index 31d45d42c..83b3da0b7 100644
--- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala
+++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
@@ -351,8 +351,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case SeqLiteral(elems, elemtpt) =>
"[" ~ toTextGlobal(elems, ",") ~ " : " ~ toText(elemtpt) ~ "]"
case tree @ Inlined(call, bindings, body) =>
- if (homogenizedView) toTextCore(Inliner.dropInlined(tree.asInstanceOf[tpd.Inlined]))
- else "/* inlined from " ~ toText(call) ~ "*/ " ~ blockText(bindings :+ body)
+ (("/* inlined from " ~ toText(call) ~ "*/ ") provided !homogenizedView) ~
+ blockText(bindings :+ body)
case tpt: untpd.DerivedTypeTree =>
"<derived typetree watching " ~ summarized(toText(tpt.watched)) ~ ">"
case TypeTree() =>
@@ -526,7 +526,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
else if (!tree.isDef) txt = ("<" ~ txt ~ ":" ~ toText(tp) ~ ">").close
}
if (ctx.settings.Yprintpos.value && !tree.isInstanceOf[WithoutTypeOrPos[_]]) {
- val pos = if (homogenizedView) tree.pos.toSynthetic else tree.pos
+ val pos =
+ if (homogenizedView && !tree.isInstanceOf[MemberDef]) tree.pos.toSynthetic
+ else tree.pos
txt = (txt ~ "@" ~ pos.toString /*~ tree.getClass.toString*/).close
}
tree match {