@@ -254,7 +254,8 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
254
254
case TYPEARGtype =>
255
255
TypeArgRef (readType(), readType().asInstanceOf [TypeRef ], readNat())
256
256
case BIND =>
257
- val sym = ctx.newSymbol(ctx.owner, readName().toTypeName, BindDefinedType , readType())
257
+ val sym = ctx.newSymbol(ctx.owner, readName().toTypeName, BindDefinedType , readType(),
258
+ coord = coordAt(start))
258
259
registerSym(start, sym)
259
260
if (currentAddr != end) readType()
260
261
TypeRef (NoPrefix , sym)
@@ -453,11 +454,14 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
453
454
rootd.symbol
454
455
case _ =>
455
456
val completer = adjustIfModule(new Completer (ctx.owner, subReader(start, end)))
457
+
458
+ val coord = coordAt(start)
459
+
456
460
if (isClass)
457
- ctx.newClassSymbol(ctx.owner, name.asTypeName, flags, completer, privateWithin, coord = start.index )
461
+ ctx.newClassSymbol(ctx.owner, name.asTypeName, flags, completer, privateWithin, coord)
458
462
else
459
- ctx.newSymbol(ctx.owner, name, flags, completer, privateWithin, coord = start.index )
460
- } // TODO set position somehow (but take care not to upset Symbol#isDefinedInCurrentRun)
463
+ ctx.newSymbol(ctx.owner, name, flags, completer, privateWithin, coord)
464
+ }
461
465
sym.annotations = annots
462
466
ctx.enter(sym)
463
467
registerSym(start, sym)
@@ -985,7 +989,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
985
989
case BIND =>
986
990
val name = readName()
987
991
val info = readType()
988
- val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags , info)
992
+ val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags , info, coord = coordAt(start) )
989
993
registerSym(start, sym)
990
994
Bind (sym, readTerm())
991
995
case ALTERNATIVE =>
@@ -1001,7 +1005,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
1001
1005
val argPats = until(end)(readTerm())
1002
1006
UnApply (fn, implicitArgs, argPats, patType)
1003
1007
case REFINEDtpt =>
1004
- val refineCls = ctx.newRefinedClassSymbol
1008
+ val refineCls = ctx.newRefinedClassSymbol(coordAt(start))
1005
1009
typeAtAddr(start) = refineCls.typeRef
1006
1010
val parent = readTpt()
1007
1011
val refinements = readStats(refineCls, end)(localContext(refineCls))
@@ -1077,21 +1081,32 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
1077
1081
1078
1082
// ------ Setting positions ------------------------------------------------
1079
1083
1080
- /** Set position of `tree` at given `addr`. */
1081
- def setPos [ T <: untpd. Tree ] (addr : Addr , tree : T )(implicit ctx : Context ): tree. type =
1084
+ /** Pickled position for `addr`. */
1085
+ def posAt (addr : Addr )(implicit ctx : Context ): Position =
1082
1086
if (ctx.mode.is(Mode .ReadPositions )) {
1083
1087
posUnpicklerOpt match {
1084
1088
case Some (posUnpickler) =>
1085
- // println(i"setPos $tree / ${tree.getClass} at $addr to ${posUnpickler.posAt(addr)}")
1086
- val pos = posUnpickler.posAt(addr)
1087
- if (pos.exists) tree.setPosUnchecked(pos)
1088
- tree
1089
+ posUnpickler.posAt(addr)
1089
1090
case _ =>
1090
- // println(i"no pos $tree")
1091
- tree
1091
+ NoPosition
1092
1092
}
1093
- }
1094
- else tree
1093
+ } else NoPosition
1094
+
1095
+ /** Coordinate for the symbol at `addr`. */
1096
+ def coordAt (addr : Addr )(implicit ctx : Context ): Coord = {
1097
+ val pos = posAt(addr)
1098
+ if (pos.exists)
1099
+ positionCoord(pos)
1100
+ else
1101
+ indexCoord(addr.index)
1102
+ }
1103
+
1104
+ /** Set position of `tree` at given `addr`. */
1105
+ def setPos [T <: untpd.Tree ](addr : Addr , tree : T )(implicit ctx : Context ): tree.type = {
1106
+ val pos = posAt(addr)
1107
+ if (pos.exists) tree.setPosUnchecked(pos)
1108
+ tree
1109
+ }
1095
1110
}
1096
1111
1097
1112
class LazyReader [T <: AnyRef ](reader : TreeReader , op : TreeReader => Context => T ) extends Trees .Lazy [T ] {
0 commit comments