@@ -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,36 +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
72
assert(ctx.settings.YretainTrees .value)
73
73
val className = unit.className.toTypeName
74
- ctx.base.staticRef(className) match {
75
- case clsd : ClassDenotation =>
76
- def cannotUnpickle (reason : String ) =
77
- ctx.error(s " class $className cannot be unpickled because $reason" )
78
- def tryToLoad = clsd.infoOrCompleter match {
79
- case info : ClassfileLoader =>
80
- info.load(clsd)
81
- Option (clsd.symbol.asClass.tree).orElse {
82
- cannotUnpickle(s " its class file ${info.classfile} does not have a TASTY attribute " )
83
- None
84
- }
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
78
+ }
79
+ compilationUnits
80
+ }
85
81
86
- case info =>
87
- cannotUnpickle(s " its info of type ${info.getClass} is not a ClassfileLoader " )
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 " )
88
93
None
89
- }
90
- Option (clsd.symbol.asClass.tree).orElse(tryToLoad)
91
- .map(unpickled => CompilationUnit .mkCompilationUnit(clsd, unpickled, forceTrees = true ))
92
- .getOrElse(unit)
94
+ }
93
95
94
- case _ =>
95
- ctx.error(s " class not found: $className" )
96
- unit
97
- }
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
+ }
98
106
}
99
107
}
100
108
}
0 commit comments