@@ -259,7 +259,8 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
259
259
case TYPEARGtype =>
260
260
TypeArgRef (readType(), readType().asInstanceOf [TypeRef ], readNat())
261
261
case BIND =>
262
- val sym = ctx.newSymbol(ctx.owner, readName().toTypeName, BindDefinedType , readType())
262
+ val sym = ctx.newSymbol(ctx.owner, readName().toTypeName, BindDefinedType , readType(),
263
+ coord = coordAt(start))
263
264
registerSym(start, sym)
264
265
if (currentAddr != end) readType()
265
266
TypeRef (NoPrefix , sym)
@@ -464,11 +465,14 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
464
465
rootd.symbol
465
466
case _ =>
466
467
val completer = adjustIfModule(new Completer (ctx.owner, subReader(start, end)))
468
+
469
+ val coord = coordAt(start)
470
+
467
471
if (isClass)
468
- ctx.newClassSymbol(ctx.owner, name.asTypeName, flags, completer, privateWithin, coord = start.index )
472
+ ctx.newClassSymbol(ctx.owner, name.asTypeName, flags, completer, privateWithin, coord)
469
473
else
470
- ctx.newSymbol(ctx.owner, name, flags, completer, privateWithin, coord = start.index )
471
- } // TODO set position somehow (but take care not to upset Symbol#isDefinedInCurrentRun)
474
+ ctx.newSymbol(ctx.owner, name, flags, completer, privateWithin, coord)
475
+ }
472
476
sym.annotations = annots
473
477
ctx.enter(sym)
474
478
registerSym(start, sym)
@@ -995,7 +999,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
995
999
case BIND =>
996
1000
val name = readName()
997
1001
val info = readType()
998
- val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags , info)
1002
+ val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags , info, coord = coordAt(start) )
999
1003
registerSym(start, sym)
1000
1004
Bind (sym, readTerm())
1001
1005
case ALTERNATIVE =>
@@ -1011,7 +1015,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
1011
1015
val argPats = until(end)(readTerm())
1012
1016
UnApply (fn, implicitArgs, argPats, patType)
1013
1017
case REFINEDtpt =>
1014
- val refineCls = ctx.newRefinedClassSymbol
1018
+ val refineCls = ctx.newRefinedClassSymbol(coordAt(start))
1015
1019
typeAtAddr(start) = refineCls.typeRef
1016
1020
val parent = readTpt()
1017
1021
val refinements = readStats(refineCls, end)(localContext(refineCls))
@@ -1087,21 +1091,32 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
1087
1091
1088
1092
// ------ Setting positions ------------------------------------------------
1089
1093
1090
- /** Set position of `tree` at given `addr`. */
1091
- def setPos [ T <: untpd. Tree ] (addr : Addr , tree : T )(implicit ctx : Context ): tree. type =
1094
+ /** Pickled position for `addr`. */
1095
+ def posAt (addr : Addr )(implicit ctx : Context ): Position =
1092
1096
if (ctx.mode.is(Mode .ReadPositions )) {
1093
1097
posUnpicklerOpt match {
1094
1098
case Some (posUnpickler) =>
1095
- // println(i"setPos $tree / ${tree.getClass} at $addr to ${posUnpickler.posAt(addr)}")
1096
- val pos = posUnpickler.posAt(addr)
1097
- if (pos.exists) tree.setPosUnchecked(pos)
1098
- tree
1099
+ posUnpickler.posAt(addr)
1099
1100
case _ =>
1100
- // println(i"no pos $tree")
1101
- tree
1101
+ NoPosition
1102
1102
}
1103
- }
1104
- else tree
1103
+ } else NoPosition
1104
+
1105
+ /** Coordinate for the symbol at `addr`. */
1106
+ def coordAt (addr : Addr )(implicit ctx : Context ): Coord = {
1107
+ val pos = posAt(addr)
1108
+ if (pos.exists)
1109
+ positionCoord(pos)
1110
+ else
1111
+ indexCoord(addr.index)
1112
+ }
1113
+
1114
+ /** Set position of `tree` at given `addr`. */
1115
+ def setPos [T <: untpd.Tree ](addr : Addr , tree : T )(implicit ctx : Context ): tree.type = {
1116
+ val pos = posAt(addr)
1117
+ if (pos.exists) tree.setPosUnchecked(pos)
1118
+ tree
1119
+ }
1105
1120
}
1106
1121
1107
1122
class LazyReader [T <: AnyRef ](reader : TreeReader , op : TreeReader => Context => T ) extends Trees .Lazy [T ] {
0 commit comments