@@ -9,44 +9,40 @@ import TastyFormat._, NameTags._, TastyTagOps._, TastyRefs._
99
1010object TastyUnpickler {
1111 def unpickleClass (in : TastyReader , clazz : ClassInfo , path : String ): Unit = {
12- // val doPrint = false
13- // val doPrint = path.contains("v1") && !path.contains("experimental2 .tasty")
12+ val doPrint = false
13+ // val doPrint = path.contains("v1") && !path.contains("exclude .tasty")
1414 // if (doPrint) TastyPrinter.printClassNames(in.fork, path)
15- // if (doPrint) TastyPrinter.printPickle(in.fork, path)
16- unpickle(in, clazz, path)
17- }
15+ if (doPrint) TastyPrinter .printPickle(in.fork, path)
1816
19- def unpickle (in : TastyReader , clazz : ClassInfo , path : String ): Unit = {
2017 readHeader(in)
2118 val names = readNames(in)
2219 val tree = unpickleTree(getTreeReader(in, names), names)
2320
24- object trav extends Traverser {
21+ copyAnnotations(tree, clazz)
22+ }
23+
24+ def copyAnnotations (tree : Tree , clazz : ClassInfo ): Unit = {
25+ new Traverser {
2526 var pkgNames = List .empty[Name ]
2627 var clsNames = List .empty[Name ]
2728
28- def dropHead [A ](xs : List [A ], head : A ) = xs match {
29- case `head` :: ys => ys
30- case x :: _ => throw new AssertionError (s " assertion failed: Expected head= $head but it was $x" )
31- case _ => throw new AssertionError (s " assertion failed: Expected head= $head but list was empty " )
32- }
33-
3429 override def traversePkg (pkg : Pkg ): Unit = {
35- val pkgName = pkg.path match {
36- case TypeRefPkg (fullyQual) => fullyQual
37- case p : UnknownPath => SimpleName (p.show)
38- }
39- pkgNames ::= pkgName
30+ pkgNames ::= getPkgName(pkg)
4031 super .traversePkg(pkg)
41- pkgNames = dropHead( pkgNames, pkgName)
32+ pkgNames = pkgNames.tail
4233 }
4334
4435 override def traverseClsDef (clsDef : ClsDef ): Unit = {
4536 forEachClass(clsDef, pkgNames, clsNames)
4637 clsNames ::= clsDef.name
4738 super .traverseClsDef(clsDef)
48- clsNames = dropHead( clsNames, clsDef.name)
39+ clsNames = clsNames.tail
4940 }
41+ }.traverse(tree)
42+
43+ def getPkgName (pkg : Pkg ) = pkg.path match {
44+ case TypeRefPkg (fullyQual) => fullyQual
45+ case p : UnknownPath => SimpleName (p.show)
5046 }
5147
5248 def forEachClass (clsDef : ClsDef , pkgNames : List [Name ], clsNames : List [Name ]): Unit = {
@@ -55,22 +51,16 @@ object TastyUnpickler {
5551 val clsName = (clsDef.name :: clsNames).reverseIterator.mkString(" $" )
5652 val cls = clazz.owner.classes.getOrElse(clsName, NoClass )
5753 if (cls != NoClass ) {
58- cls._experimental |= clsDef.annots.exists(_.tycon.toString == " scala.annotation.experimental" )
59- cls._experimental |= clsDef.annots.exists(_.tycon.toString == " scala.annotation.experimental2" )
54+ cls._annotations ++= clsDef.annots.map(annot => AnnotInfo (annot.tycon.toString))
6055
6156 for (defDef <- clsDef.template.meths) {
62- val isExperimental =
63- defDef.annots.exists(_.tycon.toString == " scala.annotation.experimental" ) ||
64- defDef.annots.exists(_.tycon.toString == " scala.annotation.experimental2" )
65- if (isExperimental)
66- for (meth <- cls.lookupClassMethods(new MethodInfo (cls, defDef.name.source, 0 , " ()V" )))
67- meth._experimental = true
57+ val annots = defDef.annots.map(annot => AnnotInfo (annot.tycon.toString))
58+ for (meth <- cls.lookupClassMethods(new MethodInfo (cls, defDef.name.source, 0 , " ()V" )))
59+ meth._annotations ++= annots
6860 }
6961 }
7062 }
7163 }
72-
73- trav.traverse(tree)
7464 }
7565
7666 def unpickleTree (in : TastyReader , names : Names ): Tree = {
@@ -219,7 +209,7 @@ object TastyUnpickler {
219209
220210 sealed trait Path extends Type
221211 final case class UnknownPath (tag : Int ) extends Path { def show = s " UnknownPath( ${astTagToString(tag)}) " }
222- final case class TypeRefPkg (fullyQual : Name ) extends Path { def show = s " $fullyQual" }
212+ final case class TypeRefPkg (fullyQual : Name ) extends Path { def show = s " $fullyQual" }
223213
224214 final case class Annot (tycon : Type , fullAnnotation : Tree ) extends Tree { def show = s " @ $tycon" }
225215
@@ -320,16 +310,16 @@ object TastyUnpickler {
320310
321311 val name = tag match {
322312 case UTF8 => val start = currentAddr; goto(end); SimpleName (new String (bytes.slice(start.index, end.index), " UTF-8" ))
323- case QUALIFIED => QualifiedName (readName(), PathSep , readName().asSimpleName)
324- case EXPANDED => QualifiedName (readName(), ExpandedSep , readName().asSimpleName)
325- case EXPANDPREFIX => QualifiedName (readName(), ExpandPrefixSep , readName().asSimpleName)
313+ case QUALIFIED => QualifiedName (readName(), Name . PathSep , readName().asSimpleName)
314+ case EXPANDED => QualifiedName (readName(), Name . ExpandedSep , readName().asSimpleName)
315+ case EXPANDPREFIX => QualifiedName (readName(), Name . ExpandPrefixSep , readName().asSimpleName)
326316
327- case UNIQUE => UniqueName (sep = readName().asSimpleName, num = readNat(), qual = ifBefore(end)(readName(), Empty ))
317+ case UNIQUE => UniqueName (sep = readName().asSimpleName, num = readNat(), qual = ifBefore(end)(readName(), Name . Empty ))
328318 case DEFAULTGETTER => DefaultName (readName(), readNat())
329319
330- case SUPERACCESSOR => PrefixName (SuperPrefix , readName())
331- case INLINEACCESSOR => PrefixName (InlinePrefix , readName())
332- case BODYRETAINER => SuffixName (readName(), BodyRetainerSuffix )
320+ case SUPERACCESSOR => PrefixName ( Name . SuperPrefix , readName())
321+ case INLINEACCESSOR => PrefixName (Name . InlinePrefix , readName())
322+ case BODYRETAINER => SuffixName (readName(), Name . BodyRetainerSuffix )
333323 case OBJECTCLASS => ObjectName (readName())
334324
335325 case SIGNED => val name = readName(); readSignedRest(name, name)
@@ -375,14 +365,16 @@ object TastyUnpickler {
375365
376366 final case class SignedName (qual : Name , sig : MethodSignature [ErasedTypeRef ], target : Name ) extends Name
377367
378- val Empty = SimpleName (" " )
379- val PathSep = SimpleName (" ." )
380- val ExpandedSep = SimpleName (" $$" )
381- val ExpandPrefixSep = SimpleName (" $" )
382- val InlinePrefix = SimpleName (" inline$" )
383- val SuperPrefix = SimpleName (" super$" )
384- val BodyRetainerSuffix = SimpleName (" $retainedBody" )
385- val Constructor = SimpleName (" <init>" )
368+ object Name {
369+ val Empty = SimpleName (" " )
370+ val PathSep = SimpleName (" ." )
371+ val ExpandedSep = SimpleName (" $$" )
372+ val ExpandPrefixSep = SimpleName (" $" )
373+ val InlinePrefix = SimpleName (" inline$" )
374+ val SuperPrefix = SimpleName (" super$" )
375+ val BodyRetainerSuffix = SimpleName (" $retainedBody" )
376+ val Constructor = SimpleName (" <init>" )
377+ }
386378
387379 object nme {
388380 def NoSymbol = SimpleName (" NoSymbol" )
@@ -416,18 +408,18 @@ object TastyUnpickler {
416408
417409 def apply (tname : Name ): ErasedTypeRef = {
418410 def name (qual : Name , tname : SimpleName , isModule : Boolean ) = {
419- val qualified = if (qual == Empty ) tname else QualifiedName (qual, PathSep , tname)
411+ val qualified = if (qual == Name . Empty ) tname else QualifiedName (qual, Name . PathSep , tname)
420412 if (isModule) ObjectName (qualified) else qualified
421413 }
422414 def specialised (qual : Name , terminal : String , isModule : Boolean , arrayDims : Int = 0 ): ErasedTypeRef = terminal match {
423415 case InnerRegex (inner) => specialised(qual, inner, isModule, arrayDims + 1 )
424416 case clazz => ErasedTypeRef (name(qual, SimpleName (clazz), isModule).toTypeName, arrayDims)
425417 }
426418 def transform (name : Name , isModule : Boolean = false ): ErasedTypeRef = name match {
427- case ObjectName (classKind) => transform(classKind, isModule = true )
428- case SimpleName (raw) => specialised(Empty , raw, isModule) // unqualified in the <empty> package
429- case QualifiedName (path, PathSep , sel) => specialised(path, sel.raw, isModule)
430- case _ => throw new AssertionError (s " Unexpected erased type ref ${name.debug}" )
419+ case ObjectName (classKind) => transform(classKind, isModule = true )
420+ case SimpleName (raw) => specialised(Name . Empty , raw, isModule) // unqualified in the <empty> package
421+ case QualifiedName (path, Name . PathSep , sel) => specialised(path, sel.raw, isModule)
422+ case _ => throw new AssertionError (s " Unexpected erased type ref ${name.debug}" )
431423 }
432424 transform(tname.toTermName)
433425 }
@@ -447,7 +439,7 @@ object TastyUnpickler {
447439
448440 object SourceEncoder extends StringBuilderEncoder {
449441 def traverse (sb : StringBuilder , name : Name ): StringBuilder = name match {
450- case Constructor => sb
442+ case Name . Constructor => sb
451443 case SimpleName (raw) => sb ++= raw
452444 case ObjectName (base) => traverse(sb, base)
453445 case TypeName (base) => traverse(sb, base)
0 commit comments