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