@@ -12,12 +12,12 @@ import SymDenotations._
1212import typer .FrontEnd
1313import Phases .Phase
1414import util ._
15- import reporting .Reporter
1615import Decorators ._
16+ import dotty .tools .dotc .ast .tpd
17+ import dotty .tools .dotc .core ._
18+ import dotty .tools .dotc .core .Names ._
19+ import dotty .tools .dotc .core .NameOps ._
1720import dotty .tools .dotc .transform .Pickler
18- import tasty .DottyUnpickler
19- import ast .tpd ._
20- import NameKinds .QualifiedName
2121
2222/** Compiler for TASTY files.
2323 * Usage:
@@ -65,31 +65,44 @@ object FromTasty extends Driver {
6565 override def isTyper = false
6666
6767 override def runOn (units : List [CompilationUnit ])(implicit ctx : Context ): List [CompilationUnit ] =
68- units.map (readTASTY)
68+ units.flatMap (readTASTY)
6969
70- def readTASTY (unit : CompilationUnit )(implicit ctx : Context ): CompilationUnit = unit match {
70+ def readTASTY (unit : CompilationUnit )(implicit ctx : Context ): List [ CompilationUnit ] = unit match {
7171 case unit : TASTYCompilationUnit =>
72+ assert(ctx.settings.YretainTrees .value)
7273 val className = unit.className.toTypeName
73- val clsd = ctx.base.staticRef(className)
74- def cannotUnpickle (reason : String ) = {
75- ctx.error(s " class $className cannot be unpickled because $reason" )
76- unit
77- }
78- clsd match {
79- case clsd : ClassDenotation =>
80- clsd.infoOrCompleter match {
81- case info : ClassfileLoader =>
82- info.load(clsd)
83- val unpickled = clsd.symbol.asClass.tree
84- if (unpickled != null ) CompilationUnit .mkCompilationUnit(clsd, unpickled, forceTrees = true )
85- else cannotUnpickle(s " its class file ${info.classfile} does not have a TASTY attribute " )
86- case info =>
87- cannotUnpickle(s " its info of type ${info.getClass} is not a ClassfileLoader " )
88- }
89- case _ =>
90- ctx.error(s " class not found: $className" )
91- unit
74+ val compilationUnits = List (tree(className), tree(className.moduleClassName)).flatMap {
75+ case Some ((clsd, unpickled)) if ! unpickled.isEmpty =>
76+ List (CompilationUnit .mkCompilationUnit(clsd, unpickled, forceTrees = true ))
77+ case _ => Nil
9278 }
79+ compilationUnits
80+ }
81+
82+ private def tree (className : TypeName )(implicit ctx : Context ): Option [(ClassDenotation , tpd.Tree )] = {
83+ val clsd = ctx.base.staticRef(className)
84+ ctx.base.staticRef(className) match {
85+ case clsd : ClassDenotation =>
86+ def cannotUnpickle (reason : String ) =
87+ ctx.error(s " class $className cannot be unpickled because $reason" )
88+ def tryToLoad = clsd.infoOrCompleter match {
89+ case info : ClassfileLoader =>
90+ info.load(clsd)
91+ Option (clsd.symbol.asClass.tree).orElse {
92+ cannotUnpickle(s " its class file ${info.classfile} does not have a TASTY attribute " )
93+ None
94+ }
95+
96+ case info =>
97+ cannotUnpickle(s " its info of type ${info.getClass} is not a ClassfileLoader " )
98+ None
99+ }
100+ Option (clsd.symbol.asClass.tree).orElse(tryToLoad).map(tree => (clsd, tree))
101+
102+ case _ =>
103+ ctx.error(s " class not found: $className" )
104+ None
105+ }
93106 }
94107 }
95108}
0 commit comments