@@ -6,6 +6,9 @@ import Contexts._
6
6
import Periods ._
7
7
import Symbols ._
8
8
import Phases ._
9
+ import Types ._
10
+ import Scopes ._
11
+ import typer .{FrontEnd , Typer , ImportInfo , RefChecks }
9
12
import Decorators ._
10
13
import dotty .tools .dotc .transform .TreeTransforms .TreeTransformer
11
14
import io .PlainFile
@@ -22,12 +25,41 @@ import dotty.tools.io.VirtualFile
22
25
import scala .util .control .NonFatal
23
26
24
27
/** A compiler run. Exports various methods to compile source files */
25
- class Run (comp : Compiler )(implicit ctx : Context ) {
26
-
27
- assert(ctx.runId <= Periods .MaxPossibleRunId )
28
+ class Run (comp : Compiler , ictx : Context ) {
28
29
29
30
var units : List [CompilationUnit ] = _
30
31
32
+ /** Produces the following contexts, from outermost to innermost
33
+ *
34
+ * bootStrap: A context with next available runId and a scope consisting of
35
+ * the RootPackage _root_
36
+ * start A context with RootClass as owner and the necessary initializations
37
+ * for type checking.
38
+ * imports For each element of RootImports, an import context
39
+ */
40
+ protected [this ] def rootContext (implicit ctx : Context ): Context = {
41
+ ctx.initialize()(ctx)
42
+ ctx.setPhasePlan(comp.phases)
43
+ val rootScope = new MutableScope
44
+ val bootstrap = ctx.fresh
45
+ .setPeriod(Period (comp.nextRunId, FirstPhaseId ))
46
+ .setScope(rootScope)
47
+ rootScope.enter(ctx.definitions.RootPackage )(bootstrap)
48
+ val start = bootstrap.fresh
49
+ .setOwner(defn.RootClass )
50
+ .setTyper(new Typer )
51
+ .addMode(Mode .ImplicitsEnabled )
52
+ .setTyperState(new MutableTyperState (ctx.typerState, ctx.typerState.reporter, isCommittable = true ))
53
+ .setFreshNames(new FreshNameCreator .Default )
54
+ ctx.initialize()(start) // re-initialize the base context with start
55
+ def addImport (ctx : Context , refFn : () => TermRef ) =
56
+ ctx.fresh.setImportInfo(ImportInfo .rootImport(refFn)(ctx))
57
+ (start.setRunInfo(new RunInfo (start)) /: defn.RootImportFns )(addImport)
58
+ }
59
+
60
+ protected [this ] implicit val ctx : Context = rootContext(ictx)
61
+ assert(ctx.runId <= Periods .MaxPossibleRunId )
62
+
31
63
def getSource (fileName : String ): SourceFile = {
32
64
val f = new PlainFile (fileName)
33
65
if (f.isDirectory) {
@@ -63,7 +95,17 @@ class Run(comp: Compiler)(implicit ctx: Context) {
63
95
compileUnits()
64
96
}
65
97
66
- protected def compileUnits () = Stats .monitorHeartBeat {
98
+ def compileUnits (us : List [CompilationUnit ]): Unit = {
99
+ units = us
100
+ compileUnits()
101
+ }
102
+
103
+ def compileUnits (us : List [CompilationUnit ], ctx : Context ): Unit = {
104
+ units = us
105
+ compileUnits()(ctx)
106
+ }
107
+
108
+ protected def compileUnits ()(implicit ctx : Context ) = Stats .monitorHeartBeat {
67
109
ctx.checkSingleThreaded()
68
110
69
111
// If testing pickler, make sure to stop after pickling phase:
@@ -76,7 +118,7 @@ class Run(comp: Compiler)(implicit ctx: Context) {
76
118
ctx.usePhases(phases)
77
119
var lastPrintedTree : PrintedTree = NoPrintedTree
78
120
for (phase <- ctx.allPhases)
79
- if (! ctx.reporter.hasErrors ) {
121
+ if (phase.isRunnable ) {
80
122
val start = System .currentTimeMillis
81
123
units = phase.runOn(units)
82
124
if (ctx.settings.Xprint .value.containsPhase(phase)) {
0 commit comments