@@ -228,6 +228,39 @@ class TreeUnpickler(reader: TastyReader,
228
228
createSymbol()
229
229
}
230
230
231
+ def readConstant (tag : Int )(implicit ctx : Context ): Constant = (tag : @ switch) match {
232
+ case UNITconst =>
233
+ Constant (())
234
+ case TRUEconst =>
235
+ Constant (true )
236
+ case FALSEconst =>
237
+ Constant (false )
238
+ case BYTEconst =>
239
+ Constant (readInt().toByte)
240
+ case SHORTconst =>
241
+ Constant (readInt().toShort)
242
+ case CHARconst =>
243
+ Constant (readNat().toChar)
244
+ case INTconst =>
245
+ Constant (readInt())
246
+ case LONGconst =>
247
+ Constant (readLongInt())
248
+ case FLOATconst =>
249
+ Constant (java.lang.Float .intBitsToFloat(readInt()))
250
+ case DOUBLEconst =>
251
+ Constant (java.lang.Double .longBitsToDouble(readLongInt()))
252
+ case STRINGconst =>
253
+ Constant (readName().toString)
254
+ case NULLconst =>
255
+ Constant (null )
256
+ case CLASSconst =>
257
+ Constant (readType())
258
+ case ENUMconst =>
259
+ Constant (readTermRef().termSymbol)
260
+ case SYMBOLconst =>
261
+ Constant (scala.Symbol (readName().toString))
262
+ }
263
+
231
264
/** Read a type */
232
265
def readType ()(implicit ctx : Context ): Type = {
233
266
val start = currentAddr
@@ -313,10 +346,6 @@ class TreeUnpickler(reader: TastyReader,
313
346
readTypeRef() match {
314
347
case binder : LambdaType => binder.paramRefs(readNat())
315
348
}
316
- case CLASSconst =>
317
- ConstantType (Constant (readType()))
318
- case ENUMconst =>
319
- ConstantType (Constant (readTermRef().termSymbol))
320
349
case HOLE =>
321
350
readHole(end, isType = true ).tpe
322
351
}
@@ -356,38 +385,10 @@ class TreeUnpickler(reader: TastyReader,
356
385
case SHAREDtype =>
357
386
val ref = readAddr()
358
387
typeAtAddr.getOrElseUpdate(ref, forkAt(ref).readType())
359
- case UNITconst =>
360
- ConstantType (Constant (()))
361
- case TRUEconst =>
362
- ConstantType (Constant (true ))
363
- case FALSEconst =>
364
- ConstantType (Constant (false ))
365
- case BYTEconst =>
366
- ConstantType (Constant (readInt().toByte))
367
- case SHORTconst =>
368
- ConstantType (Constant (readInt().toShort))
369
- case CHARconst =>
370
- ConstantType (Constant (readNat().toChar))
371
- case INTconst =>
372
- ConstantType (Constant (readInt()))
373
- case LONGconst =>
374
- ConstantType (Constant (readLongInt()))
375
- case FLOATconst =>
376
- ConstantType (Constant (java.lang.Float .intBitsToFloat(readInt())))
377
- case DOUBLEconst =>
378
- ConstantType (Constant (java.lang.Double .longBitsToDouble(readLongInt())))
379
- case STRINGconst =>
380
- ConstantType (Constant (readName().toString))
381
- case NULLconst =>
382
- ConstantType (Constant (null ))
383
- case CLASSconst =>
384
- ConstantType (Constant (readType()))
385
- case ENUMconst =>
386
- ConstantType (Constant (readTermRef().termSymbol))
387
- case SYMBOLconst =>
388
- ConstantType (Constant (scala.Symbol (readName().toString)))
389
388
case BYNAMEtype =>
390
389
ExprType (readType())
390
+ case _ =>
391
+ ConstantType (readConstant(tag))
391
392
}
392
393
393
394
if (tag < firstLengthTreeTag) readSimpleType() else readLengthType()
@@ -420,7 +421,7 @@ class TreeUnpickler(reader: TastyReader,
420
421
421
422
// ------ Reading definitions -----------------------------------------------------
422
423
423
- private def noRhs (end : Addr ): Boolean =
424
+ private def nothingButMods (end : Addr ): Boolean =
424
425
currentAddr == end || isModifierTag(nextByte)
425
426
426
427
private def localContext (owner : Symbol )(implicit ctx : Context ) =
@@ -510,7 +511,7 @@ class TreeUnpickler(reader: TastyReader,
510
511
val templateStart = currentAddr
511
512
skipTree() // tpt
512
513
val rhsStart = currentAddr
513
- val rhsIsEmpty = noRhs (end)
514
+ val rhsIsEmpty = nothingButMods (end)
514
515
if (! rhsIsEmpty) skipTree()
515
516
val (givenFlags, annots, privateWithin) = readModifiers(end)
516
517
pickling.println(i " creating symbol $name at $start with flags $givenFlags" )
@@ -562,7 +563,7 @@ class TreeUnpickler(reader: TastyReader,
562
563
*/
563
564
def readModifiers (end : Addr )(implicit ctx : Context ): (FlagSet , List [Annotation ], Symbol ) = {
564
565
var flags : FlagSet = EmptyFlags
565
- var annots = new mutable. ListBuffer [Annotation ]
566
+ var annots : List [Annotation ] = Nil
566
567
var privateWithin : Symbol = NoSymbol
567
568
while (currentAddr.index != end.index) {
568
569
def addFlag (flag : FlagSet ) = {
@@ -613,18 +614,23 @@ class TreeUnpickler(reader: TastyReader,
613
614
addFlag(Protected )
614
615
privateWithin = readType().typeSymbol
615
616
case ANNOTATION =>
616
- readByte()
617
- val end = readEnd()
618
- val tp = readType()
619
- val lazyAnnotTree = readLater(end, rdr => ctx => rdr.readTerm()(ctx))
620
- annots += Annotation .deferredSymAndTree(
621
- implicit ctx => tp.typeSymbol,
622
- implicit ctx => lazyAnnotTree.complete)
617
+ annots = readAnnot(ctx) :: annots
623
618
case tag =>
624
619
assert(false , s " illegal modifier tag $tag at $currentAddr, end = $end" )
625
620
}
626
621
}
627
- (flags, annots.toList, privateWithin)
622
+ (flags, annots.reverse, privateWithin)
623
+ }
624
+
625
+ private val readAnnot : Context => Annotation = {
626
+ implicit ctx =>
627
+ readByte()
628
+ val end = readEnd()
629
+ val tp = readType()
630
+ val lazyAnnotTree = readLater(end, rdr => ctx => rdr.readTerm()(ctx))
631
+ Annotation .deferredSymAndTree(
632
+ implicit ctx => tp.typeSymbol,
633
+ implicit ctx => lazyAnnotTree.complete)
628
634
}
629
635
630
636
/** Create symbols for the definitions in the statement sequence between
@@ -721,7 +727,7 @@ class TreeUnpickler(reader: TastyReader,
721
727
val localCtx = localContext(sym)
722
728
723
729
def readRhs (implicit ctx : Context ) =
724
- if (noRhs (end)) EmptyTree
730
+ if (nothingButMods (end)) EmptyTree
725
731
else readLater(end, rdr => ctx => rdr.readTerm()(ctx.retractMode(Mode .InSuperCall )))
726
732
727
733
def ValDef (tpt : Tree ) =
@@ -786,7 +792,7 @@ class TreeUnpickler(reader: TastyReader,
786
792
}
787
793
case PARAM =>
788
794
val tpt = readTpt()(localCtx)
789
- if (noRhs (end)) {
795
+ if (nothingButMods (end)) {
790
796
sym.info = tpt.tpe
791
797
ValDef (tpt)
792
798
}
0 commit comments