@@ -228,6 +228,39 @@ class TreeUnpickler(reader: TastyReader,
228228 createSymbol()
229229 }
230230
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+
231264 /** Read a type */
232265 def readType ()(implicit ctx : Context ): Type = {
233266 val start = currentAddr
@@ -313,10 +346,6 @@ class TreeUnpickler(reader: TastyReader,
313346 readTypeRef() match {
314347 case binder : LambdaType => binder.paramRefs(readNat())
315348 }
316- case CLASSconst =>
317- ConstantType (Constant (readType()))
318- case ENUMconst =>
319- ConstantType (Constant (readTermRef().termSymbol))
320349 case HOLE =>
321350 readHole(end, isType = true ).tpe
322351 }
@@ -356,38 +385,10 @@ class TreeUnpickler(reader: TastyReader,
356385 case SHAREDtype =>
357386 val ref = readAddr()
358387 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)))
389388 case BYNAMEtype =>
390389 ExprType (readType())
390+ case _ =>
391+ ConstantType (readConstant(tag))
391392 }
392393
393394 if (tag < firstLengthTreeTag) readSimpleType() else readLengthType()
@@ -420,7 +421,7 @@ class TreeUnpickler(reader: TastyReader,
420421
421422// ------ Reading definitions -----------------------------------------------------
422423
423- private def noRhs (end : Addr ): Boolean =
424+ private def nothingButMods (end : Addr ): Boolean =
424425 currentAddr == end || isModifierTag(nextByte)
425426
426427 private def localContext (owner : Symbol )(implicit ctx : Context ) =
@@ -510,7 +511,7 @@ class TreeUnpickler(reader: TastyReader,
510511 val templateStart = currentAddr
511512 skipTree() // tpt
512513 val rhsStart = currentAddr
513- val rhsIsEmpty = noRhs (end)
514+ val rhsIsEmpty = nothingButMods (end)
514515 if (! rhsIsEmpty) skipTree()
515516 val (givenFlags, annots, privateWithin) = readModifiers(end)
516517 pickling.println(i " creating symbol $name at $start with flags $givenFlags" )
@@ -562,7 +563,7 @@ class TreeUnpickler(reader: TastyReader,
562563 */
563564 def readModifiers (end : Addr )(implicit ctx : Context ): (FlagSet , List [Annotation ], Symbol ) = {
564565 var flags : FlagSet = EmptyFlags
565- var annots = new mutable. ListBuffer [Annotation ]
566+ var annots : List [Annotation ] = Nil
566567 var privateWithin : Symbol = NoSymbol
567568 while (currentAddr.index != end.index) {
568569 def addFlag (flag : FlagSet ) = {
@@ -613,18 +614,23 @@ class TreeUnpickler(reader: TastyReader,
613614 addFlag(Protected )
614615 privateWithin = readType().typeSymbol
615616 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
623618 case tag =>
624619 assert(false , s " illegal modifier tag $tag at $currentAddr, end = $end" )
625620 }
626621 }
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)
628634 }
629635
630636 /** Create symbols for the definitions in the statement sequence between
@@ -721,7 +727,7 @@ class TreeUnpickler(reader: TastyReader,
721727 val localCtx = localContext(sym)
722728
723729 def readRhs (implicit ctx : Context ) =
724- if (noRhs (end)) EmptyTree
730+ if (nothingButMods (end)) EmptyTree
725731 else readLater(end, rdr => ctx => rdr.readTerm()(ctx.retractMode(Mode .InSuperCall )))
726732
727733 def ValDef (tpt : Tree ) =
@@ -786,7 +792,7 @@ class TreeUnpickler(reader: TastyReader,
786792 }
787793 case PARAM =>
788794 val tpt = readTpt()(localCtx)
789- if (noRhs (end)) {
795+ if (nothingButMods (end)) {
790796 sym.info = tpt.tpe
791797 ValDef (tpt)
792798 }
0 commit comments