@@ -23,41 +23,50 @@ class DottyTest {
23
23
import base .settings ._
24
24
val ctx = base.initialCtx.fresh
25
25
.withSetting(verbose, true )
26
- // .withSetting(debug, true)
27
- // .withSetting(debugTrace, true)
28
- // .withSetting(prompt, true)
26
+ // .withSetting(debug, true)
27
+ // .withSetting(debugTrace, true)
28
+ // .withSetting(prompt, true)
29
29
.withSetting(Ylogcp , true )
30
30
.withSetting(printtypes, true )
31
31
.withSetting(pageWidth, 90 )
32
32
.withSetting(log, List (" <some" ))
33
- // .withTyperState(new TyperState(new ConsoleReporter()(base.initialCtx)))
33
+ // .withTyperState(new TyperState(new ConsoleReporter()(base.initialCtx)))
34
34
35
- // .withSetting(uniqid, true)
35
+ // .withSetting(uniqid, true)
36
36
println(ctx.settings)
37
37
base.definitions.init(ctx)
38
38
ctx
39
39
}
40
40
41
- def checkCompile (checkAfterPhase : String , source: String )(assertion: tpd.Tree => Unit ): Unit = {
42
- val c = new Compiler {
43
- override def phases = {
44
- val allPhases = super .phases
45
- val targetPhase = allPhases.find{p=> p.name == checkAfterPhase}
46
- assert(targetPhase isDefined)
47
- val phasesBefore = allPhases.takeWhile(x=> ! (x eq targetPhase.get))
48
-
49
- val checker = new Phase {
50
- def name = " assertionChecker"
51
- override def run (implicit ctx : Context ): Unit = assertion(ctx.compilationUnit.tpdTree)
52
- }
53
- phasesBefore::: List (targetPhase.get, checker)
41
+ private def compilerWithChecker (phase : String )(assertion: (tpd.Tree , Context ) => Unit ) = new Compiler {
42
+ override def phases = {
43
+ val allPhases = super .phases
44
+ val targetPhase = allPhases.find{p=> p.name == phase}
45
+ assert(targetPhase isDefined)
46
+ val phasesBefore = allPhases.takeWhile(x=> ! (x eq targetPhase.get))
47
+
48
+ val checker = new Phase {
49
+ def name = " assertionChecker"
50
+ override def run (implicit ctx : Context ): Unit = assertion(ctx.compilationUnit.tpdTree, ctx)
54
51
}
52
+ phasesBefore::: List (targetPhase.get, checker)
55
53
}
54
+ }
55
+
56
+ def checkCompile (checkAfterPhase : String , source: String )(assertion: (tpd.Tree , Context ) => Unit ): Unit = {
57
+ val c = compilerWithChecker(checkAfterPhase)(assertion)
56
58
c.rootContext(ctx)
57
59
val run = c.newRun
58
60
run.compile(source)
59
61
}
60
62
63
+ def checkCompile (checkAfterPhase : String , sources: List [String ])(assertion: (tpd.Tree , Context ) => Unit ): Unit = {
64
+ val c = compilerWithChecker(checkAfterPhase)(assertion)
65
+ c.rootContext(ctx)
66
+ val run = c.newRun
67
+ run.compile(sources)
68
+ }
69
+
61
70
def methType (names : String * )(paramTypes : Type * )(resultType : Type = defn.UnitType ) =
62
71
MethodType (names.toList map (_.toTermName), paramTypes.toList, resultType)
63
72
}
0 commit comments