2
2
* Copyright 2005-2015 LAMP/EPFL
3
3
* @author Martin Odersky
4
4
*/
5
- package dotty .tools
6
- package dotc
5
+ package dotty .tools .dotc
7
6
8
- import core ._
9
- import Contexts ._
10
- import Symbols ._
11
- import SymDenotations ._
12
- import typer .FrontEnd
13
- import Phases .Phase
14
- import util ._
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 ._
20
- import dotty .tools .dotc .transform .Pickler
7
+ import dotty .tools .dotc .core .Contexts ._
8
+ import dotty .tools .dotc .fromtasty .TASTYCompiler
21
9
22
10
/** Compiler for TASTY files.
23
11
* Usage:
@@ -32,83 +20,4 @@ import dotty.tools.dotc.transform.Pickler
32
20
*/
33
21
object FromTasty extends Driver {
34
22
override def newCompiler (implicit ctx : Context ): Compiler = new TASTYCompiler
35
-
36
- class TASTYCompiler extends Compiler {
37
-
38
- override def phases : List [List [Phase ]] = {
39
- val backendPhases = super .phases.dropWhile {
40
- case List (_ : Pickler ) => false
41
- case _ => true
42
- }.tail
43
- List (new ReadTastyTreesFromClasses ) :: backendPhases
44
- }
45
-
46
- override def newRun (implicit ctx : Context ): Run = {
47
- reset()
48
- new TASTYRun (this , ctx)
49
- }
50
- }
51
-
52
- class TASTYRun (comp : Compiler , ictx : Context ) extends Run (comp, ictx) {
53
- override def compile (classNames : List [String ]) = {
54
- units = classNames.map(new TASTYCompilationUnit (_))
55
- compileUnits()
56
- }
57
- }
58
-
59
- class TASTYCompilationUnit (val className : String ) extends CompilationUnit (NoSource ) {
60
- override def toString = s " class file $className"
61
- }
62
-
63
- class ReadTastyTreesFromClasses extends FrontEnd {
64
-
65
- override def isTyper = false
66
-
67
- override def runOn (units : List [CompilationUnit ])(implicit ctx : Context ): List [CompilationUnit ] =
68
- units.flatMap(readTASTY)
69
-
70
- def readTASTY (unit : CompilationUnit )(implicit ctx : Context ): Option [CompilationUnit ] = unit match {
71
- case unit : TASTYCompilationUnit =>
72
- assert(ctx.settings.YretainTrees .value)
73
- val className = unit.className.toTypeName
74
- def compilationUnit (className : TypeName ): Option [CompilationUnit ] = {
75
- tree(className).flatMap { case (clsd, unpickled) =>
76
- if (unpickled.isEmpty) None
77
- else Some (CompilationUnit .mkCompilationUnit(clsd, unpickled, forceTrees = true ))
78
- }
79
- }
80
- // The TASTY section in a/b/C.class may either contain a class a.b.C, an object a.b.C, or both.
81
- // We first try to load the class and fallback to loading the object if the class doesn't exist.
82
- // Note that if both the class and the object are present, then loading the class will also load
83
- // the object, this is why we use orElse here, otherwise we could load the object twice and
84
- // create ambiguities!
85
- compilationUnit(className).orElse(compilationUnit(className.moduleClassName))
86
- }
87
-
88
- private def tree (className : TypeName )(implicit ctx : Context ): Option [(ClassDenotation , tpd.Tree )] = {
89
- val clsd = ctx.base.staticRef(className)
90
- ctx.base.staticRef(className) match {
91
- case clsd : ClassDenotation =>
92
- def cannotUnpickle (reason : String ) =
93
- ctx.error(s " class $className cannot be unpickled because $reason" )
94
- def tryToLoad = clsd.infoOrCompleter match {
95
- case info : ClassfileLoader =>
96
- info.load(clsd)
97
- Option (clsd.symbol.asClass.tree).orElse {
98
- cannotUnpickle(s " its class file ${info.classfile} does not have a TASTY attribute " )
99
- None
100
- }
101
-
102
- case info =>
103
- cannotUnpickle(s " its info of type ${info.getClass} is not a ClassfileLoader " )
104
- None
105
- }
106
- Option (clsd.symbol.asClass.tree).orElse(tryToLoad).map(tree => (clsd, tree))
107
-
108
- case _ =>
109
- ctx.error(s " class not found: $className" )
110
- None
111
- }
112
- }
113
- }
114
23
}
0 commit comments