@@ -12,12 +12,12 @@ import SymDenotations._
12
12
import typer .FrontEnd
13
13
import Phases .Phase
14
14
import util ._
15
- import reporting .Reporter
16
15
import 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 ._
17
20
import dotty .tools .dotc .transform .Pickler
18
- import tasty .DottyUnpickler
19
- import ast .tpd ._
20
- import NameKinds .QualifiedName
21
21
22
22
/** Compiler for TASTY files.
23
23
* Usage:
@@ -65,31 +65,44 @@ object FromTasty extends Driver {
65
65
override def isTyper = false
66
66
67
67
override def runOn (units : List [CompilationUnit ])(implicit ctx : Context ): List [CompilationUnit ] =
68
- units.map (readTASTY)
68
+ units.flatMap (readTASTY)
69
69
70
- def readTASTY (unit : CompilationUnit )(implicit ctx : Context ): CompilationUnit = unit match {
70
+ def readTASTY (unit : CompilationUnit )(implicit ctx : Context ): List [ CompilationUnit ] = unit match {
71
71
case unit : TASTYCompilationUnit =>
72
+ assert(ctx.settings.YretainTrees .value)
72
73
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
92
78
}
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
+ }
93
106
}
94
107
}
95
108
}
0 commit comments